aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-09-24 20:54:07 -0600
committerSelene ToyKeeper2017-09-24 20:54:07 -0600
commit520f5cdb983045c5518325f3c3665f59ca85435e (patch)
treedb05070d81d080743555075150e8133c6e5e84dd /spaghetti-monster
parentForgot to include a copy of the GPL before. (diff)
downloadanduril-520f5cdb983045c5518325f3c3665f59ca85435e.tar.gz
anduril-520f5cdb983045c5518325f3c3665f59ca85435e.tar.bz2
anduril-520f5cdb983045c5518325f3c3665f59ca85435e.zip
Added idle_mode() for slightly lower power use without turning off any regular functions.
(PWM, ADC, WDT all still enabled; only useful in moon mode) Changed default ceilings in Anduril FW3A config.
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/anduril/anduril.c17
-rw-r--r--spaghetti-monster/fsm-main.c16
-rw-r--r--spaghetti-monster/fsm-standby.c17
-rw-r--r--spaghetti-monster/fsm-standby.h7
4 files changed, 54 insertions, 3 deletions
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c
index 22f6eb9..d15b5cb 100644
--- a/spaghetti-monster/anduril/anduril.c
+++ b/spaghetti-monster/anduril/anduril.c
@@ -34,6 +34,7 @@
#define MAX_CLICKS 5
#define USE_EEPROM
#define EEPROM_BYTES 12
+#define USE_IDLE_MODE
#include "spaghetti-monster.h"
// Options specific to this UI (not inherited from SpaghettiMonster)
@@ -86,9 +87,14 @@ uint8_t memorized_level = MAX_1x7135;
// smooth vs discrete ramping
volatile uint8_t ramp_style = 0; // 0 = smooth, 1 = discrete
volatile uint8_t ramp_smooth_floor = 5;
+#if PWM_CHANNELS == 3
+volatile uint8_t ramp_smooth_ceil = MAX_Nx7135;
+volatile uint8_t ramp_discrete_ceil = MAX_Nx7135;
+#else
volatile uint8_t ramp_smooth_ceil = MAX_LEVEL - 30;
-volatile uint8_t ramp_discrete_floor = 20;
volatile uint8_t ramp_discrete_ceil = MAX_LEVEL - 30;
+#endif
+volatile uint8_t ramp_discrete_floor = 20;
volatile uint8_t ramp_discrete_steps = 7;
uint8_t ramp_discrete_step_size; // don't set this
@@ -323,6 +329,9 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
if (!(arg & 7)) gradual_tick();
//if (!(arg & 3)) gradual_tick();
//gradual_tick();
+ #ifdef USE_IDLE_MODE
+ // go_to_idle = 1; // use less power when nothing is happening
+ #endif
return MISCHIEF_MANAGED;
}
#endif
@@ -939,6 +948,12 @@ void setup() {
void loop() {
+ #ifdef USE_IDLE_MODE
+ if (current_state == steady_state) {
+ idle_mode();
+ } else
+ #endif
+
if (current_state == strobe_state) {
// party / tactical strobe
if (strobe_type < 2) {
diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c
index d526455..a47a4bf 100644
--- a/spaghetti-monster/fsm-main.c
+++ b/spaghetti-monster/fsm-main.c
@@ -72,8 +72,8 @@ int main() {
PORTB = (1 << SWITCH_PIN); // e-switch is the only input
PCMSK = (1 << SWITCH_PIN); // pin change interrupt uses this pin
- // configure sleep mode
- set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+ //// configure sleep mode
+ //set_sleep_mode(SLEEP_MODE_PWR_DOWN);
// Read config values and saved state
@@ -133,8 +133,20 @@ int main() {
standby_mode();
}
+ #ifdef USE_IDLE_MODE
+ /*
+ // enter idle mode if requested
+ // (works better if deferred like this)
+ if (go_to_idle) {
+ go_to_idle = 0;
+ idle_mode();
+ }
+ */
+ #endif
+
// give the recipe some time slices
loop();
+
}
}
diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c
index 44a2e0a..5312f94 100644
--- a/spaghetti-monster/fsm-standby.c
+++ b/spaghetti-monster/fsm-standby.c
@@ -40,6 +40,9 @@ void sleep_until_eswitch_pressed()
PCINT_on(); // wake on e-switch event
+ // configure sleep mode
+ set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+
sleep_enable();
sleep_bod_disable();
sleep_cpu(); // wait here
@@ -57,4 +60,18 @@ void sleep_until_eswitch_pressed()
WDT_on();
}
+#ifdef USE_IDLE_MODE
+void idle_mode()
+{
+ // configure sleep mode
+ set_sleep_mode(SLEEP_MODE_IDLE);
+
+ sleep_enable();
+ sleep_cpu(); // wait here
+
+ // something happened; wake up
+ sleep_disable();
+}
+#endif
+
#endif
diff --git a/spaghetti-monster/fsm-standby.h b/spaghetti-monster/fsm-standby.h
index a23bd0c..3a917fd 100644
--- a/spaghetti-monster/fsm-standby.h
+++ b/spaghetti-monster/fsm-standby.h
@@ -28,6 +28,13 @@ volatile uint8_t go_to_standby = 0;
#define standby_mode sleep_until_eswitch_pressed
void sleep_until_eswitch_pressed();
+#ifdef USE_IDLE_MODE
+// deferred "idle" state trigger
+// stops processing until next click or timer tick
+//volatile uint8_t go_to_idle = 0;
+void idle_mode();
+#endif
+
// TODO: half-sleep "twilight" mode with WDT on but running slowly
#endif