/** * @file BNO08x.hpp * @author Myles Parfeniuk */ #pragma once // etl includes #include #include #include // esp-idf includes #include #include #include #include #include #include #include // in-house includes #include "BNO08xGlobalTypes.hpp" #include "BNO08xPrivateTypes.hpp" #include "BNO08xSH2HAL.hpp" #include "BNO08xReports.hpp" /** * @class BNO08x * * @brief BNO08x IMU driver class. * */ class BNO08x { public: BNO08x(bno08x_config_t imu_config = bno08x_config_t()); ~BNO08x(); bool initialize(); bool hard_reset(); bool soft_reset(); BNO08xResetReason get_reset_reason(); bool on(); bool sleep(); // sh2_startCal (cmd id 12, calibration) bool enable_dynamic_calibration(BNO08xCalSel sensor); bool disable_dynamic_calibration(BNO08xCalSel sensor); bool enable_autosave_dynamic_calibration(); bool disable_autosave_dynamic_calibration(); bool save_dynamic_calibration(); bool clear_dynamic_calibration(); bool get_frs(uint16_t frs_ID, uint32_t (&data)[16], uint16_t& rx_data_sz); sh2_ProductIds_t get_product_IDs(); bool data_available(); bool register_cb(std::function cb_fxn); bool register_cb(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); static const char* accuracy_to_str(BNO08xAccuracy accuracy); BNO08xRptAcceleration rpt_accelerometer; BNO08xRptLinearAcceleration rpt_linear_accelerometer; BNO08xRptGravity rpt_gravity; BNO08xRptCalMagnetometer rpt_cal_magnetometer; BNO08xRptUncalMagnetometer rpt_uncal_magnetometer; BNO08xRptCalGyro rpt_cal_gyro; BNO08xRptUncalGyro rpt_uncal_gyro; BNO08xRptRV rpt_rv; BNO08xRptGameRV rpt_rv_game; BNO08xRptARVRStabilizedRV rpt_rv_ARVR_stabilized; BNO08xRptARVRStabilizedGameRV rpt_rv_ARVR_stabilized_game; BNO08xRptIGyroRV rpt_rv_gyro_integrated; BNO08xRptRVGeomag rpt_rv_geomagnetic; BNO08xRptRawMEMSGyro rpt_raw_gyro; BNO08xRptRawMEMSAccelerometer rpt_raw_accelerometer; BNO08xRptRawMEMSMagnetometer rpt_raw_magnetometer; BNO08xRptStepCounter rpt_step_counter; BNO08xRptActivityClassifier rpt_activity_classifier; BNO08xStabilityClassifier rpt_stability_classifier; BNO08xShakeDetector rpt_shake_detector; BNO08xTapDetector rpt_tap_detector; private: // data processing task static const constexpr configSTACK_DEPTH_TYPE DATA_PROC_TASK_SZ = CONFIG_ESP32_BNO08X_DATA_PROC_TASK_SZ; ///< Size of data_proc_task() stack in bytes TaskHandle_t data_proc_task_hdl; /// en_report_ids; ///< Vector to contain IDs of currently enabled reports // clang-format off etl::map> usr_reports = { {SH2_ACCELEROMETER, &rpt_accelerometer}, {SH2_LINEAR_ACCELERATION, &rpt_linear_accelerometer}, {SH2_GRAVITY, &rpt_gravity}, {SH2_MAGNETIC_FIELD_CALIBRATED, &rpt_cal_magnetometer}, {SH2_MAGNETIC_FIELD_UNCALIBRATED, &rpt_uncal_magnetometer}, {SH2_GYROSCOPE_CALIBRATED, &rpt_cal_gyro}, {SH2_GYROSCOPE_UNCALIBRATED, &rpt_uncal_gyro}, {SH2_ROTATION_VECTOR, &rpt_rv}, {SH2_GAME_ROTATION_VECTOR, &rpt_rv_game}, {SH2_ARVR_STABILIZED_RV, &rpt_rv_ARVR_stabilized}, {SH2_ARVR_STABILIZED_GRV, &rpt_rv_ARVR_stabilized_game}, {SH2_GYRO_INTEGRATED_RV, &rpt_rv_gyro_integrated}, {SH2_GEOMAGNETIC_ROTATION_VECTOR, &rpt_rv_geomagnetic}, {SH2_RAW_GYROSCOPE, &rpt_raw_gyro}, {SH2_RAW_ACCELEROMETER, &rpt_raw_accelerometer}, {SH2_RAW_MAGNETOMETER, &rpt_raw_magnetometer}, {SH2_STEP_COUNTER, &rpt_step_counter}, {SH2_PERSONAL_ACTIVITY_CLASSIFIER, &rpt_activity_classifier}, {SH2_STABILITY_CLASSIFIER, &rpt_stability_classifier}, {SH2_SHAKE_DETECTOR, &rpt_shake_detector}, {SH2_TAP_DETECTOR, &rpt_tap_detector}, // not implemented, see include/report for existing implementations to add your own {SH2_PRESSURE, nullptr}, // requires auxilary i2c sensor {SH2_AMBIENT_LIGHT, nullptr}, // requires auxilary i2c sensor {SH2_HUMIDITY, nullptr}, // requires auxilary i2c sensor {SH2_PROXIMITY, nullptr}, // requires auxilary i2c sensor {SH2_TEMPERATURE, nullptr}, // requires auxilary i2c sensor {SH2_HEART_RATE_MONITOR, nullptr}, // requires auxilary i2c sensor {SH2_STEP_DETECTOR, nullptr}, {SH2_SIGNIFICANT_MOTION, nullptr}, {SH2_FLIP_DETECTOR, nullptr}, {SH2_PICKUP_DETECTOR, nullptr}, {SH2_STABILITY_DETECTOR, nullptr}, {SH2_SLEEP_DETECTOR, nullptr}, {SH2_TILT_DETECTOR, nullptr}, {SH2_POCKET_DETECTOR, nullptr}, {SH2_CIRCLE_DETECTOR, nullptr}, {SH2_IZRO_MOTION_REQUEST, nullptr} }; // clang-format on static void IRAM_ATTR hint_handler(void* arg); static const constexpr uint16_t RX_DATA_LENGTH = 300U; ///