From a64156388fc92da1d151a1094e25d9d89240bb38 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 25 Jul 2015 06:21:11 +0200 Subject: o Cleaning up #if usage and config.h. --- trygvisio_soil_moisture.ino | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'trygvisio_soil_moisture.ino') diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino index 53936e3..c09f091 100644 --- a/trygvisio_soil_moisture.ino +++ b/trygvisio_soil_moisture.ino @@ -1,3 +1,6 @@ +// See config.h on how to configure the sketch +#include "config-check.h" + #include #include #include @@ -5,8 +8,6 @@ #include #include -// See config.h on how to configure the sketch -#include "config.h" #include "services.h" #include "app.h" #include "Debug.h" @@ -27,7 +28,7 @@ static hal_aci_evt_t aci_data; static boolean timing_change_done = false; void __ble_assert(const char *file, uint16_t line) -{ +{ debug.print("ERROR "); debug.print(file); debug.print(": "); @@ -36,14 +37,12 @@ void __ble_assert(const char *file, uint16_t line) while (1) {}; } -#if defined(__AVR_ATmega32U4__) -static void go_to_sleep() { - LowPower.idle(SLEEP_1S, ADC_OFF, TIMER4_OFF, TIMER3_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART1_OFF, TWI_OFF, USB_OFF); -} +static void go_to_sleep(); + +#ifdef USE_LOW_POWER +static const bool use_low_power=1; #else -#warning No sleep support for current CPU architecture. -static void go_to_sleep() { -} +static const bool use_low_power=0; #endif void setup() { @@ -60,7 +59,7 @@ void setup() { debug.begin((unsigned int)115200); -#if WAIT_FOR_SERIAL_BEFORE_STARING == 1 +#if WAIT_FOR_SERIAL_BEFORE_STARING // Wait until the serial port is available (useful only for the Leonardo) // As the Leonardo board is not reseted every time you open the Serial Monitor #if defined (__AVR_ATmega32U4__) @@ -350,6 +349,17 @@ static void aci_loop() { } } +static void go_to_sleep() { +#ifdef USE_LOW_POWER +#if defined(__AVR_ATmega32U4__) + LowPower.idle(SLEEP_1S, ADC_OFF, TIMER4_OFF, TIMER3_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART1_OFF, TWI_OFF, USB_OFF); +} +#else +# warning No sleep support for current CPU architecture. +#endif +#endif // USE_LOW_POWER +} + static uint8_t value = 0; void loop() { static unsigned long last = 0, now; @@ -392,14 +402,13 @@ void loop() { sm_loop(); -#ifdef USE_LOW_POWER_MODE == 1 -#ifdef SM_DEBUG == 1 - debug.println(F("Sleeping...")); - debug.flush(); + if (use_low_power) { +#ifdef SM_DEBUG + debug.println(F("Sleeping...")); + debug.flush(); #endif // SM_DEBUG - - go_to_sleep(); -#endif // USE_LOW_POWER_MODE + go_to_sleep(); + } } static void show_pipes() { @@ -472,13 +481,13 @@ void notify_soil_moisture(const struct sm_res &res, uint8_t body_len) { return; } -#if SM_DEBUG +#ifdef SM_DEBUG debug.println("write_res"); write_res(res); #endif if (aci_state.data_credit_available == 0) { -#if SM_DEBUG +#ifdef SM_DEBUG debug.println("Not enough credits to send notification."); #endif return; @@ -488,7 +497,7 @@ void notify_soil_moisture(const struct sm_res &res, uint8_t body_len) { if (sent) { aci_state.data_credit_available--; } else { -#if SM_DEBUG +#ifdef SM_DEBUG debug.println("Sending failed"); #endif } -- cgit v1.2.3