From 1abff035cb4711591e460c62819ce978ac88a9e3 Mon Sep 17 00:00:00 2001 From: rbaron Date: Sat, 12 Feb 2022 18:37:43 +0100 Subject: [PATCH] Adds PRST_BLINK_LED config to save battery --- code/b-parasite/config/prst_config.h | 3 +++ code/b-parasite/src/main.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/code/b-parasite/config/prst_config.h b/code/b-parasite/config/prst_config.h index b41c38e..895e11d 100644 --- a/code/b-parasite/config/prst_config.h +++ b/code/b-parasite/config/prst_config.h @@ -11,6 +11,9 @@ #define PRST_VERSION_1_2_X // Built-in LED. +// Wether or not to turn the LED on/off during the wake-up cycle. Impacts +// battery life. +#define PRST_BLINK_LED 0 #define PRST_LED_PIN NRF_GPIO_PIN_MAP(0, 28) // Deep sleep. diff --git a/code/b-parasite/src/main.c b/code/b-parasite/src/main.c index 821da77..6140a88 100644 --- a/code/b-parasite/src/main.c +++ b/code/b-parasite/src/main.c @@ -56,7 +56,9 @@ static void power_manage(void) { // - Turn on BLE advertising for a while; // - Turn everything off and return back to sleep. static void rtc_callback() { +#if PRST_BLINK_LED nrf_gpio_pin_set(PRST_LED_PIN); +#endif prst_shtc3_read_t temp_humi = prst_shtc3_read(); nrf_gpio_pin_set(PRST_FAST_DISCH_PIN); prst_pwm_init(); @@ -81,7 +83,9 @@ static void rtc_callback() { prst_adv_start(); nrf_delay_ms(PRST_BLE_ADV_TIME_IN_MS); prst_adv_stop(); +#if PRST_BLINK_LED nrf_gpio_pin_clear(PRST_LED_PIN); +#endif NRF_LOG_FLUSH(); run_counter++; } @@ -94,6 +98,11 @@ int main(void) { prst_adc_init(); prst_shtc3_init(); + // Quick LED flash. + nrf_gpio_pin_set(PRST_LED_PIN); + nrf_delay_ms(200); + nrf_gpio_pin_clear(PRST_LED_PIN); + // Set up RTC. It will call our custom callback at a regular interval, defined // by PRST_DEEP_SLEEP_IN_SECONDS. prst_rtc_set_callback(rtc_callback);