From 7f29dab8b36fecf7a0e9e39ff14bf6caf5aeb532 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 13 Apr 2017 18:33:21 +0700 Subject: [PATCH] update sketches --- .../examples/Peripheral/bleuart/bleuart.ino | 26 +++++++++++++---- .../Peripheral/custom_hrm/custom_hrm.ino | 28 ++++++++++++++----- .../Peripheral/hid_keyboard/hid_keyboard.ino | 24 ++++++++++++---- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino index 398f22b4..9bf7f277 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bleuart/bleuart.ino @@ -28,7 +28,7 @@ void setup() // Initialize blinkTimer for 1000 ms and start it blinkTimer.begin(1000, blink_timer_callback); - blinkTimer.start(); + //blinkTimer.start(); // Setup the BLE LED to be enabled on CONNECT // Note: This is actually the default behaviour, but provided @@ -134,9 +134,22 @@ void blink_timer_callback(TimerHandle_t xTimerID) * there is no bluetooth or hw event. This is the ideal place to handle * background data. * - * NOTE: After this callback returns, MCU will enter low-power mode - * via waitForEvent() internally. Therefore you SHOULD NOT call - * waitForEvent() in this callback! + * NOTE: It is recommended to call waitForEvent() to put MCU into low-power mode + * at the end of this callback. You could also turn off other Peripherals such as + * Serial/PWM and turn them back on if wanted + * + * e.g + * + * void rtos_idle_callback(void) + * { + * Serial.stop(); // will lose data when sleeping + * waitForEvent(); + * Serial.begin(115200); + * } + * + * NOTE2: If rtos_idle_callback() is not defined at all. Bluefruit will force + * waitForEvent() to save power. If you don't want MCU to sleep at all, define + * an rtos_idle_callback() with empty body ! * * WARNING: This function MUST NOT call any blocking FreeRTOS API * such as delay(), xSemaphoreTake() etc ... for more information @@ -144,9 +157,10 @@ void blink_timer_callback(TimerHandle_t xTimerID) */ void rtos_idle_callback(void) { + // Don't call any other FreeRTOS blocking API() // Perform background task(s) here - // waitForEvent() will be invoked internally when this callback returns. - // Don't call waitForEvent() in this function nor any other blocking API()! + // Request CPU to enter low-power mode until an event/interrupt occurs + waitForEvent(); } diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/custom_hrm/custom_hrm.ino b/libraries/Bluefruit52Lib/examples/Peripheral/custom_hrm/custom_hrm.ino index c7da2160..6032af79 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/custom_hrm/custom_hrm.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/custom_hrm/custom_hrm.ino @@ -206,8 +206,8 @@ void loop() // Only send update once per second delay(1000); - // No need to call waitForEvent() here, it is already invoked - // by above delay() via Idle Task internally. See the note below + // No need to call waitForEvent() here, it will be invoked by + // rtos_idle_callback() caused by above delay() } /** @@ -216,9 +216,22 @@ void loop() * there is no bluetooth or hw event. This is the ideal place to handle * background data. * - * NOTE: After this callback returns, MCU will enter low-power mode - * via waitForEvent() internally. Therefore you SHOULD NOT call - * waitForEvent() in this callback! + * NOTE: It is recommended to call waitForEvent() to put MCU into low-power mode + * at the end of this callback. You could also turn off other Peripherals such as + * Serial/PWM and turn them back on if wanted + * + * e.g + * + * void rtos_idle_callback(void) + * { + * Serial.stop(); // will lose data when sleeping + * waitForEvent(); + * Serial.begin(115200); + * } + * + * NOTE2: If rtos_idle_callback() is not defined at all. Bluefruit will force + * waitForEvent() to save power. If you don't want MCU to sleep at all, define + * an rtos_idle_callback() with empty body ! * * WARNING: This function MUST NOT call any blocking FreeRTOS API * such as delay(), xSemaphoreTake() etc ... for more information @@ -226,8 +239,9 @@ void loop() */ void rtos_idle_callback(void) { + // Don't call any other FreeRTOS blocking API() // Perform background task(s) here - // waitForEvent() will be invoked internally when this callback returns. - // Don't call waitForEvent() in this function nor any other blocking API()! + // Request CPU to enter low-power mode until an event/interrupt occurs + waitForEvent(); } diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/hid_keyboard/hid_keyboard.ino b/libraries/Bluefruit52Lib/examples/Peripheral/hid_keyboard/hid_keyboard.ino index c35e0ab0..e75bec0a 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/hid_keyboard/hid_keyboard.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/hid_keyboard/hid_keyboard.ino @@ -114,9 +114,22 @@ void loop() * there is no bluetooth or hw event. This is the ideal place to handle * background data. * - * NOTE: After this callback returns, MCU will enter low-power mode - * via waitForEvent() internally. Therefore you SHOULD NOT call - * waitForEvent() in this callback! + * NOTE: It is recommended to call waitForEvent() to put MCU into low-power mode + * at the end of this callback. You could also turn off other Peripherals such as + * Serial/PWM and turn them back on if wanted + * + * e.g + * + * void rtos_idle_callback(void) + * { + * Serial.stop(); // will lose data when sleeping + * waitForEvent(); + * Serial.begin(115200); + * } + * + * NOTE2: If rtos_idle_callback() is not defined at all. Bluefruit will force + * waitForEvent() to save power. If you don't want MCU to sleep at all, define + * an rtos_idle_callback() with empty body ! * * WARNING: This function MUST NOT call any blocking FreeRTOS API * such as delay(), xSemaphoreTake() etc ... for more information @@ -124,8 +137,9 @@ void loop() */ void rtos_idle_callback(void) { + // Don't call any other FreeRTOS blocking API() // Perform background task(s) here - // waitForEvent() will be invoked internally when this callback returns. - // Don't call waitForEvent() in this function nor any other blocking API()! + // Request CPU to enter low-power mode until an event/interrupt occurs + waitForEvent(); }