Skip to content

Commit

Permalink
Update sample print format
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Feb 10, 2025
1 parent f0102d4 commit 103476e
Show file tree
Hide file tree
Showing 39 changed files with 418 additions and 139 deletions.
3 changes: 2 additions & 1 deletion examples/AW9364_LedDriver/AW9364_LedDriver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void setup()
void loop()
{
// 16 dimming levels
Serial.printf("level:%u\n", level);
Serial.print("level:");
Serial.println(level);
ledDriver.setBrightness(level);
level++;
level %= MAX_BRIGHTNESS_STEPS;
Expand Down
46 changes: 39 additions & 7 deletions examples/BHI260AP_6DoF/BHI260AP_6DoF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,24 @@ void xyz_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, ui
float scaling_factor = bhy.getScaling(sensor_id);
bhy2_parse_xyz(data_ptr, &data);
Serial.print(bhy.getSensorName(sensor_id));
Serial.print(":");
Serial.printf("x: %f, y: %f, z: %f;\r\n",
data.x * scaling_factor,
data.y * scaling_factor,
data.z * scaling_factor);
Serial.print(" ");
Serial.print("x: ");
Serial.print(data.x * scaling_factor);
Serial.print(", y: ");
Serial.print(data.y * scaling_factor);
Serial.print(", z: ");
Serial.print(data.z * scaling_factor);
Serial.println(";");
}
#endif

// Firmware update progress callback
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
Serial.print("Upload progress: ");
Serial.print(progress);
Serial.println("%");
}


Expand Down Expand Up @@ -210,7 +215,11 @@ void setup()

// Output all sensors info to Serial
BoschSensorInfo info = bhy.getSensorInfo();
#ifdef PLATFORM_HAS_PRINTF
info.printInfo(Serial);
#else
info.printInfo();
#endif

float sample_rate = 100.0; /* Read out data measured at 100Hz */
uint32_t report_latency_ms = 0; /* Report immediately */
Expand Down Expand Up @@ -249,11 +258,34 @@ void loop()
uint32_t s;
uint32_t ns;
accel.getLastTime(s, ns);

#ifdef PLATFORM_HAS_PRINTF
Serial.printf("[T: %" PRIu32 ".%09" PRIu32 "] AX:%+7.2f AY:%+7.2f AZ:%+7.2f GX:%+7.2f GY:%+7.2f GZ:%+7.2f \n",
s, ns, accel.getX(), accel.getY(), accel.getZ(),
gyro.getX(), gyro.getY(), gyro.getZ());
}

#else
Serial.print("[T: ");
Serial.print(s);
Serial.print(".");
Serial.print(ns);
Serial.print("] AX:");
Serial.print(accel.getX(), 2);
Serial.print(" AY:");
Serial.print(accel.getY(), 2);
Serial.print(" AZ:");
Serial.print(accel.getZ(), 2);
Serial.print(" GX:");
Serial.print(gyro.getX(), 2);
Serial.print(" GY:");
Serial.print(gyro.getY(), 2);
Serial.print(" GZ:");
Serial.print(gyro.getZ(), 2);
Serial.println();
#endif

}
#endif /*USING_DATA_HELPER*/
delay(50);
}

Expand Down
9 changes: 7 additions & 2 deletions examples/BHI260AP_Activity/BHI260AP_Activity.ino
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ void dataReadyISR()
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
Serial.print("Upload progress: ");
Serial.print(progress);
Serial.println("%");
}

void setup()
Expand Down Expand Up @@ -184,8 +186,11 @@ void setup()

// Output all sensors info to Serial
BoschSensorInfo info = bhy.getSensorInfo();
#ifdef PLATFORM_HAS_PRINTF
info.printInfo(Serial);

#else
info.printInfo();
#endif

float sample_rate = 1.0;
uint32_t report_latency_ms = 0;
Expand Down
9 changes: 7 additions & 2 deletions examples/BHI260AP_Euler/BHI260AP_Euler.ino
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ void dataReadyISR()
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
Serial.print("Upload progress: ");
Serial.print(progress);
Serial.println("%");
}

