39#if !defined(USE_I2C_INTERFACE) && !defined(USE_SPI_INTERFACE)
40#define USE_I2C_INTERFACE
41#warning "No interface type is selected, use I2C interface"
44#if defined(USE_SPI_INTERFACE)
90#define BOSCH_BHI260_KLIO
104#define USING_SENSOR_IRQ_METHOD
107#ifdef USING_SENSOR_IRQ_METHOD
119 float progress = (float)transferred / total * 100;
120 Serial.print(
"Upload progress: ");
121 Serial.print(progress);
146 Serial.print(
"<-Recognition[Id:");
147 Serial.print(pattern_id);
148 Serial.print(
" Count:");
172 Serial.print(
"->Learning [Progress:");
173 Serial.print(progress);
174 Serial.print(
" Reason:");
175 Serial.print(
static_cast<uint8_t
>(reason));
176 Serial.print(
" ID:");
177 Serial.print(learn_index);
183 uint8_t tmp_buf[252];
185 uint16_t bufsize =
sizeof(tmp_buf);
190 if (!learn_success) {
192 Serial.print(
"Read learnt failed. Reason:");
196 Serial.println(
"Learning the action successfully");
197 Serial.println(
"PATTERN LEARNT: ");
198 Serial.print(
"const uint8_t * learn_pattern = { ");
200 for (uint16_t
i = 0;
i < bufsize;
i++) {
201 if (
i > 0 &&
i % 8 == 0) {
205 Serial.print(
"0x"); Serial.print(tmp_buf[
i], HEX);
206 if (
i < bufsize - 1) {
211 Serial.println(
" \n};\n");
214 Serial.println(
"Write the learning pattern.");
216 uint8_t examples_id = 1;
220 Serial.println(
"Klio write pattern failed!");
223 Serial.println(
"Start recognizing actions");
224 Serial.println(
"Please perform the learned action instructions and the sensor will start to recognize the number of actions.");
232 Serial.begin(115200);
253 Serial.println(
"Initializing Sensors...");
255#ifdef USE_I2C_INTERFACE
260 Serial.print(
"Failed to initialize sensor - error code:");
261 Serial.println(
bhy.getError());
268#ifdef USE_SPI_INTERFACE
271 Serial.print(
"Failed to initialize sensor - error code:");
272 Serial.println(
bhy.getError());
279 Serial.println(
"Initializing the sensor successfully!");
282 BoschSensorInfo info =
bhy.getSensorInfo();
285 ArduinoStreamPrinter printer(Serial);
286 info.printInfo(printer);
288 info.printInfo([](
const char *format, ...) ->
int {
290 va_start(args, format);
291 int result = vprintf(format, args);
301 Serial.println(
"Failed to initialize Klio sensor. Are you currently using a firmware that includes Klio sensor functionality?");
309 Serial.print(
"Klio sensor max patterns:");
310 Serial.println(max_patterns);
332 float sample_rate = 25.0;
337 uint32_t report_latency_ms = 0;
344#ifdef USING_SENSOR_IRQ_METHOD
355 Serial.println(
"Please repeat the movements you want to learn and the sensor will start recording.");
361#ifdef USING_SENSOR_IRQ_METHOD
371#ifdef USING_SENSOR_IRQ_METHOD
volatile bool isInterruptTriggered
SensorBHI260AP_Klio klio(bhy)
void recognition_event_callback(uint8_t pattern_id, float count, void *user_data)
Callback function for handling KLIO sensor recognition events.
void progress_callback(uint32_t total, uint32_t transferred, void *user_data)
bool force_update_flash_firmware
void learning_event_callback(SensorBHI260AP_Klio::LearningChangeReason reason, uint32_t progress, int learn_index, void *user_data)
Callback function for KLIO sensor learning events.
bool getLearnPattern(uint8_t *pattern, uint16_t *size)
Retrieve the learned pattern from the sensor.
void setLearningCallback(LearningCallback cb, void *user_data)
Set the callback function for the learning event.
static constexpr int8_t INVALID_LEARNING_INDEX
bool writePattern(uint8_t idx, const uint8_t *parameter_data, uint16_t size)
Write a pattern to the KLIO sensor.
bool begin()
Initialize the interaction with the KLIO functionality of the BHI260AP sensor.
bool enable(float sample_rate, uint32_t report_latency_ms)
Enable the KLIO sensor with specified sample rate and report latency.
bool learning()
Start the learning function of the KLIO sensor.
uint8_t getMaxPatterns()
Retrieve the maximum number of recognition patterns allowed.
const char * errorToString() const
Convert the error information to a string.
bool recognition(const uint8_t *pattern_ids, size_t size)
Start the recognition function of the KLIO sensor for the specified pattern IDs.
void setRecognitionCallback(RecognitionCallback cb, void *user_data)
Set the callback function for the recognition event.
void setBootFromFlash(bool boot_from_flash)
setBootFromFlash