SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
SensorBHI260AP_Klio Class Reference

#include <SensorBHI260AP_Klio.hpp>

Public Types

enum  LearningChangeReason { LEARNING_PROGRESSING , LEARNING_NO_REPETITIVE_ACTIVITY , LEARNING_NO_SIGNIFICANT }
 
enum  KlioPatternState { PATTERN_STATE_DISABLE = 0 , PATTERN_STATE_ENABLE , PATTERN_STATE_SWITCH_HAND , PATTERN_STATE_AP_DISABLE }
 
using KlioParameter = bhy2_klio_parameter_t
 
using KlioError = bhy2_klio_driver_error_state_t
 
using KlioState = bhy2_klio_sensor_state_t
 
using RecognitionCallback = void(*)(uint8_t pattern_id, float count, void *user_data)
 
using LearningCallback = void(*)(LearningChangeReason reason, uint32_t progress, int learn_index, void *user_data)
 

Public Member Functions

 SensorBHI260AP_Klio (SensorBHI260AP &sensor)
 Constructor to initialize the SensorBHI260AP_Klio object.
 
 ~SensorBHI260AP_Klio ()
 Destructor to release resources occupied by the SensorBHI260AP_Klio object.
 
void end ()
 End the interaction with the KLIO functionality of the BHI260AP sensor and release related resources.
 
bool begin ()
 Initialize the interaction with the KLIO functionality of the BHI260AP sensor.
 
bool setState (bool learning_enable, bool learning_reset, bool recognition_enable, bool recognition_reset)
 Set the learning and recognition states of the KLIO sensor.
 
KlioState getState ()
 Get the current state of the KLIO sensor.
 
bool setState (KlioState sensor_state)
 Set the state of the KLIO sensor using a KlioState object.
 
bool learning ()
 Start the learning function of the KLIO sensor.
 
bool recognition (const uint8_t *pattern_ids, size_t size)
 Start the recognition function of the KLIO sensor for the specified pattern IDs.
 
bool getLearnPattern (uint8_t *pattern, uint16_t *size)
 Retrieve the learned pattern from the sensor.
 
uint8_t getMaxPatterns ()
 Retrieve the maximum number of recognition patterns allowed.
 
bool getParameter (KlioParameter id, uint8_t *parameter_data, uint16_t *size)
 Get a parameter from the KLIO sensor.
 
bool setParameter (KlioParameter id, const void *parameter_data, uint16_t size)
 Set a parameter of the KLIO sensor.
 
bool writePattern (uint8_t idx, const uint8_t *parameter_data, uint16_t size)
 Write a pattern to the KLIO sensor.
 
bool writeMultiplePatterns (const uint8_t *ids, const uint8_t **parameter_data_array, const uint16_t *sizes, uint8_t count)
 Write multiple patterns to the KLIO sensor.
 
bool setPattern (KlioPatternState operation, const uint8_t *pattern_ids, uint16_t size)
 Set the state of patterns in the KLIO sensor.
 
bool enablePattern (const uint8_t *pattern_ids, uint16_t size)
 Enable specified patterns in the KLIO sensor.
 
bool readPattern (uint8_t idx, uint8_t *buffer, uint16_t *length)
 Read a pattern from the KLIO sensor.
 
bool enable (float sample_rate, uint32_t report_latency_ms)
 Enable the KLIO sensor with specified sample rate and report latency.
 
void disable ()
 Disable the KLIO sensor.
 
bool logout (float sample_rate, uint32_t report_latency_ms)
 Log out the KLIO sensor with specified sample rate and report latency.
 
void setLearningCallback (LearningCallback cb, void *user_data)
 Set the callback function for the learning event.
 
void setRecognitionCallback (RecognitionCallback cb, void *user_data)
 Set the callback function for the recognition event.
 
bool checkError ()
 Check if there is an error in the KLIO sensor.
 
KlioError getError () const
 Get the error information of the KLIO sensor.
 
const char * errorToString () const
 Convert the error information to a string.
 

Static Public Attributes

static constexpr int8_t INVALID_LEARNING_INDEX = -1
 

Detailed Description

Definition at line 39 of file sensor/imu/bhi260/SensorBHI260AP_Klio.hpp.

Member Typedef Documentation

◆ KlioError

using SensorBHI260AP_Klio::KlioError = bhy2_klio_driver_error_state_t

Definition at line 58 of file sensor/imu/bhi260/SensorBHI260AP_Klio.hpp.

◆ KlioParameter

using SensorBHI260AP_Klio::KlioParameter = bhy2_klio_parameter_t

Definition at line 57 of file sensor/imu/bhi260/SensorBHI260AP_Klio.hpp.

◆ KlioState

