aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-08-27 20:25:00 -0600
committerSelene ToyKeeper2017-08-27 20:25:00 -0600
commit916c212ce6c8abdcedf11cbea8c1ab1d58609969 (patch)
treecfadc6458f0ad5209f9cfd8f2511bfd1745bc20f /spaghetti-monster
parentMade ramp config mode significantly easier to use. (diff)
downloadanduril-916c212ce6c8abdcedf11cbea8c1ab1d58609969.tar.gz
anduril-916c212ce6c8abdcedf11cbea8c1ab1d58609969.tar.bz2
anduril-916c212ce6c8abdcedf11cbea8c1ab1d58609969.zip
Now remembers ramp and strobe settings after battery change.
Also, set new defaults for ramping: - ~50% power maximum - 0.3 lm min for smooth ramping, 10 lm min for discrete ramping
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/anduril.c65
-rw-r--r--spaghetti-monster/anduril.txt2
2 files changed, 48 insertions, 19 deletions
diff --git a/spaghetti-monster/anduril.c b/spaghetti-monster/anduril.c
index 0b4241d..fc6805c 100644
--- a/spaghetti-monster/anduril.c
+++ b/spaghetti-monster/anduril.c
@@ -30,6 +30,8 @@
#define BATTCHECK_VpT
#define RAMP_LENGTH 150
#define MAX_CLICKS 6
+#define USE_EEPROM
+#define EEPROM_BYTES 8
#include "spaghetti-monster.h"
// FSM states
@@ -50,15 +52,18 @@ volatile uint8_t number_entry_value;
void blink_confirm(uint8_t num);
+void load_config();
+void save_config();
+
// brightness control
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 = 1;
-volatile uint8_t ramp_smooth_ceil = MAX_LEVEL;
-volatile uint8_t ramp_discrete_floor = 20;
-volatile uint8_t ramp_discrete_ceil = MAX_LEVEL - 50;
-volatile uint8_t ramp_discrete_steps = 3;
+volatile uint8_t ramp_smooth_ceil = MAX_LEVEL - 30;
+volatile uint8_t ramp_discrete_floor = 15;
+volatile uint8_t ramp_discrete_ceil = MAX_LEVEL - 30;
+volatile uint8_t ramp_discrete_steps = 5;
uint8_t ramp_discrete_step_size; // don't set this
// calculate the nearest ramp level which would be valid at the moment
@@ -208,7 +213,7 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
else if (event == EV_3clicks) {
ramp_style ^= 1;
memorized_level = nearest_level(memorized_level);
- //save_config();
+ save_config();
set_level(0);
delay_4ms(20/4);
set_level(memorized_level);
@@ -299,11 +304,7 @@ uint8_t strobe_state(EventPtr event, uint16_t arg) {
// 2 clicks: toggle party strobe vs tactical strobe
else if (event == EV_2clicks) {
strobe_type ^= 1;
- return MISCHIEF_MANAGED;
- }
- // 3 clicks: go back to regular modes
- else if (event == EV_3clicks) {
- set_state(steady_state, memorized_level);
+ save_config();
return MISCHIEF_MANAGED;
}
// hold: change speed (go faster)
@@ -320,6 +321,12 @@ uint8_t strobe_state(EventPtr event, uint16_t arg) {
}
return MISCHIEF_MANAGED;
}
+ // release hold: save new strobe speed
+ else if ((event == EV_click1_hold_release)
+ || (event == EV_click2_hold_release)) {
+ save_config();
+ return MISCHIEF_MANAGED;
+ }
return EVENT_NOT_HANDLED;
}
@@ -423,7 +430,7 @@ uint8_t ramp_config_mode(EventPtr event, uint16_t arg) {
push_state(number_entry_state, config_step + 1);
}
else {
- // TODO: save_config();
+ save_config();
// TODO: blink out some sort of success pattern
// return to steady mode
set_state(steady_state, memorized_level);
@@ -462,13 +469,6 @@ uint8_t ramp_config_mode(EventPtr event, uint16_t arg) {
}
#endif
config_step ++;
- /* handled at next EV_tick
- if (config_step > num_config_steps) {
- // TODO: save_config();
- // exit config mode
- set_state(steady_state, memorized_level);
- }
- */
return MISCHIEF_MANAGED;
}
return EVENT_NOT_HANDLED;
@@ -602,6 +602,33 @@ void blink_confirm(uint8_t num) {
}
+void load_config() {
+ if (load_eeprom()) {
+ ramp_style = eeprom[0];
+ ramp_smooth_floor = eeprom[1];
+ ramp_smooth_ceil = eeprom[2];
+ ramp_discrete_floor = eeprom[3];
+ ramp_discrete_ceil = eeprom[4];
+ ramp_discrete_steps = eeprom[5];
+ strobe_type = eeprom[6];
+ strobe_delay = eeprom[7];
+ }
+}
+
+void save_config() {
+ eeprom[0] = ramp_style;
+ eeprom[1] = ramp_smooth_floor;
+ eeprom[2] = ramp_smooth_ceil;
+ eeprom[3] = ramp_discrete_floor;
+ eeprom[4] = ramp_discrete_ceil;
+ eeprom[5] = ramp_discrete_steps;
+ eeprom[6] = strobe_type;
+ eeprom[7] = strobe_delay;
+
+ save_eeprom();
+}
+
+
void low_voltage() {
// "step down" from strobe to something low
if (current_state == strobe_state) {
@@ -628,6 +655,8 @@ void setup() {
delay_4ms(3);
set_level(0);
+ load_config();
+
push_state(off_state, 0);
}
diff --git a/spaghetti-monster/anduril.txt b/spaghetti-monster/anduril.txt
index 97f13fa..28d27f9 100644
--- a/spaghetti-monster/anduril.txt
+++ b/spaghetti-monster/anduril.txt
@@ -62,6 +62,6 @@ Momentary mode:
* To exit, disconnect power. (loosen/tighten the tailcap)
TODO:
- - save settings in eeprom
+ * save settings in eeprom
- a way to blink out the firmware version?
- a way to configure indicator LED behavior?
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.