Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Steven Strange committed Aug 13, 2023
0 parents commit b758d65
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ColumnLimit: 140
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 1
- Regex: '^<.*\.h>'
Priority: 2
- Regex: '^"ext/.*\.h"'
Priority: 3
- Regex: '^".*"'
Priority: 4
SortIncludes: CaseSensitive
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <u>not</u> allowed** to include **any** `Arduino` dependencies.
15 changes: 15 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -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
}
}
48 changes: 48 additions & 0 deletions src/IAllSensors.h
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions src/ICapacitiveSensorAdapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef DIALER_ICAPACITIVESENSORADAPTER_H
#define DIALER_ICAPACITIVESENSORADAPTER_H

#include <cstdint>

/**
* @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
28 changes: 28 additions & 0 deletions src/IHapticSensorAdapter.h
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions src/IMacroKeys.h
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions src/IRotaryEncoderAdapter.h
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions src/ISpaceNavigatorSensorAdapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef DIALER_ISPACENAVIGATORSENSORADAPTER_H
#define DIALER_ISPACENAVIGATORSENSORADAPTER_H

#include <cstdint>

/**
* @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
* (<code>dmpInitDone = 0</code>).
*
* @return (bool) <code>true</code> if the DMP initialization finished
* successfully, <code>false</code> otherwise
*/
virtual bool isDmpInitDone() = 0;
};

#endif // DIALER_ISPACENAVIGATORSENSORADAPTER_H

0 comments on commit b758d65

Please sign in to comment.