diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..41f2255 --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +ColumnLimit: 140 +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 2 + - Regex: '^"ext/.*\.h"' + Priority: 3 + - Regex: '^".*"' + Priority: 4 +SortIncludes: CaseSensitive \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d23721c --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# Ignore MacOS generated directory +/**/.DS_Store + +# Ignore PlatformIO build directory +.pio + +# Ignore CLion artifacts +.idea +cmake-build-* +CMakeListsPrivate.txt + +# Ignore Doxygen output directory +docs + +# Ignore compiled and linked binaries +*.o +*.a +*.so +*.dll +*.exe +*.out + +# Ignore backup files created by text editors +*~ +*.bak +*.swp +*.swo + +# Ignore macOS system files +.DS_Store +._* + +# Ignore other common temp or cache files +*.log +*.tmp +*.pid +*.pyc +*.lo +*.la +*-stamp diff --git a/README.md b/README.md new file mode 100644 index 0000000..8729061 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# AhmsVille Dial 2 sensor adapter interfaces +This package contains the sensor adapter interfaces necessary for AhmsVille Dial 2 to work. + +The intention of this library is to provide abstract sensor adapter interfaces to decouple sensor-related operations +from the application firmware in order to be able to test the firmware properly. + +This library **is not allowed** to include **any** `Arduino` dependencies. \ No newline at end of file diff --git a/library.json b/library.json new file mode 100644 index 0000000..46002a1 --- /dev/null +++ b/library.json @@ -0,0 +1,15 @@ +{ + "name": "Dial2AbstractSensors", + "keywords": "sensors, abstract, interfaces", + "description": "A simple library containing abstract interfaces for sensor adapters for the AhmsVille Dial 2", + "version": "1.00.0", + "authors": { + "name": "Igor Voronin", + "url": "https://github.com/divStar" + }, + "frameworks": "*", + "platforms": "*", + "build": { + "libArchive": false + } +} diff --git a/src/IAllSensors.h b/src/IAllSensors.h new file mode 100644 index 0000000..029182f --- /dev/null +++ b/src/IAllSensors.h @@ -0,0 +1,48 @@ +#ifndef DIALER_IALLSENSORS_H +#define DIALER_IALLSENSORS_H + +#include "ICapacitiveSensorAdapter.h" +#include "IHapticSensorAdapter.h" +#include "IMacroKeys.h" +#include "IRotaryEncoderAdapter.h" +#include "ISpaceNavigatorSensorAdapter.h" + +class IAllSensors { +public: + /** + * @brief Creates the sensor adapters depending on the concrete implementation. + */ + virtual void createSensorAdapters() = 0; + + /** + * @return (IMacroKeys) returns the macro keys sensor adapter + */ + virtual IMacroKeys &getMacroKeys() = 0; + + /** + * @return (IRotaryEncoderAdapter) returns the upper knob sensor adapter + */ + virtual IRotaryEncoderAdapter &getUpperKnobSensor() = 0; + + /** + * @return (IRotaryEncoderAdapter) returns the lower knob sensor adapter + */ + virtual IRotaryEncoderAdapter &getLowerKnobSensor() = 0; + + /** + * @return (IHapticSensorAdapter) returns the haptic sensor adapter + */ + virtual IHapticSensorAdapter &getHapticSensor() = 0; + + /** + * @return (ICapacitiveSensorAdapter) returns the capacitive sensor adapter + */ + virtual ICapacitiveSensorAdapter &getCapacitiveSensor() = 0; + + /** + * @return (ISpaceNavigatorSensorAdapter) returns the space navigator sensor adapter + */ + virtual ISpaceNavigatorSensorAdapter &getSpaceNavigatorSensors() = 0; +}; + +#endif // DIALER_IALLSENSORS_H diff --git a/src/ICapacitiveSensorAdapter.h b/src/ICapacitiveSensorAdapter.h new file mode 100644 index 0000000..27ab36d --- /dev/null +++ b/src/ICapacitiveSensorAdapter.h @@ -0,0 +1,37 @@ +#ifndef DIALER_ICAPACITIVESENSORADAPTER_H +#define DIALER_ICAPACITIVESENSORADAPTER_H + +#include + +/** + * @class ICapacitiveSensorAdapter + * @brief Interface to decouple the actual capacitive sensor from the task + * processing it. + * + * This interface decouples the capacitive sensor from the task, that uses it, + * and allows for proper testing. + * + * @author Igor Voronin + * @date 06.08.2023 + */ +class ICapacitiveSensorAdapter { +public: + virtual ~ICapacitiveSensorAdapter() = default; + + /** + * @brief Sets the exact same value on the actual sensor class (or mock). + * + * @param millis (unsigned long) milliseconds to reset to + */ + virtual void set_CS_AutocaL_Millis(unsigned long millis) = 0; + + /** + * @brief Retrieves the sensor values, uses the given amount of samples. + * + * @param samples (uint8_t) amount of samples of the sensor value + * @return (long) sensor value + */ + virtual long capacitiveSensor(uint8_t samples) = 0; +}; + +#endif // DIALER_ICAPACITIVESENSORADAPTER_H diff --git a/src/IHapticSensorAdapter.h b/src/IHapticSensorAdapter.h new file mode 100644 index 0000000..22d5eae --- /dev/null +++ b/src/IHapticSensorAdapter.h @@ -0,0 +1,28 @@ +#ifndef DIALER_IHAPTICSENSORADAPTER_H +#define DIALER_IHAPTICSENSORADAPTER_H + +/** + * @class IHapticSensorAdapter + * @brief Interface to decouple the actual haptic sensor from the task + * processing it. + * + * This interface decouples the haptic sensor from the task, that uses it, and + * allows for proper testing. + * + * @author Igor Voronin + * @date 06.08.2023 + */ +class IHapticSensorAdapter { +public: + virtual ~IHapticSensorAdapter() = default; + + /** + * @brief Writes the given strength value to the haptic sensor. + * + * @param strength (uint8_t) strength value for the haptic sensor; 0 to 255 seem + * like sensible values + */ + virtual void writeStrength(uint8_t strength) = 0; +}; + +#endif // DIALER_IHAPTICSENSORADAPTER_H diff --git a/src/IMacroKeys.h b/src/IMacroKeys.h new file mode 100644 index 0000000..2f1d7d3 --- /dev/null +++ b/src/IMacroKeys.h @@ -0,0 +1,22 @@ +#ifndef DIALER_IMACROKEYS_H +#define DIALER_IMACROKEYS_H + +/** + * @class IMacroKeys + * @brief Interface to decouple the actual macro key adapter-interfaces from the task + * processing it. + * + * @author Igor Voronin + * @date 06.08.2023 + */ +class IMacroKeys { +public: + virtual ~IMacroKeys() = default; + + /** + * @brief Initializes the macro keys (or mocks thereof). + */ + virtual void initializeMacroKeys() = 0; +}; + +#endif // DIALER_IMACROKEYS_H diff --git a/src/IRotaryEncoderAdapter.h b/src/IRotaryEncoderAdapter.h new file mode 100644 index 0000000..b82d58e --- /dev/null +++ b/src/IRotaryEncoderAdapter.h @@ -0,0 +1,31 @@ +#ifndef DIALER_IROTARYENCODERADAPTER_H +#define DIALER_IROTARYENCODERADAPTER_H + +/** + * @class IRotaryEncoderAdapter + * @brief Interface to decouple the actual rotary encoder adapter-interfaces from the + * task processing it. + * + * This interface decouples the rotary encoder adapter-interfaces from the task, that uses + * it, and allows for proper testing. + * + * @author Igor Voronin + * @date 06.08.2023 + */ +class IRotaryEncoderAdapter { +public: + virtual ~IRotaryEncoderAdapter() = default; + + /** + * @brief Reads values from the sensor. + */ + virtual void readValues() = 0; + + /** + * @return (float) Gets the positive or negative rotation angle delta between + * the current and the previous angle. + */ + [[nodiscard]] virtual float getRotationAngleDelta() const = 0; +}; + +#endif // DIALER_IROTARYENCODERADAPTER_H diff --git a/src/ISpaceNavigatorSensorAdapter.h b/src/ISpaceNavigatorSensorAdapter.h new file mode 100644 index 0000000..09bafb6 --- /dev/null +++ b/src/ISpaceNavigatorSensorAdapter.h @@ -0,0 +1,59 @@ +#ifndef DIALER_ISPACENAVIGATORSENSORADAPTER_H +#define DIALER_ISPACENAVIGATORSENSORADAPTER_H + +#include + +/** + * @class ISpaceNavigatorSensorAdapter + * @brief Interface to decouple the actual MPU6050 sensor(s) from the task + * processing it. + * + * This interface decouples the MPU6050 sensor(s) from the task, that uses it, + * and allows for proper testing. + * + * @author Igor Voronin + * @date 06.08.2023 + */ +class ISpaceNavigatorSensorAdapter { +public: + virtual ~ISpaceNavigatorSensorAdapter() = default; + + /** + * @brief Sets up the MPU6050 sensor (or a mock thereof). + */ + virtual void setup() = 0; + + /** + * @brief Calibrates the MPU6050 sensor (or a mock thereof). + */ + virtual void calibrate() = 0; + + /** + * @brief Tests the connection to the MPU6050 sensor (or a mock thereof). + */ + virtual bool testConnection() = 0; + + /** + * @brief Retrieves the accelerometer and gyroscope x, y and z values and + * writes them to the supplied variables. + * + * @param ax (int16_t) accelerometer X + * @param ay (int16_t) accelerometer Y + * @param az (int16_t) accelerometer Z + * @param gx (int16_t) gyroscope X + * @param gy (int16_t) gyroscope Y + * @param gz (int16_t) gyroscope Z + */ + virtual void getMotion6(int16_t *ax, int16_t *ay, int16_t *az, int16_t *gx, int16_t *gy, int16_t *gz) = 0; + + /** + * @brief Retrieves whether the DMP initialization has finished successfully + * (dmpInitDone = 0). + * + * @return (bool) true if the DMP initialization finished + * successfully, false otherwise + */ + virtual bool isDmpInitDone() = 0; +}; + +#endif // DIALER_ISPACENAVIGATORSENSORADAPTER_H