esp32_BNO08x 1.4 C++ BNO08x IMU driver component for esp-idf.

BNO08xRpt.hpp
Go to the documentation of this file.
1
6#pragma once
7
8// standard library includes
9#include <functional>
10// esp-idf includes
11#include "esp_log.h"
12// in-house includes
13#include "BNO08xGlobalTypes.hpp"
14#include "BNO08xPrivateTypes.hpp"
15// hill-crest labs includes (apache 2.0 license, compatible with MIT)
16#include "sh2.h"
17#include "sh2_SensorValue.h"
18#include "sh2_err.h"
19
25 class BNO08xRpt
26{
27 public:
28 bool disable(sh2_SensorConfig_t sensor_cfg = BNO08xPrivateTypes::default_sensor_cfg);
29 bool register_cb(std::function<void(void)> cb_fxn);
30 bool has_new_data();
31 bool flush();
32 bool get_sample_counts(bno08x_sample_counts_t& sample_counts);
33 bool clear_sample_counts();
34 bool get_meta_data(bno08x_meta_data_t& meta_data);
35 virtual bool enable(
36 uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg = BNO08xPrivateTypes::default_sensor_cfg) = 0;
37
38 protected:
39 uint8_t ID;
40 EventBits_t rpt_bit;
41 uint32_t period_us;
42 BNO08xPrivateTypes::bno08x_sync_ctx_t* sync_ctx;
43
44 bool rpt_enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg = BNO08xPrivateTypes::default_sensor_cfg);
45 virtual void update_data(sh2_SensorValue_t* sensor_val) = 0;
46
59 BNO08xRpt(uint8_t ID, EventBits_t rpt_bit, BNO08xPrivateTypes::bno08x_sync_ctx_t* sync_ctx)
60 : ID(ID)
61 , rpt_bit(rpt_bit)
62 , period_us(0UL)
63 , sync_ctx(sync_ctx)
64
65 {
66 }
67
68 void unlock_sh2_HAL();
69 void lock_sh2_HAL();
70 void unlock_user_data();
71 void lock_user_data();
72 void signal_data_available();
73
74 static const constexpr float RAD_2_DEG =
75 (180.0f / M_PI);
76
77 static const constexpr char* TAG = "BNO08xRpt";
78
79 friend class BNO08x;
80};
BNO08xGlobalTypes.hpp
BNO08xPrivateTypes.hpp
BNO08x
BNO08x IMU driver class.
Definition: BNO08x.hpp:33
BNO08xRpt
Class to represent and manage reports returned from BNO08x.
Definition: BNO08xRpt.hpp:26
BNO08xRpt::clear_sample_counts
bool clear_sample_counts()
Clears BNO08x internal sample counts for this sensor. (see SH-2 ref manual 6.4.3.1)
Definition: BNO08xRpt.cpp:195
BNO08xRpt::BNO08xRpt
BNO08xRpt(uint8_t ID, EventBits_t rpt_bit, BNO08xPrivateTypes::bno08x_sync_ctx_t *sync_ctx)
BNO08xRpt report constructor.
Definition: BNO08xRpt.hpp:59
BNO08xRpt::period_us
uint32_t period_us
The period/interval of the report in microseconds.
Definition: BNO08xRpt.hpp:41
BNO08xRpt::RAD_2_DEG
static const constexpr float RAD_2_DEG
Constant for radian to degree conversions, sed in quaternion to euler function conversions.
Definition: BNO08xRpt.hpp:74
BNO08xRpt::unlock_user_data
void unlock_user_data()
Unlocks user data to allow other tasks to read/modify it.
Definition: BNO08xRpt.cpp:266
BNO08xRpt::TAG
static const constexpr char * TAG
Definition: BNO08xRpt.hpp:77
BNO08xRpt::signal_data_available
void signal_data_available()
Signals to BNO08x::data_available() that a new report has arrived.
Definition: BNO08xRpt.cpp:276
BNO08xRpt::lock_user_data
void lock_user_data()
Locks locks user data to only allow the calling task to read/modify it.
Definition: BNO08xRpt.cpp:256
BNO08xRpt::enable
virtual bool enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg=BNO08xPrivateTypes::default_sensor_cfg)=0
BNO08xRpt::sync_ctx
BNO08xPrivateTypes::bno08x_sync_ctx_t * sync_ctx
Definition: BNO08xRpt.hpp:42
BNO08xRpt::register_cb
bool register_cb(std::function< void(void)> cb_fxn)
Registers a callback to execute when new data from a specific report is received.
Definition: BNO08xRpt.cpp:118
BNO08xRpt::unlock_sh2_HAL
void unlock_sh2_HAL()
Unlocks sh2 HAL lib to allow other tasks to call its APIs.
Definition: BNO08xRpt.cpp:246
BNO08xRpt::ID
uint8_t ID
Report ID, ex. SH2_ACCELERATION.
Definition: BNO08xRpt.hpp:39
BNO08xRpt::has_new_data
bool has_new_data()
Checks if a new report has been received since the last time this function was called.
Definition: BNO08xRpt.cpp:134
BNO08xRpt::lock_sh2_HAL
void lock_sh2_HAL()
Locks sh2 HAL lib to only allow the calling task to call its APIs.
Definition: BNO08xRpt.cpp:236
BNO08xRpt::get_sample_counts
bool get_sample_counts(bno08x_sample_counts_t &sample_counts)
Gets sample counts for this sensor (see SH-2 ref manual 6.4.3.1)
Definition: BNO08xRpt.cpp:170
BNO08xRpt::disable
bool disable(sh2_SensorConfig_t sensor_cfg=BNO08xPrivateTypes::default_sensor_cfg)
Disables a sensor report by setting its period to 0us such that the BNO08x stops sending it.
Definition: BNO08xRpt.cpp:68
BNO08xRpt::update_data
virtual void update_data(sh2_SensorValue_t *sensor_val)=0
BNO08xRpt::rpt_enable
bool rpt_enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg=BNO08xPrivateTypes::default_sensor_cfg)
Enables a sensor report such that the BNO08x begins sending it.
Definition: BNO08xRpt.cpp:17
BNO08xRpt::flush
bool flush()
Flush all buffered reports for this sensor/report module.
Definition: BNO08xRpt.cpp:152
BNO08xRpt::get_meta_data
bool get_meta_data(bno08x_meta_data_t &meta_data)
Retrieves meta data for this sensor/report by reading respective record in FRS (flash record system).
Definition: BNO08xRpt.cpp:215
BNO08xRpt::rpt_bit
EventBits_t rpt_bit
Respective enable and data bit for report in evt_grp_rpt_en and evt_grp_rpt_data.
Definition: BNO08xRpt.hpp:40
BNO08xPrivateTypes::bno08x_sync_ctx_t
Holds context used to synchronize tasks and callback execution.
Definition: BNO08xPrivateTypes.hpp:57
bno08x_meta_data_t
Struct to represent sensor/report meta data, returned from BNO08xRpt::get_meta_data()
Definition: BNO08xGlobalTypes.hpp:1047
bno08x_sample_counts_t
Struct to represent sample counts, returned from BNO08xRpt::get_sample_counts()
Definition: BNO08xGlobalTypes.hpp:1018