From 2cbd4b971ec838523faa966335e222a5f484400a Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 4 Jun 2019 18:55:42 -0600 Subject: reduced size by 28 bytes and made code slightly cleaner by moving a common 2-line pattern into its own function (instead of "target_level = x; set_level(x);", it does "set_level_and_therm_target(x);") --- spaghetti-monster/anduril/anduril.c | 67 ++++++++++++------------------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index dffa981..913a857 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -380,6 +380,9 @@ uint8_t nearest_level(int16_t target); #ifdef USE_THERMAL_REGULATION // brightness before thermal step-down uint8_t target_level = 0; +void set_level_and_therm_target(uint8_t level); +#else +#define set_level_and_therm_target(level) set_level(level) #endif // internal numbering for strobe modes @@ -634,10 +637,7 @@ uint8_t steady_state(Event event, uint16_t arg) { memorized_level = arg; // use the requested level even if not memorized arg = nearest_level(arg); - #ifdef USE_THERMAL_REGULATION - target_level = arg; - #endif - set_level(arg); + set_level_and_therm_target(arg); #ifdef USE_REVERSING ramp_direction = 1; #endif @@ -647,18 +647,12 @@ uint8_t steady_state(Event event, uint16_t arg) { // 1 click (early): off, if configured for early response else if (event == EV_click1_release) { level_before_off = actual_level; - #ifdef USE_THERMAL_REGULATION - target_level = 0; - #endif - set_level(0); + set_level_and_therm_target(0); return MISCHIEF_MANAGED; } // 2 clicks (early): abort turning off, if configured for early response else if (event == EV_click2_press) { - #ifdef USE_THERMAL_REGULATION - target_level = level_before_off; - #endif - set_level(level_before_off); + set_level_and_therm_target(level_before_off); return MISCHIEF_MANAGED; } #endif // if (B_TIMING_OFF == B_RELEASE_T) @@ -670,36 +664,24 @@ uint8_t steady_state(Event event, uint16_t arg) { // 2 clicks: go to/from highest level else if (event == EV_2clicks) { if (actual_level < MAX_LEVEL) { - #ifdef USE_THERMAL_REGULATION - target_level = MAX_LEVEL; - #endif // true turbo, not the mode-specific ceiling - set_level(MAX_LEVEL); + set_level_and_therm_target(MAX_LEVEL); } else { - #ifdef USE_THERMAL_REGULATION - target_level = memorized_level; - #endif - set_level(memorized_level); + set_level_and_therm_target(memorized_level); } return MISCHIEF_MANAGED; } // 3 clicks: toggle smooth vs discrete ramping else if (event == EV_3clicks) { ramp_style = !ramp_style; - memorized_level = nearest_level(actual_level); - #ifdef USE_THERMAL_REGULATION - target_level = memorized_level; - #ifdef USE_SET_LEVEL_GRADUALLY - //set_level_gradually(lvl); - #endif - #endif save_config(); #ifdef START_AT_MEMORIZED_LEVEL save_config_wl(); #endif blip(); - set_level(memorized_level); + memorized_level = nearest_level(actual_level); + set_level_and_therm_target(memorized_level); return MISCHIEF_MANAGED; } #ifdef USE_RAMP_CONFIG @@ -729,9 +711,6 @@ uint8_t steady_state(Event event, uint16_t arg) { #else memorized_level = nearest_level((int16_t)actual_level + ramp_step_size); #endif - #ifdef USE_THERMAL_REGULATION - target_level = memorized_level; - #endif #if defined(BLINK_AT_RAMP_CEILING) || defined(BLINK_AT_RAMP_MIDDLE) // only blink once for each threshold if ((memorized_level != actual_level) && ( @@ -766,7 +745,7 @@ uint8_t steady_state(Event event, uint16_t arg) { blip(); } #endif - set_level(memorized_level); + set_level_and_therm_target(memorized_level); return MISCHIEF_MANAGED; } #if defined(USE_REVERSING) || defined(START_AT_MEMORIZED_LEVEL) @@ -792,9 +771,6 @@ uint8_t steady_state(Event event, uint16_t arg) { } // TODO? make it ramp up instead, if already at min? memorized_level = nearest_level((int16_t)actual_level - ramp_step_size); - #ifdef USE_THERMAL_REGULATION - target_level = memorized_level; - #endif #if defined(BLINK_AT_RAMP_FLOOR) || defined(BLINK_AT_RAMP_MIDDLE) // only blink once for each threshold if ((memorized_level != actual_level) && ( @@ -826,7 +802,7 @@ uint8_t steady_state(Event event, uint16_t arg) { blip(); } #endif - set_level(memorized_level); + set_level_and_therm_target(memorized_level); return MISCHIEF_MANAGED; } #ifdef START_AT_MEMORIZED_LEVEL @@ -917,10 +893,10 @@ uint8_t steady_state(Event event, uint16_t arg) { if (actual_level > THERM_FASTER_LEVEL) { #ifdef USE_SET_LEVEL_GRADUALLY set_level_gradually(THERM_FASTER_LEVEL); + target_level = THERM_FASTER_LEVEL; #else - set_level(THERM_FASTER_LEVEL); + set_level_and_therm_target(THERM_FASTER_LEVEL); #endif - target_level = THERM_FASTER_LEVEL; } else #endif if (actual_level > MIN_THERM_STEPDOWN) { @@ -2111,6 +2087,12 @@ uint8_t nearest_level(int16_t target) { return this_level; } +#ifdef USE_THERMAL_REGULATION +void set_level_and_therm_target(uint8_t level) { + target_level = level; + set_level(level); +} +#endif void blink_confirm(uint8_t num) { for (; num>0; num--) { @@ -2266,14 +2248,7 @@ void low_voltage() { else if (state == steady_state) { if (actual_level > 1) { uint8_t lvl = (actual_level >> 1) + (actual_level >> 2); - set_level(lvl); - #ifdef USE_THERMAL_REGULATION - target_level = lvl; - #ifdef USE_SET_LEVEL_GRADUALLY - // not needed? - //set_level_gradually(lvl); - #endif - #endif + set_level_and_therm_target(lvl); } else { set_state(off_state, 0); -- cgit v1.2.3 From cf98788bafdbc6f7fdd246b4085248eeefb7c915 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 21 Jun 2019 05:19:55 -0600 Subject: anduril manual: added info about manual memory, 2-level lockout, and aux LED colors --- spaghetti-monster/anduril/anduril-manual.txt | 19 ++++++++++++++++++- spaghetti-monster/anduril/anduril.txt | 18 +++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/spaghetti-monster/anduril/anduril-manual.txt b/spaghetti-monster/anduril/anduril-manual.txt index 3684b50..3f17f41 100644 --- a/spaghetti-monster/anduril/anduril-manual.txt +++ b/spaghetti-monster/anduril/anduril-manual.txt @@ -56,6 +56,13 @@ While the light is on, a few basic actions are available: - Click, hold: Change brightness (down). - 3 clicks: Switch to the other ramp. - 4 clicks: Go to ramp config mode. + - 5 clicks: Activate manual memory and save the current brightness. + - 5 clicks, but hold the last click: Go back to automatic memory. + +The "automatic" vs "manual" memory modes change the level the light goes +to with 1 click from off. In automatic mode, it uses the last +brightness the user ramped to. In manual mode, it uses the brightness +the user explicitly saved with 5 clicks. Other Modes @@ -215,7 +222,10 @@ then return to the regular "off" mode. Lockout mode also doubles as a momentary moon mode, so the user can do quick tasks without having to unlock the light. The brightness in -lockout mode is determined by the floor setting of the current ramp. +lockout mode has two levels: + + - Hold: light up at the floor level of the current ramp. + - Click, Hold: light up at the floor level of the other ramp. Momentary Mode @@ -364,6 +374,13 @@ click the button a few times: This should change the aux LEDs to the next mode supported on this light. +If the aux LEDs can change color, there are additional actions to change +the color. It is the same as above, but hold the button on the last +click and then let go when the desired color is reached. + + - Off mode: 7 clicks, but hold the last click. + - Lockout mode: 3 clicks, but hold the last click. + For lights with a button LED, the button LED typically stays on while the main emitters are on. Its brightness level is set in a way which mirrors the main LED -- off, low, or high. diff --git a/spaghetti-monster/anduril/anduril.txt b/spaghetti-monster/anduril/anduril.txt index 3e0328c..db73cdb 100644 --- a/spaghetti-monster/anduril/anduril.txt +++ b/spaghetti-monster/anduril/anduril.txt @@ -20,6 +20,8 @@ From off: * On hardware with an indicator LED... * 7 clicks: Change aux LED mode used in "off" mode. (the modes are usually off/low/high/blinking) + * 7 clicks (but hold the last click): + Change aux LED color used in "off" mode. In steady / ramping mode: * 1 click: off @@ -28,6 +30,8 @@ In steady / ramping mode: * 2 clicks: to/from turbo (actual turbo, not just highest ramp level) * 3 clicks: toggle smooth vs discrete ramping * 4 clicks: configure current ramp + * 5 clicks: activate manual memory and save current brightness + * 5 clicks (but hold the last click): go back to automatic memory Smooth ramp config mode: * Setting 1: low end @@ -104,14 +108,18 @@ Discrete ramp config mode: At buzz, click N times to set thermal limit to roughly 30 C + N. Lockout mode: - * Hold: momentary moon + * Hold: momentary moon (current ramp floor) + * Click, Hold: momentary moon (other ramp floor) * 4 clicks: exit lockout (return to regular "off" mode) * On hardware with an indicator LED... * 3 clicks: Change aux LED brightness used in lockout mode. (the modes are usually off/low/high/blinking) + * 3 clicks (but hold the last click): + Change aux LED color used in lockout mode. Momentary mode: - * Press button: Light on (at memorized level). + * Press button: Light on (at memorized mode/level). + (uses either a steady mode or a strobe-group mode) * Release button: Light off. * To exit, disconnect power. (loosen/tighten the tailcap) @@ -148,6 +156,10 @@ Indicator LED / aux LED support: - High - Blinking + If the aux LEDs can change color, the user can configure the color + using exactly the same method... except hold the last click until the + desired color is reached. + TODO: * save settings in eeprom @@ -167,7 +179,7 @@ TODO: * move all config menus to four clicks * candle mode timer, with three clicks to add 30 minutes * diagram updates for 3-click special actions + * add a toggle for memory (manual vs automatic memory) - candle mode: smoother adjustments? - make sunset mode timer and brightness configurable? - make beacon mode actually sleep between pulses - - add a toggle for memory? -- cgit v1.2.3 From 41fef25bf05bb8fa377c9bcbbc7c0b5858cd20a1 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 27 Jun 2019 02:40:38 -0600 Subject: added factory reset function to Anduril, and reboot function for FSM --- spaghetti-monster/anduril/anduril.c | 80 ++++++++++++++++++++++++++++++++++-- spaghetti-monster/anduril/cfg-fw3a.h | 3 ++ spaghetti-monster/fsm-main.c | 5 +++ spaghetti-monster/fsm-misc.c | 17 ++++++++ spaghetti-monster/fsm-misc.h | 4 ++ 5 files changed, 106 insertions(+), 3 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 913a857..c2a4b77 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -28,6 +28,14 @@ #define USE_THERMAL_REGULATION #define DEFAULT_THERM_CEIL 45 // try not to get hotter than this +#define USE_FACTORY_RESET +//#define USE_SOFT_FACTORY_RESET // only needed on models which can't use hold-button-at-boot + +// dual-switch support (second switch is a tail clicky) +// (currently incompatible with factory reset) +//#define START_AT_MEMORIZED_LEVEL + + // short blip when crossing from "click" to "hold" from off // (helps the user hit moon mode exactly, instead of holding too long // or too short) @@ -81,9 +89,6 @@ //#define USE_POLICE_STROBE_MODE //#define USE_SOS_MODE -// dual-switch support (second switch is a tail clicky) -//#define START_AT_MEMORIZED_LEVEL - /***** specific settings for known driver types *****/ #include "tk.h" #include incfile(CONFIGFILE) @@ -201,6 +206,10 @@ typedef enum { #endif #endif +#ifdef USE_SOFT_FACTORY_RESET +#define USE_REBOOT +#endif + #include "spaghetti-monster.h" @@ -291,6 +300,10 @@ void blip(); void indicator_blink(uint8_t arg); #endif +#ifdef USE_FACTORY_RESET +void factory_reset(); +#endif + // remember stuff even after battery was changed void load_config(); void save_config(); @@ -603,6 +616,13 @@ uint8_t off_state(Event event, uint16_t arg) { return MISCHIEF_MANAGED; } #endif + #if defined(USE_FACTORY_RESET) && defined(USE_SOFT_FACTORY_RESET) + // 13 clicks and hold the last click: invoke factory reset (reboot) + else if (event == EV_click13_hold) { + reboot(); + return MISCHIEF_MANAGED; + } + #endif return EVENT_NOT_HANDLED; } @@ -2136,6 +2156,55 @@ void indicator_blink(uint8_t arg) { #endif +#ifdef USE_FACTORY_RESET +void factory_reset() { + // display a warning for a few seconds before doing the actual reset, + // so the user has time to abort if they want + #define SPLODEY_TIME 3000 + #define SPLODEY_STEPS 64 + #define SPLODEY_TIME_PER_STEP (SPLODEY_TIME/SPLODEY_STEPS) + uint8_t bright; + uint8_t reset = 1; + // wind up to an explosion + for (bright=0; bright>1); + delay_4ms(SPLODEY_TIME_PER_STEP/2/4); + if (! button_is_pressed()) { + reset = 0; + break; + } + } + // explode, if button pressed long enough + if (reset) { + #ifdef USE_THERMAL_REGULATION + // auto-calibrate temperature... assume current temperature is 21 C + config_state_values[0] = 21; + config_state_values[1] = 0; + thermal_config_save(); + #endif + // save all settings to eeprom + // (assuming they're all at default because we haven't loaded them yet) + save_config(); + + bright = MAX_LEVEL; + for (; bright > 0; bright--) { + set_level(bright); + delay_4ms(SPLODEY_TIME_PER_STEP/6/4); + } + } + // explosion cancelled, fade away + else { + for (; bright > 0; bright--) { + set_level(bright); + delay_4ms(SPLODEY_TIME_PER_STEP/3/4); + } + } +} +#endif + + void load_config() { if (load_eeprom()) { ramp_style = eeprom[ramp_style_e]; @@ -2286,6 +2355,11 @@ void setup() { delay_4ms(3); set_level(0); + #ifdef USE_FACTORY_RESET + if (button_is_pressed()) + factory_reset(); + #endif + load_config(); #ifdef USE_TINT_RAMPING diff --git a/spaghetti-monster/anduril/cfg-fw3a.h b/spaghetti-monster/anduril/cfg-fw3a.h index a28d12a..489766c 100644 --- a/spaghetti-monster/anduril/cfg-fw3a.h +++ b/spaghetti-monster/anduril/cfg-fw3a.h @@ -17,3 +17,6 @@ #define THERM_FASTER_LEVEL MAX_Nx7135 #define USE_TENCLICK_THERMAL_CONFIG + +// can't reset the normal way because power is connected before the button +#define USE_SOFT_FACTORY_RESET diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c index 6f74e9b..1c28f5f 100644 --- a/spaghetti-monster/fsm-main.c +++ b/spaghetti-monster/fsm-main.c @@ -40,6 +40,11 @@ int main() { // Don't allow interrupts while booting cli(); + #ifdef USE_REBOOT // prevent reboot loops + MCUSR &= ~(1< 286759 bytes spaghetti-monster/anduril/anduril.svg | 982 ++++++++++++++++++++++--------- 2 files changed, 688 insertions(+), 294 deletions(-) diff --git a/spaghetti-monster/anduril/anduril-ui.png b/spaghetti-monster/anduril/anduril-ui.png index b778a30..3c032bc 100644 Binary files a/spaghetti-monster/anduril/anduril-ui.png and b/spaghetti-monster/anduril/anduril-ui.png differ diff --git a/spaghetti-monster/anduril/anduril.svg b/spaghetti-monster/anduril/anduril.svg index ab2926d..36840a4 100644 --- a/spaghetti-monster/anduril/anduril.svg +++ b/spaghetti-monster/anduril/anduril.svg @@ -12,14 +12,14 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="18.056446cm" - height="26.675991cm" + height="30.084438cm" id="svg2" version="1.1" - inkscape:version="0.92.1 r15371" + inkscape:version="0.92.4 (5da689c313, 2019-01-14)" sodipodi:docname="anduril.svg" inkscape:export-filename="/tmp/anduril-ui.png" - inkscape:export-xdpi="342.78015" - inkscape:export-ydpi="342.78015"> + inkscape:export-xdpi="109.75774" + inkscape:export-ydpi="109.75774"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + originy="95.554798" /> @@ -2747,6 +2869,12 @@ x="-885.51392" y="1093.7063" style="font-size:29.33333397px;line-height:1.25;stroke-width:1.06666672">Strobes + - + + style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:3.20000005;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> BeaconCfg @@ -2981,113 +3108,11 @@ style="fill:none;stroke:#000000;stroke-width:2.39758635;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - - - Faster - - Slower - - Faster - - Slower - - Brighter - - Dimmer - @@ -3237,8 +3256,8 @@ inkscape:connector-curvature="0" sodipodi:nodetypes="csc" /> @@ -3347,7 +3366,7 @@ sodipodi:role="line" x="1444.4535" y="854.61517" - id="tspan58146"> (click N times for 1+Turbo-N) (click N times for Nth highest) (click N times for 30 C + N) + id="tspan39625"> (click N times for N + 30 C) for N seconds per flash) + transform="translate(-742.72705,222.13423)"> Actions 1 Fast Click + style="font-size:17.06666756px;line-height:1.25;stroke-width:1.06666672">1 Click Hold 3 Fast Clicks + style="font-size:17.06666756px;line-height:1.25;stroke-width:1.06666672">3 Clicks Other Action @@ -3546,24 +3565,24 @@ 2 Fast Clicks + style="font-size:17.06666756px;line-height:1.25;fill:#009d00;fill-opacity:1;stroke-width:1.06666672">2 Clicks Click, Hold @@ -3579,7 +3598,7 @@ sodipodi:role="line" id="tspan6532-6">Andúril‎ UI Beacon Cfg - - - Lockout - - - - - Momentary - - Signalling - / Faster - @@ -3846,15 +3791,6 @@ x="1172.5502" y="720.89923" style="font-size:25.60000038px;line-height:1.25;stroke-width:1.06666672">Muggle - Momentary - - OFF + style="fill:none;stroke:#ffffff;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-end:url(#Arrow1Mend-31-1-0-9-9-9)" /> + + + + + OFF + + While On: + 1C + 1H + 3C + 2C + 2H + Brightness: Off, Low, High, Blinking + + 3C. Smooth /4C. Ramp Cfg5C. Manual Memory5H. Automatic Memory + Stepped ramp + + + + + + + + + + Color: R, Y, G, C, B, V, W, Rainbow, Volts + + + + + Lockout + + 7C + 7H + + Aux /ButtonLEDs + 3C + 3H + 3C + 3 Clicks + 3C + + + + + Lockout + + Momentary Moon / Low + + + + On / Strobes + + Factory Reset: Loosen tailcap, Hold button, Tighten tailcap, Hold 3s (or 13H from Off) -- cgit v1.2.3 From ba961635820f16e4726bf19bfb012aa7d7876c47 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 30 Jul 2019 14:39:55 -0600 Subject: ensure muggle thermal step-down can't overflow or wrap around --- spaghetti-monster/anduril/anduril.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index c2a4b77..24211d7 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -1846,7 +1846,7 @@ uint8_t muggle_state(Event event, uint16_t arg) { blip(); #endif // step down proportional to the amount of overheating - uint8_t new = actual_level - arg; + int16_t new = actual_level - arg; if (new < MUGGLE_FLOOR) { new = MUGGLE_FLOOR; } set_level(new); return MISCHIEF_MANAGED; -- cgit v1.2.3