HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
Loading...
Searching...
No Matches
Bno08xHandler Class Reference

Unified handler for BNO08x IMU sensor family. More...

#include <Bno08xHandler.h>

Collaboration diagram for Bno08xHandler:
[legend]

Public Member Functions

 Bno08xHandler (BaseI2c &i2c_device, const Bno08xConfig &config=Bno08xConfig{}, BaseGpio *reset_gpio=nullptr, BaseGpio *int_gpio=nullptr) noexcept
 Construct BNO08x handler with I2C interface.
 
 Bno08xHandler (BaseSpi &spi_device, const Bno08xConfig &config=Bno08xConfig{}, BaseGpio *reset_gpio=nullptr, BaseGpio *int_gpio=nullptr, BaseGpio *wake_gpio=nullptr) noexcept
 Construct BNO08x handler with SPI interface.
 
 ~Bno08xHandler () noexcept=default
 
 Bno08xHandler (const Bno08xHandler &)=delete
 
Bno08xHandleroperator= (const Bno08xHandler &)=delete
 
 Bno08xHandler (Bno08xHandler &&)=delete
 
Bno08xHandleroperator= (Bno08xHandler &&)=delete
 
Bno08xError Initialize () noexcept
 Initialize the BNO08x sensor.
 
bool EnsureInitialized () noexcept
 Ensure the BNO08x is initialized (lazy init entrypoint).
 
Bno08xError Deinitialize () noexcept
 Deinitialize the sensor.
 
bool IsInitialized () const noexcept
 Check if sensor is initialized and ready.
 
Bno08xError Update () noexcept
 Update sensor - must be called regularly to pump the SH-2 service loop.
 
void SetSensorCallback (SensorCallback callback) noexcept
 Set callback for sensor events.
 
void ClearSensorCallback () noexcept
 Clear sensor event callback.
 
BNO085Interface GetInterfaceType () const noexcept
 Get the communication interface type.
 
IBno08xDriverOpsGetSensor () noexcept
 Get direct access to the underlying sensor driver (type-erased).
 
const IBno08xDriverOpsGetSensor () const noexcept
 Const overload of GetSensor().
 
IBno08xDriverOpsGetDriver () noexcept
 Naming-consistent alias of GetSensor().
 
const IBno08xDriverOpsGetDriver () const noexcept
 
template<typename Fn >
auto visitDriver (Fn &&fn) noexcept -> decltype(fn(std::declval< IBno08xDriverOps & >()))
 Visit the underlying IMU driver under handler mutex protection.
 
Bno08xError GetLastError () const noexcept
 Get the last handler error code.
 
int GetLastDriverError () const noexcept
 Get the last driver-level SH-2 error code.
 
const char * GetDescription () const noexcept
 Get a human-readable description of the handler.
 
void DumpDiagnostics () const noexcept
 Dump comprehensive diagnostics to the logger.
 

Static Public Member Functions

static void QuaternionToEuler (const Bno08xQuaternion &quaternion, Bno08xEulerAngles &euler_angles) noexcept
 Convert quaternion to Euler angles (roll, pitch, yaw in radians).
 
static Bno08xConfig GetDefaultConfig () noexcept
 Get default sensor configuration.
 

Private Member Functions

bool ensureInitializedLocked () noexcept
 Internal: ensure initialized (assumes mutex is held).
 
bool applyConfigLocked () noexcept
 Internal: apply configured sensor enables (assumes mutex is held).
 

Static Private Member Functions

static Bno08xError mapDriverError (int sh2_error) noexcept
 Internal: map SH-2 error code to Bno08xError.
 

Private Attributes

std::unique_ptr< IBno08xDriverOpsdriver_ops_
 Type-erased driver.
 
Bno08xConfig config_
 Current configuration.
 
RtosMutex handler_mutex_
 Thread safety mutex.
 
bool initialized_ {false}
 Initialization state.
 
Bno08xError last_error_ {Bno08xError::SUCCESS}
 Last error.
 
BNO085Interface interface_type_
 I2C or SPI.
 
SensorCallback user_callback_
 User's sensor callback.
 
char description_ [64] {}
 Description string.
 

Detailed Description

Unified handler for BNO08x IMU sensor family.

