aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-18 22:51:24 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-18 22:53:05 +0200
commit678dfb7e93f1d613fb9a513d60a685d5e3c1c3b3 (patch)
tree66c68327fa0176d361bd3d1d06b8c5877ec0223d
parenta3c966300ce48b3ba758170238d4a44ba0c7fecb (diff)
downloadtrygvisio_soil_moisture-678dfb7e93f1d613fb9a513d60a685d5e3c1c3b3.tar.gz
trygvisio_soil_moisture-678dfb7e93f1d613fb9a513d60a685d5e3c1c3b3.tar.bz2
trygvisio_soil_moisture-678dfb7e93f1d613fb9a513d60a685d5e3c1c3b3.tar.xz
trygvisio_soil_moisture-678dfb7e93f1d613fb9a513d60a685d5e3c1c3b3.zip
o First round of low power, going low power when sleeping.
-rw-r--r--trygvisio_soil_moisture.ino21
1 files changed, 19 insertions, 2 deletions
diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino
index e524f71..8185754 100644
--- a/trygvisio_soil_moisture.ino
+++ b/trygvisio_soil_moisture.ino
@@ -1,8 +1,8 @@
+#include <LowPower.h>
#include <EEPROM.h>
#include <SPI.h>
#include <lib_aci.h>
#include <aci_setup.h>
-#include <avr/sleep.h>
// See config.h on how to configure the sketch
#include "config.h"
@@ -34,6 +34,16 @@ 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);
+}
+#else
+#warning No sleep support for current CPU architecture.
+static void go_to_sleep() {
+}
+#endif
+
void setup() {
#if defined(BLEND_MICRO_8MHZ)
// As the F_CPU = 8000000UL, the USB core make the PLLCSR = 0x02
@@ -96,7 +106,7 @@ static void setup_rf() {
aci_state.aci_pins.active_pin = UNUSED;
aci_state.aci_pins.optional_chip_sel_pin = UNUSED;
- aci_state.aci_pins.interface_is_interrupt = false; //Interrupts still not available in Chipkit
+ aci_state.aci_pins.interface_is_interrupt = false;
aci_state.aci_pins.interrupt_number = 4;
// We reset the nRF8001 here by toggling the RESET line connected to the nRF8001
@@ -341,6 +351,13 @@ void loop() {
}
sm_loop();
+
+#ifdef SM_DEBUG
+ Serial.println(F("Sleeping..."));
+ Serial.flush();
+#endif // SM_DEBUG
+
+ go_to_sleep();
}
static void show_pipes() {