diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-25 06:21:11 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-25 19:37:44 +0200 |
commit | a64156388fc92da1d151a1094e25d9d89240bb38 (patch) | |
tree | f65eb7c8b4d7dccb400b67ebc7b82e861ffec13c /trygvisio_soil_moisture.ino | |
parent | 77e261f12089bd7db854d21fc81a42eaa60e0b67 (diff) | |
download | trygvisio_soil_moisture-a64156388fc92da1d151a1094e25d9d89240bb38.tar.gz trygvisio_soil_moisture-a64156388fc92da1d151a1094e25d9d89240bb38.tar.bz2 trygvisio_soil_moisture-a64156388fc92da1d151a1094e25d9d89240bb38.tar.xz trygvisio_soil_moisture-a64156388fc92da1d151a1094e25d9d89240bb38.zip |
o Cleaning up #if usage and config.h.
Diffstat (limited to 'trygvisio_soil_moisture.ino')
-rw-r--r-- | trygvisio_soil_moisture.ino | 51 |
1 files changed, 30 insertions, 21 deletions
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 <LowPower.h> #include <EEPROM.h> #include <SPI.h> @@ -5,8 +8,6 @@ #include <aci_setup.h> #include <aci_evts.h> -// 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 } |