Provides a comprehensive, non-templated interface for BNO08x sensors with:

  • Lazy initialization pattern
  • Exception-free design with noexcept methods
  • Thread-safe operations with recursive mutex protection
  • Bridge pattern integration with BaseI2c/BaseSpi via CRTP adapters
  • Type erasure to hide template complexity from users
  • Complete SH-2 mode sensor access (9-DOF, gestures, activity)
  • Configurable sensor enable/disable and interval management
  • Hardware control (reset, boot, wake, interface selection)

Constructor & Destructor Documentation

◆ Bno08xHandler() [1/4]

Bno08xHandler::Bno08xHandler ( BaseI2c & i2c_device,
const Bno08xConfig & config = Bno08xConfig{},
BaseGpio * reset_gpio = nullptr,
BaseGpio * int_gpio = nullptr )
explicitnoexcept

Construct BNO08x handler with I2C interface.

Parameters
i2c_deviceReference to BaseI2c implementation (address pre-configured)
configInitial sensor configuration
reset_gpioOptional GPIO for hardware reset
int_gpioOptional GPIO for interrupt monitoring

◆ Bno08xHandler() [2/4]

Bno08xHandler::Bno08xHandler ( BaseSpi & spi_device,
const Bno08xConfig & config = Bno08xConfig{},
BaseGpio * reset_gpio = nullptr,
BaseGpio * int_gpio = nullptr,
BaseGpio * wake_gpio = nullptr )
explicitnoexcept

Construct BNO08x handler with SPI interface.

Parameters
spi_deviceReference to BaseSpi implementation
configInitial sensor configuration
reset_gpioOptional GPIO for hardware reset
int_gpioOptional GPIO for interrupt monitoring
wake_gpioOptional GPIO for wake control (SPI mode)

◆ ~Bno08xHandler()

Bno08xHandler::~Bno08xHandler ( )
defaultnoexcept

◆ Bno08xHandler() [3/4]

Bno08xHandler::Bno08xHandler ( const Bno08xHandler & )
delete

◆ Bno08xHandler() [4/4]

Bno08xHandler::Bno08xHandler ( Bno08xHandler && )
delete

Member Function Documentation

◆ applyConfigLocked()

bool Bno08xHandler::applyConfigLocked ( )
privatenoexcept

Internal: apply configured sensor enables (assumes mutex is held).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearSensorCallback()

void Bno08xHandler::ClearSensorCallback ( )
noexcept

Clear sensor event callback.

◆ Deinitialize()

Bno08xError Bno08xHandler::Deinitialize ( )
noexcept

Deinitialize the sensor.

Returns
Bno08xError::SUCCESS if successful
Here is the call graph for this function:

◆ DumpDiagnostics()

void Bno08xHandler::DumpDiagnostics ( ) const
noexcept

Dump comprehensive diagnostics to the logger.

Here is the call graph for this function:

◆ EnsureInitialized()

bool Bno08xHandler::EnsureInitialized ( )
noexcept

Ensure the BNO08x is initialized (lazy init entrypoint).

Returns
true if initialized and ready.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensureInitializedLocked()

bool Bno08xHandler::ensureInitializedLocked ( )
privatenoexcept

Internal: ensure initialized (assumes mutex is held).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDefaultConfig()

static Bno08xConfig Bno08xHandler::GetDefaultConfig ( )
inlinestaticnoexcept

Get default sensor configuration.

Returns
Default Bno08xConfig structure with sensible defaults

◆ GetDescription()

const char * Bno08xHandler::GetDescription ( ) const
noexcept

Get a human-readable description of the handler.

Returns
String e.g. "BNO08x IMU (I2C @0x4A)" or "BNO08x IMU (SPI)"

◆ GetDriver() [1/2]

const IBno08xDriverOps * Bno08xHandler::GetDriver ( ) const
inlinenoexcept

◆ GetDriver() [2/2]

IBno08xDriverOps * Bno08xHandler::GetDriver ( )
inlinenoexcept

Naming-consistent alias of GetSensor().

Warning
Raw pointer — NOT mutex-protected. Prefer visitDriver().

◆ GetInterfaceType()

BNO085Interface Bno08xHandler::GetInterfaceType ( ) const
noexcept

Get the communication interface type.

Returns
BNO085Interface::I2C or BNO085Interface::SPI

◆ GetLastDriverError()

int Bno08xHandler::GetLastDriverError ( ) const
noexcept

Get the last driver-level SH-2 error code.

Returns
SH2_OK (0) or negative value from sh2_err.h; -1 if not initialized
Here is the call graph for this function:

◆ GetLastError()

