aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-06-27 02:40:38 -0600
committerSelene ToyKeeper2019-06-27 02:40:38 -0600
commit41fef25bf05bb8fa377c9bcbbc7c0b5858cd20a1 (patch)
tree901d6eaac250e2f1bc3a1695536486e16ac83e45
parentanduril manual: added info about manual memory, 2-level lockout, and aux LED ... (diff)
downloadanduril-41fef25bf05bb8fa377c9bcbbc7c0b5858cd20a1.tar.gz
anduril-41fef25bf05bb8fa377c9bcbbc7c0b5858cd20a1.tar.bz2
anduril-41fef25bf05bb8fa377c9bcbbc7c0b5858cd20a1.zip
added factory reset function to Anduril, and reboot function for FSM
Diffstat (limited to '')
-rw-r--r--spaghetti-monster/anduril/anduril.c80
-rw-r--r--spaghetti-monster/anduril/cfg-fw3a.h3
-rw-r--r--spaghetti-monster/fsm-main.c5
-rw-r--r--spaghetti-monster/fsm-misc.c17
-rw-r--r--spaghetti-monster/fsm-misc.h4
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<SPLODEY_STEPS; bright++) {
+ set_level(bright);
+ delay_4ms(SPLODEY_TIME_PER_STEP/2/4);
+ set_level(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<<WDRF); // reset status flag
+ wdt_disable();
+ #endif
+
#ifdef HALFSPEED
// run at half speed
CLKPR = 1<<CLKPCE;
diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c
index 9f953fa..eced482 100644
--- a/spaghetti-monster/fsm-misc.c
+++ b/spaghetti-monster/fsm-misc.c
@@ -154,4 +154,21 @@ uint8_t triangle_wave(uint8_t phase) {
}
#endif
+#ifdef USE_REBOOT
+void reboot() {
+ #if 1 // WDT method, safer but larger
+ cli();
+ WDTCR = 0xD8 | WDTO_15MS;
+ sei();
+ wdt_reset();
+ while (1) {}
+ #else // raw assembly method, doesn't reset registers or anything
+ __asm__ __volatile__ (
+ "cli" "\n\t"
+ "rjmp 0x00" "\n\t"
+ );
+ #endif
+}
+#endif
+
#endif
diff --git a/spaghetti-monster/fsm-misc.h b/spaghetti-monster/fsm-misc.h
index 6e41b6c..1381ca2 100644
--- a/spaghetti-monster/fsm-misc.h
+++ b/spaghetti-monster/fsm-misc.h
@@ -50,4 +50,8 @@ void indicator_led(uint8_t lvl);
uint8_t triangle_wave(uint8_t phase);
#endif
+#ifdef USE_REBOOT
+void reboot();
+#endif
+
#endif