shake detector rpts on change, ActivityClassifer enable bugfix, removed

circle detector
This commit is contained in:
myles-parfeniuk 2024-12-26 16:42:48 -08:00
parent fe9c1922ad
commit 1f48d4602a
8 changed files with 15 additions and 143 deletions

View File

@ -92,7 +92,6 @@ class BNO08x
BNO08xRptStabilityClassifier stability_classifier; BNO08xRptStabilityClassifier stability_classifier;
BNO08xRptShakeDetector shake_detector; BNO08xRptShakeDetector shake_detector;
BNO08xRptTapDetector tap_detector; BNO08xRptTapDetector tap_detector;
BNO08xRptCircleDetector circle_detector;
bno08x_reports_t(BNO08xPrivateTypes::bno08x_sync_ctx_t* sync_ctx) bno08x_reports_t(BNO08xPrivateTypes::bno08x_sync_ctx_t* sync_ctx)
: accelerometer(SH2_ACCELEROMETER, BNO08xPrivateTypes::EVT_GRP_RPT_ACCELEROMETER_BIT, 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) 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) , 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) , 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; } bno08x_reports_t;
@ -226,7 +224,6 @@ class BNO08x
{SH2_STABILITY_CLASSIFIER, &rpt.stability_classifier}, {SH2_STABILITY_CLASSIFIER, &rpt.stability_classifier},
{SH2_SHAKE_DETECTOR, &rpt.shake_detector}, {SH2_SHAKE_DETECTOR, &rpt.shake_detector},
{SH2_TAP_DETECTOR, &rpt.tap_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 // not implemented, see include/report for existing implementations to add your own
{SH2_PRESSURE, nullptr}, // requires auxilary i2c sensor {SH2_PRESSURE, nullptr}, // requires auxilary i2c sensor
@ -243,6 +240,7 @@ class BNO08x
{SH2_SLEEP_DETECTOR, nullptr}, {SH2_SLEEP_DETECTOR, nullptr},
{SH2_TILT_DETECTOR, nullptr}, {SH2_TILT_DETECTOR, nullptr},
{SH2_POCKET_DETECTOR, nullptr}, {SH2_POCKET_DETECTOR, nullptr},
{SH2_CIRCLE_DETECTOR, nullptr},
{SH2_IZRO_MOTION_REQUEST, nullptr} {SH2_IZRO_MOTION_REQUEST, nullptr}
}; };
// clang-format on // clang-format on

View File

@ -20,5 +20,4 @@
#include "BNO08xRptActivityClassifier.hpp" #include "BNO08xRptActivityClassifier.hpp"
#include "BNO08xRptStabilityClassifier.hpp" #include "BNO08xRptStabilityClassifier.hpp"
#include "BNO08xRptShakeDetector.hpp" #include "BNO08xRptShakeDetector.hpp"
#include "BNO08xRptTapDetector.hpp" #include "BNO08xRptTapDetector.hpp"
#include "BNO08xRptCircleDetector.hpp"

View File

@ -21,7 +21,7 @@ class BNO08xRptActivityClassifier : public BNO08xRpt
} }
bool enable( 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(); bno08x_activity_classifier_t get();
BNO08xActivity get_most_likely_activity(); BNO08xActivity get_most_likely_activity();
void set_activities_to_enable(BNO08xActivityEnable activities_to_enable); void set_activities_to_enable(BNO08xActivityEnable activities_to_enable);

View File

@ -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";
};

View File

@ -1178,7 +1178,10 @@ bool BNO08x::disable_all_reports()
attempts++; 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; continue;
} }
ESP_LOGI(TAG, "Re-enabling. %d", rpt->ID);
if (rpt->rpt_bit & report_en_bits) if (rpt->rpt_bit & report_en_bits)
{ {
if (!rpt->enable(rpt->period_us)) if (!rpt->enable(rpt->period_us))

View File

@ -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 not already enabled (ie user called this, not re_enable_reports())
if (idx == -1) if (idx == -1)
{
ESP_LOGI(TAG, "ADDED: %d", ID);
sync_ctx->en_report_ids.push_back(ID); // add report ID to enabled report IDs sync_ctx->en_report_ids.push_back(ID); // add report ID to enabled report IDs
}
unlock_user_data(); unlock_user_data();
return true; return true;
@ -102,10 +100,8 @@ bool BNO08xRpt::disable(sh2_SensorConfig_t sensor_cfg)
period_us = 0UL; // update the period period_us = 0UL; // update the period
if (idx != -1) if (idx != -1)
{
ESP_LOGW(TAG, "ERASED: %d", ID);
sync_ctx->en_report_ids.erase(sync_ctx->en_report_ids.begin() + idx); sync_ctx->en_report_ids.erase(sync_ctx->en_report_ids.begin() + idx);
}
unlock_user_data(); unlock_user_data();
} }

View File

@ -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<uint32_t>(4.0f / SCALE_Q(24)), static_cast<uint32_t>(0.1f / SCALE_Q(30)),
static_cast<uint32_t>((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;
}

View File

@ -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 report_period_us The period/interval of the report in microseconds.
* @param sensor_cfg Sensor special configuration (optional, see * @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. * @return True if report was successfully enabled.
*/ */
bool BNO08xRptShakeDetector::enable( bool BNO08xRptShakeDetector::enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg)
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); return BNO08xRpt::rpt_enable(time_between_reports, sensor_cfg);
} }