Bno08xError Bno08xHandler::GetLastError ( ) const
noexcept

Get the last handler error code.

Returns
Last Bno08xError from a handler API call

◆ GetSensor() [1/2]

const IBno08xDriverOps * Bno08xHandler::GetSensor ( ) const
noexcept

Const overload of GetSensor().

Here is the call graph for this function:

◆ GetSensor() [2/2]

IBno08xDriverOps * Bno08xHandler::GetSensor ( )
noexcept

Get direct access to the underlying sensor driver (type-erased).

The returned pointer exposes the same SH-2 API as the concrete BNO085 driver: Update(), EnableSensor(), DisableSensor(), SetCallback(), HasNewData(), GetLatest(), GetLastError(), HardwareReset(), etc. Use it when you need to call driver methods directly (e.g. custom callbacks, low-level control). Valid for the lifetime of this handler.

Returns
Non-owning pointer to the driver interface, or nullptr if not constructed
Warning
Raw pointer — NOT mutex-protected. Caller is responsible for external synchronization in multi-task environments. Prefer visitDriver() for thread-safe access.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Initialize()

Bno08xError Bno08xHandler::Initialize ( )
noexcept

Initialize the BNO08x sensor.

Performs hardware reset (if GPIO available), calls Begin() on the driver, and applies the initial sensor configuration.

Returns
Bno08xError::SUCCESS if successful, error code otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsInitialized()

bool Bno08xHandler::IsInitialized ( ) const
noexcept

Check if sensor is initialized and ready.

Returns
true if Initialize() succeeded and driver is ready
Here is the caller graph for this function:

◆ mapDriverError()

Bno08xError Bno08xHandler::mapDriverError ( int sh2_error)
staticprivatenoexcept

Internal: map SH-2 error code to Bno08xError.

Here is the caller graph for this function:

◆ operator=() [1/2]

Bno08xHandler & Bno08xHandler::operator= ( Bno08xHandler && )
delete

◆ operator=() [2/2]

Bno08xHandler & Bno08xHandler::operator= ( const Bno08xHandler & )
delete

◆ QuaternionToEuler()

void Bno08xHandler::QuaternionToEuler ( const Bno08xQuaternion & quaternion,
Bno08xEulerAngles & euler_angles )
staticnoexcept

Convert quaternion to Euler angles (roll, pitch, yaw in radians).

Parameters
quaternionInput quaternion (must have valid == true for output)
euler_anglesOutput: roll, pitch, yaw, accuracy, timestamp, valid

◆ SetSensorCallback()

void Bno08xHandler::SetSensorCallback ( SensorCallback callback)
noexcept

Set callback for sensor events.

The callback is invoked from within Update() whenever a sensor report arrives. Only one callback can be active at a time.

Parameters
callbackCallback function for sensor events

◆ Update()

Bno08xError Bno08xHandler::Update ( )
noexcept

Update sensor - must be called regularly to pump the SH-2 service loop.

Call this every 5-10 ms (or faster) for optimal data throughput. Sensor callbacks are dispatched from within this method.

Returns
Bno08xError::SUCCESS if successful
Here is the call graph for this function:

◆ visitDriver()

template<typename Fn >
auto Bno08xHandler::visitDriver ( Fn && fn) -> decltype(fn(std::declval<IBno08xDriverOps&>()))
inlinenoexcept

Visit the underlying IMU driver under handler mutex protection.

Returns
Callable result or default-constructed value when driver is unavailable.

Member Data Documentation

◆ config_

Bno08xConfig Bno08xHandler::config_
private

Current configuration.

◆ description_

char Bno08xHandler::description_[64] {}
private

Description string.

◆ driver_ops_

std::unique_ptr<IBno08xDriverOps> Bno08xHandler::driver_ops_
private

Type-erased driver.

◆ handler_mutex_

RtosMutex Bno08xHandler::handler_mutex_
mutableprivate

Thread safety mutex.

◆ initialized_

bool Bno08xHandler::initialized_ {false}
private

Initialization state.

◆ interface_type_

BNO085Interface Bno08xHandler::interface_type_
private

I2C or SPI.

◆ last_error_

Bno08xError Bno08xHandler::last_error_ {Bno08xError::SUCCESS}
mutableprivate

Last error.

◆ user_callback_

SensorCallback Bno08xHandler::user_callback_
private

User's sensor callback.


The documentation for this class was generated from the following files: