diff --git a/include/BNO08x.hpp b/include/BNO08x.hpp index d15c73c..fea31dc 100644 --- a/include/BNO08x.hpp +++ b/include/BNO08x.hpp @@ -92,7 +92,6 @@ class BNO08x BNO08xRptStabilityClassifier stability_classifier; BNO08xRptShakeDetector shake_detector; BNO08xRptTapDetector tap_detector; - BNO08xRptCircleDetector circle_detector; bno08x_reports_t(BNO08xPrivateTypes::bno08x_sync_ctx_t* sync_ctx) : accelerometer(SH2_ACCELEROMETER, BNO08xPrivateTypes::EVT_GRP_RPT_ACCELEROMETER_BIT, sync_ctx) @@ -122,7 +121,6 @@ class BNO08x SH2_STABILITY_CLASSIFIER, BNO08xPrivateTypes::EVT_GRP_RPT_STABILITY_CLASSIFIER_BIT, sync_ctx) , shake_detector(SH2_SHAKE_DETECTOR, BNO08xPrivateTypes::EVT_GRP_RPT_SHAKE_DETECTOR_BIT, sync_ctx) , tap_detector(SH2_TAP_DETECTOR, BNO08xPrivateTypes::EVT_GRP_RPT_TAP_DETECTOR_BIT, sync_ctx) - , circle_detector(SH2_CIRCLE_DETECTOR, BNO08xPrivateTypes::EVT_GRP_RPT_CIRCLE_DETECTOR_BIT, sync_ctx) { } } bno08x_reports_t; @@ -226,7 +224,6 @@ class BNO08x {SH2_STABILITY_CLASSIFIER, &rpt.stability_classifier}, {SH2_SHAKE_DETECTOR, &rpt.shake_detector}, {SH2_TAP_DETECTOR, &rpt.tap_detector}, - {SH2_CIRCLE_DETECTOR, &rpt.circle_detector}, // not implemented, see include/report for existing implementations to add your own {SH2_PRESSURE, nullptr}, // requires auxilary i2c sensor @@ -243,6 +240,7 @@ class BNO08x {SH2_SLEEP_DETECTOR, nullptr}, {SH2_TILT_DETECTOR, nullptr}, {SH2_POCKET_DETECTOR, nullptr}, + {SH2_CIRCLE_DETECTOR, nullptr}, {SH2_IZRO_MOTION_REQUEST, nullptr} }; // clang-format on diff --git a/include/report/BNO08xReports.hpp b/include/report/BNO08xReports.hpp index c74f636..c6f5a4f 100644 --- a/include/report/BNO08xReports.hpp +++ b/include/report/BNO08xReports.hpp @@ -20,5 +20,4 @@ #include "BNO08xRptActivityClassifier.hpp" #include "BNO08xRptStabilityClassifier.hpp" #include "BNO08xRptShakeDetector.hpp" -#include "BNO08xRptTapDetector.hpp" -#include "BNO08xRptCircleDetector.hpp" \ No newline at end of file +#include "BNO08xRptTapDetector.hpp" \ No newline at end of file diff --git a/include/report/BNO08xRptActivityClassifier.hpp b/include/report/BNO08xRptActivityClassifier.hpp index d6b2148..c9ab076 100644 --- a/include/report/BNO08xRptActivityClassifier.hpp +++ b/include/report/BNO08xRptActivityClassifier.hpp @@ -21,7 +21,7 @@ class BNO08xRptActivityClassifier : public BNO08xRpt } bool enable( - uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg) override; + uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg = BNO08xPrivateTypes::default_sensor_cfg) override; bno08x_activity_classifier_t get(); BNO08xActivity get_most_likely_activity(); void set_activities_to_enable(BNO08xActivityEnable activities_to_enable); diff --git a/include/report/BNO08xRptCircleDetector.hpp b/include/report/BNO08xRptCircleDetector.hpp deleted file mode 100644 index 09c91c1..0000000 --- a/include/report/BNO08xRptCircleDetector.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @file BNO08xRptCircleDetector.hpp - * @author Myles Parfeniuk - */ - -#pragma once - -#include "BNO08xRpt.hpp" - -/** - * @class BNO08xRptCircleDetector - * - * @brief Class to represent circle detector reports. (See Ref. Manual 6.40.2) - */ -class BNO08xRptCircleDetector : public BNO08xRpt -{ - public: - BNO08xRptCircleDetector(uint8_t ID, EventBits_t rpt_bit, BNO08xPrivateTypes::bno08x_sync_ctx_t* sync_ctx) - : BNO08xRpt(ID, rpt_bit, sync_ctx) - { - } - - bool enable( - uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg = BNO08xPrivateTypes::default_sensor_cfg) override; - uint16_t get(); - - private: - void update_data(sh2_SensorValue_t* sensor_val) override; - uint16_t data; ///< Total amount of circles detected. - static const constexpr char* TAG = "BNO08xRptCircleDetector"; -}; diff --git a/source/BNO08x.cpp b/source/BNO08x.cpp index 1cb83ca..841142f 100644 --- a/source/BNO08x.cpp +++ b/source/BNO08x.cpp @@ -1178,7 +1178,10 @@ bool BNO08x::disable_all_reports() attempts++; } - return true; + if (attempts < TOTAL_RPT_COUNT) + return true; + else + return false; } /** @@ -1552,8 +1555,6 @@ esp_err_t BNO08x::re_enable_reports() continue; } - ESP_LOGI(TAG, "Re-enabling. %d", rpt->ID); - if (rpt->rpt_bit & report_en_bits) { if (!rpt->enable(rpt->period_us)) diff --git a/source/BNO08xRpt.cpp b/source/BNO08xRpt.cpp index 8b4e9ff..bb8aa52 100644 --- a/source/BNO08xRpt.cpp +++ b/source/BNO08xRpt.cpp @@ -48,10 +48,8 @@ bool BNO08xRpt::rpt_enable(uint32_t time_between_reports, sh2_SensorConfig_t sen // if not already enabled (ie user called this, not re_enable_reports()) if (idx == -1) - { - ESP_LOGI(TAG, "ADDED: %d", ID); sync_ctx->en_report_ids.push_back(ID); // add report ID to enabled report IDs - } + unlock_user_data(); return true; @@ -102,10 +100,8 @@ bool BNO08xRpt::disable(sh2_SensorConfig_t sensor_cfg) period_us = 0UL; // update the period if (idx != -1) - { - ESP_LOGW(TAG, "ERASED: %d", ID); sync_ctx->en_report_ids.erase(sync_ctx->en_report_ids.begin() + idx); - } + unlock_user_data(); } diff --git a/source/report/BNO08xRptCircleDetector.cpp b/source/report/BNO08xRptCircleDetector.cpp deleted file mode 100644 index 9da489e..0000000 --- a/source/report/BNO08xRptCircleDetector.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/** - * @file BNO08xRptCircleDetector.cpp - * @author Myles Parfeniuk - */ - -#define SCALE_Q(n) (1.0f / (1 << n)) - -#include "BNO08xRptCircleDetector.hpp" -#include "esp_log.h" -#include "math.h" - -/** - * @brief Enables circle detector reports such that the BNO08x begins sending them (only sends reports - * when a circle gesture is detected). - * - * @param time_between_reports The period/interval of the report in microseconds. - * @param sensor_cfg Sensor special configuration (optional, see - * BNO08xPrivateTypes::default_sensor_cfg for defaults). - * - * @return True if report was successfully enabled. - */ -bool BNO08xRptCircleDetector::enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg) -{ - static bool configured = false; - - sensor_cfg.changeSensitivity = 0U; - sensor_cfg.changeSensitivityRelative = true; - sensor_cfg.changeSensitivityEnabled = true; - int op_success = SH2_ERR; - - uint32_t settings[3] = {static_cast(4.0f / SCALE_Q(24)), static_cast(0.1f / SCALE_Q(30)), - static_cast((3.0f * M_PI) / SCALE_Q(25))}; - - if (!configured) - { - lock_sh2_HAL(); - op_success = sh2_setFrs(CIRCLE_DETECTOR_CONFIG, settings, 0U); - unlock_sh2_HAL(); - - if (op_success != SH2_OK) - { - ESP_LOGE(TAG, "%d", op_success); - return false; - } - else - { - ESP_LOGE(TAG, "erased"); - } - - lock_sh2_HAL(); - op_success = sh2_setFrs(CIRCLE_DETECTOR_CONFIG, settings, 3U); - unlock_sh2_HAL(); - - if (op_success != SH2_OK) - { - ESP_LOGE(TAG, "%d", op_success); - return false; - } - - configured = true; - } - - return BNO08xRpt::rpt_enable(time_between_reports, sensor_cfg); -} - -/** - * @brief Updates circle detector data from decoded sensor event. - * - * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. - * - * @return void, nothing to return - */ -void BNO08xRptCircleDetector::update_data(sh2_SensorValue_t* sensor_val) -{ - lock_user_data(); - data += sensor_val->un.circleDetector.circle; - unlock_user_data(); - - if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en)) - signal_data_available(); -} - -/** - * @brief Grabs most recent circle detector detector data. - * - * @return Struct containing requested data; - */ -uint16_t BNO08xRptCircleDetector::get() -{ - lock_user_data(); - uint16_t rqdata = data; - unlock_user_data(); - return rqdata; -} \ No newline at end of file diff --git a/source/report/BNO08xRptShakeDetector.cpp b/source/report/BNO08xRptShakeDetector.cpp index 149a951..e41f8d2 100644 --- a/source/report/BNO08xRptShakeDetector.cpp +++ b/source/report/BNO08xRptShakeDetector.cpp @@ -24,7 +24,8 @@ void BNO08xRptShakeDetector::update_data(sh2_SensorValue_t* sensor_val) } /** - * @brief Enables shake detector reports such that the BNO08x begins sending them. + * @brief Enables shake detector reports such that the BNO08x begins sending them (only sends reports + * when a shake is detected). * * @param report_period_us The period/interval of the report in microseconds. * @param sensor_cfg Sensor special configuration (optional, see @@ -32,9 +33,11 @@ void BNO08xRptShakeDetector::update_data(sh2_SensorValue_t* sensor_val) * * @return True if report was successfully enabled. */ -bool BNO08xRptShakeDetector::enable( - uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg) +bool BNO08xRptShakeDetector::enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg) { + sensor_cfg.changeSensitivityEnabled = true; // this must be set regardless of user cfg or no reports will be received + sensor_cfg.changeSensitivity = 0U; // this must be set regardless of user cfg or no reports will be received + return BNO08xRpt::rpt_enable(time_between_reports, sensor_cfg); }