From 3322f7303b8c8237467968e2b47aae1111df90d3 Mon Sep 17 00:00:00 2001
From: Selene ToyKeeper
Date: Tue, 28 Jul 2020 01:26:17 -0600
Subject: renamed strobes.* to strobe-modes.*
---
spaghetti-monster/anduril/anduril.c | 6 +-
spaghetti-monster/anduril/ff-strobe-modes.c | 66 +++++
spaghetti-monster/anduril/ff-strobe-modes.h | 32 ++
spaghetti-monster/anduril/ff-strobes.c | 66 -----
spaghetti-monster/anduril/ff-strobes.h | 32 --
spaghetti-monster/anduril/strobe-modes-fsm.h | 44 +++
spaghetti-monster/anduril/strobe-modes.c | 427 +++++++++++++++++++++++++++
spaghetti-monster/anduril/strobe-modes.h | 103 +++++++
spaghetti-monster/anduril/strobes-fsm.h | 44 ---
spaghetti-monster/anduril/strobes.c | 427 ---------------------------
spaghetti-monster/anduril/strobes.h | 103 -------
11 files changed, 675 insertions(+), 675 deletions(-)
create mode 100644 spaghetti-monster/anduril/ff-strobe-modes.c
create mode 100644 spaghetti-monster/anduril/ff-strobe-modes.h
delete mode 100644 spaghetti-monster/anduril/ff-strobes.c
delete mode 100644 spaghetti-monster/anduril/ff-strobes.h
create mode 100644 spaghetti-monster/anduril/strobe-modes-fsm.h
create mode 100644 spaghetti-monster/anduril/strobe-modes.c
create mode 100644 spaghetti-monster/anduril/strobe-modes.h
delete mode 100644 spaghetti-monster/anduril/strobes-fsm.h
delete mode 100644 spaghetti-monster/anduril/strobes.c
delete mode 100644 spaghetti-monster/anduril/strobes.h
(limited to 'spaghetti-monster')
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c
index b479552..7416fb7 100644
--- a/spaghetti-monster/anduril/anduril.c
+++ b/spaghetti-monster/anduril/anduril.c
@@ -74,7 +74,7 @@
#endif
// enable FSM features needed by strobe modes
-#include "strobes-fsm.h"
+#include "strobe-modes-fsm.h"
// figure out how many bytes of eeprom are needed,
// based on which UI features are enabled
@@ -134,7 +134,7 @@
#endif
// this one detects its own enable/disable settings
-#include "strobes.h"
+#include "strobe-modes.h"
#ifdef USE_SOS_MODE
#include "sos-mode.h"
@@ -189,7 +189,7 @@
#endif
#ifdef USE_STROBE_STATE
-#include "strobes.c"
+#include "strobe-modes.c"
#endif
#ifdef USE_SOS_MODE
diff --git a/spaghetti-monster/anduril/ff-strobe-modes.c b/spaghetti-monster/anduril/ff-strobe-modes.c
new file mode 100644
index 0000000..eaac92a
--- /dev/null
+++ b/spaghetti-monster/anduril/ff-strobe-modes.c
@@ -0,0 +1,66 @@
+/*
+ * ff-strobe-modes.c: Fireflies Flashlights strobe modes for Anduril.
+ *
+ * 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 .
+ */
+
+#ifndef FF_STROBE_MODES_C
+#define FF_STROBE_MODES_C
+
+#include "ff-strobe-modes.h"
+
+uint8_t boring_strobe_state(Event event, uint16_t arg) {
+ // police strobe and SOS, meh
+ // 'st' reduces ROM size by avoiding access to a volatile var
+ // (maybe I should just make it nonvolatile?)
+ uint8_t st = boring_strobe_type;
+
+ if (event == EV_enter_state) {
+ return MISCHIEF_MANAGED;
+ }
+ // 1 click: off
+ else if (event == EV_1click) {
+ // reset to police strobe for next time
+ boring_strobe_type = 0;
+ set_state(off_state, 0);
+ return MISCHIEF_MANAGED;
+ }
+ // 2 clicks: rotate through strobe/flasher modes
+ else if (event == EV_2clicks) {
+ boring_strobe_type = (st + 1) % NUM_BORING_STROBES;
+ return MISCHIEF_MANAGED;
+ }
+ return EVENT_NOT_HANDLED;
+}
+
+#ifdef USE_POLICE_STROBE_MODE
+inline void police_strobe_iter() {
+ // one iteration of main loop()
+ // flash at 16 Hz then 8 Hz, 8 times each
+ for (uint8_t del=41; del<100; del+=41) {
+ for (uint8_t f=0; f<8; f++) {
+ set_level(STROBE_BRIGHTNESS);
+ nice_delay_ms(del >> 1);
+ set_level(0);
+ nice_delay_ms(del);
+ }
+ }
+}
+#endif
+
+
+#endif
+
diff --git a/spaghetti-monster/anduril/ff-strobe-modes.h b/spaghetti-monster/anduril/ff-strobe-modes.h
new file mode 100644
index 0000000..75a38e3
--- /dev/null
+++ b/spaghetti-monster/anduril/ff-strobe-modes.h
@@ -0,0 +1,32 @@
+/*
+ * ff-strobe-modes.h: Fireflies Flashlights strobe modes for Anduril.
+ *
+ * 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 .
+ */
+
+#ifndef FF_STROBE_MODES_H
+#define FF_STROBE_MODES_H
+
+uint8_t boring_strobe_state(Event event, uint16_t arg);
+volatile uint8_t boring_strobe_type = 0;
+void sos_blink(uint8_t num, uint8_t dah);
+#ifdef USE_POLICE_STROBE_MODE
+inline void police_strobe_iter();
+#endif
+#define NUM_BORING_STROBES 2
+
+
+#endif
diff --git a/spaghetti-monster/anduril/ff-strobes.c b/spaghetti-monster/anduril/ff-strobes.c
deleted file mode 100644
index c0b655e..0000000
--- a/spaghetti-monster/anduril/ff-strobes.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * ff-strobes.c: Fireflies Flashlights strobe modes for Anduril.
- *
- * 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 .
- */
-
-#ifndef FF_STROBES_C
-#define FF_STROBES_C
-
-#include "ff-strobes.h"
-
-uint8_t boring_strobe_state(Event event, uint16_t arg) {
- // police strobe and SOS, meh
- // 'st' reduces ROM size by avoiding access to a volatile var
- // (maybe I should just make it nonvolatile?)
- uint8_t st = boring_strobe_type;
-
- if (event == EV_enter_state) {
- return MISCHIEF_MANAGED;
- }
- // 1 click: off
- else if (event == EV_1click) {
- // reset to police strobe for next time
- boring_strobe_type = 0;
- set_state(off_state, 0);
- return MISCHIEF_MANAGED;
- }
- // 2 clicks: rotate through strobe/flasher modes
- else if (event == EV_2clicks) {
- boring_strobe_type = (st + 1) % NUM_BORING_STROBES;
- return MISCHIEF_MANAGED;
- }
- return EVENT_NOT_HANDLED;
-}
-
-#ifdef USE_POLICE_STROBE_MODE
-inline void police_strobe_iter() {
- // one iteration of main loop()
- // flash at 16 Hz then 8 Hz, 8 times each
- for (uint8_t del=41; del<100; del+=41) {
- for (uint8_t f=0; f<8; f++) {
- set_level(STROBE_BRIGHTNESS);
- nice_delay_ms(del >> 1);
- set_level(0);
- nice_delay_ms(del);
- }
- }
-}
-#endif
-
-
-#endif
-
diff --git a/spaghetti-monster/anduril/ff-strobes.h b/spaghetti-monster/anduril/ff-strobes.h
deleted file mode 100644
index 0c57e2c..0000000
--- a/spaghetti-monster/anduril/ff-strobes.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * ff-strobes.h: Fireflies Flashlights strobe modes for Anduril.
- *
- * 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 .
- */
-
-#ifndef FF_STROBES_H
-#define FF_STROBES_H
-
-uint8_t boring_strobe_state(Event event, uint16_t arg);
-volatile uint8_t boring_strobe_type = 0;
-void sos_blink(uint8_t num, uint8_t dah);
-#ifdef USE_POLICE_STROBE_MODE
-inline void police_strobe_iter();
-#endif
-#define NUM_BORING_STROBES 2
-
-
-#endif
diff --git a/spaghetti-monster/anduril/strobe-modes-fsm.h b/spaghetti-monster/anduril/strobe-modes-fsm.h
new file mode 100644
index 0000000..002a951
--- /dev/null
+++ b/spaghetti-monster/anduril/strobe-modes-fsm.h
@@ -0,0 +1,44 @@
+/*
+ * strobe-modes-fsm.h: FSM config for strobe modes in Anduril.
+ *
+ * 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 .
+ */
+
+#ifndef STROBE_MODES_FSM_H
+#define STROBE_MODES_FSM_H
+
+// enable the random number generator if we need it
+#if defined(USE_LIGHTNING_MODE) || defined(USE_CANDLE_MODE)
+#define USE_PSEUDO_RAND
+#endif
+
+// party strobe uses really short pulses
+#ifdef USE_PARTY_STROBE_MODE
+#define USE_DELAY_ZERO
+#endif
+
+// candle mode is basically a bunch of stacked random triangle waves
+#if defined(USE_CANDLE_MODE)
+#define USE_TRIANGLE_WAVE
+#endif
+
+// the presence of strobe mode(s) affects how many eeprom bytes we need,
+// so it's relevant for FSM configuration
+#if defined(USE_CANDLE_MODE) || defined(USE_BIKE_FLASHER_MODE) || defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE) || defined(USE_LIGHTNING_MODE)
+#define USE_STROBE_STATE
+#endif
+
+#endif
diff --git a/spaghetti-monster/anduril/strobe-modes.c b/spaghetti-monster/anduril/strobe-modes.c
new file mode 100644
index 0000000..8c5f34d
--- /dev/null
+++ b/spaghetti-monster/anduril/strobe-modes.c
@@ -0,0 +1,427 @@
+/*
+ * strobe-modes.c: Strobe modes for Anduril.
+ *
+ * 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 .
+ */
+
+#ifndef STROBE_MODES_C
+#define STROBE_MODES_C
+
+#include "strobe-modes.h"
+
+#ifdef USE_STROBE_STATE
+uint8_t strobe_state(Event event, uint16_t arg) {
+ static int8_t ramp_direction = 1;
+
+ // 'st' reduces ROM size by avoiding access to a volatile var
+ // (maybe I should just make it nonvolatile?)
+ strobe_mode_te st = strobe_type;
+
+ #ifdef USE_MOMENTARY_MODE
+ momentary_mode = 1; // 0 = ramping, 1 = strobes
+ #endif
+
+ #ifdef USE_CANDLE_MODE
+ // pass all events to candle mode, when it's active
+ // (the code is in its own pseudo-state to keep things cleaner)
+ if (st == candle_mode_e) {
+ candle_mode_state(event, arg);
+ }
+ #endif
+
+ if (0) {} // placeholder
+ // init anything which needs to be initialized
+ else if (event == EV_enter_state) {
+ ramp_direction = 1;
+ return MISCHIEF_MANAGED;
+ }
+ // 1 click: off
+ else if (event == EV_1click) {
+ set_state(off_state, 0);
+ return MISCHIEF_MANAGED;
+ }
+ // 2 clicks: rotate through strobe/flasher modes
+ else if (event == EV_2clicks) {
+ strobe_type = (st + 1) % NUM_STROBES;
+ save_config();
+ return MISCHIEF_MANAGED;
+ }
+ // hold: change speed (go faster)
+ // or change brightness (brighter)
+ else if (event == EV_click1_hold) {
+ if (0) {} // placeholder
+
+ // party / tactical strobe faster
+ #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
+ #ifdef USE_TACTICAL_STROBE_MODE
+ else if (st <= tactical_strobe_e) {
+ #else
+ else if (st == party_strobe_e) {
+ #endif
+ if ((arg & 1) == 0) {
+ uint8_t d = strobe_delays[st];
+ d -= ramp_direction;
+ if (d < 8) d = 8;
+ else if (d > 254) d = 254;
+ strobe_delays[st] = d;
+ }
+ }
+ #endif
+
+ // lightning has no adjustments
+ //else if (st == lightning_storm_e) {}
+
+ // biking mode brighter
+ #ifdef USE_BIKE_FLASHER_MODE
+ else if (st == bike_flasher_e) {
+ bike_flasher_brightness += ramp_direction;
+ if (bike_flasher_brightness < 2) bike_flasher_brightness = 2;
+ else if (bike_flasher_brightness > MAX_BIKING_LEVEL) bike_flasher_brightness = MAX_BIKING_LEVEL;
+ set_level(bike_flasher_brightness);
+ }
+ #endif
+
+ return MISCHIEF_MANAGED;
+ }
+ // reverse ramp direction on hold release
+ // ... and save new strobe settings
+ else if (event == EV_click1_hold_release) {
+ ramp_direction = -ramp_direction;
+ save_config();
+ return MISCHIEF_MANAGED;
+ }
+ // click, hold: change speed (go slower)
+ // or change brightness (dimmer)
+ else if (event == EV_click2_hold) {
+ ramp_direction = 1;
+
+ if (0) {} // placeholder
+
+ // party / tactical strobe slower
+ #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
+ #ifdef USE_TACTICAL_STROBE_MODE
+ else if (st <= tactical_strobe_e) {
+ #else
+ else if (st == party_strobe_e) {
+ #endif
+ if ((arg & 1) == 0) {
+ if (strobe_delays[st] < 255) strobe_delays[st] ++;
+ }
+ }
+ #endif
+
+ // lightning has no adjustments
+ //else if (st == lightning_storm_e) {}
+
+ // biking mode dimmer
+ #ifdef USE_BIKE_FLASHER_MODE
+ else if (st == bike_flasher_e) {
+ if (bike_flasher_brightness > 2)
+ bike_flasher_brightness --;
+ set_level(bike_flasher_brightness);
+ }
+ #endif
+
+ return MISCHIEF_MANAGED;
+ }
+ // release hold: save new strobe settings
+ else if (event == EV_click2_hold_release) {
+ save_config();
+ return MISCHIEF_MANAGED;
+ }
+ #ifdef USE_MOMENTARY_MODE
+ // 5 clicks: go to momentary mode (momentary strobe)
+ else if (event == EV_5clicks) {
+ set_state(momentary_state, 0);
+ set_level(0);
+ return MISCHIEF_MANAGED;
+ }
+ #endif
+ #if defined(USE_LIGHTNING_MODE) || defined(USE_CANDLE_MODE)
+ // clock tick: bump the random seed
+ else if (event == EV_tick) {
+ // un-reverse after 1 second
+ if (arg == TICKS_PER_SECOND) ramp_direction = 1;
+
+ pseudo_rand_seed += arg;
+ return MISCHIEF_MANAGED;
+ }
+ #endif
+ return EVENT_NOT_HANDLED;
+}
+
+// runs repeatedly in FSM loop() whenever UI is in strobe_state or momentary strobe
+inline void strobe_state_iter() {
+ uint8_t st = strobe_type;
+
+ switch(st) {
+ #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
+ #ifdef USE_PARTY_STROBE_MODE
+ case party_strobe_e:
+ #endif
+ #ifdef USE_TACTICAL_STROBE_MODE
+ case tactical_strobe_e:
+ #endif
+ party_tactical_strobe_mode_iter(st);
+ break;
+ #endif
+
+ #ifdef USE_LIGHTNING_MODE
+ case lightning_storm_e:
+ lightning_storm_iter();
+ break;
+ #endif
+
+ #ifdef USE_BIKE_FLASHER_MODE
+ case bike_flasher_e:
+ bike_flasher_iter();
+ break;
+ #endif
+ }
+}
+#endif // ifdef USE_STROBE_STATE
+
+#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
+inline void party_tactical_strobe_mode_iter(uint8_t st) {
+ // one iteration of main loop()
+ uint8_t del = strobe_delays[st];
+ // TODO: make tac strobe brightness configurable?
+ set_level(STROBE_BRIGHTNESS);
+ if (0) {} // placeholde0
+ #ifdef USE_PARTY_STROBE_MODE
+ else if (st == party_strobe_e) { // party strobe
+ #ifdef PARTY_STROBE_ONTIME
+ nice_delay_ms(PARTY_STROBE_ONTIME);
+ #else
+ if (del < 42) delay_zero();
+ else nice_delay_ms(1);
+ #endif
+ }
+ #endif
+ #ifdef USE_TACTICAL_STROBE_MODE
+ else { //tactical strobe
+ nice_delay_ms(del >> 1);
+ }
+ #endif
+ set_level(0);
+ nice_delay_ms(del); // no return check necessary on final delay
+}
+#endif
+
+#ifdef USE_LIGHTNING_MODE
+inline void lightning_storm_iter() {
+ // one iteration of main loop()
+ int16_t brightness;
+ uint16_t rand_time;
+
+ // turn the emitter on at a random level,
+ // for a random amount of time between 1ms and 32ms
+ //rand_time = 1 << (pseudo_rand() % 7);
+ rand_time = pseudo_rand() & 63;
+ brightness = 1 << (pseudo_rand() % 7); // 1, 2, 4, 8, 16, 32, 64
+ brightness += 1 << (pseudo_rand() % 5); // 2 to 80 now
+ brightness += pseudo_rand() % brightness; // 2 to 159 now (w/ low bias)
+ if (brightness > MAX_LEVEL) brightness = MAX_LEVEL;
+ set_level(brightness);
+ nice_delay_ms(rand_time);
+
+ // decrease the brightness somewhat more gradually, like lightning
+ uint8_t stepdown = brightness >> 3;
+ if (stepdown < 1) stepdown = 1;
+ while(brightness > 1) {
+ nice_delay_ms(rand_time);
+ brightness -= stepdown;
+ if (brightness < 0) brightness = 0;
+ set_level(brightness);
+ /*
+ if ((brightness < MAX_LEVEL/2) && (! (pseudo_rand() & 15))) {
+ brightness <<= 1;
+ set_level(brightness);
+ }
+ */
+ if (! (pseudo_rand() & 3)) {
+ nice_delay_ms(rand_time);
+ set_level(brightness>>1);
+ }
+ }
+
+ // turn the emitter off,
+ // for a random amount of time between 1ms and 8192ms
+ // (with a low bias)
+ rand_time = 1 << (pseudo_rand() % 13);
+ rand_time += pseudo_rand() % rand_time;
+ set_level(0);
+ nice_delay_ms(rand_time); // no return check necessary on final delay
+}
+#endif
+
+#ifdef USE_BIKE_FLASHER_MODE
+inline void bike_flasher_iter() {
+ // one iteration of main loop()
+ uint8_t burst = bike_flasher_brightness << 1;
+ if (burst > MAX_LEVEL) burst = MAX_LEVEL;
+ for(uint8_t i=0; i<4; i++) {
+ set_level(burst);
+ nice_delay_ms(5);
+ set_level(bike_flasher_brightness);
+ nice_delay_ms(65);
+ }
+ nice_delay_ms(720); // no return check necessary on final delay
+}
+#endif
+
+#ifdef USE_CANDLE_MODE
+uint8_t candle_mode_state(Event event, uint16_t arg) {
+ static int8_t ramp_direction = 1;
+ #define MAX_CANDLE_LEVEL (RAMP_LENGTH-CANDLE_AMPLITUDE-15)
+ static uint8_t candle_wave1 = 0;
+ static uint8_t candle_wave2 = 0;
+ static uint8_t candle_wave3 = 0;
+ static uint8_t candle_wave2_speed = 0;
+ // these should add up to 100
+ #define CANDLE_WAVE1_MAXDEPTH 30
+ #define CANDLE_WAVE2_MAXDEPTH 45
+ #define CANDLE_WAVE3_MAXDEPTH 25
+ static const uint8_t candle_wave1_depth = CANDLE_WAVE1_MAXDEPTH * CANDLE_AMPLITUDE / 100;
+ static uint8_t candle_wave2_depth = CANDLE_WAVE2_MAXDEPTH * CANDLE_AMPLITUDE / 100;
+ static uint8_t candle_wave3_depth = CANDLE_WAVE3_MAXDEPTH * CANDLE_AMPLITUDE / 100;
+ static uint8_t candle_mode_brightness = 24;
+ static uint8_t candle_mode_timer = 0;
+ #define TICKS_PER_CANDLE_MINUTE 4096 // about 65 seconds
+ #define MINUTES_PER_CANDLE_HALFHOUR 27 // ish
+
+ if (event == EV_enter_state) {
+ candle_mode_timer = 0; // in case any time was left over from earlier
+ ramp_direction = 1;
+ return MISCHIEF_MANAGED;
+ }
+ // 2 clicks: cancel timer
+ else if (event == EV_2clicks) {
+ // parent state just rotated through strobe/flasher modes,
+ // so cancel timer... in case any time was left over from earlier
+ candle_mode_timer = 0;
+ return MISCHIEF_MANAGED;
+ }
+ // hold: change brightness (brighter)
+ else if (event == EV_click1_hold) {
+ // ramp away from extremes
+ if (! arg) {
+ if (candle_mode_brightness >= MAX_CANDLE_LEVEL) { ramp_direction = -1; }
+ else if (candle_mode_brightness <= 1) { ramp_direction = 1; }
+ }
+ // change brightness, but not too far
+ candle_mode_brightness += ramp_direction;
+ if (candle_mode_brightness < 1) candle_mode_brightness = 1;
+ else if (candle_mode_brightness > MAX_CANDLE_LEVEL) candle_mode_brightness = MAX_CANDLE_LEVEL;
+ return MISCHIEF_MANAGED;
+ }
+ // reverse ramp direction on hold release
+ else if (event == EV_click1_hold_release) {
+ ramp_direction = -ramp_direction;
+ return MISCHIEF_MANAGED;
+ }
+ // click, hold: change brightness (dimmer)
+ else if (event == EV_click2_hold) {
+ ramp_direction = 1;
+ if (candle_mode_brightness > 1)
+ candle_mode_brightness --;
+ return MISCHIEF_MANAGED;
+ }
+ // 3 clicks: add 30m to candle timer
+ else if (event == EV_3clicks) {
+ if (candle_mode_timer < (255 - MINUTES_PER_CANDLE_HALFHOUR)) {
+ // add 30m to the timer
+ candle_mode_timer += MINUTES_PER_CANDLE_HALFHOUR;
+ // blink to confirm
+ set_level(actual_level + 32);
+ delay_4ms(2);
+ }
+ return MISCHIEF_MANAGED;
+ }
+ // clock tick: animate candle brightness
+ else if (event == EV_tick) {
+ // un-reverse after 1 second
+ if (arg == TICKS_PER_SECOND) ramp_direction = 1;
+
+ // self-timer dims the light during the final minute
+ uint8_t subtract = 0;
+ if (candle_mode_timer == 1) {
+ subtract = ((candle_mode_brightness+CANDLE_AMPLITUDE)
+ * ((arg & (TICKS_PER_CANDLE_MINUTE-1)) >> 4))
+ >> 8;
+ }
+ // we passed a minute mark, decrease timer if it's running
+ if ((arg & (TICKS_PER_CANDLE_MINUTE-1)) == (TICKS_PER_CANDLE_MINUTE - 1)) {
+ if (candle_mode_timer > 0) {
+ candle_mode_timer --;
+ //set_level(0); delay_4ms(2);
+ // if the timer ran out, shut off
+ if (! candle_mode_timer) {
+ set_state(off_state, 0);
+ }
+ }
+ }
+ // 3-oscillator synth for a relatively organic pattern
+ uint8_t add;
+ add = ((triangle_wave(candle_wave1) * candle_wave1_depth) >> 8)
+ + ((triangle_wave(candle_wave2) * candle_wave2_depth) >> 8)
+ + ((triangle_wave(candle_wave3) * candle_wave3_depth) >> 8);
+ int8_t brightness = candle_mode_brightness + add - subtract;
+ if (brightness < 0) { brightness = 0; }
+ set_level(brightness);
+
+ // wave1: slow random LFO
+ // TODO: make wave slower and more erratic?
+ if ((arg & 1) == 0) candle_wave1 += pseudo_rand() & 1;
+ // wave2: medium-speed erratic LFO
+ candle_wave2 += candle_wave2_speed;
+ // wave3: erratic fast wave
+ candle_wave3 += pseudo_rand() % 37;
+ // S&H on wave2 frequency to make it more erratic
+ if ((pseudo_rand() & 0b00111111) == 0)
+ candle_wave2_speed = pseudo_rand() % 13;
+ // downward sawtooth on wave2 depth to simulate stabilizing
+ if ((candle_wave2_depth > 0) && ((pseudo_rand() & 0b00111111) == 0))
+ candle_wave2_depth --;
+ // random sawtooth retrigger
+ if (pseudo_rand() == 0) {
+ // random amplitude
+ //candle_wave2_depth = 2 + (pseudo_rand() % ((CANDLE_WAVE2_MAXDEPTH * CANDLE_AMPLITUDE / 100) - 2));
+ candle_wave2_depth = pseudo_rand() % (CANDLE_WAVE2_MAXDEPTH * CANDLE_AMPLITUDE / 100);
+ //candle_wave3_depth = 5;
+ candle_wave2 = 0;
+ }
+ // downward sawtooth on wave3 depth to simulate stabilizing
+ if ((candle_wave3_depth > 2) && ((pseudo_rand() & 0b00011111) == 0))
+ candle_wave3_depth --;
+ if ((pseudo_rand() & 0b01111111) == 0)
+ // random amplitude
+ //candle_wave3_depth = 2 + (pseudo_rand() % ((CANDLE_WAVE3_MAXDEPTH * CANDLE_AMPLITUDE / 100) - 2));
+ candle_wave3_depth = pseudo_rand() % (CANDLE_WAVE3_MAXDEPTH * CANDLE_AMPLITUDE / 100);
+ return MISCHIEF_MANAGED;
+ }
+ return EVENT_NOT_HANDLED;
+}
+#endif // #ifdef USE_CANDLE_MODE
+
+
+#ifdef USE_BORING_STROBE_STATE
+#include "ff-strobe-modes.c"
+#endif
+
+
+#endif
+
diff --git a/spaghetti-monster/anduril/strobe-modes.h b/spaghetti-monster/anduril/strobe-modes.h
new file mode 100644
index 0000000..e2711f2
--- /dev/null
+++ b/spaghetti-monster/anduril/strobe-modes.h
@@ -0,0 +1,103 @@
+/*
+ * strobe-modes.h: Strobe modes for Anduril.
+ *
+ * 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 .
+ */
+
+#ifndef STROBE_MODES_H
+#define STROBE_MODES_H
+
+// internal numbering for strobe modes
+#ifdef USE_STROBE_STATE
+typedef enum {
+ #ifdef USE_PARTY_STROBE_MODE
+ party_strobe_e,
+ #endif
+ #ifdef USE_TACTICAL_STROBE_MODE
+ tactical_strobe_e,
+ #endif
+ #ifdef USE_LIGHTNING_MODE
+ lightning_storm_e,
+ #endif
+ #ifdef USE_CANDLE_MODE
+ candle_mode_e,
+ #endif
+ #ifdef USE_BIKE_FLASHER_MODE
+ bike_flasher_e,
+ #endif
+ strobe_mode_END
+} strobe_mode_te;
+
+const int NUM_STROBES = strobe_mode_END;
+
+// which strobe mode is active?
+#ifdef USE_CANDLE_MODE
+volatile strobe_mode_te strobe_type = candle_mode_e;
+#else
+volatile strobe_mode_te strobe_type = 0;
+#endif
+#endif
+
+
+// full FET strobe can be a bit much... use max regulated level instead,
+// if there's a bright enough regulated level
+#ifndef STROBE_BRIGHTNESS
+#ifdef MAX_Nx7135
+#define STROBE_BRIGHTNESS MAX_Nx7135
+#else
+#define STROBE_BRIGHTNESS MAX_LEVEL
+#endif
+#endif
+
+// party and tactical strobes
+#ifdef USE_STROBE_STATE
+uint8_t strobe_state(Event event, uint16_t arg);
+inline void strobe_state_iter();
+#endif
+
+#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
+// party / tactical strobe timing
+volatile uint8_t strobe_delays[] = { 41, 67 }; // party strobe 24 Hz, tactical strobe 10 Hz
+inline void party_tactical_strobe_mode_iter(uint8_t st);
+#endif
+
+#ifdef USE_LIGHTNING_MODE
+inline void lightning_storm_iter();
+#endif
+
+// bike mode config options
+#ifdef USE_BIKE_FLASHER_MODE
+#define MAX_BIKING_LEVEL 120 // should be 127 or less
+volatile uint8_t bike_flasher_brightness = MAX_1x7135;
+inline void bike_flasher_iter();
+#endif
+
+#ifdef USE_CANDLE_MODE
+uint8_t candle_mode_state(Event event, uint16_t arg);
+// moved to fsm-misc.c because tint ramping power correction
+//uint8_t triangle_wave(uint8_t phase);
+#ifndef CANDLE_AMPLITUDE
+#define CANDLE_AMPLITUDE 25
+#endif
+#endif
+
+
+#if defined(USE_POLICE_STROBE_MODE) || defined(USE_SOS_MODE_IN_FF_GROUP)
+#define USE_BORING_STROBE_STATE
+#include "ff-strobe-modes.h"
+#endif
+
+#endif
diff --git a/spaghetti-monster/anduril/strobes-fsm.h b/spaghetti-monster/anduril/strobes-fsm.h
deleted file mode 100644
index 2eb2d79..0000000
--- a/spaghetti-monster/anduril/strobes-fsm.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * strobes-fsm.h: FSM config for strobe modes in Anduril.
- *
- * 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 .
- */
-
-#ifndef STROBES_FSM_H
-#define STROBES_FSM_H
-
-// enable the random number generator if we need it
-#if defined(USE_LIGHTNING_MODE) || defined(USE_CANDLE_MODE)
-#define USE_PSEUDO_RAND
-#endif
-
-// party strobe uses really short pulses
-#ifdef USE_PARTY_STROBE_MODE
-#define USE_DELAY_ZERO
-#endif
-
-// candle mode is basically a bunch of stacked random triangle waves
-#if defined(USE_CANDLE_MODE)
-#define USE_TRIANGLE_WAVE
-#endif
-
-// the presence of strobe mode(s) affects how many eeprom bytes we need,
-// so it's relevant for FSM configuration
-#if defined(USE_CANDLE_MODE) || defined(USE_BIKE_FLASHER_MODE) || defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE) || defined(USE_LIGHTNING_MODE)
-#define USE_STROBE_STATE
-#endif
-
-#endif
diff --git a/spaghetti-monster/anduril/strobes.c b/spaghetti-monster/anduril/strobes.c
deleted file mode 100644
index 1037c0e..0000000
--- a/spaghetti-monster/anduril/strobes.c
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * strobes.c: Strobe modes for Anduril.
- *
- * 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 .
- */
-
-#ifndef STROBES_C
-#define STROBES_C
-
-#include "strobes.h"
-
-#ifdef USE_STROBE_STATE
-uint8_t strobe_state(Event event, uint16_t arg) {
- static int8_t ramp_direction = 1;
-
- // 'st' reduces ROM size by avoiding access to a volatile var
- // (maybe I should just make it nonvolatile?)
- strobe_mode_te st = strobe_type;
-
- #ifdef USE_MOMENTARY_MODE
- momentary_mode = 1; // 0 = ramping, 1 = strobes
- #endif
-
- #ifdef USE_CANDLE_MODE
- // pass all events to candle mode, when it's active
- // (the code is in its own pseudo-state to keep things cleaner)
- if (st == candle_mode_e) {
- candle_mode_state(event, arg);
- }
- #endif
-
- if (0) {} // placeholder
- // init anything which needs to be initialized
- else if (event == EV_enter_state) {
- ramp_direction = 1;
- return MISCHIEF_MANAGED;
- }
- // 1 click: off
- else if (event == EV_1click) {
- set_state(off_state, 0);
- return MISCHIEF_MANAGED;
- }
- // 2 clicks: rotate through strobe/flasher modes
- else if (event == EV_2clicks) {
- strobe_type = (st + 1) % NUM_STROBES;
- save_config();
- return MISCHIEF_MANAGED;
- }
- // hold: change speed (go faster)
- // or change brightness (brighter)
- else if (event == EV_click1_hold) {
- if (0) {} // placeholder
-
- // party / tactical strobe faster
- #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
- #ifdef USE_TACTICAL_STROBE_MODE
- else if (st <= tactical_strobe_e) {
- #else
- else if (st == party_strobe_e) {
- #endif
- if ((arg & 1) == 0) {
- uint8_t d = strobe_delays[st];
- d -= ramp_direction;
- if (d < 8) d = 8;
- else if (d > 254) d = 254;
- strobe_delays[st] = d;
- }
- }
- #endif
-
- // lightning has no adjustments
- //else if (st == lightning_storm_e) {}
-
- // biking mode brighter
- #ifdef USE_BIKE_FLASHER_MODE
- else if (st == bike_flasher_e) {
- bike_flasher_brightness += ramp_direction;
- if (bike_flasher_brightness < 2) bike_flasher_brightness = 2;
- else if (bike_flasher_brightness > MAX_BIKING_LEVEL) bike_flasher_brightness = MAX_BIKING_LEVEL;
- set_level(bike_flasher_brightness);
- }
- #endif
-
- return MISCHIEF_MANAGED;
- }
- // reverse ramp direction on hold release
- // ... and save new strobe settings
- else if (event == EV_click1_hold_release) {
- ramp_direction = -ramp_direction;
- save_config();
- return MISCHIEF_MANAGED;
- }
- // click, hold: change speed (go slower)
- // or change brightness (dimmer)
- else if (event == EV_click2_hold) {
- ramp_direction = 1;
-
- if (0) {} // placeholder
-
- // party / tactical strobe slower
- #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
- #ifdef USE_TACTICAL_STROBE_MODE
- else if (st <= tactical_strobe_e) {
- #else
- else if (st == party_strobe_e) {
- #endif
- if ((arg & 1) == 0) {
- if (strobe_delays[st] < 255) strobe_delays[st] ++;
- }
- }
- #endif
-
- // lightning has no adjustments
- //else if (st == lightning_storm_e) {}
-
- // biking mode dimmer
- #ifdef USE_BIKE_FLASHER_MODE
- else if (st == bike_flasher_e) {
- if (bike_flasher_brightness > 2)
- bike_flasher_brightness --;
- set_level(bike_flasher_brightness);
- }
- #endif
-
- return MISCHIEF_MANAGED;
- }
- // release hold: save new strobe settings
- else if (event == EV_click2_hold_release) {
- save_config();
- return MISCHIEF_MANAGED;
- }
- #ifdef USE_MOMENTARY_MODE
- // 5 clicks: go to momentary mode (momentary strobe)
- else if (event == EV_5clicks) {
- set_state(momentary_state, 0);
- set_level(0);
- return MISCHIEF_MANAGED;
- }
- #endif
- #if defined(USE_LIGHTNING_MODE) || defined(USE_CANDLE_MODE)
- // clock tick: bump the random seed
- else if (event == EV_tick) {
- // un-reverse after 1 second
- if (arg == TICKS_PER_SECOND) ramp_direction = 1;
-
- pseudo_rand_seed += arg;
- return MISCHIEF_MANAGED;
- }
- #endif
- return EVENT_NOT_HANDLED;
-}
-
-// runs repeatedly in FSM loop() whenever UI is in strobe_state or momentary strobe
-inline void strobe_state_iter() {
- uint8_t st = strobe_type;
-
- switch(st) {
- #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
- #ifdef USE_PARTY_STROBE_MODE
- case party_strobe_e:
- #endif
- #ifdef USE_TACTICAL_STROBE_MODE
- case tactical_strobe_e:
- #endif
- party_tactical_strobe_mode_iter(st);
- break;
- #endif
-
- #ifdef USE_LIGHTNING_MODE
- case lightning_storm_e:
- lightning_storm_iter();
- break;
- #endif
-
- #ifdef USE_BIKE_FLASHER_MODE
- case bike_flasher_e:
- bike_flasher_iter();
- break;
- #endif
- }
-}
-#endif // ifdef USE_STROBE_STATE
-
-#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
-inline void party_tactical_strobe_mode_iter(uint8_t st) {
- // one iteration of main loop()
- uint8_t del = strobe_delays[st];
- // TODO: make tac strobe brightness configurable?
- set_level(STROBE_BRIGHTNESS);
- if (0) {} // placeholde0
- #ifdef USE_PARTY_STROBE_MODE
- else if (st == party_strobe_e) { // party strobe
- #ifdef PARTY_STROBE_ONTIME
- nice_delay_ms(PARTY_STROBE_ONTIME);
- #else
- if (del < 42) delay_zero();
- else nice_delay_ms(1);
- #endif
- }
- #endif
- #ifdef USE_TACTICAL_STROBE_MODE
- else { //tactical strobe
- nice_delay_ms(del >> 1);
- }
- #endif
- set_level(0);
- nice_delay_ms(del); // no return check necessary on final delay
-}
-#endif
-
-#ifdef USE_LIGHTNING_MODE
-inline void lightning_storm_iter() {
- // one iteration of main loop()
- int16_t brightness;
- uint16_t rand_time;
-
- // turn the emitter on at a random level,
- // for a random amount of time between 1ms and 32ms
- //rand_time = 1 << (pseudo_rand() % 7);
- rand_time = pseudo_rand() & 63;
- brightness = 1 << (pseudo_rand() % 7); // 1, 2, 4, 8, 16, 32, 64
- brightness += 1 << (pseudo_rand() % 5); // 2 to 80 now
- brightness += pseudo_rand() % brightness; // 2 to 159 now (w/ low bias)
- if (brightness > MAX_LEVEL) brightness = MAX_LEVEL;
- set_level(brightness);
- nice_delay_ms(rand_time);
-
- // decrease the brightness somewhat more gradually, like lightning
- uint8_t stepdown = brightness >> 3;
- if (stepdown < 1) stepdown = 1;
- while(brightness > 1) {
- nice_delay_ms(rand_time);
- brightness -= stepdown;
- if (brightness < 0) brightness = 0;
- set_level(brightness);
- /*
- if ((brightness < MAX_LEVEL/2) && (! (pseudo_rand() & 15))) {
- brightness <<= 1;
- set_level(brightness);
- }
- */
- if (! (pseudo_rand() & 3)) {
- nice_delay_ms(rand_time);
- set_level(brightness>>1);
- }
- }
-
- // turn the emitter off,
- // for a random amount of time between 1ms and 8192ms
- // (with a low bias)
- rand_time = 1 << (pseudo_rand() % 13);
- rand_time += pseudo_rand() % rand_time;
- set_level(0);
- nice_delay_ms(rand_time); // no return check necessary on final delay
-}
-#endif
-
-#ifdef USE_BIKE_FLASHER_MODE
-inline void bike_flasher_iter() {
- // one iteration of main loop()
- uint8_t burst = bike_flasher_brightness << 1;
- if (burst > MAX_LEVEL) burst = MAX_LEVEL;
- for(uint8_t i=0; i<4; i++) {
- set_level(burst);
- nice_delay_ms(5);
- set_level(bike_flasher_brightness);
- nice_delay_ms(65);
- }
- nice_delay_ms(720); // no return check necessary on final delay
-}
-#endif
-
-#ifdef USE_CANDLE_MODE
-uint8_t candle_mode_state(Event event, uint16_t arg) {
- static int8_t ramp_direction = 1;
- #define MAX_CANDLE_LEVEL (RAMP_LENGTH-CANDLE_AMPLITUDE-15)
- static uint8_t candle_wave1 = 0;
- static uint8_t candle_wave2 = 0;
- static uint8_t candle_wave3 = 0;
- static uint8_t candle_wave2_speed = 0;
- // these should add up to 100
- #define CANDLE_WAVE1_MAXDEPTH 30
- #define CANDLE_WAVE2_MAXDEPTH 45
- #define CANDLE_WAVE3_MAXDEPTH 25
- static const uint8_t candle_wave1_depth = CANDLE_WAVE1_MAXDEPTH * CANDLE_AMPLITUDE / 100;
- static uint8_t candle_wave2_depth = CANDLE_WAVE2_MAXDEPTH * CANDLE_AMPLITUDE / 100;
- static uint8_t candle_wave3_depth = CANDLE_WAVE3_MAXDEPTH * CANDLE_AMPLITUDE / 100;
- static uint8_t candle_mode_brightness = 24;
- static uint8_t candle_mode_timer = 0;
- #define TICKS_PER_CANDLE_MINUTE 4096 // about 65 seconds
- #define MINUTES_PER_CANDLE_HALFHOUR 27 // ish
-
- if (event == EV_enter_state) {
- candle_mode_timer = 0; // in case any time was left over from earlier
- ramp_direction = 1;
- return MISCHIEF_MANAGED;
- }
- // 2 clicks: cancel timer
- else if (event == EV_2clicks) {
- // parent state just rotated through strobe/flasher modes,
- // so cancel timer... in case any time was left over from earlier
- candle_mode_timer = 0;
- return MISCHIEF_MANAGED;
- }
- // hold: change brightness (brighter)
- else if (event == EV_click1_hold) {
- // ramp away from extremes
- if (! arg) {
- if (candle_mode_brightness >= MAX_CANDLE_LEVEL) { ramp_direction = -1; }
- else if (candle_mode_brightness <= 1) { ramp_direction = 1; }
- }
- // change brightness, but not too far
- candle_mode_brightness += ramp_direction;
- if (candle_mode_brightness < 1) candle_mode_brightness = 1;
- else if (candle_mode_brightness > MAX_CANDLE_LEVEL) candle_mode_brightness = MAX_CANDLE_LEVEL;
- return MISCHIEF_MANAGED;
- }
- // reverse ramp direction on hold release
- else if (event == EV_click1_hold_release) {
- ramp_direction = -ramp_direction;
- return MISCHIEF_MANAGED;
- }
- // click, hold: change brightness (dimmer)
- else if (event == EV_click2_hold) {
- ramp_direction = 1;
- if (candle_mode_brightness > 1)
- candle_mode_brightness --;
- return MISCHIEF_MANAGED;
- }
- // 3 clicks: add 30m to candle timer
- else if (event == EV_3clicks) {
- if (candle_mode_timer < (255 - MINUTES_PER_CANDLE_HALFHOUR)) {
- // add 30m to the timer
- candle_mode_timer += MINUTES_PER_CANDLE_HALFHOUR;
- // blink to confirm
- set_level(actual_level + 32);
- delay_4ms(2);
- }
- return MISCHIEF_MANAGED;
- }
- // clock tick: animate candle brightness
- else if (event == EV_tick) {
- // un-reverse after 1 second
- if (arg == TICKS_PER_SECOND) ramp_direction = 1;
-
- // self-timer dims the light during the final minute
- uint8_t subtract = 0;
- if (candle_mode_timer == 1) {
- subtract = ((candle_mode_brightness+CANDLE_AMPLITUDE)
- * ((arg & (TICKS_PER_CANDLE_MINUTE-1)) >> 4))
- >> 8;
- }
- // we passed a minute mark, decrease timer if it's running
- if ((arg & (TICKS_PER_CANDLE_MINUTE-1)) == (TICKS_PER_CANDLE_MINUTE - 1)) {
- if (candle_mode_timer > 0) {
- candle_mode_timer --;
- //set_level(0); delay_4ms(2);
- // if the timer ran out, shut off
- if (! candle_mode_timer) {
- set_state(off_state, 0);
- }
- }
- }
- // 3-oscillator synth for a relatively organic pattern
- uint8_t add;
- add = ((triangle_wave(candle_wave1) * candle_wave1_depth) >> 8)
- + ((triangle_wave(candle_wave2) * candle_wave2_depth) >> 8)
- + ((triangle_wave(candle_wave3) * candle_wave3_depth) >> 8);
- int8_t brightness = candle_mode_brightness + add - subtract;
- if (brightness < 0) { brightness = 0; }
- set_level(brightness);
-
- // wave1: slow random LFO
- // TODO: make wave slower and more erratic?
- if ((arg & 1) == 0) candle_wave1 += pseudo_rand() & 1;
- // wave2: medium-speed erratic LFO
- candle_wave2 += candle_wave2_speed;
- // wave3: erratic fast wave
- candle_wave3 += pseudo_rand() % 37;
- // S&H on wave2 frequency to make it more erratic
- if ((pseudo_rand() & 0b00111111) == 0)
- candle_wave2_speed = pseudo_rand() % 13;
- // downward sawtooth on wave2 depth to simulate stabilizing
- if ((candle_wave2_depth > 0) && ((pseudo_rand() & 0b00111111) == 0))
- candle_wave2_depth --;
- // random sawtooth retrigger
- if (pseudo_rand() == 0) {
- // random amplitude
- //candle_wave2_depth = 2 + (pseudo_rand() % ((CANDLE_WAVE2_MAXDEPTH * CANDLE_AMPLITUDE / 100) - 2));
- candle_wave2_depth = pseudo_rand() % (CANDLE_WAVE2_MAXDEPTH * CANDLE_AMPLITUDE / 100);
- //candle_wave3_depth = 5;
- candle_wave2 = 0;
- }
- // downward sawtooth on wave3 depth to simulate stabilizing
- if ((candle_wave3_depth > 2) && ((pseudo_rand() & 0b00011111) == 0))
- candle_wave3_depth --;
- if ((pseudo_rand() & 0b01111111) == 0)
- // random amplitude
- //candle_wave3_depth = 2 + (pseudo_rand() % ((CANDLE_WAVE3_MAXDEPTH * CANDLE_AMPLITUDE / 100) - 2));
- candle_wave3_depth = pseudo_rand() % (CANDLE_WAVE3_MAXDEPTH * CANDLE_AMPLITUDE / 100);
- return MISCHIEF_MANAGED;
- }
- return EVENT_NOT_HANDLED;
-}
-#endif // #ifdef USE_CANDLE_MODE
-
-
-#ifdef USE_BORING_STROBE_STATE
-#include "ff-strobes.c"
-#endif
-
-
-#endif
-
diff --git a/spaghetti-monster/anduril/strobes.h b/spaghetti-monster/anduril/strobes.h
deleted file mode 100644
index c74b4a0..0000000
--- a/spaghetti-monster/anduril/strobes.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * strobes.h: Strobe modes for Anduril.
- *
- * 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 .
- */
-
-#ifndef STROBES_H
-#define STROBES_H
-
-// internal numbering for strobe modes
-#ifdef USE_STROBE_STATE
-typedef enum {
- #ifdef USE_PARTY_STROBE_MODE
- party_strobe_e,
- #endif
- #ifdef USE_TACTICAL_STROBE_MODE
- tactical_strobe_e,
- #endif
- #ifdef USE_LIGHTNING_MODE
- lightning_storm_e,
- #endif
- #ifdef USE_CANDLE_MODE
- candle_mode_e,
- #endif
- #ifdef USE_BIKE_FLASHER_MODE
- bike_flasher_e,
- #endif
- strobe_mode_END
-} strobe_mode_te;
-
-const int NUM_STROBES = strobe_mode_END;
-
-// which strobe mode is active?
-#ifdef USE_CANDLE_MODE
-volatile strobe_mode_te strobe_type = candle_mode_e;
-#else
-volatile strobe_mode_te strobe_type = 0;
-#endif
-#endif
-
-
-// full FET strobe can be a bit much... use max regulated level instead,
-// if there's a bright enough regulated level
-#ifndef STROBE_BRIGHTNESS
-#ifdef MAX_Nx7135
-#define STROBE_BRIGHTNESS MAX_Nx7135
-#else
-#define STROBE_BRIGHTNESS MAX_LEVEL
-#endif
-#endif
-
-// party and tactical strobes
-#ifdef USE_STROBE_STATE
-uint8_t strobe_state(Event event, uint16_t arg);
-inline void strobe_state_iter();
-#endif
-
-#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
-// party / tactical strobe timing
-volatile uint8_t strobe_delays[] = { 41, 67 }; // party strobe 24 Hz, tactical strobe 10 Hz
-inline void party_tactical_strobe_mode_iter(uint8_t st);
-#endif
-
-#ifdef USE_LIGHTNING_MODE
-inline void lightning_storm_iter();
-#endif
-
-// bike mode config options
-#ifdef USE_BIKE_FLASHER_MODE
-#define MAX_BIKING_LEVEL 120 // should be 127 or less
-volatile uint8_t bike_flasher_brightness = MAX_1x7135;
-inline void bike_flasher_iter();
-#endif
-
-#ifdef USE_CANDLE_MODE
-uint8_t candle_mode_state(Event event, uint16_t arg);
-// moved to fsm-misc.c because tint ramping power correction
-//uint8_t triangle_wave(uint8_t phase);
-#ifndef CANDLE_AMPLITUDE
-#define CANDLE_AMPLITUDE 25
-#endif
-#endif
-
-
-#if defined(USE_POLICE_STROBE_MODE) || defined(USE_SOS_MODE_IN_FF_GROUP)
-#define USE_BORING_STROBE_STATE
-#include "ff-strobes.h"
-#endif
-
-#endif
--
cgit v1.2.3