From b51d775fa3c94da3023448d617995df138ad10ae Mon Sep 17 00:00:00 2001 From: myles-parfeniuk Date: Sat, 23 Nov 2024 19:22:06 -0800 Subject: [PATCH] near comprehensive report implementation --- include/BNO08x.hpp | 169 ++++---- include/BNO08xRpt.hpp | 2 + include/BNO08xSH2HAL.hpp | 44 +++ include/BNO08x_global_types.hpp | 371 ++++++++++++++++-- include/BNO08x_macros.hpp | 58 --- .../report/BNO08xRptARVRStabilizedGameRV.hpp | 3 +- include/report/BNO08xRptARVRStabilizedRV.hpp | 3 +- include/report/BNO08xRptAcceleration.hpp | 7 +- .../report/BNO08xRptActivityClassifier.hpp | 24 ++ include/report/BNO08xRptCalGyro.hpp | 22 ++ include/report/BNO08xRptCalMagnetometer.hpp | 7 +- include/report/BNO08xRptGameRV.hpp | 3 +- include/report/BNO08xRptGravity.hpp | 7 +- include/report/BNO08xRptIGyroRV.hpp | 23 ++ .../report/BNO08xRptLinearAcceleration.hpp | 7 +- include/report/BNO08xRptRV.hpp | 3 +- include/report/BNO08xRptRVGeneric.hpp | 3 +- include/report/BNO08xRptRVGeomag.hpp | 19 + .../report/BNO08xRptRawMEMSAccelerometer.hpp | 22 ++ include/report/BNO08xRptRawMEMSGyro.hpp | 22 ++ .../report/BNO08xRptRawMEMSMagnetometer.hpp | 22 ++ include/report/BNO08xRptStepCounter.hpp | 25 ++ include/report/BNO08xRptUncalGyro.hpp | 25 ++ include/report/BNO08xRptUncalMagnetometer.hpp | 25 ++ include/report/BNO08xShakeDetector.hpp | 22 ++ include/report/BNO08xStabilityClassifier.hpp | 22 ++ include/report/BNO08xTapDetector.hpp | 23 ++ source/BNO08x.cpp | 106 ++++- source/BNO08xRpt.cpp | 17 +- source/BNO08xSH2HAL.cpp | 1 - source/report/BNO08xRptAcceleration.cpp | 6 +- source/report/BNO08xRptActivityClassifier.cpp | 58 +++ source/report/BNO08xRptCalGyro.cpp | 29 ++ source/report/BNO08xRptCalMagnetometer.cpp | 8 +- source/report/BNO08xRptGravity.cpp | 6 +- source/report/BNO08xRptIGyroRV.cpp | 46 +++ source/report/BNO08xRptLinearAcceleration.cpp | 6 +- source/report/BNO08xRptRVGeneric.cpp | 3 +- source/report/BNO08xRptRVGeomag.cpp | 16 + .../report/BNO08xRptRawMEMSAccelerometer.cpp | 29 ++ source/report/BNO08xRptRawMEMSGyro.cpp | 29 ++ .../report/BNO08xRptRawMEMSMagnetometer.cpp | 29 ++ source/report/BNO08xRptStepCounter.cpp | 53 +++ source/report/BNO08xRptUncalGyro.cpp | 59 +++ source/report/BNO08xRptUncalMagnetometer.cpp | 59 +++ source/report/BNO08xShakeDetector.cpp | 29 ++ source/report/BNO08xStabilityClassifier.cpp | 29 ++ source/report/BNO08xTapDetector.cpp | 45 +++ 48 files changed, 1411 insertions(+), 235 deletions(-) delete mode 100644 include/BNO08x_macros.hpp create mode 100644 include/report/BNO08xRptActivityClassifier.hpp create mode 100644 include/report/BNO08xRptCalGyro.hpp create mode 100644 include/report/BNO08xRptIGyroRV.hpp create mode 100644 include/report/BNO08xRptRVGeomag.hpp create mode 100644 include/report/BNO08xRptRawMEMSAccelerometer.hpp create mode 100644 include/report/BNO08xRptRawMEMSGyro.hpp create mode 100644 include/report/BNO08xRptRawMEMSMagnetometer.hpp create mode 100644 include/report/BNO08xRptStepCounter.hpp create mode 100644 include/report/BNO08xRptUncalGyro.hpp create mode 100644 include/report/BNO08xRptUncalMagnetometer.hpp create mode 100644 include/report/BNO08xShakeDetector.hpp create mode 100644 include/report/BNO08xStabilityClassifier.hpp create mode 100644 include/report/BNO08xTapDetector.hpp create mode 100644 source/report/BNO08xRptActivityClassifier.cpp create mode 100644 source/report/BNO08xRptCalGyro.cpp create mode 100644 source/report/BNO08xRptIGyroRV.cpp create mode 100644 source/report/BNO08xRptRVGeomag.cpp create mode 100644 source/report/BNO08xRptRawMEMSAccelerometer.cpp create mode 100644 source/report/BNO08xRptRawMEMSGyro.cpp create mode 100644 source/report/BNO08xRptRawMEMSMagnetometer.cpp create mode 100644 source/report/BNO08xRptStepCounter.cpp create mode 100644 source/report/BNO08xRptUncalGyro.cpp create mode 100644 source/report/BNO08xRptUncalMagnetometer.cpp create mode 100644 source/report/BNO08xShakeDetector.cpp create mode 100644 source/report/BNO08xStabilityClassifier.cpp create mode 100644 source/report/BNO08xTapDetector.cpp diff --git a/include/BNO08x.hpp b/include/BNO08x.hpp index 9690cae..5dd8f62 100644 --- a/include/BNO08x.hpp +++ b/include/BNO08x.hpp @@ -28,10 +28,23 @@ #include "BNO08xRptLinearAcceleration.hpp" #include "BNO08xRptGravity.hpp" #include "BNO08xRptCalMagnetometer.hpp" +#include "BNO08xRptUncalMagnetometer.hpp" +#include "BNO08xRptCalGyro.hpp" +#include "BNO08xRptUncalGyro.hpp" #include "BNO08xRptRV.hpp" #include "BNO08xRptGameRV.hpp" #include "BNO08xRptARVRStabilizedRV.hpp" #include "BNO08xRptARVRStabilizedGameRV.hpp" +#include "BNO08xRptIGyroRV.hpp" +#include "BNO08xRptRVGeomag.hpp" +#include "BNO08xRptRawMEMSGyro.hpp" +#include "BNO08xRptRawMEMSAccelerometer.hpp" +#include "BNO08xRptRawMEMSMagnetometer.hpp" +#include "BNO08xRptStepCounter.hpp" +#include "BNO08xRptActivityClassifier.hpp" +#include "BNO08xStabilityClassifier.hpp" +#include "BNO08xShakeDetector.hpp" +#include "BNO08xTapDetector.hpp" /** * @class BNO08x @@ -60,18 +73,34 @@ class BNO08x bool data_available(uint8_t& report_ID); void register_cb(std::function cb_fxn); void register_cb(std::function cb_fxn); - void register_report_cb(uint8_t report_ID, std::function cb_fxn); void print_product_ids(); + // enum helper fxns + static const char* activity_to_str(BNO08xActivity activity); + static const char* stability_to_str(BNO08xStability stability); + BNO08xRptAcceleration accelerometer; BNO08xRptLinearAcceleration linear_accelerometer; BNO08xRptGravity gravity; - BNO08xRptCalMagnetometer calibrated_magnetometer; - BNO08xRptRV rotation_vector; - BNO08xRptGameRV game_rotation_vector; - BNO08xRptARVRStabilizedRV ARVR_stabilized_rotation_vector; - BNO08xRptARVRStabilizedGameRV ARVR_stabilized_game_rotation_vector; + BNO08xRptCalMagnetometer cal_magnetometer; + BNO08xRptUncalMagnetometer uncal_magnetometer; + BNO08xRptCalGyro cal_gyro; + BNO08xRptUncalGyro uncal_gyro; + BNO08xRptRV rv; + BNO08xRptGameRV rv_game; + BNO08xRptARVRStabilizedRV rv_ARVR_stabilized; + BNO08xRptARVRStabilizedGameRV rv_ARVR_stabilized_game; + BNO08xRptIGyroRV rv_gyro_integrated; + BNO08xRptRVGeomag rv_geomagnetic; + BNO08xRptRawMEMSGyro raw_gyro; + BNO08xRptRawMEMSAccelerometer raw_accelerometer; + BNO08xRptRawMEMSMagnetometer raw_magnetometer; + BNO08xRptStepCounter step_counter; + BNO08xRptActivityClassifier activity_classifier; + BNO08xStabilityClassifier stability_classifier; + BNO08xShakeDetector shake_detector; + BNO08xTapDetector tap_detector; private: /// @brief Holds info about which functionality has been successfully initialized (used by deconstructor during cleanup). @@ -104,37 +133,6 @@ class BNO08x } } bno08x_init_status_t; - /// @brief Holds data returned from sensor reports. - typedef struct bno08x_data_t - { - bno08x_step_counter_data_t step_counter; - bno08x_activity_classifier_data_t activity_classifier; - bno08x_gyro_data_t cal_gyro; - bno08x_raw_gyro_data_t mems_raw_gyro; - bno08x_raw_accel_data_t mems_raw_accel; - bno08x_raw_magf_data_t mems_raw_magnetometer; - bno08x_quat_t rv; - bno08x_quat_t game_rv; - bno08x_quat_t arvr_s_rv; - bno08x_quat_t arvr_s_game_rv; - - bno08x_data_t() - : step_counter({0UL, 0U}) - , activity_classifier(bno08x_activity_classifier_data_t()) - , cal_gyro({0.0f, 0.0f, 0.0f}) - , mems_raw_gyro({0, 0, 0, 0, 0UL}) - , mems_raw_accel({0, 0, 0, 0UL}) - , mems_raw_magnetometer({0, 0, 0, 0UL}) - , rv(bno08x_quat_t()) - , game_rv(bno08x_quat_t()) - , arvr_s_rv(bno08x_quat_t()) - , arvr_s_game_rv(bno08x_quat_t()) - - { - } - - } bno08x_data_t; - using bno08x_cb_t = std::variant, std::function>; /// @brief Holds registered callback info. typedef struct bno08x_cb_data_t @@ -144,14 +142,14 @@ class BNO08x } bno08x_cb_data_t; // data processing task - static const constexpr configSTACK_DEPTH_TYPE DATA_PROC_TASK_SZ = 2048; ///< Size of data_proc_task() stack in bytes - TaskHandle_t data_proc_task_hdl; /// usr_reports = {{SH2_ACCELEROMETER, &accelerometer}, {SH2_LINEAR_ACCELERATION, &linear_accelerometer}, - {SH2_GRAVITY, &gravity}, {SH2_MAGNETIC_FIELD_CALIBRATED, &calibrated_magnetometer}, {SH2_ROTATION_VECTOR, &rotation_vector}, - {SH2_GAME_ROTATION_VECTOR, &game_rotation_vector}, {SH2_ARVR_STABILIZED_RV, &ARVR_stabilized_rotation_vector}, - {SH2_ARVR_STABILIZED_GRV, &ARVR_stabilized_game_rotation_vector}}; + {SH2_GRAVITY, &gravity}, {SH2_MAGNETIC_FIELD_CALIBRATED, &cal_magnetometer}, {SH2_MAGNETIC_FIELD_UNCALIBRATED, &uncal_magnetometer}, + {SH2_GYROSCOPE_CALIBRATED, &cal_gyro}, {SH2_GYROSCOPE_UNCALIBRATED, &uncal_gyro}, {SH2_ROTATION_VECTOR, &rv}, + {SH2_GAME_ROTATION_VECTOR, &rv_game}, {SH2_ARVR_STABILIZED_RV, &rv_ARVR_stabilized}, + {SH2_ARVR_STABILIZED_GRV, &rv_ARVR_stabilized_game}, {SH2_GYRO_INTEGRATED_RV, &rv_gyro_integrated}, + {SH2_GEOMAGNETIC_ROTATION_VECTOR, &rv_geomagnetic}, {SH2_RAW_GYROSCOPE, &raw_gyro}, {SH2_RAW_ACCELEROMETER, &raw_accelerometer}, + {SH2_RAW_MAGNETOMETER, &raw_magnetometer}, {SH2_STEP_COUNTER, &step_counter}, + {SH2_PERSONAL_ACTIVITY_CLASSIFIER, &activity_classifier}, {SH2_STABILITY_CLASSIFIER, &stability_classifier}, + {SH2_SHAKE_DETECTOR, &shake_detector}, {SH2_TAP_DETECTOR, &tap_detector}}; static void IRAM_ATTR hint_handler(void* arg); @@ -242,41 +245,52 @@ class BNO08x // evt_grp_bno08x_task bits static const constexpr EventBits_t EVT_GRP_BNO08x_TASKS_RUNNING = - (1U << 0U); /// +#include #include "BNO08x_global_types.hpp" // forward dec to prevent compile errors @@ -25,6 +26,7 @@ class BNO08xRpt bool enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg = default_sensor_cfg); bool disable(sh2_SensorConfig_t sensor_cfg = default_sensor_cfg); + void register_cb(std::function cb_fxn); virtual void update_data(sh2_SensorValue_t* sensor_val) = 0; diff --git a/include/BNO08xSH2HAL.hpp b/include/BNO08xSH2HAL.hpp index 769c822..4a8112e 100644 --- a/include/BNO08xSH2HAL.hpp +++ b/include/BNO08xSH2HAL.hpp @@ -13,6 +13,50 @@ #include #include +/** + * @brief Clears the most significant byte of a 16-bit value. + * + * @param val_16bit The 16-bit value to modify. + * @return The value with the MSB cleared. + */ +#define UINT16_CLR_MSB(val_16bit) ((val_16bit) & 0x00FFU) + +/** + * @brief Clears the least significant byte of a 16-bit value. + * + * @param val_16bit The 16-bit value to modify. + * @return The value with the MSB cleared. + */ +#define UINT16_CLR_LSB(val_16bit) ((val_16bit) & 0xFF00U) + +/** + * @brief Clears a specified byte in a 32-bit value. + * + * @param val_32bit The 32-bit value to modify. + * @param byte2clear The byte index to clear (0 = LSB, 3 = MSB). + * @return The value with the specified byte cleared. + */ +#define UINT32_CLR_BYTE(val_32bit, byte2clear) ((val_32bit) & ~(0xFFUL << (byte2clear * 8UL))) + +/** + * @brief Masks a specified byte in a 32-bit value. + * + * @param val_32bit The 32-bit value to modify. + * @param byte2mask The byte index to mask (0 = LSB, 3 = MSB). + * @return The value with the specified byte masked. + */ +#define UINT32_MSK_BYTE(val_32bit, byte2mask) ((val_32bit) & (0xFFUL << (byte2mask * 8UL))) + +// parsing universal to any packet + +/** + * @brief Parse length from SHTP packet header. + * + * @param packet Pointer to bno08x_rx_packet_t containing data. + * @return Length of SHTP packet. + */ +#define PARSE_PACKET_LENGTH(header) (UINT16_CLR_LSB(static_cast(header[1]) << 8U) | UINT16_CLR_MSB(static_cast(header[0]))) + // forward dec to prevent compile errors class BNO08x; diff --git a/include/BNO08x_global_types.hpp b/include/BNO08x_global_types.hpp index f461c85..ffeac65 100644 --- a/include/BNO08x_global_types.hpp +++ b/include/BNO08x_global_types.hpp @@ -10,7 +10,36 @@ #include #include "sh2_SensorValue.h" -/// @brief BNO08xActivity states returned from get_activity_classifier() +// macros for bno08x_tap_detector_t +#define TAP_DETECTED_X_AXIS(tap) ((tap) & (1U << 0U) ? 1 : 0) +#define TAP_DETECTED_X_AXIS_POSITIVE(tap) ((tap) & (1U << 1U) ? 1 : 0) +#define TAP_DETECTED_Y_AXIS(tap) ((tap) & (1U << 2U) ? 1 : 0) +#define TAP_DETECTED_Y_AXIS_POSITIVE(tap) ((tap) & (1U << 3U) ? 1 : 0) +#define TAP_DETECTED_Z_AXIS(tap) ((tap) & (1U << 4U) ? 1 : 0) +#define TAP_DETECTED_Z_AXIS_POSITIVE(tap) ((tap) & (1U << 5U) ? 1 : 0) +#define TAP_DETECTED_DOUBLE(tap) ((tap) & (1U << 6U) ? 1 : 0) + +// macros for bno08x_shake_detector_t +#define SHAKE_DETECTED_X(tap) ((tap) & (1U << 0U) ? 1 : 0) +#define SHAKE_DETECTED_Y(tap) ((tap) & (1U << 1U) ? 1 : 0) +#define SHAKE_DETECTED_Z(tap) ((tap) & (1U << 2U) ? 1 : 0) + +/// @brief BNO08xActivity Classifier enable bits passed to enable_activity_classifier() +enum class BNO08xActivityEnable +{ + UNKNOWN = (1U << 0U), + IN_VEHICLE = (1U << 1U), + ON_BICYCLE = (1U << 2U), + ON_FOOT = (1U << 3U), + STILL = (1U << 4U), + TILTING = (1U << 5U), + WALKING = (1U << 6U), + RUNNING = (1U << 7U), + ON_STAIRS = (1U << 8U), + ALL = 0x1FU +}; + +/// @brief BNO08xActivity states returned from BNO08x::activity_classifier.get() enum class BNO08xActivity { UNKNOWN = 0, // 0 = unknown @@ -25,13 +54,17 @@ enum class BNO08xActivity UNDEFINED = 9 // used for unit tests }; -/// @brief BNO08xStability states returned from get_stability_classifier() +/// @brief BNO08xStability states returned from BNO08x::stability_classifier.get() enum class BNO08xStability { UNKNOWN = 0, // 0 = unknown ON_TABLE = 1, // 1 = on table STATIONARY = 2, // 2 = stationary - UNDEFINED = 3 // used for unit tests + STABLE = 3, // 3 = stable + MOTION = 4, // 4 = in motion + RESERVED = 5, // 5 = reserved (not used) + UNDEFINED = 6 // used for unit tests + }; /// @brief IMU configuration settings passed into constructor @@ -83,35 +116,7 @@ typedef struct bno08x_config_t } } bno08x_config_t; -typedef struct bno08x_activity_classifier_data_t -{ - uint8_t page; - bool lastPage; - BNO08xActivity mostLikelyState; - uint8_t confidence[10]; - - bno08x_activity_classifier_data_t() - : page(0U) - , lastPage(false) - , mostLikelyState(BNO08xActivity::UNDEFINED) - , confidence({}) - { - } - - // conversion from sh2_PersonalActivityClassifier_t - bno08x_activity_classifier_data_t& operator=(const sh2_PersonalActivityClassifier_t& source) - { - this->page = source.page; - this->lastPage = source.lastPage; - this->mostLikelyState = static_cast(source.mostLikelyState); - - for (int i = 0; i < 10; ++i) - this->confidence[i] = source.confidence[i]; - - return *this; - } -} bno08x_activity_classifier_data_t; - +/// @brief Struct to represent unit quaternion. typedef struct bno08x_quat_t { float real; @@ -129,8 +134,7 @@ typedef struct bno08x_quat_t { } - // overloaded assignment operators to handle both sh2 structs: - + // overloaded assignment operator to handle RV with accuracy bno08x_quat_t& operator=(const sh2_RotationVectorWAcc_t& source) { this->real = source.real; @@ -141,6 +145,7 @@ typedef struct bno08x_quat_t return *this; } + // overloaded assignment operator to handle RV with w/o accuracy bno08x_quat_t& operator=(const sh2_RotationVector_t& source) { this->real = source.real; @@ -151,8 +156,22 @@ typedef struct bno08x_quat_t return *this; } + // overloaded assignment operator to handle IRV report + + // overloaded assignment operator to handle RV with w/o accuracy + bno08x_quat_t& operator=(const sh2_GyroIntegratedRV_t& source) + { + this->real = source.real; + this->i = source.i; + this->j = source.j; + this->k = source.k; + this->accuracy = 0.0f; + return *this; + } + } bno08x_quat_t; +/// @brief Struct to represent euler angle (units in degrees or rads) typedef struct bno08x_euler_angle_t { float x; @@ -191,12 +210,282 @@ typedef struct bno08x_euler_angle_t } bno08x_euler_angle_t; -typedef sh2_Accelerometer_t bno08x_accel_data_t; ///< Acceleration data. -typedef sh2_MagneticField_t bno08x_magf_data_t; ///< Magnetic field data. -typedef sh2_StepCounter bno08x_step_counter_data_t; -typedef sh2_Gyroscope_t bno08x_gyro_data_t; -typedef sh2_RawGyroscope_t bno08x_raw_gyro_data_t; -typedef sh2_RawAccelerometer bno08x_raw_accel_data_t; -typedef sh2_RawMagnetometer_t bno08x_raw_magf_data_t; +/// @brief Struct to represent angular velocity (units in rad/s) +typedef struct bno08x_ang_vel_t +{ + float x; + float y; + float z; + + bno08x_ang_vel_t() + : x(0.0f) + , y(0.0f) + , z(0.0f) + { + } + + // overloaded *= operator for rad2deg conversions + template + bno08x_ang_vel_t& operator*=(T value) + { + x *= static_cast(value); + y *= static_cast(value); + z *= static_cast(value); + return *this; + } + + // strip sh2_GyroIntegratedRV_t of velocity data for IRV reports + bno08x_ang_vel_t& operator=(const sh2_GyroIntegratedRV_t& source) + { + this->x = source.angVelX; + this->y = source.angVelY; + this->z = source.angVelZ; + return *this; + } +} bno08x_ang_vel_t; + +/// @brief Struct to represent magnetic field data (units in uTesla) +typedef struct bno08x_magf_t +{ + float x; + float y; + float z; + + bno08x_magf_t() + : x(0.0f) + , y(0.0f) + , z(0.0f) + { + } + + // overloaded = operator for sh2_MagneticField_t conversion + bno08x_magf_t& operator=(const sh2_MagneticField_t& source) + { + this->x = source.x; + this->y = source.y; + this->z = source.z; + return *this; + } + + // overloaded = operator for sh2_MagneticFieldUncalibrated_t conversion + bno08x_magf_t& operator=(const sh2_MagneticFieldUncalibrated_t& source) + { + this->x = source.x; + this->y = source.y; + this->z = source.z; + return *this; + } + +} bno08x_magf_t; + +/// @brief Struct to represent magnetic field bias data (units in uTesla) +typedef struct bno08x_magf_bias_t +{ + float x; + float y; + float z; + + bno08x_magf_bias_t() + : x(0.0f) + , y(0.0f) + , z(0.0f) + { + } + + // overloaded = operator for sh2_MagneticFieldUncalibrated_t conversion + bno08x_magf_bias_t& operator=(const sh2_MagneticFieldUncalibrated_t& source) + { + this->x = source.biasX; + this->y = source.biasY; + this->z = source.biasZ; + return *this; + } + +} bno08x_magf_bias_t; + +/// @brief Struct to represent gyro data (units in rad/s) +typedef struct bno08x_gyro_t +{ + float x; + float y; + float z; + + bno08x_gyro_t() + : x(0.0f) + , y(0.0f) + , z(0.0f) + { + } + + // overloaded = operator for sh2_Gyroscope_t conversion + bno08x_gyro_t& operator=(const sh2_Gyroscope_t& source) + { + this->x = source.x; + this->y = source.y; + this->z = source.z; + return *this; + } + + // overloaded = operator for sh2_GyroscopeUncalibrated conversion + bno08x_gyro_t& operator=(const sh2_GyroscopeUncalibrated& source) + { + this->x = source.x; + this->y = source.y; + this->z = source.z; + return *this; + } + +} bno08x_gyro_t; + +/// @brief Struct to represent gyro bias data (units in rad/s) +typedef struct bno08x_gyro_bias_t +{ + float x; + float y; + float z; + + bno08x_gyro_bias_t() + : x(0.0f) + , y(0.0f) + , z(0.0f) + { + } + + // overloaded = operator for sh2_GyroscopeUncalibrated conversion + bno08x_gyro_bias_t& operator=(const sh2_GyroscopeUncalibrated& source) + { + this->x = source.biasX; + this->y = source.biasY; + this->z = source.biasZ; + return *this; + } + +} bno08x_gyro_bias_t; + +/// @brief Struct to represent activity classifier data. +typedef struct bno08x_activity_classifier_t +{ + uint8_t page; + bool lastPage; + BNO08xActivity mostLikelyState; + uint8_t confidence[10]; + + bno08x_activity_classifier_t() + : page(0U) + , lastPage(false) + , mostLikelyState(BNO08xActivity::UNDEFINED) + , confidence({}) + { + } + + // conversion from sh2_PersonalActivityClassifier_t + bno08x_activity_classifier_t& operator=(const sh2_PersonalActivityClassifier_t& source) + { + this->page = source.page; + this->lastPage = source.lastPage; + this->mostLikelyState = static_cast(source.mostLikelyState); + + for (int i = 0; i < 10; ++i) + this->confidence[i] = source.confidence[i]; + + return *this; + } +} bno08x_activity_classifier_t; + +/// @brief Struct to represent tap detector data (flag meaning: 0 = no tap, 1 = positive tap on axis, -1 = negative tap on axis) +typedef struct bno08x_tap_detector_t +{ + int8_t x_flag; + int8_t y_flag; + int8_t z_flag; + bool double_tap; + + bno08x_tap_detector_t() + : x_flag(0) + , y_flag(0) + , z_flag(0) + , double_tap(false) + { + } + + // overloaded = operator for sh2_GyroscopeUncalibrated conversion + bno08x_tap_detector_t& operator=(const sh2_TapDetector_t& source) + { + if (TAP_DETECTED_X_AXIS(source.flags)) + this->x_flag = -1; + else + this->x_flag = 0; + + if (TAP_DETECTED_X_AXIS_POSITIVE(source.flags)) + this->x_flag = 1; + + if (TAP_DETECTED_Y_AXIS(source.flags)) + this->y_flag = -1; + else + this->y_flag = 0; + + if (TAP_DETECTED_Y_AXIS_POSITIVE(source.flags)) + this->y_flag = 1; + + if (TAP_DETECTED_Z_AXIS(source.flags)) + this->z_flag = -1; + else + this->z_flag = 0; + + if (TAP_DETECTED_Z_AXIS_POSITIVE(source.flags)) + this->z_flag = 1; + + if (TAP_DETECTED_DOUBLE(source.flags)) + this->double_tap = true; + else + this->double_tap = false; + + return *this; + } + +} bno08x_tap_detector_t; + +/// @brief Struct to represent shake detector data (flag meaning: 0 = no shake 1 = shake detected) +typedef struct bno08x_shake_detector_t +{ + uint8_t x_flag; + uint8_t y_flag; + uint8_t z_flag; + + bno08x_shake_detector_t() + : x_flag(0U) + , y_flag(0U) + , z_flag(0U) + { + } + + // overloaded = operator for sh2_GyroscopeUncalibrated conversion + bno08x_shake_detector_t& operator=(const sh2_ShakeDetector_t& source) + { + if (SHAKE_DETECTED_X(source.shake)) + this->x_flag = 1U; + else + this->x_flag = 0U; + + if (SHAKE_DETECTED_Y(source.shake)) + this->y_flag = 1U; + else + this->y_flag = 0U; + + if (SHAKE_DETECTED_Z(source.shake)) + this->z_flag = 1U; + else + this->z_flag = 0U; + + return *this; + } + +} bno08x_shake_detector_t; + +typedef sh2_Accelerometer_t bno08x_accel_t; ///< Acceleration data. +typedef sh2_StepCounter bno08x_step_counter_t; +typedef sh2_RawGyroscope_t bno08x_raw_gyro_t; +typedef sh2_RawAccelerometer bno08x_raw_accel_t; +typedef sh2_RawMagnetometer_t bno08x_raw_magf_t; typedef bno08x_config_t imu_config_t; // legacy version compatibility \ No newline at end of file diff --git a/include/BNO08x_macros.hpp b/include/BNO08x_macros.hpp deleted file mode 100644 index d3f53f7..0000000 --- a/include/BNO08x_macros.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file BNO08x_macros.hpp - * @author Myles Parfeniuk - */ -#pragma once - -// standard library includes -#include - -// esp-idf includes -#include -#include - -// packet parsing macros - -/** - * @brief Clears the most significant byte of a 16-bit value. - * - * @param val_16bit The 16-bit value to modify. - * @return The value with the MSB cleared. - */ -#define UINT16_CLR_MSB(val_16bit) ((val_16bit) & 0x00FFU) - -/** - * @brief Clears the least significant byte of a 16-bit value. - * - * @param val_16bit The 16-bit value to modify. - * @return The value with the MSB cleared. - */ -#define UINT16_CLR_LSB(val_16bit) ((val_16bit) & 0xFF00U) - -/** - * @brief Clears a specified byte in a 32-bit value. - * - * @param val_32bit The 32-bit value to modify. - * @param byte2clear The byte index to clear (0 = LSB, 3 = MSB). - * @return The value with the specified byte cleared. - */ -#define UINT32_CLR_BYTE(val_32bit, byte2clear) ((val_32bit) & ~(0xFFUL << (byte2clear * 8UL))) - -/** - * @brief Masks a specified byte in a 32-bit value. - * - * @param val_32bit The 32-bit value to modify. - * @param byte2mask The byte index to mask (0 = LSB, 3 = MSB). - * @return The value with the specified byte masked. - */ -#define UINT32_MSK_BYTE(val_32bit, byte2mask) ((val_32bit) & (0xFFUL << (byte2mask * 8UL))) - -// parsing universal to any packet - -/** - * @brief Parse length from SHTP packet header. - * - * @param packet Pointer to bno08x_rx_packet_t containing data. - * @return Length of SHTP packet. - */ -#define PARSE_PACKET_LENGTH(header) (UINT16_CLR_LSB(static_cast(header[1]) << 8U) | UINT16_CLR_MSB(static_cast(header[0]))) diff --git a/include/report/BNO08xRptARVRStabilizedGameRV.hpp b/include/report/BNO08xRptARVRStabilizedGameRV.hpp index 19bbd9d..209450d 100644 --- a/include/report/BNO08xRptARVRStabilizedGameRV.hpp +++ b/include/report/BNO08xRptARVRStabilizedGameRV.hpp @@ -1,6 +1,6 @@ #pragma once -#include "BNO08xRptRVGeneric.hpp" // Include the base class header +#include "BNO08xRptRVGeneric.hpp" /** * @brief Class to represent ARVR stabilized rotation vector reports. (See Ref. Manual 6.5.43) @@ -8,7 +8,6 @@ class BNO08xRptARVRStabilizedGameRV : public BNO08xRptRVGeneric { public: - // Constructor declaration BNO08xRptARVRStabilizedGameRV(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) : BNO08xRptRVGeneric(imu, report_ID, period_us, rpt_bit) { diff --git a/include/report/BNO08xRptARVRStabilizedRV.hpp b/include/report/BNO08xRptARVRStabilizedRV.hpp index fae0377..4b94ca4 100644 --- a/include/report/BNO08xRptARVRStabilizedRV.hpp +++ b/include/report/BNO08xRptARVRStabilizedRV.hpp @@ -1,6 +1,6 @@ #pragma once -#include "BNO08xRptRVGeneric.hpp" // Include the base class header +#include "BNO08xRptRVGeneric.hpp" /** * @brief Class to represent ARVR stabilized rotation vector reports. (See Ref. Manual 6.5.42) @@ -8,7 +8,6 @@ class BNO08xRptARVRStabilizedRV : public BNO08xRptRVGeneric { public: - // Constructor declaration BNO08xRptARVRStabilizedRV(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) : BNO08xRptRVGeneric(imu, report_ID, period_us, rpt_bit) { diff --git a/include/report/BNO08xRptAcceleration.hpp b/include/report/BNO08xRptAcceleration.hpp index 3664746..9f86fce 100644 --- a/include/report/BNO08xRptAcceleration.hpp +++ b/include/report/BNO08xRptAcceleration.hpp @@ -1,6 +1,6 @@ #pragma once -#include "BNO08xRpt.hpp" // Include the base class header +#include "BNO08xRpt.hpp" /** * @brief Class to represent accelerometer reports. (See Ref. Manual 6.5.9) @@ -8,16 +8,15 @@ class BNO08xRptAcceleration : public BNO08xRpt { public: - // Constructor declaration BNO08xRptAcceleration(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) : BNO08xRpt(imu, report_ID, period_us, rpt_bit) { } - bno08x_accel_data_t get(); + bno08x_accel_t get(); private: void update_data(sh2_SensorValue_t* sensor_val) override; - bno08x_accel_data_t data; + bno08x_accel_t data; static const constexpr char* TAG = "BNO08xRptAcceleration"; }; diff --git a/include/report/BNO08xRptActivityClassifier.hpp b/include/report/BNO08xRptActivityClassifier.hpp new file mode 100644 index 0000000..7f29ee1 --- /dev/null +++ b/include/report/BNO08xRptActivityClassifier.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent activity classifier reports. (See Ref. Manual 6.5.36) + */ +class BNO08xRptActivityClassifier : public BNO08xRpt +{ + public: + BNO08xRptActivityClassifier(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + bool enable(uint32_t time_between_reports, BNO08xActivityEnable activities_to_enable, sh2_SensorConfig_t sensor_cfg = default_sensor_cfg); + bno08x_activity_classifier_t get(); + BNO08xActivity get_most_likely_activity(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_activity_classifier_t data; ///< Most recent report data, doesn't account for step rollover. + static const constexpr char* TAG = "BNO08xRptActivityClassifier"; +}; diff --git a/include/report/BNO08xRptCalGyro.hpp b/include/report/BNO08xRptCalGyro.hpp new file mode 100644 index 0000000..1437265 --- /dev/null +++ b/include/report/BNO08xRptCalGyro.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent calibrated gyro reports. (See Ref. Manual 6.5.13) + */ +class BNO08xRptCalGyro : public BNO08xRpt +{ + public: + BNO08xRptCalGyro(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + bno08x_gyro_t get(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_gyro_t data; + static const constexpr char* TAG = "BNO08xRptCalGyro"; +}; diff --git a/include/report/BNO08xRptCalMagnetometer.hpp b/include/report/BNO08xRptCalMagnetometer.hpp index b0cfb2d..b90ac13 100644 --- a/include/report/BNO08xRptCalMagnetometer.hpp +++ b/include/report/BNO08xRptCalMagnetometer.hpp @@ -1,6 +1,6 @@ #pragma once -#include "BNO08xRpt.hpp" // Include the base class header +#include "BNO08xRpt.hpp" /** * @brief Class to represent calibrated magnetometer reports. (See Ref. Manual 6.5.16) @@ -8,16 +8,15 @@ class BNO08xRptCalMagnetometer : public BNO08xRpt { public: - // Constructor declaration BNO08xRptCalMagnetometer(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) : BNO08xRpt(imu, report_ID, period_us, rpt_bit) { } - bno08x_magf_data_t get(); + bno08x_magf_t get(); private: void update_data(sh2_SensorValue_t* sensor_val) override; - bno08x_magf_data_t data; + bno08x_magf_t data; static const constexpr char* TAG = "BNO08xRptCalMagnetometer"; }; diff --git a/include/report/BNO08xRptGameRV.hpp b/include/report/BNO08xRptGameRV.hpp index 449f0ca..2b7e327 100644 --- a/include/report/BNO08xRptGameRV.hpp +++ b/include/report/BNO08xRptGameRV.hpp @@ -1,6 +1,6 @@ #pragma once -#include "BNO08xRptRVGeneric.hpp" // Include the base class header +#include "BNO08xRptRVGeneric.hpp" /** * @brief Class to represent game rotation vector reports. (See Ref. Manual 6.5.19) @@ -8,7 +8,6 @@ class BNO08xRptGameRV : public BNO08xRptRVGeneric { public: - // Constructor declaration BNO08xRptGameRV(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) : BNO08xRptRVGeneric(imu, report_ID, period_us, rpt_bit) { diff --git a/include/report/BNO08xRptGravity.hpp b/include/report/BNO08xRptGravity.hpp index d610368..2a39489 100644 --- a/include/report/BNO08xRptGravity.hpp +++ b/include/report/BNO08xRptGravity.hpp @@ -1,6 +1,6 @@ #pragma once -#include "BNO08xRpt.hpp" // Include the base class header +#include "BNO08xRpt.hpp" /** * @brief Class to represent gravity reports. (See Ref. Manual 6.5.11) @@ -8,16 +8,15 @@ class BNO08xRptGravity : public BNO08xRpt { public: - // Constructor declaration BNO08xRptGravity(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) : BNO08xRpt(imu, report_ID, period_us, rpt_bit) { } - bno08x_accel_data_t get(); + bno08x_accel_t get(); private: void update_data(sh2_SensorValue_t* sensor_val) override; - bno08x_accel_data_t data; + bno08x_accel_t data; static const constexpr char* TAG = "BNO08xRptGravity"; }; diff --git a/include/report/BNO08xRptIGyroRV.hpp b/include/report/BNO08xRptIGyroRV.hpp new file mode 100644 index 0000000..e5f6bfa --- /dev/null +++ b/include/report/BNO08xRptIGyroRV.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "BNO08xRptRVGeneric.hpp" + +/** + * @brief Class to represent integrated gyro rotation vector reports. (See Ref. Manual 6.5.44) + */ +class BNO08xRptIGyroRV : public BNO08xRptRVGeneric +{ + public: + BNO08xRptIGyroRV(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRptRVGeneric(imu, report_ID, period_us, rpt_bit) + { + } + + void get(bno08x_quat_t& quat, bno08x_ang_vel_t& vel); + bno08x_ang_vel_t get_vel(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_ang_vel_t data_vel; + static const constexpr char* TAG = "BNO08xRptIGyroRV"; +}; diff --git a/include/report/BNO08xRptLinearAcceleration.hpp b/include/report/BNO08xRptLinearAcceleration.hpp index cb8800a..8ad5b88 100644 --- a/include/report/BNO08xRptLinearAcceleration.hpp +++ b/include/report/BNO08xRptLinearAcceleration.hpp @@ -1,6 +1,6 @@ #pragma once -#include "BNO08xRpt.hpp" // Include the base class header +#include "BNO08xRpt.hpp" /** * @brief Class to represent linear accelerometer reports. (See Ref. Manual 6.5.10) @@ -8,16 +8,15 @@ class BNO08xRptLinearAcceleration : public BNO08xRpt { public: - // Constructor declaration BNO08xRptLinearAcceleration(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) : BNO08xRpt(imu, report_ID, period_us, rpt_bit) { } - bno08x_accel_data_t get(); + bno08x_accel_t get(); private: void update_data(sh2_SensorValue_t* sensor_val) override; - bno08x_accel_data_t data; + bno08x_accel_t data; static const constexpr char* TAG = "BNO08xRptLinearAcceleration"; }; diff --git a/include/report/BNO08xRptRV.hpp b/include/report/BNO08xRptRV.hpp index 5752699..29ce14b 100644 --- a/include/report/BNO08xRptRV.hpp +++ b/include/report/BNO08xRptRV.hpp @@ -1,6 +1,6 @@ #pragma once -#include "BNO08xRptRVGeneric.hpp" // Include the base class header +#include "BNO08xRptRVGeneric.hpp" /** * @brief Class to represent rotation vector reports. (See Ref. Manual 6.5.18) @@ -8,7 +8,6 @@ class BNO08xRptRV : public BNO08xRptRVGeneric { public: - // Constructor declaration BNO08xRptRV(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) : BNO08xRptRVGeneric(imu, report_ID, period_us, rpt_bit) { diff --git a/include/report/BNO08xRptRVGeneric.hpp b/include/report/BNO08xRptRVGeneric.hpp index 9c193db..dfbd697 100644 --- a/include/report/BNO08xRptRVGeneric.hpp +++ b/include/report/BNO08xRptRVGeneric.hpp @@ -1,6 +1,6 @@ #pragma once -#include "BNO08xRpt.hpp" // Include the base class header +#include "BNO08xRpt.hpp" /** * @brief Class to represent rotation vector reports. @@ -12,7 +12,6 @@ class BNO08xRptRVGeneric : public BNO08xRpt bno08x_euler_angle_t get_euler(bool in_degrees = true); protected: - // Constructor declaration BNO08xRptRVGeneric(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) : BNO08xRpt(imu, report_ID, period_us, rpt_bit) { diff --git a/include/report/BNO08xRptRVGeomag.hpp b/include/report/BNO08xRptRVGeomag.hpp new file mode 100644 index 0000000..9696787 --- /dev/null +++ b/include/report/BNO08xRptRVGeomag.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "BNO08xRptRVGeneric.hpp" + +/** + * @brief Class to represent geomagnetic rotation vector reports. (See Ref. Manual 6.5.20) + */ +class BNO08xRptRVGeomag : public BNO08xRptRVGeneric +{ + public: + BNO08xRptRVGeomag(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRptRVGeneric(imu, report_ID, period_us, rpt_bit) + { + } + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + static const constexpr char* TAG = "BNO08xRptRVGeomag"; +}; diff --git a/include/report/BNO08xRptRawMEMSAccelerometer.hpp b/include/report/BNO08xRptRawMEMSAccelerometer.hpp new file mode 100644 index 0000000..b403a36 --- /dev/null +++ b/include/report/BNO08xRptRawMEMSAccelerometer.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent raw accelerometer reports. (See Ref. Manual 6.5.8) + */ +class BNO08xRptRawMEMSAccelerometer : public BNO08xRpt +{ + public: + BNO08xRptRawMEMSAccelerometer(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + bno08x_raw_accel_t get(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_raw_accel_t data; + static const constexpr char* TAG = "BNO08xRptRawMEMSAccelerometer"; +}; diff --git a/include/report/BNO08xRptRawMEMSGyro.hpp b/include/report/BNO08xRptRawMEMSGyro.hpp new file mode 100644 index 0000000..b80b832 --- /dev/null +++ b/include/report/BNO08xRptRawMEMSGyro.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent raw gyro reports. (See Ref. Manual 6.5.12) + */ +class BNO08xRptRawMEMSGyro : public BNO08xRpt +{ + public: + BNO08xRptRawMEMSGyro(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + bno08x_raw_gyro_t get(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_raw_gyro_t data; + static const constexpr char* TAG = "BNO08xRptRawMEMSGyro"; +}; diff --git a/include/report/BNO08xRptRawMEMSMagnetometer.hpp b/include/report/BNO08xRptRawMEMSMagnetometer.hpp new file mode 100644 index 0000000..a52b78e --- /dev/null +++ b/include/report/BNO08xRptRawMEMSMagnetometer.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent raw magnetometer reports. (See Ref. Manual 6.5.15) + */ +class BNO08xRptRawMEMSMagnetometer : public BNO08xRpt +{ + public: + BNO08xRptRawMEMSMagnetometer(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + bno08x_raw_magf_t get(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_raw_magf_t data; + static const constexpr char* TAG = "BNO08xRptRawMEMSMagnetometer"; +}; diff --git a/include/report/BNO08xRptStepCounter.hpp b/include/report/BNO08xRptStepCounter.hpp new file mode 100644 index 0000000..2d47c14 --- /dev/null +++ b/include/report/BNO08xRptStepCounter.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent step counter reports. (See Ref. Manual 6.5.29) + */ +class BNO08xRptStepCounter : public BNO08xRpt +{ + public: + BNO08xRptStepCounter(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + bno08x_step_counter_t get(); + uint32_t get_total_steps(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_step_counter_t data; ///< Most recent report data, doesn't account for step rollover. + uint32_t step_accumulator = + 0UL; ///< Every time step count rolls over, the previous steps are accumulated here such that the total steps can always be calculated. + static const constexpr char* TAG = "BNO08xRptStepCounter"; +}; diff --git a/include/report/BNO08xRptUncalGyro.hpp b/include/report/BNO08xRptUncalGyro.hpp new file mode 100644 index 0000000..58075d9 --- /dev/null +++ b/include/report/BNO08xRptUncalGyro.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent uncalibrated gyro reports. (See Ref. Manual 6.5.14) + */ +class BNO08xRptUncalGyro : public BNO08xRpt +{ + public: + BNO08xRptUncalGyro(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + void get(bno08x_gyro_t& vel, bno08x_gyro_bias_t& bias); + bno08x_gyro_t get_vel(); + bno08x_gyro_bias_t get_bias(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_gyro_t data; + bno08x_gyro_bias_t bias_data; + static const constexpr char* TAG = "BNO08xRptUncalGyro"; +}; diff --git a/include/report/BNO08xRptUncalMagnetometer.hpp b/include/report/BNO08xRptUncalMagnetometer.hpp new file mode 100644 index 0000000..52a9e00 --- /dev/null +++ b/include/report/BNO08xRptUncalMagnetometer.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent uncalibrated magnetometer reports. (See Ref. Manual 6.5.17) + */ +class BNO08xRptUncalMagnetometer : public BNO08xRpt +{ + public: + BNO08xRptUncalMagnetometer(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + void get(bno08x_magf_t& magf, bno08x_magf_bias_t& bias); + bno08x_magf_t get_magf(); + bno08x_magf_bias_t get_bias(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_magf_t data; + bno08x_magf_bias_t bias_data; + static const constexpr char* TAG = "BNO08xRptUncalMagnetometer"; +}; diff --git a/include/report/BNO08xShakeDetector.hpp b/include/report/BNO08xShakeDetector.hpp new file mode 100644 index 0000000..f7e6e1d --- /dev/null +++ b/include/report/BNO08xShakeDetector.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent shake detector reports. (See Ref. Manual 6.5.32) + */ +class BNO08xShakeDetector : public BNO08xRpt +{ + public: + BNO08xShakeDetector(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + bno08x_shake_detector_t get(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_shake_detector_t data; + static const constexpr char* TAG = "BNO08xShakeDetector"; +}; diff --git a/include/report/BNO08xStabilityClassifier.hpp b/include/report/BNO08xStabilityClassifier.hpp new file mode 100644 index 0000000..b380bf7 --- /dev/null +++ b/include/report/BNO08xStabilityClassifier.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent stability classifier reports. (See Ref. Manual 6.5.31) + */ +class BNO08xStabilityClassifier : public BNO08xRpt +{ + public: + BNO08xStabilityClassifier(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + BNO08xStability get(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + sh2_StabilityClassifier_t data = {0U}; + static const constexpr char* TAG = "BNO08xStabilityClassifier"; +}; diff --git a/include/report/BNO08xTapDetector.hpp b/include/report/BNO08xTapDetector.hpp new file mode 100644 index 0000000..f760386 --- /dev/null +++ b/include/report/BNO08xTapDetector.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "BNO08xRpt.hpp" + +/** + * @brief Class to represent tap detector reports. (See Ref. Manual 6.5.27) + */ +class BNO08xTapDetector : public BNO08xRpt +{ + public: + BNO08xTapDetector(BNO08x* imu, uint8_t report_ID, uint32_t period_us, uint32_t rpt_bit) + : BNO08xRpt(imu, report_ID, period_us, rpt_bit) + { + } + + bool enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg = default_sensor_cfg); + bno08x_tap_detector_t get(); + + private: + void update_data(sh2_SensorValue_t* sensor_val) override; + bno08x_tap_detector_t data; + static const constexpr char* TAG = "BNO08xTapDetector"; +}; diff --git a/source/BNO08x.cpp b/source/BNO08x.cpp index 29bdff2..740256a 100644 --- a/source/BNO08x.cpp +++ b/source/BNO08x.cpp @@ -1,5 +1,4 @@ #include "BNO08x.hpp" -#include "BNO08x_macros.hpp" /** * @brief BNO08x imu constructor. @@ -13,11 +12,24 @@ BNO08x::BNO08x(bno08x_config_t imu_config) : accelerometer(this, SH2_ACCELEROMETER, 0UL, EVT_GRP_RPT_ACCELEROMETER_BIT) , linear_accelerometer(this, SH2_LINEAR_ACCELERATION, 0UL, EVT_GRP_RPT_LINEAR_ACCELEROMETER_BIT) , gravity(this, SH2_GRAVITY, 0UL, EVT_GRP_RPT_GRAVITY_BIT) - , calibrated_magnetometer(this, SH2_MAGNETIC_FIELD_CALIBRATED, 0UL, EVT_GRP_RPT_CAL_MAGNETOMETER_BIT) - , rotation_vector(this, SH2_ROTATION_VECTOR, 0UL, EVT_GRP_RPT_RV_BIT) - , game_rotation_vector(this, SH2_GAME_ROTATION_VECTOR, 0UL, EVT_GRP_RPT_GAME_RV_BIT) - , ARVR_stabilized_rotation_vector(this, SH2_ARVR_STABILIZED_RV, 0UL, EVT_GRP_RPT_ARVR_S_RV_BIT) - , ARVR_stabilized_game_rotation_vector(this, SH2_ARVR_STABILIZED_GRV, 0UL, EVT_GRP_RPT_ARVR_S_GAME_RV_BIT) + , cal_magnetometer(this, SH2_MAGNETIC_FIELD_CALIBRATED, 0UL, EVT_GRP_RPT_CAL_MAGNETOMETER_BIT) + , uncal_magnetometer(this, SH2_MAGNETIC_FIELD_UNCALIBRATED, 0UL, EVT_GRP_RPT_UNCAL_MAGNETOMETER_BIT) + , cal_gyro(this, SH2_GYROSCOPE_CALIBRATED, 0UL, EVT_GRP_RPT_CAL_GYRO_BIT) + , uncal_gyro(this, SH2_GYROSCOPE_UNCALIBRATED, 0UL, EVT_GRP_RPT_UNCAL_GYRO_BIT) + , rv(this, SH2_ROTATION_VECTOR, 0UL, EVT_GRP_RPT_RV_BIT) + , rv_game(this, SH2_GAME_ROTATION_VECTOR, 0UL, EVT_GRP_RPT_RV_GAME_BIT) + , rv_ARVR_stabilized(this, SH2_ARVR_STABILIZED_RV, 0UL, EVT_GRP_RPT_RV_ARVR_S_BIT) + , rv_ARVR_stabilized_game(this, SH2_ARVR_STABILIZED_GRV, 0UL, EVT_GRP_RPT_RV_ARVR_S_GAME_BIT) + , rv_gyro_integrated(this, SH2_GYRO_INTEGRATED_RV, 0UL, EVT_GRP_RPT_GYRO_INTEGRATED_RV_BIT) + , rv_geomagnetic(this, SH2_GEOMAGNETIC_ROTATION_VECTOR, 0UL, EVT_GRP_RPT_GEOMAG_RV_BIT) + , raw_gyro(this, SH2_RAW_GYROSCOPE, 0UL, EVT_GRP_RPT_RAW_GYRO_BIT) + , raw_accelerometer(this, SH2_RAW_ACCELEROMETER, 0UL, EVT_GRP_RPT_RAW_ACCELEROMETER_BIT) + , raw_magnetometer(this, SH2_RAW_MAGNETOMETER, 0UL, EVT_GRP_RPT_RAW_MAGNETOMETER_BIT) + , step_counter(this, SH2_STEP_COUNTER, 0UL, EVT_GRP_RPT_STEP_COUNTER_BIT) + , activity_classifier(this, SH2_PERSONAL_ACTIVITY_CLASSIFIER, 0UL, EVT_GRP_RPT_ACTIVITY_CLASSIFIER_BIT) + , stability_classifier(this, SH2_STABILITY_CLASSIFIER, 0UL, EVT_GRP_RPT_STABILITY_CLASSIFIER_BIT) + , shake_detector(this, SH2_SHAKE_DETECTOR, 0UL, EVT_GRP_RPT_SHAKE_DETECTOR_BIT) + , tap_detector(this, SH2_TAP_DETECTOR, 0UL, EVT_GRP_RPT_TAP_DETECTOR_BIT) , data_proc_task_hdl(NULL) , sh2_HAL_service_task_hdl(NULL) , cb_task_hdl(NULL) @@ -1108,7 +1120,8 @@ esp_err_t BNO08x::re_enable_reports() bool BNO08x::data_available() { - if (xEventGroupWaitBits(evt_grp_bno08x_task, EVT_GRP_BNO08x_TASK_DATA_AVAILABLE, pdTRUE, pdFALSE, DATA_AVAILABLE_TIMEOUT_MS) != pdFALSE) + if (xEventGroupWaitBits(evt_grp_bno08x_task, EVT_GRP_BNO08x_TASK_DATA_AVAILABLE, pdTRUE, pdFALSE, DATA_AVAILABLE_TIMEOUT_MS) & + EVT_GRP_BNO08x_TASK_DATA_AVAILABLE) return true; return false; @@ -1124,12 +1137,14 @@ bool BNO08x::data_available() bool BNO08x::data_available(uint8_t& report_ID) { - if (xEventGroupWaitBits(evt_grp_bno08x_task, EVT_GRP_BNO08x_TASK_DATA_AVAILABLE, pdTRUE, pdFALSE, DATA_AVAILABLE_TIMEOUT_MS) != pdFALSE) + if (xEventGroupWaitBits(evt_grp_bno08x_task, EVT_GRP_BNO08x_TASK_DATA_AVAILABLE, pdTRUE, pdFALSE, DATA_AVAILABLE_TIMEOUT_MS) & + EVT_GRP_BNO08x_TASK_DATA_AVAILABLE) { report_ID = most_recent_rpt; return true; } + report_ID = 0U; return false; } @@ -1157,19 +1172,6 @@ void BNO08x::register_cb(std::function cb_fxn) cb_list.push_back({0U, cb_fxn}); } -/** - * @brief Registers a callback to execute when new data from a specific report is received. - * - * @param report_ID The ID of the report the callback is to be registered to. - * @param cb_fxn Pointer to the call-back function should be of void return type void input param. - * - * @return void, nothing to return - */ -void BNO08x::register_report_cb(uint8_t report_ID, std::function cb_fxn) -{ - cb_list.push_back({report_ID, cb_fxn}); -} - /** * @brief Prints product IDs received at initialization. * @@ -1193,6 +1195,68 @@ void BNO08x::print_product_ids() } } +/** + * @brief Converts a BNO08xActivity enum to string. + * + * @return The resulting string conversion of the enum. + */ +const char* BNO08x::activity_to_str(BNO08xActivity activity) +{ + switch (activity) + { + case BNO08xActivity::UNKNOWN: + return "UNKNOWN"; + case BNO08xActivity::IN_VEHICLE: + return "IN_VEHICLE"; + case BNO08xActivity::ON_BICYCLE: + return "ON_BICYCLE"; + case BNO08xActivity::ON_FOOT: + return "ON_FOOT"; + case BNO08xActivity::STILL: + return "STILL"; + case BNO08xActivity::TILTING: + return "TILTING"; + case BNO08xActivity::WALKING: + return "WALKING"; + case BNO08xActivity::RUNNING: + return "RUNNING"; + case BNO08xActivity::ON_STAIRS: + return "ON_STAIRS"; + case BNO08xActivity::UNDEFINED: + return "UNDEFINED"; + default: + return "UNDEFINED"; + } +} + +/** + * @brief Converts a BNO08xStability enum to string. + * + * @return The resulting string conversion of the enum. + */ +const char* BNO08x::stability_to_str(BNO08xStability stability) +{ + switch (stability) + { + case BNO08xStability::UNKNOWN: + return "UNKNOWN"; + case BNO08xStability::ON_TABLE: + return "ON_TABLE"; + case BNO08xStability::STATIONARY: + return "STATIONARY"; + case BNO08xStability::STABLE: + return "STABLE"; + case BNO08xStability::MOTION: + return "MOTION"; + case BNO08xStability::RESERVED: + return "RESERVED"; + case BNO08xStability::UNDEFINED: + return "UNDEFINED"; + default: + return "UNDEFINED"; + } +} + /** * @brief HINT interrupt service routine, handles falling edge of BNO08x HINT pin. * diff --git a/source/BNO08xRpt.cpp b/source/BNO08xRpt.cpp index be71ab2..5300414 100644 --- a/source/BNO08xRpt.cpp +++ b/source/BNO08xRpt.cpp @@ -4,11 +4,10 @@ /** * @brief Enables a sensor report such that the BNO08x begins sending it. * - * @param sensor_ID The ID of the sensor for the respective report to be enabled. * @param report_period_us The period/interval of the report in microseconds. - * @param sensor_cfg Sensor special configuration. + * @param sensor_cfg Sensor special configuration (optional, see BNO08xRpt::default_sensor_cfg for defaults). * - * @return ESP_OK if report was successfully enabled. + * @return True if report was successfully enabled. */ bool BNO08xRpt::enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg) { @@ -52,4 +51,16 @@ bool BNO08xRpt::disable(sh2_SensorConfig_t sensor_cfg) } return true; +} + +/** + * @brief Registers a callback to execute when new data from a specific report is received. + * + * @param cb_fxn Pointer to the call-back function should be of void return type void input param. + * + * @return void, nothing to return + */ +void BNO08xRpt::register_cb(std::function cb_fxn) +{ + imu->cb_list.push_back({ID, cb_fxn}); } \ No newline at end of file diff --git a/source/BNO08xSH2HAL.cpp b/source/BNO08xSH2HAL.cpp index e4e5e6a..0609a00 100644 --- a/source/BNO08xSH2HAL.cpp +++ b/source/BNO08xSH2HAL.cpp @@ -1,5 +1,4 @@ #include "BNO08xSH2HAL.hpp" -#include "BNO08x_macros.hpp" #include "BNO08x.hpp" BNO08x* BNO08xSH2HAL::imu; diff --git a/source/report/BNO08xRptAcceleration.cpp b/source/report/BNO08xRptAcceleration.cpp index 450b129..e61cbec 100644 --- a/source/report/BNO08xRptAcceleration.cpp +++ b/source/report/BNO08xRptAcceleration.cpp @@ -1,4 +1,4 @@ -#include "BNO08xRptAcceleration.hpp" // Include the header file for the class +#include "BNO08xRptAcceleration.hpp" #include "BNO08x.hpp" /** @@ -20,10 +20,10 @@ void BNO08xRptAcceleration::update_data(sh2_SensorValue_t* sensor_val) * * @return Struct containing requested data. */ -bno08x_accel_data_t BNO08xRptAcceleration::get() +bno08x_accel_t BNO08xRptAcceleration::get() { imu->lock_user_data(); - bno08x_accel_data_t rqdata = data; + bno08x_accel_t rqdata = data; imu->unlock_user_data(); return rqdata; } \ No newline at end of file diff --git a/source/report/BNO08xRptActivityClassifier.cpp b/source/report/BNO08xRptActivityClassifier.cpp new file mode 100644 index 0000000..7e433d1 --- /dev/null +++ b/source/report/BNO08xRptActivityClassifier.cpp @@ -0,0 +1,58 @@ +#include "BNO08xRptActivityClassifier.hpp" +#include "BNO08x.hpp" + +/** + * @brief Enables activity classifier reports such that the BNO08x begins sending them. + * + * @param time_between_reports The period/interval of the report in microseconds. + * @param activities_to_enable Which activities to enable. + * @param sensor_cfg Sensor special configuration (optional, see BNO08xRpt::default_sensor_cfg for defaults). + * + * @return True if report was successfully enabled. + */ +bool BNO08xRptActivityClassifier::enable(uint32_t time_between_reports, BNO08xActivityEnable activities_to_enable, sh2_SensorConfig_t sensor_cfg) +{ + sensor_cfg.sensorSpecific = static_cast(activities_to_enable); // this must be set regardless of user cfg or no reports will be received + + return BNO08xRpt::enable(time_between_reports, sensor_cfg); +} + +/** + * @brief Updates activity classifier data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptActivityClassifier::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.personalActivityClassifier; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent activity classifier data. + * + * @return Struct containing requested data. + */ +bno08x_activity_classifier_t BNO08xRptActivityClassifier::get() +{ + imu->lock_user_data(); + bno08x_activity_classifier_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} + +/** + * @brief Grabs most the most likely activity from most recent activity classifier data. + * + * @return BNO08xActivity object with detected state. + */ +BNO08xActivity BNO08xRptActivityClassifier::get_most_likely_activity() +{ + imu->lock_user_data(); + BNO08xActivity rqdata = static_cast(data.mostLikelyState); + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xRptCalGyro.cpp b/source/report/BNO08xRptCalGyro.cpp new file mode 100644 index 0000000..17c20e1 --- /dev/null +++ b/source/report/BNO08xRptCalGyro.cpp @@ -0,0 +1,29 @@ +#include "BNO08xRptCalGyro.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates calibrated gyro data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptCalGyro::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.gyroscope; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent gyroscope data (velocity), units are in rad/s. + * + * @return Struct containing requested data. + */ +bno08x_gyro_t BNO08xRptCalGyro::get() +{ + imu->lock_user_data(); + bno08x_gyro_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xRptCalMagnetometer.cpp b/source/report/BNO08xRptCalMagnetometer.cpp index a1acbda..d1c5f66 100644 --- a/source/report/BNO08xRptCalMagnetometer.cpp +++ b/source/report/BNO08xRptCalMagnetometer.cpp @@ -1,8 +1,8 @@ -#include "BNO08xRptCalMagnetometer.hpp" // Include the header file for the class +#include "BNO08xRptCalMagnetometer.hpp" #include "BNO08x.hpp" /** - * @brief Updates accelerometer data from decoded sensor event. + * @brief Updates calibrated magnetometer data from decoded sensor event. * * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. * @@ -20,10 +20,10 @@ void BNO08xRptCalMagnetometer::update_data(sh2_SensorValue_t* sensor_val) * * @return Struct containing requested data. */ -bno08x_magf_data_t BNO08xRptCalMagnetometer::get() +bno08x_magf_t BNO08xRptCalMagnetometer::get() { imu->lock_user_data(); - bno08x_magf_data_t rqdata = data; + bno08x_magf_t rqdata = data; imu->unlock_user_data(); return rqdata; } \ No newline at end of file diff --git a/source/report/BNO08xRptGravity.cpp b/source/report/BNO08xRptGravity.cpp index 55da4cc..277a893 100644 --- a/source/report/BNO08xRptGravity.cpp +++ b/source/report/BNO08xRptGravity.cpp @@ -1,4 +1,4 @@ -#include "BNO08xRptGravity.hpp" // Include the header file for the class +#include "BNO08xRptGravity.hpp" #include "BNO08x.hpp" /** @@ -20,10 +20,10 @@ void BNO08xRptGravity::update_data(sh2_SensorValue_t* sensor_val) * * @return Struct containing requested data. */ -bno08x_accel_data_t BNO08xRptGravity::get() +bno08x_accel_t BNO08xRptGravity::get() { imu->lock_user_data(); - bno08x_accel_data_t rqdata = data; + bno08x_accel_t rqdata = data; imu->unlock_user_data(); return rqdata; } \ No newline at end of file diff --git a/source/report/BNO08xRptIGyroRV.cpp b/source/report/BNO08xRptIGyroRV.cpp new file mode 100644 index 0000000..658835f --- /dev/null +++ b/source/report/BNO08xRptIGyroRV.cpp @@ -0,0 +1,46 @@ +#include "BNO08xRptIGyroRV.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates gyro integrated rotation vector data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptIGyroRV::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.gyroIntegratedRV; + data_vel = sensor_val->un.gyroIntegratedRV; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent gyro integrated rotation vector data. + * + * @param quat Struct to store requested unit quaternion data. + * @param vel Struct to store requested velocity data (units in rad/s). + * + * @return void, nothing to return + */ +void BNO08xRptIGyroRV::get(bno08x_quat_t& quat, bno08x_ang_vel_t& vel) +{ + imu->lock_user_data(); + quat = data; + vel = data_vel; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent gyro integrated rotation vector angular velocity data, units are in rad/s. + * + * @return Struct containing requested data. + */ +bno08x_ang_vel_t BNO08xRptIGyroRV::get_vel() +{ + imu->lock_user_data(); + bno08x_ang_vel_t rqdata = data_vel; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xRptLinearAcceleration.cpp b/source/report/BNO08xRptLinearAcceleration.cpp index fb181a9..af8bf4f 100644 --- a/source/report/BNO08xRptLinearAcceleration.cpp +++ b/source/report/BNO08xRptLinearAcceleration.cpp @@ -1,4 +1,4 @@ -#include "BNO08xRptLinearAcceleration.hpp" // Include the header file for the class +#include "BNO08xRptLinearAcceleration.hpp" #include "BNO08x.hpp" /** @@ -20,10 +20,10 @@ void BNO08xRptLinearAcceleration::update_data(sh2_SensorValue_t* sensor_val) * * @return Struct containing requested data. */ -bno08x_accel_data_t BNO08xRptLinearAcceleration::get() +bno08x_accel_t BNO08xRptLinearAcceleration::get() { imu->lock_user_data(); - bno08x_accel_data_t rqdata = data; + bno08x_accel_t rqdata = data; imu->unlock_user_data(); return rqdata; } \ No newline at end of file diff --git a/source/report/BNO08xRptRVGeneric.cpp b/source/report/BNO08xRptRVGeneric.cpp index 53322c6..feeb916 100644 --- a/source/report/BNO08xRptRVGeneric.cpp +++ b/source/report/BNO08xRptRVGeneric.cpp @@ -2,11 +2,12 @@ #include "BNO08x.hpp" /** - * @brief Grabs most recent rotation vector data in form of unit quaternion, accuracy units in radians (if available). + * @brief Grabs most recent rotation vector data in form of unit quaternion, accuracy units in radians (if available, else constant 0.0f). * * The following RV reports have accuracy data: * * - rotation vector + * - geomagnetic rotation vector * * * @return Struct containing requested data. diff --git a/source/report/BNO08xRptRVGeomag.cpp b/source/report/BNO08xRptRVGeomag.cpp new file mode 100644 index 0000000..8e7f108 --- /dev/null +++ b/source/report/BNO08xRptRVGeomag.cpp @@ -0,0 +1,16 @@ +#include "BNO08xRptRVGeomag.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates geomagnetic rotation vector data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptRVGeomag::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.geoMagRotationVector; + imu->unlock_user_data(); +} \ No newline at end of file diff --git a/source/report/BNO08xRptRawMEMSAccelerometer.cpp b/source/report/BNO08xRptRawMEMSAccelerometer.cpp new file mode 100644 index 0000000..5ea0b47 --- /dev/null +++ b/source/report/BNO08xRptRawMEMSAccelerometer.cpp @@ -0,0 +1,29 @@ +#include "BNO08xRptRawMEMSAccelerometer.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates raw accelerometer data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptRawMEMSAccelerometer::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.rawAccelerometer; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent raw accelerometer data, units are ADC counts, time_stamp in microseconds. + * + * @return Struct containing requested data. + */ +bno08x_raw_accel_t BNO08xRptRawMEMSAccelerometer::get() +{ + imu->lock_user_data(); + bno08x_raw_accel_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xRptRawMEMSGyro.cpp b/source/report/BNO08xRptRawMEMSGyro.cpp new file mode 100644 index 0000000..21b1625 --- /dev/null +++ b/source/report/BNO08xRptRawMEMSGyro.cpp @@ -0,0 +1,29 @@ +#include "BNO08xRptRawMEMSGyro.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates raw mems gyro data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptRawMEMSGyro::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.rawGyroscope; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent raw mems gyro report (units in ADC counts, time_stamp in microseconds) + * + * @return Struct containing requested data. + */ +bno08x_raw_gyro_t BNO08xRptRawMEMSGyro::get() +{ + imu->lock_user_data(); + bno08x_raw_gyro_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xRptRawMEMSMagnetometer.cpp b/source/report/BNO08xRptRawMEMSMagnetometer.cpp new file mode 100644 index 0000000..1e14b11 --- /dev/null +++ b/source/report/BNO08xRptRawMEMSMagnetometer.cpp @@ -0,0 +1,29 @@ +#include "BNO08xRptRawMEMSMagnetometer.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates raw magnetometer data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptRawMEMSMagnetometer::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.rawMagnetometer; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent raw magnetometer data, units are ADC counts, time_stamp in microseconds. + * + * @return Struct containing requested data. + */ +bno08x_raw_magf_t BNO08xRptRawMEMSMagnetometer::get() +{ + imu->lock_user_data(); + bno08x_raw_magf_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xRptStepCounter.cpp b/source/report/BNO08xRptStepCounter.cpp new file mode 100644 index 0000000..95fb091 --- /dev/null +++ b/source/report/BNO08xRptStepCounter.cpp @@ -0,0 +1,53 @@ +#include "BNO08xRptStepCounter.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates step counter data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptStepCounter::update_data(sh2_SensorValue_t* sensor_val) +{ + static uint16_t prev_steps = 0; + + imu->lock_user_data(); + data = sensor_val->un.stepCounter; + + if (prev_steps > data.steps) + { + // rollover detected + step_accumulator += prev_steps; + prev_steps = 0UL; + } + + prev_steps = data.steps; + imu->unlock_user_data(); +} + +/** + * @brief Grabs the total step count since boot, accounts for rollover in report data. + * + * @return Total steps since boot. + */ +uint32_t BNO08xRptStepCounter::get_total_steps() +{ + imu->lock_user_data(); + uint32_t total_steps = step_accumulator + data.steps; + imu->unlock_user_data(); + return total_steps; +} + +/** + * @brief Grabs most recent step counter data (rollover not accounted for in step count, just most recent report data). + * + * @return Struct containing requested data. + */ +bno08x_step_counter_t BNO08xRptStepCounter::get() +{ + imu->lock_user_data(); + bno08x_step_counter_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xRptUncalGyro.cpp b/source/report/BNO08xRptUncalGyro.cpp new file mode 100644 index 0000000..df58712 --- /dev/null +++ b/source/report/BNO08xRptUncalGyro.cpp @@ -0,0 +1,59 @@ +#include "BNO08xRptUncalGyro.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates uncalibrated gyro data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptUncalGyro::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.gyroscopeUncal; + bias_data = sensor_val->un.gyroscopeUncal; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent uncalibrated gyroscope data, units are in rad/s. + * + * @param vel Reference to save velocity data. + * @param bias Reference to save bias data. + * + * @return void, nothing to return + */ +void BNO08xRptUncalGyro::get(bno08x_gyro_t& vel, bno08x_gyro_bias_t& bias) +{ + imu->lock_user_data(); + vel = data; + bias = bias_data; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent uncalibrated gyroscope velocity data, units are in rad/s. + * + * @return Struct containing requested data. + */ +bno08x_gyro_t BNO08xRptUncalGyro::get_vel() +{ + imu->lock_user_data(); + bno08x_gyro_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} + +/** + * @brief Grabs most recent uncalibrated gyroscope bias data, units are in rad/s. + * + * @return Struct containing requested data. + */ +bno08x_gyro_bias_t BNO08xRptUncalGyro::get_bias() +{ + imu->lock_user_data(); + bno08x_gyro_bias_t rqdata = bias_data; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xRptUncalMagnetometer.cpp b/source/report/BNO08xRptUncalMagnetometer.cpp new file mode 100644 index 0000000..b41a0e4 --- /dev/null +++ b/source/report/BNO08xRptUncalMagnetometer.cpp @@ -0,0 +1,59 @@ +#include "BNO08xRptUncalMagnetometer.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates uncalibrated magf data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xRptUncalMagnetometer::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.magneticFieldUncal; + bias_data = sensor_val->un.magneticFieldUncal; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent uncalibrated magnetometer data, units are in uTesla. + * + * @param magf Struct to store requested magf data. + * @param bias Struct to store requested bias data. + * + * @return void, nothing to return + */ +void BNO08xRptUncalMagnetometer::get(bno08x_magf_t& magf, bno08x_magf_bias_t& bias) +{ + imu->lock_user_data(); + magf = data; + bias = bias_data; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent uncalibrated magnetometer magnetic field data, units are in uTesla. + * + * @return Struct containing requested data. + */ +bno08x_magf_t BNO08xRptUncalMagnetometer::get_magf() +{ + imu->lock_user_data(); + bno08x_magf_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} + +/** + * @brief Grabs most recent uncalibrated magnetometer bias data, units are in uTesla. + * + * @return Struct containing requested data. + */ +bno08x_magf_bias_t BNO08xRptUncalMagnetometer::get_bias() +{ + imu->lock_user_data(); + bno08x_magf_bias_t rqdata = bias_data; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xShakeDetector.cpp b/source/report/BNO08xShakeDetector.cpp new file mode 100644 index 0000000..f8d3524 --- /dev/null +++ b/source/report/BNO08xShakeDetector.cpp @@ -0,0 +1,29 @@ +#include "BNO08xShakeDetector.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates shake 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 BNO08xShakeDetector::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.shakeDetector; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent shake detector detector data. + * + * @return Struct containing the requested data. + */ +bno08x_shake_detector_t BNO08xShakeDetector::get() +{ + imu->lock_user_data(); + bno08x_shake_detector_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xStabilityClassifier.cpp b/source/report/BNO08xStabilityClassifier.cpp new file mode 100644 index 0000000..a3650f0 --- /dev/null +++ b/source/report/BNO08xStabilityClassifier.cpp @@ -0,0 +1,29 @@ +#include "BNO08xStabilityClassifier.hpp" +#include "BNO08x.hpp" + +/** + * @brief Updates stability classifier data from decoded sensor event. + * + * @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call. + * + * @return void, nothing to return + */ +void BNO08xStabilityClassifier::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.stabilityClassifier; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent stability classifier data. + * + * @return BNO08xStability enum object with detected state. + */ +BNO08xStability BNO08xStabilityClassifier::get() +{ + imu->lock_user_data(); + BNO08xStability rqdata = static_cast(data.classification); + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file diff --git a/source/report/BNO08xTapDetector.cpp b/source/report/BNO08xTapDetector.cpp new file mode 100644 index 0000000..7b40580 --- /dev/null +++ b/source/report/BNO08xTapDetector.cpp @@ -0,0 +1,45 @@ +#include "BNO08xTapDetector.hpp" +#include "BNO08x.hpp" + +/** + * @brief Enables tap detector reports such that the BNO08x begins sending them (only sends reports when a tap is detected). + * + * @param time_between_reports The period/interval of the report in microseconds. + * @param sensor_cfg Sensor special configuration (optional, see BNO08xRpt::default_sensor_cfg for defaults). + * + * @return True if report was successfully enabled. + */ +bool BNO08xTapDetector::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::enable(time_between_reports, sensor_cfg); +} + +/** + * @brief Updates tap 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 BNO08xTapDetector::update_data(sh2_SensorValue_t* sensor_val) +{ + imu->lock_user_data(); + data = sensor_val->un.tapDetector; + imu->unlock_user_data(); +} + +/** + * @brief Grabs most recent tap detector detector data. + * + * @return Struct containing requested data; + */ +bno08x_tap_detector_t BNO08xTapDetector::get() +{ + imu->lock_user_data(); + bno08x_tap_detector_t rqdata = data; + imu->unlock_user_data(); + return rqdata; +} \ No newline at end of file