From 433793b7f3be3dfe6569a06ecc38d21e4383df5e Mon Sep 17 00:00:00 2001 From: Leonid Meleshin Date: Thu, 22 Feb 2024 22:04:34 +0400 Subject: [PATCH 1/2] feat: deduct interpolation template --- .../battery/input/battery_sensor.hpp | 5 ++- lib/core/senseshift/core/helpers.hpp | 26 ++++++++------- lib/io/senseshift/input/filter.hpp | 8 ++--- test/test_core_helpers/main.cpp | 29 ++++++++--------- test/test_io_filter/main.cpp | 32 ++++++++++++++++++- 5 files changed, 67 insertions(+), 33 deletions(-) diff --git a/lib/battery/senseshift/battery/input/battery_sensor.hpp b/lib/battery/senseshift/battery/input/battery_sensor.hpp index d0314a03..0ac6a840 100644 --- a/lib/battery/senseshift/battery/input/battery_sensor.hpp +++ b/lib/battery/senseshift/battery/input/battery_sensor.hpp @@ -46,7 +46,10 @@ namespace SenseShift::Battery::Input { protected: [[nodiscard]] auto lookupInterpolateLevel(VoltageType voltage) -> float { - return ::SenseShift::lookup_table_interpolate(*this->lookup_table_, voltage); + return ::SenseShift::lookup_table_interpolate_linear( + *this->lookup_table_, + voltage + ); } private: diff --git a/lib/core/senseshift/core/helpers.hpp b/lib/core/senseshift/core/helpers.hpp index 1d4fb8b1..2ce47264 100644 --- a/lib/core/senseshift/core/helpers.hpp +++ b/lib/core/senseshift/core/helpers.hpp @@ -65,21 +65,25 @@ namespace SenseShift { /// Lookup a value in a table and interpolate between the two closest values. /// - /// \tparam Tp - /// \tparam To - /// \tparam Container + /// \tparam Container The type of the lookup table. + /// \tparam Tp The type of the lookup table keys. + /// \tparam To The type of the lookup table values. /// /// \param lookup_table Lookup table to use in the format of std::map in descending order. /// \param value /// /// \return - template - auto lookup_table_interpolate(Container const& lookup_table, Tp value) -> To + template< + typename Container, + typename Tp = typename Container::key_type, + typename To = typename Container::mapped_type> + [[nodiscard]] constexpr auto lookup_table_interpolate_linear(Container const& lookup_table, Tp value) -> To { - static_assert(std::is_same_v); - static_assert(std::is_same_v); - static_assert(std::is_arithmetic_v, "lookup_table_interpolate only supports arithmetic types"); - static_assert(std::is_arithmetic_v, "lookup_table_interpolate only supports arithmetic types"); + static_assert(std::is_same_v && std::is_same_v); + static_assert( + std::is_arithmetic_v && std::is_arithmetic_v, + "lookup_table_interpolate_linear only supports arithmetic types" + ); // If the value is outside the range of the lookup table, return the closest value if (value <= lookup_table.begin()->first) { @@ -111,7 +115,7 @@ namespace SenseShift { using CallbackType = std::function; /// Add a callback to the list. - void add(std::function&& callback) { this->callbacks_.push_back(std::move(callback)); } + void add(CallbackType&& callback) { this->callbacks_.push_back(std::move(callback)); } /// Call all callbacks in this manager. void call(Ts... args) @@ -126,6 +130,6 @@ namespace SenseShift { void operator()(Ts... args) { call(args...); } private: - std::vector> callbacks_; + std::vector callbacks_; }; } // namespace SenseShift diff --git a/lib/io/senseshift/input/filter.hpp b/lib/io/senseshift/input/filter.hpp index b13bc857..fe534ee4 100644 --- a/lib/io/senseshift/input/filter.hpp +++ b/lib/io/senseshift/input/filter.hpp @@ -265,7 +265,7 @@ namespace SenseShift::Input::Filter { /// Usually used to filter out noise in the joystick. class CenterDeadzoneFilter : public IFilter { public: - explicit CenterDeadzoneFilter(float deadzone, float center = 0.5f) : deadzone_(deadzone), center_(center){}; + explicit CenterDeadzoneFilter(float deadzone, float center = 0.5F) : deadzone_(deadzone), center_(center){}; auto filter(ISimpleSensor* /*sensor*/, float value) -> float override { @@ -284,9 +284,9 @@ namespace SenseShift::Input::Filter { /// /// \tparam Tp Type of the lookup table values. /// \tparam Container Type of the lookup table container. - template + template class LookupTableInterpolationFilter : public IFilter { - static_assert(std::is_same_v); + static_assert(std::is_same_v); static_assert(std::is_arithmetic_v, "LookupTableInterpolationFilter only supports arithmetic types"); public: @@ -294,7 +294,7 @@ namespace SenseShift::Input::Filter { auto filter(ISimpleSensor* /*sensor*/, Tp value) -> Tp override { - return SenseShift::lookup_table_interpolate(this->lookup_table_, value); + return SenseShift::lookup_table_interpolate_linear(this->lookup_table_, value); } private: diff --git a/test/test_core_helpers/main.cpp b/test/test_core_helpers/main.cpp index 5dbfd888..e1bcdd29 100644 --- a/test/test_core_helpers/main.cpp +++ b/test/test_core_helpers/main.cpp @@ -66,9 +66,6 @@ void test_remap_simple_float(void) TEST_ASSERT_EQUAL_FLOAT(255.0f, remap_simple(1.0f, 1.0f, 255.0f)); } -// Wtf? https://stackoverflow.com/questions/4295890 -#define COMMAE , - void test_lookup_table_interpolate_float(void) { const std::map table = { @@ -78,19 +75,19 @@ void test_lookup_table_interpolate_float(void) { 1.0f, 18.0f }, }; - TEST_ASSERT_EQUAL_FLOAT(13.0f, lookup_table_interpolate(table, 0.0f)); - TEST_ASSERT_EQUAL_FLOAT(13.6f, lookup_table_interpolate(table, 0.1f)); - TEST_ASSERT_EQUAL_FLOAT(14.2f, lookup_table_interpolate(table, 0.2f)); - TEST_ASSERT_EQUAL_FLOAT(14.5f, lookup_table_interpolate(table, 0.25f)); - TEST_ASSERT_EQUAL_FLOAT(14.8f, lookup_table_interpolate(table, 0.3f)); - TEST_ASSERT_EQUAL_FLOAT(15.4f, lookup_table_interpolate(table, 0.4f)); - TEST_ASSERT_EQUAL_FLOAT(16.0f, lookup_table_interpolate(table, 0.5f)); - TEST_ASSERT_EQUAL_FLOAT(16.5f, lookup_table_interpolate(table, 0.55f)); - TEST_ASSERT_EQUAL_FLOAT(17.0f, lookup_table_interpolate(table, 0.6f)); - TEST_ASSERT_EQUAL_FLOAT(17.25f, lookup_table_interpolate(table, 0.7f)); - TEST_ASSERT_EQUAL_FLOAT(17.5f, lookup_table_interpolate(table, 0.8f)); - TEST_ASSERT_EQUAL_FLOAT(17.75f, lookup_table_interpolate(table, 0.9f)); - TEST_ASSERT_EQUAL_FLOAT(18.0f, lookup_table_interpolate(table, 1.0f)); + TEST_ASSERT_EQUAL_FLOAT(13.0f, lookup_table_interpolate_linear(table, 0.0f)); + TEST_ASSERT_EQUAL_FLOAT(13.6f, lookup_table_interpolate_linear(table, 0.1f)); + TEST_ASSERT_EQUAL_FLOAT(14.2f, lookup_table_interpolate_linear(table, 0.2f)); + TEST_ASSERT_EQUAL_FLOAT(14.5f, lookup_table_interpolate_linear(table, 0.25f)); + TEST_ASSERT_EQUAL_FLOAT(14.8f, lookup_table_interpolate_linear(table, 0.3f)); + TEST_ASSERT_EQUAL_FLOAT(15.4f, lookup_table_interpolate_linear(table, 0.4f)); + TEST_ASSERT_EQUAL_FLOAT(16.0f, lookup_table_interpolate_linear(table, 0.5f)); + TEST_ASSERT_EQUAL_FLOAT(16.5f, lookup_table_interpolate_linear(table, 0.55f)); + TEST_ASSERT_EQUAL_FLOAT(17.0f, lookup_table_interpolate_linear(table, 0.6f)); + TEST_ASSERT_EQUAL_FLOAT(17.25f, lookup_table_interpolate_linear(table, 0.7f)); + TEST_ASSERT_EQUAL_FLOAT(17.5f, lookup_table_interpolate_linear(table, 0.8f)); + TEST_ASSERT_EQUAL_FLOAT(17.75f, lookup_table_interpolate_linear(table, 0.9f)); + TEST_ASSERT_EQUAL_FLOAT(18.0f, lookup_table_interpolate_linear(table, 1.0f)); } int process(void) diff --git a/test/test_io_filter/main.cpp b/test/test_io_filter/main.cpp index f5002158..dc3e77f2 100644 --- a/test/test_io_filter/main.cpp +++ b/test/test_io_filter/main.cpp @@ -2,6 +2,8 @@ #include #include +#include + #define ASSERT_EQUAL_FLOAT_ROUNDED(expected, actual, precision) \ TEST_ASSERT_EQUAL_FLOAT( \ std::round(expected* std::pow(10, precision)) / std::pow(10, precision), \ @@ -134,6 +136,33 @@ void test_center_deadzone_filter(void) TEST_ASSERT_EQUAL_FLOAT(1.0f, filter->filter(nullptr, 1.0f)); } +void test_lookup_table_interpolate_linear_filter(void) +{ + const std::map lookup_table = { + { 0.0f, 0.0f }, { 1.0f, 3.5f }, { 2.0f, 7.0f }, { 3.0f, 10.5f }, { 4.0f, 14.0f }, { 5.0f, 17.5f }, + }; + IFilter* filter = new LookupTableInterpolationFilter(lookup_table); + + // test existing values + TEST_ASSERT_EQUAL_FLOAT(0.0f, filter->filter(nullptr, 0.0f)); + TEST_ASSERT_EQUAL_FLOAT(3.5f, filter->filter(nullptr, 1.0f)); + TEST_ASSERT_EQUAL_FLOAT(7.0f, filter->filter(nullptr, 2.0f)); + TEST_ASSERT_EQUAL_FLOAT(10.5f, filter->filter(nullptr, 3.0f)); + TEST_ASSERT_EQUAL_FLOAT(14.0f, filter->filter(nullptr, 4.0f)); + TEST_ASSERT_EQUAL_FLOAT(17.5f, filter->filter(nullptr, 5.0f)); + + // test values in between + TEST_ASSERT_EQUAL_FLOAT(1.75f, filter->filter(nullptr, 0.5f)); + TEST_ASSERT_EQUAL_FLOAT(5.25f, filter->filter(nullptr, 1.5f)); + TEST_ASSERT_EQUAL_FLOAT(8.75f, filter->filter(nullptr, 2.5f)); + TEST_ASSERT_EQUAL_FLOAT(12.25f, filter->filter(nullptr, 3.5f)); + TEST_ASSERT_EQUAL_FLOAT(15.75f, filter->filter(nullptr, 4.5f)); + + // test out of range + TEST_ASSERT_EQUAL_FLOAT(0.0f, filter->filter(nullptr, -1.0f)); + TEST_ASSERT_EQUAL_FLOAT(17.5f, filter->filter(nullptr, 6.0f)); +} + int process(void) { UNITY_BEGIN(); @@ -147,6 +176,7 @@ int process(void) RUN_TEST(test_sliding_window_moving_average_filter); RUN_TEST(test_exponential_moving_average_filter); RUN_TEST(test_center_deadzone_filter); + RUN_TEST(test_lookup_table_interpolate_linear_filter); return UNITY_END(); } @@ -169,4 +199,4 @@ int main(int argc, char** argv) return process(); } -#endif \ No newline at end of file +#endif From c7afbe4aad62bf96137e40ae4ba8d0fc5b4e6c75 Mon Sep 17 00:00:00 2001 From: Leonid Meleshin Date: Thu, 22 Feb 2024 22:25:26 +0400 Subject: [PATCH 2/2] chore: shorten project defines prefix --- .github/scripts/get_firmware_name.sh | 4 ++-- .github/workflows/ci.yml | 16 ++++++++-------- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/release.yml | 4 ++-- firmware/mode_configs/bhaptics/tactal.cpp | 6 +++--- firmware/mode_configs/bhaptics/tactglove.cpp | 8 ++++---- firmware/mode_configs/bhaptics/tactosy2.cpp | 6 +++--- firmware/mode_configs/bhaptics/tactosyf.cpp | 6 +++--- firmware/mode_configs/bhaptics/tactosyh.cpp | 6 +++--- firmware/mode_configs/bhaptics/tactsuit_x16.cpp | 6 +++--- .../bhaptics/tactsuit_x16_pca9685.cpp | 6 +++--- firmware/mode_configs/bhaptics/tactsuit_x40.cpp | 6 +++--- firmware/mode_configs/bhaptics/tactvisor.cpp | 6 +++--- include/config/battery.h | 16 ++++++++-------- include/config/bluetooth.h | 4 ++-- ini/bhaptics.ini | 4 ++-- .../senseshift/bh/ble/connection.cpp | 8 ++++---- .../senseshift/bh/ble/connection.hpp | 2 +- platformio.ini | 4 ++-- 19 files changed, 60 insertions(+), 60 deletions(-) diff --git a/.github/scripts/get_firmware_name.sh b/.github/scripts/get_firmware_name.sh index 120fafe3..b759981f 100755 --- a/.github/scripts/get_firmware_name.sh +++ b/.github/scripts/get_firmware_name.sh @@ -8,12 +8,12 @@ getBhapticsName() { echo "::debug::Getting bHaptics name for $target" echo "::debug::Flags are $flags" - if [[ $flags =~ SENSESHIFT_BLE_USE_NIMBLE=true ]]; then + if [[ $flags =~ SS_BLE_USE_NIMBLE=true ]]; then echo "::debug::Nimble is enabled, appending +nimble to the target" target="$target+nimble" fi - if [[ $flags =~ SENSESHIFT_BATTERY_ENABLED=true ]]; then + if [[ $flags =~ SS_BATTERY_ENABLED=true ]]; then echo "::debug::Battery is enabled, appending +battery to the target" target="$target+battery" fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85d5c815..0531d546 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,8 +32,8 @@ jobs: - bhaptics_tactal - bhaptics_tactvisor - bhaptics_tactglove_right - battery_flag: [ SENSESHIFT_BATTERY_ENABLED=true ] - nimble_flag: [ SENSESHIFT_BLE_USE_NIMBLE=false ] + battery_flag: [ SS_BATTERY_ENABLED=true ] + nimble_flag: [ SS_BLE_USE_NIMBLE=false ] coverage: [ false ] include: @@ -41,18 +41,18 @@ jobs: - target: bhaptics_tactsuit_x40 os: ubuntu-latest coverage: true - battery_flag: SENSESHIFT_BATTERY_ENABLED=true - nimble_flag: SENSESHIFT_BLE_USE_NIMBLE=true + battery_flag: SS_BATTERY_ENABLED=true + nimble_flag: SS_BLE_USE_NIMBLE=true # - target: bhaptics_tactsuit_x40 # os: ubuntu-latest # coverage: true - # battery_flag: SENSESHIFT_BATTERY_ENABLED=true - # nimble_flag: SENSESHIFT_BLE_USE_NIMBLE=false + # battery_flag: SS_BATTERY_ENABLED=true + # nimble_flag: SS_BLE_USE_NIMBLE=false - target: bhaptics_tactsuit_x40 os: ubuntu-latest coverage: false - battery_flag: SENSESHIFT_BATTERY_ENABLED=true - nimble_flag: SENSESHIFT_BLE_USE_NIMBLE=true + battery_flag: SS_BATTERY_ENABLED=true + nimble_flag: SS_BLE_USE_NIMBLE=true steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 8cfbff2c..423dd5d6 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -31,7 +31,7 @@ jobs: # Enabling all flags to test build for every feature battery_flag: - - SENSESHIFT_BATTERY_ENABLED=true + - SS_BATTERY_ENABLED=true steps: - name: Checkout repository diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d2eecde2..9d042345 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,9 +33,9 @@ jobs: - bhaptics_tactglove_left - bhaptics_tactglove_right battery_flag: - - SENSESHIFT_BATTERY_ENABLED=true + - SS_BATTERY_ENABLED=true nimble_flag: - - SENSESHIFT_BLE_USE_NIMBLE=true + - SS_BLE_USE_NIMBLE=true steps: - uses: actions/checkout@v3 diff --git a/firmware/mode_configs/bhaptics/tactal.cpp b/firmware/mode_configs/bhaptics/tactal.cpp index ec8ea898..cfdd4e9c 100644 --- a/firmware/mode_configs/bhaptics/tactal.cpp +++ b/firmware/mode_configs/bhaptics/tactal.cpp @@ -55,7 +55,7 @@ void setupMode() ); bhBleConnection->begin(); -#if defined(SENSESHIFT_BATTERY_ENABLED) && SENSESHIFT_BATTERY_ENABLED == true +#if defined(SS_BATTERY_ENABLED) && SS_BATTERY_ENABLED == true auto* batteryVoltageSensor = new SimpleSensorDecorator(new AnalogSimpleSensor(36)); batteryVoltageSensor->addFilters({ new MultiplyFilter(3.3F), // Convert to raw pin voltage @@ -63,8 +63,8 @@ void setupMode() }); auto* batteryTask = new ::SenseShift::FreeRTOS::ComponentUpdateTask>( batteryVoltageSensor, - SENSESHIFT_BATTERY_SAMPLE_RATE, - { "ADC Battery", 4096, SENSESHIFT_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } + SS_BATTERY_SAMPLE_RATE, + { "ADC Battery", 4096, SS_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } ); batteryTask->begin(); diff --git a/firmware/mode_configs/bhaptics/tactglove.cpp b/firmware/mode_configs/bhaptics/tactglove.cpp index d67f58e6..d1397408 100644 --- a/firmware/mode_configs/bhaptics/tactglove.cpp +++ b/firmware/mode_configs/bhaptics/tactglove.cpp @@ -28,7 +28,7 @@ using namespace SenseShift::Body::Haptics; extern Application App; Application* app = &App; -static constexpr Body::Hands::HandSide handSide = Body::Hands::HandSide::SENSESHIFT_HAND_SIDE; +static constexpr Body::Hands::HandSide handSide = Body::Hands::HandSide::SS_HAND_SIDE; // clang-format off static const auto& bhLayout = handSide == Body::Hands::HandSide::Left ? BH::TactGloveLeftLayout : BH::TactGloveRightLayout; // clang-format on @@ -63,7 +63,7 @@ void setupMode() ); bhBleConnection->begin(); -#if defined(SENSESHIFT_BATTERY_ENABLED) && SENSESHIFT_BATTERY_ENABLED == true +#if defined(SS_BATTERY_ENABLED) && SS_BATTERY_ENABLED == true auto* batteryVoltageSensor = new SimpleSensorDecorator(new AnalogSimpleSensor(36)); batteryVoltageSensor->addFilters({ new MultiplyFilter(3.3F), // Convert to raw pin voltage @@ -71,8 +71,8 @@ void setupMode() }); auto* batteryTask = new ::SenseShift::FreeRTOS::ComponentUpdateTask>( batteryVoltageSensor, - SENSESHIFT_BATTERY_SAMPLE_RATE, - { "ADC Battery", 4096, SENSESHIFT_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } + SS_BATTERY_SAMPLE_RATE, + { "ADC Battery", 4096, SS_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } ); batteryTask->begin(); diff --git a/firmware/mode_configs/bhaptics/tactosy2.cpp b/firmware/mode_configs/bhaptics/tactosy2.cpp index c3053bd3..ea6373b4 100644 --- a/firmware/mode_configs/bhaptics/tactosy2.cpp +++ b/firmware/mode_configs/bhaptics/tactosy2.cpp @@ -56,7 +56,7 @@ void setupMode() ); bhBleConnection->begin(); -#if defined(SENSESHIFT_BATTERY_ENABLED) && SENSESHIFT_BATTERY_ENABLED == true +#if defined(SS_BATTERY_ENABLED) && SS_BATTERY_ENABLED == true auto* batteryVoltageSensor = new SimpleSensorDecorator(new AnalogSimpleSensor(36)); batteryVoltageSensor->addFilters({ new MultiplyFilter(3.3F), // Convert to raw pin voltage @@ -64,8 +64,8 @@ void setupMode() }); auto* batteryTask = new ::SenseShift::FreeRTOS::ComponentUpdateTask>( batteryVoltageSensor, - SENSESHIFT_BATTERY_SAMPLE_RATE, - { "ADC Battery", 4096, SENSESHIFT_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } + SS_BATTERY_SAMPLE_RATE, + { "ADC Battery", 4096, SS_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } ); batteryTask->begin(); diff --git a/firmware/mode_configs/bhaptics/tactosyf.cpp b/firmware/mode_configs/bhaptics/tactosyf.cpp index b2c47e26..63860af4 100644 --- a/firmware/mode_configs/bhaptics/tactosyf.cpp +++ b/firmware/mode_configs/bhaptics/tactosyf.cpp @@ -57,7 +57,7 @@ void setupMode() ); bhBleConnection->begin(); -#if defined(SENSESHIFT_BATTERY_ENABLED) && SENSESHIFT_BATTERY_ENABLED == true +#if defined(SS_BATTERY_ENABLED) && SS_BATTERY_ENABLED == true auto* batteryVoltageSensor = new SimpleSensorDecorator(new AnalogSimpleSensor(36)); batteryVoltageSensor->addFilters({ new MultiplyFilter(3.3F), // Convert to raw pin voltage @@ -65,8 +65,8 @@ void setupMode() }); auto* batteryTask = new ::SenseShift::FreeRTOS::ComponentUpdateTask>( batteryVoltageSensor, - SENSESHIFT_BATTERY_SAMPLE_RATE, - { "ADC Battery", 4096, SENSESHIFT_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } + SS_BATTERY_SAMPLE_RATE, + { "ADC Battery", 4096, SS_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } ); batteryTask->begin(); diff --git a/firmware/mode_configs/bhaptics/tactosyh.cpp b/firmware/mode_configs/bhaptics/tactosyh.cpp index 11bbe0a4..be8bfd79 100644 --- a/firmware/mode_configs/bhaptics/tactosyh.cpp +++ b/firmware/mode_configs/bhaptics/tactosyh.cpp @@ -57,7 +57,7 @@ void setupMode() ); bhBleConnection->begin(); -#if defined(SENSESHIFT_BATTERY_ENABLED) && SENSESHIFT_BATTERY_ENABLED == true +#if defined(SS_BATTERY_ENABLED) && SS_BATTERY_ENABLED == true auto* batteryVoltageSensor = new SimpleSensorDecorator(new AnalogSimpleSensor(36)); batteryVoltageSensor->addFilters({ new MultiplyFilter(3.3F), // Convert to raw pin voltage @@ -65,8 +65,8 @@ void setupMode() }); auto* batteryTask = new ::SenseShift::FreeRTOS::ComponentUpdateTask>( batteryVoltageSensor, - SENSESHIFT_BATTERY_SAMPLE_RATE, - { "ADC Battery", 4096, SENSESHIFT_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } + SS_BATTERY_SAMPLE_RATE, + { "ADC Battery", 4096, SS_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } ); batteryTask->begin(); diff --git a/firmware/mode_configs/bhaptics/tactsuit_x16.cpp b/firmware/mode_configs/bhaptics/tactsuit_x16.cpp index ae6011f2..bdc9521b 100644 --- a/firmware/mode_configs/bhaptics/tactsuit_x16.cpp +++ b/firmware/mode_configs/bhaptics/tactsuit_x16.cpp @@ -66,7 +66,7 @@ void setupMode() ); bhBleConnection->begin(); -#if defined(SENSESHIFT_BATTERY_ENABLED) && SENSESHIFT_BATTERY_ENABLED == true +#if defined(SS_BATTERY_ENABLED) && SS_BATTERY_ENABLED == true auto* batteryVoltageSensor = new SimpleSensorDecorator(new AnalogSimpleSensor(36)); batteryVoltageSensor->addFilters({ new MultiplyFilter(3.3F), // Convert to raw pin voltage @@ -74,8 +74,8 @@ void setupMode() }); auto* batteryTask = new ::SenseShift::FreeRTOS::ComponentUpdateTask>( batteryVoltageSensor, - SENSESHIFT_BATTERY_SAMPLE_RATE, - { "ADC Battery", 4096, SENSESHIFT_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } + SS_BATTERY_SAMPLE_RATE, + { "ADC Battery", 4096, SS_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } ); batteryTask->begin(); diff --git a/firmware/mode_configs/bhaptics/tactsuit_x16_pca9685.cpp b/firmware/mode_configs/bhaptics/tactsuit_x16_pca9685.cpp index b8b05c77..2042b582 100644 --- a/firmware/mode_configs/bhaptics/tactsuit_x16_pca9685.cpp +++ b/firmware/mode_configs/bhaptics/tactsuit_x16_pca9685.cpp @@ -71,7 +71,7 @@ void setupMode() ); bhBleConnection->begin(); -#if defined(SENSESHIFT_BATTERY_ENABLED) && SENSESHIFT_BATTERY_ENABLED == true +#if defined(SS_BATTERY_ENABLED) && SS_BATTERY_ENABLED == true auto* batteryVoltageSensor = new SimpleSensorDecorator(new AnalogSimpleSensor(36)); batteryVoltageSensor->addFilters({ new MultiplyFilter(3.3F), // Convert to raw pin voltage @@ -79,8 +79,8 @@ void setupMode() }); auto* batteryTask = new ::SenseShift::FreeRTOS::ComponentUpdateTask>( batteryVoltageSensor, - SENSESHIFT_BATTERY_SAMPLE_RATE, - { "ADC Battery", 4096, SENSESHIFT_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } + SS_BATTERY_SAMPLE_RATE, + { "ADC Battery", 4096, SS_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } ); batteryTask->begin(); diff --git a/firmware/mode_configs/bhaptics/tactsuit_x40.cpp b/firmware/mode_configs/bhaptics/tactsuit_x40.cpp index a3d77b06..09e0dab1 100644 --- a/firmware/mode_configs/bhaptics/tactsuit_x40.cpp +++ b/firmware/mode_configs/bhaptics/tactsuit_x40.cpp @@ -80,7 +80,7 @@ void setupMode() ); bhBleConnection->begin(); -#if defined(SENSESHIFT_BATTERY_ENABLED) && SENSESHIFT_BATTERY_ENABLED == true +#if defined(SS_BATTERY_ENABLED) && SS_BATTERY_ENABLED == true auto* batteryVoltageSensor = new SimpleSensorDecorator(new AnalogSimpleSensor(36)); batteryVoltageSensor->addFilters({ new MultiplyFilter(3.3F), // Convert to raw pin voltage @@ -88,8 +88,8 @@ void setupMode() }); auto* batteryTask = new ::SenseShift::FreeRTOS::ComponentUpdateTask>( batteryVoltageSensor, - SENSESHIFT_BATTERY_SAMPLE_RATE, - { "ADC Battery", 4096, SENSESHIFT_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } + SS_BATTERY_SAMPLE_RATE, + { "ADC Battery", 4096, SS_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } ); batteryTask->begin(); diff --git a/firmware/mode_configs/bhaptics/tactvisor.cpp b/firmware/mode_configs/bhaptics/tactvisor.cpp index 38ece6af..b6c618bc 100644 --- a/firmware/mode_configs/bhaptics/tactvisor.cpp +++ b/firmware/mode_configs/bhaptics/tactvisor.cpp @@ -55,7 +55,7 @@ void setupMode() ); bhBleConnection->begin(); -#if defined(SENSESHIFT_BATTERY_ENABLED) && SENSESHIFT_BATTERY_ENABLED == true +#if defined(SS_BATTERY_ENABLED) && SS_BATTERY_ENABLED == true auto* batteryVoltageSensor = new SimpleSensorDecorator(new AnalogSimpleSensor(36)); batteryVoltageSensor->addFilters({ new MultiplyFilter(3.3F), // Convert to raw pin voltage @@ -63,8 +63,8 @@ void setupMode() }); auto* batteryTask = new ::SenseShift::FreeRTOS::ComponentUpdateTask>( batteryVoltageSensor, - SENSESHIFT_BATTERY_SAMPLE_RATE, - { "ADC Battery", 4096, SENSESHIFT_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } + SS_BATTERY_SAMPLE_RATE, + { "ADC Battery", 4096, SS_BATTERY_TASK_PRIORITY, tskNO_AFFINITY } ); batteryTask->begin(); diff --git a/include/config/battery.h b/include/config/battery.h index 67747fa3..219b57f1 100644 --- a/include/config/battery.h +++ b/include/config/battery.h @@ -1,17 +1,17 @@ #pragma once -#ifndef SENSESHIFT_BATTERY_ENABLED -#define SENSESHIFT_BATTERY_ENABLED false +#ifndef SS_BATTERY_ENABLED +#define SS_BATTERY_ENABLED false #endif -#ifndef SENSESHIFT_BATTERY_SAMPLE_RATE -#define SENSESHIFT_BATTERY_SAMPLE_RATE 10000 +#ifndef SS_BATTERY_SAMPLE_RATE +#define SS_BATTERY_SAMPLE_RATE 10000 #endif -#ifndef SENSESHIFT_BATTERY_THRESHOLD_PERCENTAGE -#define SENSESHIFT_BATTERY_THRESHOLD_PERCENTAGE 20 +#ifndef SS_BATTERY_THRESHOLD_PERCENTAGE +#define SS_BATTERY_THRESHOLD_PERCENTAGE 20 #endif -#ifndef SENSESHIFT_BATTERY_TASK_PRIORITY -#define SENSESHIFT_BATTERY_TASK_PRIORITY 1 +#ifndef SS_BATTERY_TASK_PRIORITY +#define SS_BATTERY_TASK_PRIORITY 1 #endif diff --git a/include/config/bluetooth.h b/include/config/bluetooth.h index 3de034d4..79ac1c95 100644 --- a/include/config/bluetooth.h +++ b/include/config/bluetooth.h @@ -11,6 +11,6 @@ } #endif -#ifndef SENSESHIFT_BLE_USE_NIMBLE -#define SENSESHIFT_BLE_USE_NIMBLE false +#ifndef SS_BLE_USE_NIMBLE +#define SS_BLE_USE_NIMBLE false #endif diff --git a/ini/bhaptics.ini b/ini/bhaptics.ini index 0d3c4343..a9dc121b 100644 --- a/ini/bhaptics.ini +++ b/ini/bhaptics.ini @@ -263,7 +263,7 @@ monitor_speed = ${bhaptics.monitor_speed} build_flags = ${bhaptics.build_flags} -D BH_DEVICE_TACTGLOVE - -D SENSESHIFT_HAND_SIDE=Left + -D SS_HAND_SIDE=Left -D BH_BLE_APPEARANCE=508 '-D BLUETOOTH_NAME="TactGlove (L"' '-D BH_SERIAL_NUMBER={ 0xcd, 0x0b, 0x81, 0x45, 0x85, 0xf9, 0x2b, 0x6c, 0xed, 0x5b }' @@ -284,7 +284,7 @@ monitor_speed = ${bhaptics.monitor_speed} build_flags = ${bhaptics.build_flags} -D BH_DEVICE_TACTGLOVE - -D SENSESHIFT_HAND_SIDE=Right + -D SS_HAND_SIDE=Right -D BH_BLE_APPEARANCE=508 '-D BLUETOOTH_NAME="TactGlove (R"' '-D BH_SERIAL_NUMBER={ 0x12, 0x0b, 0xae, 0xbf, 0xbc, 0x90, 0x3b, 0x0d, 0x84, 0xdd }' diff --git a/lib/bhaptics_ble/senseshift/bh/ble/connection.cpp b/lib/bhaptics_ble/senseshift/bh/ble/connection.cpp index db642a43..2e05de3a 100644 --- a/lib/bhaptics_ble/senseshift/bh/ble/connection.cpp +++ b/lib/bhaptics_ble/senseshift/bh/ble/connection.cpp @@ -6,7 +6,7 @@ #include -#if defined(SENSESHIFT_BLE_USE_NIMBLE) && SENSESHIFT_BLE_USE_NIMBLE == true +#if defined(SS_BLE_USE_NIMBLE) && SS_BLE_USE_NIMBLE == true // BLE2902 not needed: https://github.com/h2zero/NimBLE-Arduino/blob/release/1.4/docs/Migration_guide.md#descriptors #define PROPERTY_READ NIMBLE_PROPERTY::READ @@ -77,7 +77,7 @@ namespace SenseShift::BH::BLE { ); }; -#if defined(SENSESHIFT_BLE_USE_NIMBLE) && SENSESHIFT_BLE_USE_NIMBLE == true +#if defined(SS_BLE_USE_NIMBLE) && SS_BLE_USE_NIMBLE == true void onStatus(BLECharacteristic* pCharacteristic, Status s, int code) override #else void onStatus(BLECharacteristic* pCharacteristic, Status s, uint32_t code) override @@ -182,7 +182,7 @@ namespace SenseShift::BH::BLE { | PROPERTY_NOTIFY // for whatever reason, it have to be writable, otherwise Desktop app crashes ); -#if !defined(SENSESHIFT_BLE_USE_NIMBLE) || SENSESHIFT_BLE_USE_NIMBLE != true +#if !defined(SS_BLE_USE_NIMBLE) || SS_BLE_USE_NIMBLE != true batteryChar->addDescriptor(new BLE2902()); #endif @@ -209,7 +209,7 @@ namespace SenseShift::BH::BLE { ); monitorChar->setCallbacks(new LogOutputCharCallbacks()); -#if !defined(SENSESHIFT_BLE_USE_NIMBLE) || SENSESHIFT_BLE_USE_NIMBLE != true +#if !defined(SS_BLE_USE_NIMBLE) || SS_BLE_USE_NIMBLE != true monitorChar->addDescriptor(new BLE2902()); #endif diff --git a/lib/bhaptics_ble/senseshift/bh/ble/connection.hpp b/lib/bhaptics_ble/senseshift/bh/ble/connection.hpp index e5033fb1..c35810b4 100644 --- a/lib/bhaptics_ble/senseshift/bh/ble/connection.hpp +++ b/lib/bhaptics_ble/senseshift/bh/ble/connection.hpp @@ -10,7 +10,7 @@ #include #include -#if defined(SENSESHIFT_BLE_USE_NIMBLE) && SENSESHIFT_BLE_USE_NIMBLE == true +#if defined(SS_BLE_USE_NIMBLE) && SS_BLE_USE_NIMBLE == true #include #else #include diff --git a/platformio.ini b/platformio.ini index e6d2c7c4..fb8423bb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -28,8 +28,8 @@ build_flags = -D CORE_DEBUG_LEVEL=3 ; -D DEBUG_MODE=0 ; -D DEBUG_ESP_PORT=Serial -; -D SENSESHIFT_BATTERY_ENABLED=true -; -D SENSESHIFT_BLE_USE_NIMBLE=true +; -D SS_BATTERY_ENABLED=true +; -D SS_BLE_USE_NIMBLE=true build_src_filter = +<*>