/**
Expand Down Expand Up @@ -229,8 +231,11 @@ void setup()

// Output all sensors info to Serial
BoschSensorInfo info = bhy.getSensorInfo();
#ifdef PLATFORM_HAS_PRINTF
info.printInfo(Serial);

#else
info.printInfo();
#endif

/**
* @brief Set the axis remapping for the sensor based on the specified orientation.
Expand Down
13 changes: 9 additions & 4 deletions examples/BHI260AP_Expand_GPIO/BHI260AP_Expand_GPIO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ void dataReadyISR()
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
Serial.print("Upload progress: ");
Serial.print(progress);
Serial.println("%");
}

void setup()
Expand Down Expand Up @@ -186,7 +188,11 @@ void setup()

// Output all sensors info to Serial
BoschSensorInfo info = bhy.getSensorInfo();
#ifdef PLATFORM_HAS_PRINTF
info.printInfo(Serial);
#else
info.printInfo();
#endif

initialiseCommander();

Expand Down Expand Up @@ -273,7 +279,6 @@ bool setGpioLevel(Commander &Cmdr)
}
uint8_t pin = values[0];
uint8_t level = values[1];
// Serial.printf("Set GPIO : %u to %u\n", pin, level);
bhy.digitalWrite(pin, level);
return 0;
}
Expand All @@ -295,7 +300,8 @@ bool getGpioLevel(Commander &Cmdr)
pullup = values[1];
}
uint8_t level = bhy.digitalRead(pin, pullup);
Serial.printf("Get GPIO : %u level is %u\n", pin, level);
Serial.print("Get GPIO : "); Serial.print(pin);
Serial.print(" level is "); Serial.println(level);
return 0;
}

Expand All @@ -308,7 +314,6 @@ bool disGpioMode(Commander &Cmdr)
}
Cmdr.getInt(values[0]);
uint8_t pin = values[0];
// Serial.printf("Disable GPIO : %u\n", pin);
bhy.disableGpio(pin);
return 0;
}
18 changes: 14 additions & 4 deletions examples/BHI260AP_Klio_Recognition/BHI260AP_Klio_Recognition.ino
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ void dataReadyISR()
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
Serial.print("Upload progress: ");
Serial.print(progress);
Serial.println("%");
}

void setup()
Expand Down Expand Up @@ -192,8 +194,11 @@ void setup()

// Output all sensors info to Serial
BoschSensorInfo info = bhy.getSensorInfo();
#ifdef PLATFORM_HAS_PRINTF
info.printInfo(Serial);

#else
info.printInfo();
#endif

// Attempt to initialize the KLIO sensor.
if (!klio.begin()) {
Expand All @@ -206,7 +211,8 @@ void setup()
// Call the getMaxPatterns() method of the klio object to get the maximum number of patterns allowed by the KLIO sensor.
// This method returns a value of type uint8_t representing the maximum number of patterns and stores it in the variable max_patterns.
uint8_t max_patterns = klio.getMaxPatterns();
Serial.printf("Klio sensor max patterns:%u\n", max_patterns);
Serial.print("Klio sensor max patterns:");
Serial.println(max_patterns);

// Set the callback function for the recognition event of the KLIO sensor.
// The callback function takes a pattern ID, a count value, and a pointer to user data as parameters.
Expand All @@ -215,7 +221,11 @@ void setup()
// The user data pointer setting can be set to nullptr, or custom data can be passed in.
// If the recognition action is successful, the pointer is passed to the callback function
klio.setRecognitionCallback([](uint8_t pattern_id, float count, void *user_data) {
Serial.printf("<-Recognition[Id:%d Count:%f]\n", pattern_id, count);
Serial.print("<-Recognition[Id:");
Serial.print(pattern_id);
Serial.print(" Count:");
Serial.print(count);
Serial.print("]");
}, nullptr);

// Try to write a pattern to the KLIO sensor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ void dataReadyISR()
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
Serial.print("Upload progress: ");
Serial.print(progress);
Serial.println("%");
}

/**
Expand All @@ -183,7 +185,11 @@ void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
*/
void recognition_event_callback(uint8_t pattern_id, float count, void *user_data)
{
Serial.printf("<-Recognition[Id:%d Count:%f]\n", pattern_id, count);
Serial.print("<-Recognition[Id:");
Serial.print(pattern_id);
Serial.print(" Count:");
Serial.print(count);
Serial.print("]");

// When the recognition counter is greater than 10 times, reset the recognition counter
if (count > 10) {
Expand Down Expand Up @@ -294,7 +300,11 @@ void setup()

// Output all sensors info to Serial
BoschSensorInfo info = bhy.getSensorInfo();
#ifdef PLATFORM_HAS_PRINTF
info.printInfo(Serial);
#else
info.printInfo();
#endif

// Try to initialize the KLIO sensor.
if (!klio.begin()) {
Expand Down
40 changes: 28 additions & 12 deletions examples/BHI260AP_Klio_Selflearning/BHI260AP_Klio_Selflearning.ino
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ void dataReadyISR()
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
Serial.print("Upload progress: ");
Serial.print(progress);
Serial.println("%");
}

/**
Expand All @@ -133,7 +135,11 @@ void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
*/
void recognition_event_callback(uint8_t pattern_id, float count, void *user_data)
{
Serial.printf("<-Recognition[Id:%d Count:%f]\n", pattern_id, count);
Serial.print("<-Recognition[Id:");
Serial.print(pattern_id);
Serial.print(" Count:");
Serial.print(count);
Serial.print("]");
}

/**
Expand All @@ -155,7 +161,13 @@ void recognition_event_callback(uint8_t pattern_id, float count, void *user_data
void learning_event_callback(SensorBHI260AP_Klio::LeaningChangeReason reason, uint32_t progress, int learn_index, void *user_data)
{
// Print the learning event details to the serial monitor, including the progress, reason, and learned pattern index.
Serial.printf("->Learning [Progress:%u Reason:%u ID:%d]\n", progress, static_cast<uint8_t>(reason), learn_index);
Serial.print("->Learning [Progress:");
Serial.print(progress);
Serial.print(" Reason:");
Serial.print(static_cast<uint8_t>(reason));
Serial.print(" ID:");
Serial.print(learn_index);
Serial.println("]");

// Check if the learning index is valid (not equal to INVALID_LEARNING_INDEX).
if (learn_index != SensorBHI260AP_Klio::INVALID_LEARNING_INDEX) {
Expand All @@ -173,22 +185,22 @@ void learning_event_callback(SensorBHI260AP_Klio::LeaningChangeReason reason, ui
Serial.println(klio.errorToString());
} else {
// If the retrieval is successful, print a success message and the details of the learned pattern.
Serial.printf("Learning the action successfully\n");
Serial.printf("PATTERN LEARNT: \n");
Serial.print("const uint8_t * learn_pattern = { \n");
Serial.println("Learning the action successfully");
Serial.println("PATTERN LEARNT: ");
Serial.print("const uint8_t * learn_pattern = { ");
// Iterate through the buffer and print the pattern data in hexadecimal format.
for (uint16_t i = 0; i < bufsize; i++) {
if (i > 0 && i % 8 == 0) {
// Print a new line every 8 bytes for better readability.
Serial.printf("\n");
Serial.println();
}
Serial.printf("0x%02x", tmp_buf[i]);
Serial.print("0x"); Serial.print(tmp_buf[i], HEX);
if (i < bufsize - 1) {
// Add a comma and a space after each byte except the last one.
Serial.printf(", ");
Serial.print(", ");
}
}
Serial.printf(" \n};\n");
Serial.println(" \n};\n");
}
// Print a message indicating that the learned pattern will be written.
Serial.println("Write the learning pattern.");
Expand Down Expand Up @@ -260,8 +272,11 @@ void setup()

// Output all sensors info to Serial
BoschSensorInfo info = bhy.getSensorInfo();
#ifdef PLATFORM_HAS_PRINTF
info.printInfo(Serial);

#else
info.printInfo();
#endif

// Try to initialize the KLIO sensor.
// The begin() method is called on the 'klio' object to set up the sensor.
Expand All @@ -275,7 +290,8 @@ void setup()
// Call the getMaxPatterns() method of the klio object to get the maximum number of patterns allowed by the KLIO sensor.
// This method returns a value of type uint8_t representing the maximum number of patterns and stores it in the variable max_patterns.
uint8_t max_patterns = klio.getMaxPatterns();
Serial.printf("Klio sensor max patterns:%u\n", max_patterns);
Serial.print("Klio sensor max patterns:");
Serial.println(max_patterns);

// Set the callback function for learning events.
// The setLearningCallback() method is used to register a function that will be called
Expand Down
8 changes: 7 additions & 1 deletion examples/BHI260AP_Orientation/BHI260AP_Orientation.ino
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ void dataReadyISR()
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
Serial.print("Upload progress: ");
Serial.print(progress);
Serial.println("%");
}

void print_orientation(uint8_t direction)
Expand Down Expand Up @@ -258,7 +260,11 @@ void setup()

// Output all sensors info to Serial
BoschSensorInfo info = bhy.getSensorInfo();
#ifdef PLATFORM_HAS_PRINTF
info.printInfo(Serial);
#else
info.printInfo();
#endif

// The orientation sensor will only report when it changes, so the value is 0 ~ 1
float sample_rate = 1;
Expand Down
Loading

0 comments on commit 103476e

Please sign in to comment.