using SensorBHI260AP_Klio::KlioState = bhy2_klio_sensor_state_t

Definition at line 59 of file sensor/imu/bhi260/SensorBHI260AP_Klio.hpp.

◆ LearningCallback

using SensorBHI260AP_Klio::LearningCallback = void (*)(LearningChangeReason reason, uint32_t progress, int learn_index, void *user_data)

Definition at line 61 of file sensor/imu/bhi260/SensorBHI260AP_Klio.hpp.

◆ RecognitionCallback

using SensorBHI260AP_Klio::RecognitionCallback = void (*)(uint8_t pattern_id, float count, void *user_data)

Definition at line 60 of file sensor/imu/bhi260/SensorBHI260AP_Klio.hpp.

Member Enumeration Documentation

◆ KlioPatternState

Enumerator
PATTERN_STATE_DISABLE 
PATTERN_STATE_ENABLE 
PATTERN_STATE_SWITCH_HAND 
PATTERN_STATE_AP_DISABLE 

Definition at line 50 of file sensor/imu/bhi260/SensorBHI260AP_Klio.hpp.

◆ LearningChangeReason

Enumerator
LEARNING_PROGRESSING 
LEARNING_NO_REPETITIVE_ACTIVITY 
LEARNING_NO_SIGNIFICANT 

Definition at line 44 of file sensor/imu/bhi260/SensorBHI260AP_Klio.hpp.

Constructor & Destructor Documentation

◆ SensorBHI260AP_Klio()

SensorBHI260AP_Klio::SensorBHI260AP_Klio ( SensorBHI260AP sensor)

Constructor to initialize the SensorBHI260AP_Klio object.

Parameters
sensorA reference to the SensorBHI260AP object, used for communication with the BHI260AP sensor.

Definition at line 48 of file SensorBHI260AP_Klio.cpp.

◆ ~SensorBHI260AP_Klio()

SensorBHI260AP_Klio::~SensorBHI260AP_Klio ( )

Destructor to release resources occupied by the SensorBHI260AP_Klio object.

Definition at line 61 of file SensorBHI260AP_Klio.cpp.

References end().

Member Function Documentation

◆ begin()

bool SensorBHI260AP_Klio::begin ( )

Initialize the interaction with the KLIO functionality of the BHI260AP sensor.

Returns
Returns true if the initialization is successful, otherwise false.

Definition at line 86 of file SensorBHI260AP_Klio.cpp.

References getParameter(), SENSORLIB_LOG_D, SENSORLIB_LOG_E, and setParameter().

Referenced by setup().

◆ checkError()

bool SensorBHI260AP_Klio::checkError ( )

Check if there is an error in the KLIO sensor.

Returns
Returns true if an error is detected, otherwise false.

Definition at line 346 of file SensorBHI260AP_Klio.cpp.

References SENSORLIB_LOG_E.

◆ disable()

void SensorBHI260AP_Klio::disable ( )

Disable the KLIO sensor.

Definition at line 316 of file SensorBHI260AP_Klio.cpp.

References SENSORLIB_LOG_E.

Referenced by recognition_event_callback().

◆ enable()

bool SensorBHI260AP_Klio::enable ( float  sample_rate,
uint32_t  report_latency_ms 
)

Enable the KLIO sensor with specified sample rate and report latency.

Parameters
sample_rateThe sample rate of the sensor.
report_latency_msThe report latency in milliseconds.
Returns
Returns true if the sensor is enabled successfully, otherwise false.

Definition at line 307 of file SensorBHI260AP_Klio.cpp.

References SENSORLIB_LOG_E.

Referenced by beginRecognition(), and setup().

◆ enablePattern()

bool SensorBHI260AP_Klio::enablePattern ( const uint8_t *  pattern_ids,
uint16_t  size 
)

Enable specified patterns in the KLIO sensor.

Parameters
pattern_idsAn array containing the IDs of the patterns to be enabled.
sizeThe number of elements in the pattern_ids array.
Returns
Returns true if the patterns are enabled successfully, otherwise false.

Definition at line 297 of file SensorBHI260AP_Klio.cpp.

◆ end()

void SensorBHI260AP_Klio::end ( )

End the interaction with the KLIO functionality of the BHI260AP sensor and release related resources.

Definition at line 66 of file SensorBHI260AP_Klio.cpp.

Referenced by ~SensorBHI260AP_Klio().

◆ errorToString()

const char * SensorBHI260AP_Klio::errorToString ( ) const

Convert the error information to a string.

Returns
Returns a const char* pointer to the error information string.

Definition at line 367 of file SensorBHI260AP_Klio.cpp.

Referenced by learning_event_callback().

◆ getError()

