aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-09-29 17:31:10 -0600
committerSelene ToyKeeper2017-09-29 17:31:10 -0600
commit976c5724bf0a3ddbe6d4b385841a0a5bf38f4b25 (patch)
treed2883141aa81fbcd9c9b3d554034820d9e5c25d5 /spaghetti-monster
parentMake sure hold-from-off ramps up, not down. (diff)
downloadanduril-976c5724bf0a3ddbe6d4b385841a0a5bf38f4b25.tar.gz
anduril-976c5724bf0a3ddbe6d4b385841a0a5bf38f4b25.tar.bz2
anduril-976c5724bf0a3ddbe6d4b385841a0a5bf38f4b25.zip
Added option to start at memorized level, for momentary use on dual-switch lights.
Renamed WL versions of eeprom functions, for naming consistency.
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/anduril/anduril.c46
-rw-r--r--spaghetti-monster/fsm-eeprom.c4
-rw-r--r--spaghetti-monster/fsm-eeprom.h4
3 files changed, 49 insertions, 5 deletions
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c
index 89712fe..84cc27c 100644
--- a/spaghetti-monster/anduril/anduril.c
+++ b/spaghetti-monster/anduril/anduril.c
@@ -35,6 +35,7 @@
#define GOODNIGHT_TIME 60 // minutes (approximately)
#define GOODNIGHT_LEVEL 24 // ~11 lm
#define USE_REVERSING
+//#define START_AT_MEMORIZED_LEVEL
/********* Configure SpaghettiMonster *********/
#define USE_DELAY_ZERO
@@ -45,6 +46,10 @@
#define MAX_CLICKS 5
#define USE_EEPROM
#define EEPROM_BYTES 12
+#ifdef START_AT_MEMORIZED_LEVEL
+#define USE_EEPROM_WL
+#define EEPROM_WL_BYTES 1
+#endif
#define USE_IDLE_MODE
#define USE_DYNAMIC_UNDERCLOCKING // cut clock speed at very low modes for better efficiency
#include "spaghetti-monster.h"
@@ -90,6 +95,9 @@ void blink_confirm(uint8_t num);
// remember stuff even after battery was changed
void load_config();
void save_config();
+#ifdef START_AT_MEMORIZED_LEVEL
+void save_config_wl();
+#endif
// brightness control
uint8_t memorized_level = MAX_1x7135;
@@ -280,6 +288,9 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
ramp_style ^= 1;
memorized_level = nearest_level(memorized_level);
save_config();
+ #ifdef START_AT_MEMORIZED_LEVEL
+ save_config_wl();
+ #endif
set_level(0);
delay_4ms(20/4);
set_level(memorized_level);
@@ -335,10 +346,16 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
set_level(memorized_level);
return MISCHIEF_MANAGED;
}
- #ifdef USE_REVERSING
+ #if defined(USE_REVERSING) || defined(START_AT_MEMORIZED_LEVEL)
// reverse ramp direction on hold release
else if (event == EV_click1_hold_release) {
+ #ifdef USE_REVERSING
ramp_direction = -ramp_direction;
+ #endif
+ #ifdef START_AT_MEMORIZED_LEVEL
+ save_config_wl();
+ #endif
+ return MISCHIEF_MANAGED;
}
#endif
// click, hold: change brightness (dimmer)
@@ -378,6 +395,13 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
set_level(memorized_level);
return MISCHIEF_MANAGED;
}
+ #ifdef START_AT_MEMORIZED_LEVEL
+ // click, release, hold, release: save new ramp level (if necessary)
+ else if (event == EV_click2_hold_release) {
+ save_config_wl();
+ return MISCHIEF_MANAGED;
+ }
+ #endif
#if defined(USE_SET_LEVEL_GRADUALLY) || defined(USE_REVERSING)
else if (event == EV_tick) {
#ifdef USE_SET_LEVEL_GRADUALLY
@@ -960,6 +984,11 @@ void load_config() {
therm_ceil = eeprom[11];
#endif
}
+ #ifdef START_AT_MEMORIZED_LEVEL
+ if (load_eeprom_wl()) {
+ memorized_level = eeprom_wl[0];
+ }
+ #endif
}
void save_config() {
@@ -981,6 +1010,12 @@ void save_config() {
save_eeprom();
}
+#ifdef START_AT_MEMORIZED_LEVEL
+void save_config_wl() {
+ eeprom_wl[0] = memorized_level;
+ save_eeprom_wl();
+}
+#endif
void low_voltage() {
// "step down" from strobe to something low
@@ -1004,6 +1039,14 @@ void low_voltage() {
void setup() {
+ #ifdef START_AT_MEMORIZED_LEVEL
+ // dual switch: e-switch + power clicky
+ // power clicky acts as a momentary mode
+ load_config();
+ push_state(steady_state, memorized_level);
+
+ #else
+
// blink at power-on to let user know power is connected
set_level(RAMP_SIZE/8);
delay_4ms(3);
@@ -1012,6 +1055,7 @@ void setup() {
load_config();
push_state(off_state, 0);
+ #endif
}
diff --git a/spaghetti-monster/fsm-eeprom.c b/spaghetti-monster/fsm-eeprom.c
index e464785..45cd3fa 100644
--- a/spaghetti-monster/fsm-eeprom.c
+++ b/spaghetti-monster/fsm-eeprom.c
@@ -55,7 +55,7 @@ void save_eeprom() {
uint8_t eeprom_wl[EEPROM_WL_BYTES];
EEP_OFFSET_T eep_wl_prev_offset;
-uint8_t load_wl_eeprom() {
+uint8_t load_eeprom_wl() {
cli();
// check if eeprom has been initialized; abort if it hasn't
uint8_t found = 0;
@@ -80,7 +80,7 @@ uint8_t load_wl_eeprom() {
return found;
}
-void save_wl_eeprom() {
+void save_eeprom_wl() {
cli();
// erase old state
EEP_OFFSET_T offset = eep_wl_prev_offset;
diff --git a/spaghetti-monster/fsm-eeprom.h b/spaghetti-monster/fsm-eeprom.h
index c35c822..b6e1aea 100644
--- a/spaghetti-monster/fsm-eeprom.h
+++ b/spaghetti-monster/fsm-eeprom.h
@@ -47,8 +47,8 @@ void save_eeprom();
#error Requested EEPROM_WL_BYTES too big.
#endif
uint8_t eeprom_wl[EEPROM_WL_BYTES];
-uint8_t load_wl_eeprom(); // returns 1 for success, 0 for no data found
-void save_wl_eeprom();
+uint8_t load_eeprom_wl(); // returns 1 for success, 0 for no data found
+void save_eeprom_wl();
#define EEP_WL_SIZE (EEPSIZE/2)
#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.