timestamp feature
Signed-off-by: myles <myles.parfenyuk@gmail.com>
This commit is contained in:
parent
1743f7afa4
commit
3422227f32
|
|
@ -27,9 +27,6 @@ SpaceAfterCStyleCast: true
|
|||
CommentPragmas: '^[/!]<'
|
||||
|
||||
ColumnLimit: 130
|
||||
WrapComments: true
|
||||
AllowShortCommentsOnASingleLine: true
|
||||
AlignConsecutiveComments: true
|
||||
|
||||
BreakBeforeBraces: Allman
|
||||
IndentAccessModifiers: true
|
||||
|
|
|
|||
72
README.md
72
README.md
|
|
@ -171,7 +171,7 @@ extern "C" void app_main(void)
|
|||
#include <stdio.h>
|
||||
#include "BNO08x.hpp"
|
||||
|
||||
static const constexpr char *TAG = "Main";
|
||||
static const constexpr char* TAG = "Main";
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
|
|
@ -197,49 +197,51 @@ extern "C" void app_main(void)
|
|||
imu.rpt.rv_game.enable(100000UL); // 100,000us == 100ms report interval
|
||||
imu.rpt.cal_gyro.enable(100000UL); // 100,000us == 100ms report interval
|
||||
|
||||
|
||||
// There are 3 different flavors of callbacks available:
|
||||
|
||||
// 1) register a callback to execute when new data is received for any report
|
||||
imu.register_cb([&imu]()
|
||||
{
|
||||
// check for game rotation vector report
|
||||
if (imu.rpt.rv_game.has_new_data())
|
||||
{
|
||||
// get absolute heading in degrees
|
||||
bno08x_euler_angle_t euler = imu.rpt.rv_game.get_euler();
|
||||
// display heading
|
||||
ESP_LOGI(TAG, "Euler Angle: x (roll): %.2f y (pitch): %.2f z (yaw): %.2f", euler.x, euler.y, euler.z);
|
||||
}
|
||||
});
|
||||
imu.register_cb(
|
||||
[]()
|
||||
{
|
||||
// check for game rotation vector report
|
||||
if (imu.rpt.rv_game.has_new_data())
|
||||
{
|
||||
// get absolute heading in degrees
|
||||
bno08x_euler_angle_t euler = imu.rpt.rv_game.get_euler();
|
||||
// display heading
|
||||
ESP_LOGI(TAG, "Euler Angle: x (roll): %.2f y (pitch): %.2f z (yaw): %.2f", euler.x, euler.y, euler.z);
|
||||
}
|
||||
});
|
||||
|
||||
// 2) register a callback that is only executed for a specific report
|
||||
imu.rpt.cal_gyro.register_cb([&imu]()
|
||||
{
|
||||
// get angular velocity in rad/s
|
||||
bno08x_gyro_t velocity = imu.rpt.cal_gyro.get();
|
||||
// display velocity
|
||||
ESP_LOGI(TAG, "Velocity: x: %.2f y: %.2f z: %.2f", velocity.x, velocity.y, velocity.z);
|
||||
});
|
||||
imu.rpt.cal_gyro.register_cb(
|
||||
[]()
|
||||
{
|
||||
// get angular velocity in rad/s
|
||||
bno08x_gyro_t velocity = imu.rpt.cal_gyro.get();
|
||||
// display velocity
|
||||
ESP_LOGI(TAG, "Velocity: x: %.2f y: %.2f z: %.2f", velocity.x, velocity.y, velocity.z);
|
||||
});
|
||||
|
||||
// 3) register a callback this passed report ID of report that asserted callback
|
||||
imu.register_cb([](uint8_t rpt_ID)
|
||||
{
|
||||
switch (rpt_ID)
|
||||
{
|
||||
case SH2_GAME_ROTATION_VECTOR:
|
||||
ESP_LOGW(TAG, "Game RV report RX");
|
||||
break;
|
||||
// 3) register a callback that is passed report ID of report that asserted callback
|
||||
imu.register_cb(
|
||||
[](uint8_t rpt_ID)
|
||||
{
|
||||
switch (rpt_ID)
|
||||
{
|
||||
case SH2_GAME_ROTATION_VECTOR:
|
||||
ESP_LOGW(TAG, "Game RV report RX");
|
||||
break;
|
||||
|
||||
case SH2_CAL_GYRO:
|
||||
ESP_LOGW(TAG, "Cal Gyro report RX");
|
||||
break;
|
||||
case SH2_CAL_GYRO:
|
||||
ESP_LOGW(TAG, "Cal Gyro report RX");
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class BNO08xRpt
|
|||
bool register_cb(std::function<void(void)> cb_fxn);
|
||||
bool has_new_data();
|
||||
bool flush();
|
||||
uint64_t get_timestamp_us();
|
||||
bool get_sample_counts(bno08x_sample_counts_t& sample_counts);
|
||||
bool clear_sample_counts();
|
||||
bool get_meta_data(bno08x_meta_data_t& meta_data);
|
||||
|
|
@ -39,10 +40,12 @@ class BNO08xRpt
|
|||
uint8_t ID; ///< Report ID, ex. SH2_ACCELERATION.
|
||||
EventBits_t rpt_bit; ///< Respective enable and data bit for report in evt_grp_rpt_en and evt_grp_rpt_data
|
||||
uint32_t period_us; ///< The period/interval of the report in microseconds.
|
||||
uint64_t time_stamp_us; ///< Timestamp sent in SHTP header, updated with each respective resport rx'd.
|
||||
BNO08xPrivateTypes::bno08x_sync_ctx_t* sync_ctx;
|
||||
|
||||
bool rpt_enable(uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg = BNO08xPrivateTypes::default_sensor_cfg);
|
||||
virtual void update_data(sh2_SensorValue_t* sensor_val) = 0;
|
||||
void update_timestamp(sh2_SensorValue_t* sensor_val);
|
||||
|
||||
/**
|
||||
* @brief BNO08xRpt report constructor.
|
||||
|
|
@ -60,6 +63,7 @@ class BNO08xRpt
|
|||
: ID(ID)
|
||||
, rpt_bit(rpt_bit)
|
||||
, period_us(0UL)
|
||||
, time_stamp_us(0ULL)
|
||||
, sync_ctx(sync_ctx)
|
||||
|
||||
{
|
||||
|
|
|
|||
|
|
@ -125,6 +125,20 @@ bool BNO08xRpt::register_cb(std::function<void(void)> cb_fxn)
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates timestamp of data of respective report.
|
||||
*
|
||||
* @note User data should be locked when this fxn is called.
|
||||
*
|
||||
* @param sensor_val The sh2_SensorValue_t struct used in sh2_decodeSensorEvent() call.
|
||||
*
|
||||
* @return void, nothing to return
|
||||
*/
|
||||
void BNO08xRpt::update_timestamp(sh2_SensorValue_t* sensor_val)
|
||||
{
|
||||
time_stamp_us = sensor_val->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if a new report has been received since the last time this function was called.
|
||||
*
|
||||
|
|
@ -160,6 +174,16 @@ bool BNO08xRpt::flush()
|
|||
return (success != SH2_OK) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns timestamp of most recently received report for this type.
|
||||
*
|
||||
* @return Timestamp of most recently received report.
|
||||
*/
|
||||
uint64_t BNO08xRpt::get_timestamp_us()
|
||||
{
|
||||
return time_stamp_us;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets sample counts for this sensor (see SH-2 ref manual 6.4.3.1)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptARVRStabilizedGameRV::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.arvrStabilizedGRV;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptARVRStabilizedRV::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.arvrStabilizedRV;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptAcceleration::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.accelerometer;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptActivityClassifier::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.personalActivityClassifier;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptCalGyro::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.gyroscope;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptCalMagnetometer::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.magneticField;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptGameRV::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.gameRotationVector;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptGravity::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.gravity;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ void BNO08xRptIGyroRV::update_data(sh2_SensorValue_t* sensor_val)
|
|||
data = sensor_val->un.gyroIntegratedRV;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
data_vel = sensor_val->un.gyroIntegratedRV;
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptLinearAcceleration::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.linearAcceleration;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptRV::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.rotationVector;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptRVGeomag::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.geoMagRotationVector;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptRawMEMSAccelerometer::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.rawAccelerometer;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptRawMEMSGyro::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.rawGyroscope;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptRawMEMSMagnetometer::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.rawMagnetometer;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptShakeDetector::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.shakeDetector;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ void BNO08xRptStabilityClassifier::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.stabilityClassifier;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ void BNO08xRptStepCounter::update_data(sh2_SensorValue_t* sensor_val)
|
|||
|
||||
prev_steps = data.steps;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ void BNO08xRptTapDetector::update_data(sh2_SensorValue_t* sensor_val)
|
|||
lock_user_data();
|
||||
data = sensor_val->un.tapDetector;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ void BNO08xRptUncalGyro::update_data(sh2_SensorValue_t* sensor_val)
|
|||
data = sensor_val->un.gyroscopeUncal;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
bias_data = sensor_val->un.gyroscopeUncal;
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ void BNO08xRptUncalMagnetometer::update_data(sh2_SensorValue_t* sensor_val)
|
|||
data = sensor_val->un.magneticFieldUncal;
|
||||
data.accuracy = static_cast<BNO08xAccuracy>(sensor_val->status);
|
||||
bias_data = sensor_val->un.magneticFieldUncal;
|
||||
update_timestamp(sensor_val);
|
||||
unlock_user_data();
|
||||
|
||||
if (rpt_bit & xEventGroupGetBits(sync_ctx->evt_grp_rpt_en))
|
||||
|
|
|
|||
Loading…
Reference in New Issue