SensorBHI260AP_Klio::KlioError SensorBHI260AP_Klio::getError ( ) const

Get the error information of the KLIO sensor.

Returns
Returns a KlioError object containing the error information.

Definition at line 362 of file SensorBHI260AP_Klio.cpp.

◆ getLearnPattern()

bool SensorBHI260AP_Klio::getLearnPattern ( uint8_t *  pattern,
uint16_t *  size 
)

Retrieve the learned pattern from the sensor.

This function attempts to obtain the learned pattern data from the sensor. It populates the provided buffer with the pattern data and sets the size parameter to indicate the actual size of the retrieved pattern.

Parameters
patternA pointer to a buffer where the learned pattern data will be stored. The buffer should be large enough to hold the entire pattern.
sizeA pointer to a variable of type uint16_t. On input, it can be used to specify the maximum capacity of the pattern buffer. On output, it will be updated to contain the actual size of the retrieved pattern.
Returns
Returns true if the learned pattern is successfully retrieved and stored in the provided buffer. Returns false if there is an error during the retrieval process, such as an invalid buffer, insufficient buffer size, or a problem communicating with the sensor.

Definition at line 211 of file SensorBHI260AP_Klio.cpp.

Referenced by learning_event_callback().

◆ getMaxPatterns()

uint8_t SensorBHI260AP_Klio::getMaxPatterns ( )

Retrieve the maximum number of recognition patterns allowed.

This function is used to obtain the maximum number of recognition patterns that the system or device can support. It provides an important parameter for operations related to pattern recognition, such as determining how many different patterns can be learned and stored for subsequent recognition tasks.

Returns
The maximum number of recognition patterns allowed, represented as an 8 - bit unsigned integer.

Definition at line 216 of file SensorBHI260AP_Klio.cpp.

Referenced by setup().

◆ getParameter()

bool SensorBHI260AP_Klio::getParameter ( KlioParameter  id,
uint8_t *  parameter_data,
uint16_t *  size 
)

Get a parameter from the KLIO sensor.

Parameters
idThe ID of the parameter to be retrieved.
parameter_dataA pointer to the buffer where the parameter data will be stored.
sizeA pointer to the variable that stores the size of the parameter data. On input, it should be the size of the buffer. On output, it will be the actual size of the retrieved data.
Returns
Returns true if the parameter is retrieved successfully, otherwise false.

Definition at line 266 of file SensorBHI260AP_Klio.cpp.

Referenced by begin().

◆ getState()

SensorBHI260AP_Klio::KlioState SensorBHI260AP_Klio::getState ( )

Get the current state of the KLIO sensor.

Returns
Returns a KlioState object containing the current learning and recognition state information.

Definition at line 172 of file SensorBHI260AP_Klio.cpp.

References SENSORLIB_LOG_E.

Referenced by learning(), and recognition().

◆ learning()

bool SensorBHI260AP_Klio::learning ( )

Start the learning function of the KLIO sensor.

Returns
Returns true if the learning function is started successfully, otherwise false.

Definition at line 192 of file SensorBHI260AP_Klio.cpp.

References getState(), and setState().

Referenced by setup().

◆ logout()

bool SensorBHI260AP_Klio::logout ( float  sample_rate,
uint32_t  report_latency_ms 
)

Log out the KLIO sensor with specified sample rate and report latency.

Parameters
sample_rateThe sample rate of the sensor.
report_latency_msThe report latency in milliseconds.
Returns
Returns true if the logout operation is successful, otherwise false.

Definition at line 325 of file SensorBHI260AP_Klio.cpp.

References SENSORLIB_LOG_E.

◆ readPattern()

bool SensorBHI260AP_Klio::readPattern ( uint8_t  idx,
uint8_t *  buffer,
uint16_t *  length 
)

Read a pattern from the KLIO sensor.

Parameters
idxThe index of the pattern to be read.
bufferA pointer to the buffer where the pattern data will be stored.
lengthA pointer to the variable that stores the size of the buffer. On input, it should be the size of the buffer. On output, it will be the actual size of the read data.
Returns
Returns true if the pattern is read successfully, otherwise false.

Definition at line 302 of file SensorBHI260AP_Klio.cpp.

◆ recognition()

bool SensorBHI260AP_Klio::recognition ( const uint8_t *  pattern_ids,
size_t  size 
)

Start the recognition function of the KLIO sensor for the specified pattern IDs.

Parameters
pattern_idsAn array containing the pattern IDs to be recognized.
sizeThe number of elements in the pattern_ids array.
Returns
Returns true if the recognition function is started successfully, otherwise false.

Definition at line 199 of file SensorBHI260AP_Klio.cpp.

