aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2018-11-08 17:45:09 -0700
committerSelene ToyKeeper2018-11-08 17:45:09 -0700
commite143d03198ff1d16cc91ed94d5ea529170e9bfbf (patch)
tree0f5ebc8816bea516722dfec7ea832994e4b3c9bf /spaghetti-monster
parentadded lantern pin layout (diff)
parentMade it easier to override hwdef-*.h values in cfg-*.h files. (diff)
downloadanduril-e143d03198ff1d16cc91ed94d5ea529170e9bfbf.tar.gz
anduril-e143d03198ff1d16cc91ed94d5ea529170e9bfbf.tar.bz2
anduril-e143d03198ff1d16cc91ed94d5ea529170e9bfbf.zip
merged upstream changes from fsm branch
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/anduril/Makefile7
-rw-r--r--spaghetti-monster/anduril/anduril.c43
-rw-r--r--spaghetti-monster/anduril/anduril.txt7
-rwxr-xr-xspaghetti-monster/anduril/build-all.sh3
-rw-r--r--spaghetti-monster/anduril/cfg-blf-gt.h4
-rw-r--r--spaghetti-monster/anduril/cfg-blf-q8.h4
-rw-r--r--spaghetti-monster/anduril/cfg-emisar-d4.h3
-rw-r--r--spaghetti-monster/anduril/cfg-ff-pl47.h24
-rw-r--r--spaghetti-monster/anduril/cfg-ff-rot66.h4
-rw-r--r--spaghetti-monster/anduril/cfg-fw3a.h4
-rw-r--r--spaghetti-monster/anduril/cfg-sofirn-sp36.h16
-rw-r--r--spaghetti-monster/baton/baton-simpler.c194
-rw-r--r--spaghetti-monster/baton/baton.c170
-rw-r--r--spaghetti-monster/baton/baton.txt21
-rw-r--r--spaghetti-monster/rampingios/Makefile7
-rwxr-xr-xspaghetti-monster/rampingios/build-all.sh2
16 files changed, 180 insertions, 333 deletions
diff --git a/spaghetti-monster/anduril/Makefile b/spaghetti-monster/anduril/Makefile
new file mode 100644
index 0000000..25c56fa
--- /dev/null
+++ b/spaghetti-monster/anduril/Makefile
@@ -0,0 +1,7 @@
+all:
+ ./build-all.sh
+
+clean:
+ rm -f *.hex *~ *.elf *.o
+
+.phony: clean
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c
index bd5d3b6..bebef72 100644
--- a/spaghetti-monster/anduril/anduril.c
+++ b/spaghetti-monster/anduril/anduril.c
@@ -32,6 +32,7 @@
//#define FSM_FF_ROT66_DRIVER
//#define FSM_FF_ROT66_219_DRIVER
//#define FSM_FW3A_DRIVER
+//#define FSM_SOFIRN_SP36_DRIVER
#define USE_LVP // FIXME: won't build when this option is turned off
@@ -117,6 +118,9 @@
#elif defined(FSM_FW3A_DRIVER)
#include "cfg-fw3a.h"
+#elif defined(FSM_SOFIRN_SP36_DRIVER)
+#include "cfg-sofirn-sp36.h"
+
#endif
@@ -139,16 +143,29 @@
/********* Configure SpaghettiMonster *********/
#define USE_DELAY_ZERO
#define USE_RAMPING
+#ifndef RAMP_LENGTH
#define RAMP_LENGTH 150 // default, if not overridden in a driver cfg file
+#endif
#define MAX_BIKING_LEVEL 120 // should be 127 or less
#define USE_BATTCHECK
-#ifdef USE_MUGGLE_MODE
+
+// determine the highest number of clicks to handle
+#ifdef USE_INDICATOR_LED
+#define MAX_CLICKS 7
+#elif defined(USE_MUGGLE_MODE)
#define MAX_CLICKS 6
-#define MUGGLE_FLOOR 22
-#define MUGGLE_CEILING (MAX_1x7135+20)
#else
#define MAX_CLICKS 5
#endif
+
+#if defined(USE_MUGGLE_MODE)
+#ifndef MUGGLE_FLOOR
+#define MUGGLE_FLOOR 22
+#endif
+#ifndef MUGGLE_CEILING
+#define MUGGLE_CEILING (MAX_1x7135+20)
+#endif
+#endif
#define USE_IDLE_MODE // reduce power use while awake and no tasks are pending
#define USE_DYNAMIC_UNDERCLOCKING // cut clock speed at very low modes for better efficiency
@@ -498,6 +515,24 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
return MISCHIEF_MANAGED;
}
#endif
+ #ifdef USE_INDICATOR_LED
+ // 7 clicks: change indicator LED mode
+ else if (event == EV_7clicks) {
+ uint8_t mode = (indicator_led_mode & 3) + 1;
+ #ifdef TICK_DURING_STANDBY
+ mode = mode & 3;
+ #else
+ mode = mode % 3;
+ #endif
+ #ifdef INDICATOR_LED_SKIP_LOW
+ if (mode == 1) { mode ++; }
+ #endif
+ indicator_led_mode = (indicator_led_mode & 0b11111100) | mode;
+ indicator_led(mode);
+ save_config();
+ return MISCHIEF_MANAGED;
+ }
+ #endif
return EVENT_NOT_HANDLED;
}
@@ -1241,6 +1276,7 @@ uint8_t lockout_state(EventPtr event, uint16_t arg) {
save_config();
return MISCHIEF_MANAGED;
}
+ #if 0 // old method, deprecated in favor of "7 clicks from off"
// click, click, hold: rotate through indicator LED modes (off mode)
else if (event == EV_click3_hold) {
#ifndef USE_INDICATOR_LED_WHILE_RAMPING
@@ -1273,6 +1309,7 @@ uint8_t lockout_state(EventPtr event, uint16_t arg) {
return MISCHIEF_MANAGED;
}
#endif
+ #endif
// 4 clicks: exit
else if (event == EV_4clicks) {
blink_confirm(1);
diff --git a/spaghetti-monster/anduril/anduril.txt b/spaghetti-monster/anduril/anduril.txt
index 9cbef68..f0f0b4d 100644
--- a/spaghetti-monster/anduril/anduril.txt
+++ b/spaghetti-monster/anduril/anduril.txt
@@ -17,6 +17,9 @@ From off:
* 4 clicks: lock-out
* 5 clicks: momentary mode (disconnect power to exit)
* 6 clicks: muggle mode
+ * On hardware with an indicator LED...
+ * 7 clicks: Change aux LED mode used in "off" mode.
+ (the modes are usually off/low/high/blinking)
In steady mode:
* 1 click: off
@@ -111,8 +114,8 @@ Lockout mode:
* Hold: momentary moon
* 4 clicks: exit lockout (return to regular "off" mode)
* On hardware with an indicator LED...
- * 3 clicks: Change button brightness used in lockout mode. (low/high/off)
- * Click, click, hold: Change button brightness used in "off" mode.
+ * 3 clicks: Change aux LED brightness used in lockout mode.
+ (the modes are usually off/low/high/blinking)
Momentary mode:
* Press button: Light on (at memorized level).
diff --git a/spaghetti-monster/anduril/build-all.sh b/spaghetti-monster/anduril/build-all.sh
index 06e7761..b50744f 100755
--- a/spaghetti-monster/anduril/build-all.sh
+++ b/spaghetti-monster/anduril/build-all.sh
@@ -17,8 +17,9 @@ for TARGET in \
FF_ROT66 \
FF_ROT66_219 \
FW3A \
+ SOFIRN_SP36 \
; do
echo "===== $TARGET ====="
- ../../../bin/build-85.sh "$UI" "-DFSM_${TARGET}_DRIVER"
+ ../../../bin/build.sh 85 "$UI" "-DFSM_${TARGET}_DRIVER"
mv -f "$UI".hex "$UI".$TARGET.hex
done
diff --git a/spaghetti-monster/anduril/cfg-blf-gt.h b/spaghetti-monster/anduril/cfg-blf-gt.h
index 369d028..a29d7e7 100644
--- a/spaghetti-monster/anduril/cfg-blf-gt.h
+++ b/spaghetti-monster/anduril/cfg-blf-gt.h
@@ -14,10 +14,6 @@
//#undef USE_SET_LEVEL_GRADUALLY
-#ifdef RAMP_LENGTH
-#undef RAMP_LENGTH
-#endif
-
#define RAMP_LENGTH 150
// First 60 values: level_calc.py 1 60 7135 4 5.0 255
// Remainder: all 255 (buck driver at 100% duty cycle)
diff --git a/spaghetti-monster/anduril/cfg-blf-q8.h b/spaghetti-monster/anduril/cfg-blf-q8.h
index 269aae9..1b9b971 100644
--- a/spaghetti-monster/anduril/cfg-blf-q8.h
+++ b/spaghetti-monster/anduril/cfg-blf-q8.h
@@ -7,10 +7,6 @@
// enable blinking indicator LED while off
#define TICK_DURING_STANDBY
-#ifdef RAMP_LENGTH
-#undef RAMP_LENGTH
-#endif
-
// copied from Emisar D4 ramp
// ../../bin/level_calc.py 1 65 7135 1 0.8 150
// ... mixed with this:
diff --git a/spaghetti-monster/anduril/cfg-emisar-d4.h b/spaghetti-monster/anduril/cfg-emisar-d4.h
index 251f81d..e83c62d 100644
--- a/spaghetti-monster/anduril/cfg-emisar-d4.h
+++ b/spaghetti-monster/anduril/cfg-emisar-d4.h
@@ -1,8 +1,5 @@
// Emisar D4 config options for Anduril
-#ifdef RAMP_LENGTH
-#undef RAMP_LENGTH
-#endif
// ../../bin/level_calc.py 1 65 7135 1 0.8 150
// ... mixed with this:
// ../../bin/level_calc.py 2 150 7135 4 0.33 150 FET 1 10 1500
diff --git a/spaghetti-monster/anduril/cfg-ff-pl47.h b/spaghetti-monster/anduril/cfg-ff-pl47.h
index d916e06..2e5647d 100644
--- a/spaghetti-monster/anduril/cfg-ff-pl47.h
+++ b/spaghetti-monster/anduril/cfg-ff-pl47.h
@@ -17,7 +17,8 @@
// the "low" mode doesn't work on this light's aux LEDs
// (but it does work on the switch LEDs)
-//#define INDICATOR_LED_SKIP_LOW
+// Fireflies wants to skip aux LED mode 1 (low)
+#define INDICATOR_LED_SKIP_LOW
// ... or if TICK_DURING_STANDBY is turned off:
// off mode: high (2)
@@ -25,9 +26,6 @@
//#define INDICATOR_LED_DEFAULT_MODE ((0<<2) + 2)
-#ifdef RAMP_LENGTH
-#undef RAMP_LENGTH
-#endif
#define RAMP_LENGTH 150
// driver is a FET + 3x7135, ~400 lm at highest regulated level
@@ -38,15 +36,27 @@
#define HALFSPEED_LEVEL 13
#define QUARTERSPEED_LEVEL 6
-// ceiling is level 120/150
-#define RAMP_SMOOTH_CEIL (MAX_LEVEL*4/5)
-
// thermal regulation parameters
#ifdef MIN_THERM_STEPDOWN
#undef MIN_THERM_STEPDOWN // this should be lower, because 3x7135 instead of 1x7135
#endif
#define MIN_THERM_STEPDOWN 60 // lowest value it'll step down to
+// ceiling is level 120/150
+#define RAMP_SMOOTH_CEIL 120
+
+// 10, 28, 46, 65, 83, 101, 120 (83 is highest regulated)
+#define RAMP_DISCRETE_FLOOR 10
+#define RAMP_DISCRETE_CEIL 120
+#define RAMP_DISCRETE_STEPS 7
+
+// ~25 lm to ~300 lm
+#define MUGGLE_FLOOR 30
+#define MUGGLE_CEILING MAX_1x7135
+// ~50 lm to ~500 lm
+//#define MUGGLE_FLOOR 40
+//#define MUGGLE_CEILING 90
+
// regulate down faster when the FET is active, slower otherwise
#define THERM_FASTER_LEVEL 130 // throttle back faster when high
diff --git a/spaghetti-monster/anduril/cfg-ff-rot66.h b/spaghetti-monster/anduril/cfg-ff-rot66.h
index c8e0d52..165b2ba 100644
--- a/spaghetti-monster/anduril/cfg-ff-rot66.h
+++ b/spaghetti-monster/anduril/cfg-ff-rot66.h
@@ -18,10 +18,6 @@
#define INDICATOR_LED_DEFAULT_MODE ((0<<2) + 2)
-#ifdef RAMP_LENGTH
-#undef RAMP_LENGTH
-#endif
-
// driver is a FET+N+1,
// where N=6 for the 219b version,
// or N=13 for the XP-L HI version (this version)
diff --git a/spaghetti-monster/anduril/cfg-fw3a.h b/spaghetti-monster/anduril/cfg-fw3a.h
index 65f1e48..efa70ae 100644
--- a/spaghetti-monster/anduril/cfg-fw3a.h
+++ b/spaghetti-monster/anduril/cfg-fw3a.h
@@ -1,9 +1,5 @@
// FW3A config options for Anduril
-#ifdef RAMP_LENGTH
-#undef RAMP_LENGTH
-#endif
-
// ../../bin/level_calc.py 1 65 7135 1 0.8 150
// ... mixed with this:
// ../../../bin/level_calc.py 3 150 7135 1 0.33 150 7135 1 1 850 FET 1 10 1500
diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp36.h b/spaghetti-monster/anduril/cfg-sofirn-sp36.h
new file mode 100644
index 0000000..11e3735
--- /dev/null
+++ b/spaghetti-monster/anduril/cfg-sofirn-sp36.h
@@ -0,0 +1,16 @@
+// Sofirn SP36 (small Q8) config options for Anduril
+
+#define FSM_BLF_Q8_DRIVER
+#include "cfg-blf-q8.h"
+
+// stop panicking at ~50% power or ~2000 lm
+#ifdef THERM_FASTER_LEVEL
+#undef THERM_FASTER_LEVEL
+#endif
+#define THERM_FASTER_LEVEL 125
+
+// be extra-careful at high levels
+#ifndef THERM_HARD_TURBO_DROP
+#define THERM_HARD_TURBO_DROP
+#endif
+
diff --git a/spaghetti-monster/baton/baton-simpler.c b/spaghetti-monster/baton/baton-simpler.c
deleted file mode 100644
index 96b0ea7..0000000
--- a/spaghetti-monster/baton/baton-simpler.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Baton: Olight Baton-like UI for SpaghettiMonster.
- *
- * Copyright (C) 2017 Selene ToyKeeper
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#define FSM_EMISAR_D4_DRIVER
-#define USE_LVP
-#define USE_THERMAL_REGULATION
-#define DEFAULT_THERM_CEIL 45
-#define USE_DELAY_MS
-#include "spaghetti-monster.h"
-
-// FSM states
-uint8_t off_state(EventPtr event, uint16_t arg);
-uint8_t steady_state(EventPtr event, uint16_t arg);
-uint8_t lockout_state(EventPtr event, uint16_t arg);
-
-// brightness control
-uint8_t memorized_level = 1;
-uint8_t actual_level = 0;
-#ifdef USE_THERMAL_REGULATION
-uint8_t target_level = 0;
-#endif
-
-// moon + ../../bin/level_calc.py 2 6 7135 18 10 150 FET 1 10 1500
-uint8_t pwm1_levels[] = { 3, 18, 110, 255, 255, 255, 0, };
-uint8_t pwm2_levels[] = { 0, 0, 0, 9, 58, 138, 255, };
-#define MAX_LEVEL (sizeof(pwm1_levels)-1)
-
-// set LED brightness
-void set_level(uint8_t lvl) {
- actual_level = lvl;
- PWM1_LVL = pwm1_levels[lvl];
- PWM2_LVL = pwm2_levels[lvl];
-}
-
-uint8_t off_state(EventPtr event, uint16_t arg) {
- // turn emitter off when entering state
- if (event == EV_enter_state) {
- go_to_standby = 1; // sleep while off (lower power use)
- return EVENT_HANDLED;
- }
- // hold (initially): go to lowest level, but allow abort for regular click
- else if (event == EV_click1_press) {
- set_level(0);
- return EVENT_HANDLED;
- }
- // 1 click (before timeout): go to memorized level, but allow abort for double click
- else if (event == EV_click1_release) {
- set_level(memorized_level);
- return EVENT_HANDLED;
- }
- // 1 click: regular mode
- else if (event == EV_1click) {
- set_state(steady_state, memorized_level);
- return EVENT_HANDLED;
- }
- // 2 clicks: highest mode
- else if (event == EV_2clicks) {
- set_state(steady_state, MAX_LEVEL);
- return EVENT_HANDLED;
- }
- // 4 clicks: soft lockout
- else if (event == EV_4clicks) {
- set_state(lockout_state, 0);
- return EVENT_HANDLED;
- }
- // hold: go to lowest level
- else if (event == EV_click1_hold) {
- set_state(steady_state, 0);
- return EVENT_HANDLED;
- }
- return EVENT_NOT_HANDLED;
-}
-
-uint8_t steady_state(EventPtr event, uint16_t arg) {
- // turn LED on when we first enter the mode
- if (event == EV_enter_state) {
- // remember this level, unless it's moon or turbo
- if ((arg > 0) && (arg < MAX_LEVEL))
- memorized_level = arg;
- #ifdef USE_THERMAL_REGULATION
- target_level = arg;
- #endif
- set_level(arg);
- return EVENT_HANDLED;
- }
- // 1 click: off
- else if (event == EV_1click) {
- set_state(off_state, 0);
- return EVENT_HANDLED;
- }
- // 2 clicks: go to/from highest level
- else if (event == EV_2clicks) {
- if (actual_level < MAX_LEVEL) { // go to turbo
- memorized_level = actual_level; // in case we're on moon
- #ifdef USE_THERMAL_REGULATION
- target_level = MAX_LEVEL;
- #endif
- set_level(MAX_LEVEL);
- }
- else { // return from turbo
- #ifdef USE_THERMAL_REGULATION
- target_level = memorized_level;
- #endif
- set_level(memorized_level);
- }
- return EVENT_HANDLED;
- }
- // hold: change brightness
- else if (event == EV_click1_hold) {
- if ((arg % HOLD_TIMEOUT) == 0) {
- memorized_level = (actual_level+1) % (MAX_LEVEL+1);
- #ifdef USE_THERMAL_REGULATION
- target_level = memorized_level;
- #endif
- set_level(memorized_level);
- }
- return EVENT_HANDLED;
- }
- #ifdef USE_THERMAL_REGULATION
- // overheating: drop by 1 level
- else if (event == EV_temperature_high) {
- if (actual_level > 1) {
- set_level(actual_level - 1);
- }
- return EVENT_HANDLED;
- }
- // underheating: increase by 1 level if we're lower than the target
- else if (event == EV_temperature_low) {
- if (actual_level < target_level) {
- set_level(actual_level + 1);
- }
- return EVENT_HANDLED;
- }
- #endif
- return EVENT_NOT_HANDLED;
-}
-
-uint8_t lockout_state(EventPtr event, uint16_t arg) {
- // stay asleep while locked, but allow waking long enough to click 4 times
- if (event == EV_tick) {
- static uint8_t ticks_spent_awake = 0;
- ticks_spent_awake ++;
- PWM1_LVL = 0; PWM2_LVL = 0;
- if (ticks_spent_awake > 3 * TICKS_PER_SECOND) {
- ticks_spent_awake = 0;
- go_to_standby = 1;
- }
- return MISCHIEF_MANAGED;
- }
- // 4 clicks: exit
- else if (event == EV_4clicks) {
- set_state(steady_state, 1);
- return MISCHIEF_MANAGED;
- }
- return EVENT_NOT_HANDLED;
-}
-
-void low_voltage() {
- // step down by one level or turn off
- if (actual_level > 0) {
- set_level(actual_level - 1);
- }
- else {
- set_state(off_state, 0);
- }
-}
-
-void setup() {
- // blink when power is connected
- set_level(MAX_LEVEL/2);
- delay_ms(10);
- set_level(0);
-
- push_state(off_state, 0);
-}
-
-void loop() {
-}
diff --git a/spaghetti-monster/baton/baton.c b/spaghetti-monster/baton/baton.c
index 1266ddd..d4725ef 100644
--- a/spaghetti-monster/baton/baton.c
+++ b/spaghetti-monster/baton/baton.c
@@ -20,22 +20,13 @@
#define FSM_EMISAR_D4_DRIVER
#define USE_LVP
#define USE_THERMAL_REGULATION
-#define DEFAULT_THERM_CEIL 45
-#define USE_DEBUG_BLINK
#define USE_DELAY_MS
-#define USE_DELAY_4MS
-#define USE_DELAY_ZERO
#include "spaghetti-monster.h"
-// moon + ../../bin/level_calc.py 2 6 7135 18 10 150 FET 1 10 1500
-uint8_t pwm1_modes[] = { 3, 18, 110, 255, 255, 255, 0, };
-uint8_t pwm2_modes[] = { 0, 0, 0, 9, 58, 138, 255, };
-#define MAX_LEVEL (sizeof(pwm1_modes)-1)
-
// FSM states
uint8_t off_state(EventPtr event, uint16_t arg);
uint8_t steady_state(EventPtr event, uint16_t arg);
-uint8_t party_strobe_state(EventPtr event, uint16_t arg);
+uint8_t lockout_state(EventPtr event, uint16_t arg);
// brightness control
uint8_t memorized_level = 1;
@@ -44,93 +35,90 @@ uint8_t actual_level = 0;
uint8_t target_level = 0;
#endif
+// moon + ../../bin/level_calc.py 2 6 7135 18 10 150 FET 1 10 1500
+uint8_t pwm1_levels[] = { 3, 18, 110, 255, 255, 255, 0, };
+uint8_t pwm2_levels[] = { 0, 0, 0, 9, 58, 138, 255, };
+#define MAX_LEVEL (sizeof(pwm1_levels)-1)
+
+// set LED brightness
void set_level(uint8_t lvl) {
actual_level = lvl;
- PWM1_LVL = pwm1_modes[lvl];
- PWM2_LVL = pwm2_modes[lvl];
+ PWM1_LVL = pwm1_levels[lvl];
+ PWM2_LVL = pwm2_levels[lvl];
}
uint8_t off_state(EventPtr event, uint16_t arg) {
// turn emitter off when entering state
if (event == EV_enter_state) {
- PWM1_LVL = 0;
- PWM2_LVL = 0;
- // sleep while off (lower power use)
- go_to_standby = 1;
- return 0;
+ go_to_standby = 1; // sleep while off (lower power use)
+ return EVENT_HANDLED;
}
// hold (initially): go to lowest level, but allow abort for regular click
else if (event == EV_click1_press) {
set_level(0);
- return 0;
+ return EVENT_HANDLED;
+ }
+ // hold (longer): go to lowest level
+ else if (event == EV_click1_hold) {
+ set_state(steady_state, 0);
+ return EVENT_HANDLED;
}
// 1 click (before timeout): go to memorized level, but allow abort for double click
else if (event == EV_click1_release) {
set_level(memorized_level);
- return 0;
+ return EVENT_HANDLED;
}
// 1 click: regular mode
else if (event == EV_1click) {
set_state(steady_state, memorized_level);
- return 0;
+ return EVENT_HANDLED;
}
// 2 clicks: highest mode
else if (event == EV_2clicks) {
set_state(steady_state, MAX_LEVEL);
- return 0;
+ return EVENT_HANDLED;
}
- // 3 clicks: strobe mode
- else if (event == EV_3clicks) {
- set_state(party_strobe_state, 255);
- return 0;
+ // 4 clicks: soft lockout
+ else if (event == EV_4clicks) {
+ set_state(lockout_state, 0);
+ return EVENT_HANDLED;
}
- // hold: go to lowest level
- else if (event == EV_click1_hold) {
- set_state(steady_state, 0);
- return 0;
- }
- return 1;
+ return EVENT_NOT_HANDLED;
}
uint8_t steady_state(EventPtr event, uint16_t arg) {
// turn LED on when we first enter the mode
if (event == EV_enter_state) {
// remember this level, unless it's moon or turbo
- if ((arg > 0) && (arg < MAX_LEVEL))
- memorized_level = arg;
+ if ((arg > 0) && (arg < MAX_LEVEL)) memorized_level = arg;
// use the requested level even if not memorized
#ifdef USE_THERMAL_REGULATION
target_level = arg;
#endif
set_level(arg);
- return 0;
+ return EVENT_HANDLED;
}
// 1 click: off
else if (event == EV_1click) {
set_state(off_state, 0);
- return 0;
+ return EVENT_HANDLED;
}
// 2 clicks: go to/from highest level
else if (event == EV_2clicks) {
- if (actual_level < MAX_LEVEL) {
+ if (actual_level < MAX_LEVEL) { // go to turbo
memorized_level = actual_level; // in case we're on moon
#ifdef USE_THERMAL_REGULATION
target_level = MAX_LEVEL;
#endif
set_level(MAX_LEVEL);
}
- else {
+ else { // return from turbo
#ifdef USE_THERMAL_REGULATION
target_level = memorized_level;
#endif
set_level(memorized_level);
}
- return 0;
- }
- // 3 clicks: go to strobe modes
- else if (event == EV_3clicks) {
- set_state(party_strobe_state, 0xff);
- return 0;
+ return EVENT_HANDLED;
}
// hold: change brightness
else if (event == EV_click1_hold) {
@@ -141,90 +129,60 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
#endif
set_level(memorized_level);
}
- return 0;
+ return EVENT_HANDLED;
}
#ifdef USE_THERMAL_REGULATION
// overheating: drop by 1 level
else if (event == EV_temperature_high) {
- if (actual_level > 1) {
- set_level(actual_level - 1);
- }
- return 0;
+ if (actual_level > 1) { set_level(actual_level - 1); }
+ return EVENT_HANDLED;
}
// underheating: increase by 1 level if we're lower than the target
else if (event == EV_temperature_low) {
- if (actual_level < target_level) {
- set_level(actual_level + 1);
- }
- return 0;
+ if (actual_level < target_level) { set_level(actual_level + 1); }
+ return EVENT_HANDLED;
}
#endif
- return 1;
+ return EVENT_NOT_HANDLED;
}
-uint8_t party_strobe_state(EventPtr event, uint16_t arg) {
- static volatile uint8_t frames = 0;
- static volatile uint8_t between = 2;
- if (event == EV_enter_state) {
- if (arg < 64) between = arg;
- frames = 0;
- return 0;
- }
- // tick: strobe the emitter
- else if (event == EV_tick) {
- if (frames == 0) {
- PWM1_LVL = 0;
- PWM2_LVL = 255;
- if (between < 3) delay_zero();
- else delay_ms(1);
- PWM2_LVL = 0;
- }
- //frames = (frames + 1) % between;
- frames++;
- if (frames > between) frames = 0;
- return 0;
- }
- // 1 click: off
- else if (event == EV_1click) {
- set_state(off_state, 0);
- return 0;
- }
- // 2 clicks: go back to regular modes
- else if (event == EV_2clicks) {
- set_state(steady_state, memorized_level);
- return 0;
- }
- // hold: change speed
- else if (event == EV_click1_hold) {
- if ((arg % HOLD_TIMEOUT) == 0) {
- between = (between+1)%6;
- frames = 0;
- }
- return 0;
+uint8_t lockout_state(EventPtr event, uint16_t arg) {
+ // stay asleep while locked
+ if (event == EV_tick) {
+ PWM1_LVL = 0; PWM2_LVL = 0; // make sure emitters are off
+ // sleep 1 second after user stops pressing buttons
+ if (arg > TICKS_PER_SECOND) { go_to_standby = 1; }
+ return MISCHIEF_MANAGED;
+ }
+ // 4 clicks: exit, and turn on at "low" level
+ else if (event == EV_4clicks) {
+ set_state(steady_state, 1);
+ return MISCHIEF_MANAGED;
}
- return 1;
+ return EVENT_NOT_HANDLED;
}
void low_voltage() {
- // "step down" from strobe to level 2
- if (current_state == party_strobe_state) {
- set_state(steady_state, 1);
+ // step down by one level or turn off
+ if (actual_level > 0) {
+ set_level(actual_level - 1);
+ #ifdef USE_THERMAL_REGULATION
+ target_level = actual_level; // don't let low temperature override LVP
+ #endif
}
- // in normal mode, step down by one level or turn off
- else if (current_state == steady_state) {
- if (actual_level > 0) {
- set_level(actual_level - 1);
- }
- else {
- set_state(off_state, 0);
- }
+ else {
+ set_state(off_state, 0);
}
}
void setup() {
- debug_blink(2);
+ // blink when power is connected
+ set_level(MAX_LEVEL/2);
+ delay_ms(10);
+ set_level(0);
push_state(off_state, 0);
}
-void loop() { }
+void loop() {
+}
diff --git a/spaghetti-monster/baton/baton.txt b/spaghetti-monster/baton/baton.txt
new file mode 100644
index 0000000..2f0c22f
--- /dev/null
+++ b/spaghetti-monster/baton/baton.txt
@@ -0,0 +1,21 @@
+This is a very simple clone of the Olight Baton interface. It is not
+exact, but it has the basics. Mostly, it exists for the purposes of
+demonstrating how to create interfaces in FSM.
+
+While off:
+
+ - 1 click: Turn on (at memorized level).
+ - Hold: Turn on (at moon level).
+ - 2 clicks: Turn on (at highest level).
+ - 4 clicks: Soft lockout mode.
+
+While on:
+
+ - 1 click: Turn off.
+ - Hold: Change the brightness. Goes up in steps, then wraps around.
+ - 2 clicks: Go to/from highest level.
+
+While locked:
+
+ - 4 clicks: Exit lockout mode.
+
diff --git a/spaghetti-monster/rampingios/Makefile b/spaghetti-monster/rampingios/Makefile
new file mode 100644
index 0000000..8db198e
--- /dev/null
+++ b/spaghetti-monster/rampingios/Makefile
@@ -0,0 +1,7 @@
+all:
+ ./build-all.sh
+
+clean:
+ rm -f *.hex cfg-*.h *~ *.elf *.o
+
+.phony: clean
diff --git a/spaghetti-monster/rampingios/build-all.sh b/spaghetti-monster/rampingios/build-all.sh
index 22597b7..5b75fe4 100755
--- a/spaghetti-monster/rampingios/build-all.sh
+++ b/spaghetti-monster/rampingios/build-all.sh
@@ -13,6 +13,6 @@ for TARGET in \
EMISAR_D4S_219C \
; do
echo "===== $TARGET ====="
- ../../../bin/build-85.sh "$UI" "-DFSM_${TARGET}_DRIVER"
+ ../../../bin/build.sh 85 "$UI" "-DFSM_${TARGET}_DRIVER"
mv -f "$UI".hex "$UI".$TARGET.hex
done
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.