aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2018-06-17 18:18:38 -0600
committerSelene ToyKeeper2018-06-17 18:18:38 -0600
commitcfedb2eaf4a0d62969ff05307ac40d4f1cdab2d9 (patch)
tree0d4ecd59e65b3152c44e50c9a93e679a260fac5c
parentAdded dual-switch support (tail clicky + e-switch) to muggle mode. (diff)
downloadanduril-cfedb2eaf4a0d62969ff05307ac40d4f1cdab2d9.tar.gz
anduril-cfedb2eaf4a0d62969ff05307ac40d4f1cdab2d9.tar.bz2
anduril-cfedb2eaf4a0d62969ff05307ac40d4f1cdab2d9.zip
Implemented halfsleep mode.
Will probably change it quite a bit though, so I'm checking in changes first. Needs to be "tick during standby" instead of "half sleep".
-rw-r--r--spaghetti-monster/fsm-events.h6
-rw-r--r--spaghetti-monster/fsm-standby.c38
-rw-r--r--spaghetti-monster/fsm-standby.h7
-rw-r--r--spaghetti-monster/fsm-wdt.c17
-rw-r--r--spaghetti-monster/fsm-wdt.h4
5 files changed, 63 insertions, 9 deletions
diff --git a/spaghetti-monster/fsm-events.h b/spaghetti-monster/fsm-events.h
index 2721303..84e9ea2 100644
--- a/spaghetti-monster/fsm-events.h
+++ b/spaghetti-monster/fsm-events.h
@@ -64,6 +64,7 @@ static volatile uint16_t ticks_since_last_event = 0;
#define A_OVERHEATING 9
#define A_UNDERHEATING 10
#define A_VOLTAGE_LOW 11
+#define A_HALFSLEEP_TICK 12
//#define A_VOLTAGE_CRITICAL 12
#define A_DEBUG 255 // test event for debugging
@@ -83,6 +84,11 @@ Event EV_reenter_state[] = {
Event EV_tick[] = {
A_TICK,
0 } ;
+#ifdef USE_HALFSLEEP_MODE
+Event EV_halfsleep_tick[] = {
+ A_HALFSLEEP_TICK,
+ 0 } ;
+#endif
#ifdef USE_LVP
Event EV_voltage_low[] = {
A_VOLTAGE_LOW,
diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c
index b90ccea..8e51dda 100644
--- a/spaghetti-monster/fsm-standby.c
+++ b/spaghetti-monster/fsm-standby.c
@@ -31,7 +31,17 @@
#define standby_mode sleep_until_eswitch_pressed
void sleep_until_eswitch_pressed()
{
+ #ifdef USE_HALFSLEEP_MODE
+ //uint16_t sleep_counter = 0;
+ if (halfsleep_mode) {
+ // set WDT to slow mode
+ wdt_reset();
+ WDTCR |= (1<<WDCE) | (1<<WDE); // Start timed sequence
+ WDTCR = (1<<WDIE) | 5; // Enable interrupt every 0.5s
+ } else
+ #endif
WDT_off();
+
ADC_off();
// make sure switch isn't currently pressed
@@ -41,15 +51,29 @@ void sleep_until_eswitch_pressed()
PCINT_on(); // wake on e-switch event
- // configure sleep mode
- set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+ #ifdef USE_HALFSLEEP_MODE
+ while (halfsleep_mode) {
+ f_wdt = 0; // detect if WDT was what caused a wake-up
+ #endif
+ // configure sleep mode
+ set_sleep_mode(SLEEP_MODE_PWR_DOWN);
- sleep_enable();
- sleep_bod_disable();
- sleep_cpu(); // wait here
+ sleep_enable();
+ sleep_bod_disable();
+ sleep_cpu(); // wait here
- // something happened; wake up
- sleep_disable();
+ // something happened; wake up
+ sleep_disable();
+
+ #ifdef USE_HALFSLEEP_MODE
+ // determine what woke us up... WDT or PCINT
+ if (! f_wdt) { // PCINT went off
+ halfsleep_mode = 0;
+ }
+ #endif
+ #ifdef USE_HALFSLEEP_MODE
+ }
+ #endif
#ifdef USE_THERMAL_REGULATION
// forget what the temperature was last time we were on
diff --git a/spaghetti-monster/fsm-standby.h b/spaghetti-monster/fsm-standby.h
index 0b410fa..bd362a3 100644
--- a/spaghetti-monster/fsm-standby.h
+++ b/spaghetti-monster/fsm-standby.h
@@ -25,6 +25,11 @@
// set this to nonzero to enter standby mode next time the system is idle
volatile uint8_t go_to_standby = 0;
+#ifdef USE_HALFSLEEP_MODE
+// half-sleep "twilight" mode with WDT on but running slowly
+volatile uint8_t halfsleep_mode = 0;
+#endif
+
#define standby_mode sleep_until_eswitch_pressed
void sleep_until_eswitch_pressed();
@@ -34,6 +39,4 @@ void sleep_until_eswitch_pressed();
void idle_mode();
#endif
-// TODO: half-sleep "twilight" mode with WDT on but running slowly
-
#endif
diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c
index ff96ffb..06b0b6d 100644
--- a/spaghetti-monster/fsm-wdt.c
+++ b/spaghetti-monster/fsm-wdt.c
@@ -45,6 +45,23 @@ inline void WDT_off()
// clock tick -- this runs every 16ms (62.5 fps)
ISR(WDT_vect) {
+ #ifdef USE_HALFSLEEP_MODE
+ f_wdt = 1; // WDT event happened
+
+ static uint16_t sleep_counter = 0;
+ // handle halfsleep mode specially
+ if (halfsleep_mode) {
+ // emit a halfsleep tick, and process it
+ emit(EV_halfsleep_tick, sleep_counter);
+ sleep_counter ++;
+ process_emissions();
+ //if (! halfsleep_mode)
+ // sleep_counter = 0;
+ return;
+ }
+ sleep_counter = 0;
+ #endif
+
// detect and emit button change events
uint8_t was_pressed = button_last_state;
uint8_t pressed = button_is_pressed();
diff --git a/spaghetti-monster/fsm-wdt.h b/spaghetti-monster/fsm-wdt.h
index 74851af..1173382 100644
--- a/spaghetti-monster/fsm-wdt.h
+++ b/spaghetti-monster/fsm-wdt.h
@@ -25,4 +25,8 @@
void WDT_on();
inline void WDT_off();
+#ifdef USE_HALFSLEEP_MODE
+volatile uint8_t f_wdt = 0;
+#endif
+
#endif
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.