References getState(), SENSORLIB_LOG_E, and setState().

Referenced by beginRecognition(), learning_event_callback(), and setup().

◆ setLearningCallback()

void SensorBHI260AP_Klio::setLearningCallback ( LearningCallback  cb,
void *  user_data 
)

Set the callback function for the learning event.

Parameters
cbA pointer to the callback function to be set.
user_dataA pointer to user - defined data to be passed to the callback function.

Definition at line 334 of file SensorBHI260AP_Klio.cpp.

Referenced by setup().

◆ setParameter()

bool SensorBHI260AP_Klio::setParameter ( KlioParameter  id,
const void *  parameter_data,
uint16_t  size 
)

Set a parameter of the KLIO sensor.

Parameters
idThe ID of the parameter to be set.
parameter_dataA pointer to the data to be set as the parameter.
sizeThe size of the parameter data.
Returns
Returns true if the parameter is set successfully, otherwise false.

Definition at line 271 of file SensorBHI260AP_Klio.cpp.

Referenced by begin().

◆ setPattern()

bool SensorBHI260AP_Klio::setPattern ( KlioPatternState  operation,
const uint8_t *  pattern_ids,
uint16_t  size 
)

Set the state of patterns in the KLIO sensor.

Parameters
operationThe operation to be performed on the patterns (e.g., enable, disable).
pattern_idsAn array containing the IDs of the patterns to be operated on.
sizeThe number of elements in the pattern_ids array.
Returns
Returns true if the pattern state is set successfully, otherwise false.

Definition at line 292 of file SensorBHI260AP_Klio.cpp.

◆ setRecognitionCallback()

void SensorBHI260AP_Klio::setRecognitionCallback ( RecognitionCallback  cb,
void *  user_data 
)

Set the callback function for the recognition event.

Parameters
cbA pointer to the callback function to be set.
user_dataA pointer to user - defined data to be passed to the callback function.

Definition at line 340 of file SensorBHI260AP_Klio.cpp.

Referenced by setup().

◆ setState() [1/2]

bool SensorBHI260AP_Klio::setState ( bool  learning_enable,
bool  learning_reset,
bool  recognition_enable,
bool  recognition_reset 
)

Set the learning and recognition states of the KLIO sensor.

Parameters
learning_enableWhether to enable the learning function. true for enable, false for disable.
learning_resetWhether to reset the learning state. true for reset, false for not reset.
recognition_enableWhether to enable the recognition function. true for enable, false for disable.
recognition_resetWhether to reset the recognition state. true for reset, false for not reset.
Returns
Returns true if the setting is successful, otherwise false.

Definition at line 160 of file SensorBHI260AP_Klio.cpp.

Referenced by learning(), and recognition().

◆ setState() [2/2]

bool SensorBHI260AP_Klio::setState ( KlioState  sensor_state)

Set the state of the KLIO sensor using a KlioState object.

Parameters
sensor_stateA KlioState object containing learning and recognition state information.
Returns
Returns true if the setting is successful, otherwise false.

Definition at line 183 of file SensorBHI260AP_Klio.cpp.

References SENSORLIB_LOG_E.

◆ writeMultiplePatterns()

bool SensorBHI260AP_Klio::writeMultiplePatterns ( const uint8_t *  ids,
const uint8_t **  parameter_data_array,
const uint16_t *  sizes,
uint8_t  count 
)

Write multiple patterns to the KLIO sensor.

Parameters
idsAn array containing the indices of the patterns to be written.
parameter_data_arrayAn array of pointers to the pattern data arrays.
sizesAn array containing the sizes of the pattern data arrays.
countThe number of patterns to be written.
Returns
Returns true if all patterns are written successfully, otherwise false.

Definition at line 281 of file SensorBHI260AP_Klio.cpp.

References i, and SENSORLIB_LOG_D.

Referenced by beginRecognition().

◆ writePattern()

bool SensorBHI260AP_Klio::writePattern ( uint8_t  idx,
const uint8_t *  parameter_data,
uint16_t  size 
)

Write a pattern to the KLIO sensor.

Parameters
idxThe index of the pattern to be written.
parameter_dataA pointer to the pattern data.
sizeThe size of the pattern data.
Returns
Returns true if the pattern is written successfully, otherwise false.

Definition at line 276 of file SensorBHI260AP_Klio.cpp.

Referenced by learning_event_callback(), and setup().

Member Data Documentation

◆ INVALID_LEARNING_INDEX

constexpr int8_t SensorBHI260AP_Klio::INVALID_LEARNING_INDEX = -1
staticconstexpr

Definition at line 42 of file sensor/imu/bhi260/SensorBHI260AP_Klio.hpp.

Referenced by learning_event_callback().


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