aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hwdef-emisar-2ch-fet.c8
-rw-r--r--hwdef-emisar-2ch.c8
-rw-r--r--hwdef-noctigon-m44.c8
-rw-r--r--hwdef-sofirn-lt1s-pro.c12
-rw-r--r--spaghetti-monster/anduril/channel-modes.c19
-rw-r--r--spaghetti-monster/anduril/config-mode.c5
-rw-r--r--spaghetti-monster/anduril/load-save-config-fsm.h3
-rw-r--r--spaghetti-monster/anduril/load-save-config.h6
-rw-r--r--spaghetti-monster/anduril/off-mode.c4
-rw-r--r--spaghetti-monster/anduril/ramp-mode.c12
-rw-r--r--spaghetti-monster/anduril/strobe-modes-fsm.h28
-rw-r--r--spaghetti-monster/anduril/strobe-modes.c22
-rw-r--r--spaghetti-monster/anduril/strobe-modes.h27
-rw-r--r--spaghetti-monster/anduril/tactical-mode.c5
-rw-r--r--spaghetti-monster/fsm-channels.c2
-rw-r--r--spaghetti-monster/fsm-channels.h11
-rw-r--r--spaghetti-monster/fsm-misc.c6
-rw-r--r--spaghetti-monster/fsm-ramping.c4
18 files changed, 114 insertions, 76 deletions
diff --git a/hwdef-emisar-2ch-fet.c b/hwdef-emisar-2ch-fet.c
index ea4f5e6..7cf48d3 100644
--- a/hwdef-emisar-2ch-fet.c
+++ b/hwdef-emisar-2ch-fet.c
@@ -134,7 +134,7 @@ void set_level_blend(uint8_t level) {
//uint16_t brightness = PWM_GET8 (pwm1_levels, level) << 1;
uint16_t brightness = PWM_GET8 (pwm1_levels, level) + pwm3;
uint16_t top = PWM_GET16(pwm3_levels, level);
- uint8_t blend = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t blend = cfg.channel_mode_args[channel_mode];
calc_2ch_blend(&pwm1, &pwm2, brightness, top, blend);
@@ -150,7 +150,7 @@ void set_level_auto(uint8_t level) {
uint8_t brightness = PWM_GET8 (pwm4_levels, level);
uint16_t top = PWM_GET16(pwm5_levels, level);
uint8_t blend = 255 * (uint16_t)level / RAMP_SIZE;
- if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000)
+ if (cfg.channel_mode_args[channel_mode] & 0b01000000)
blend = 255 - blend;
calc_2ch_blend(&pwm1, &pwm2, brightness, top, blend);
@@ -197,7 +197,7 @@ bool gradual_tick_blend(uint8_t level) {
//uint16_t brightness = PWM_GET8 (pwm1_levels, level) << 1;
uint16_t brightness = PWM_GET8 (pwm1_levels, level) + pwm3;
uint16_t top = PWM_GET16(pwm3_levels, level);
- uint8_t blend = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t blend = cfg.channel_mode_args[channel_mode];
calc_2ch_blend(&pwm1, &pwm2, brightness, top, blend);
@@ -209,7 +209,7 @@ bool gradual_tick_auto(uint8_t level) {
uint8_t brightness = PWM_GET8 (pwm4_levels, level);
uint16_t top = PWM_GET16(pwm5_levels, level);
uint8_t blend = 255 * (uint16_t)level / RAMP_SIZE;
- if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000)
+ if (cfg.channel_mode_args[channel_mode] & 0b01000000)
blend = 255 - blend;
calc_2ch_blend(&pwm1, &pwm2, brightness, top, blend);
diff --git a/hwdef-emisar-2ch.c b/hwdef-emisar-2ch.c
index 793e9bc..7955cf6 100644
--- a/hwdef-emisar-2ch.c
+++ b/hwdef-emisar-2ch.c
@@ -128,7 +128,7 @@ void set_level_blend(uint8_t level) {
PWM_DATATYPE ch1_pwm, ch2_pwm;
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level);
PWM_DATATYPE top = PWM_GET(pwm_tops, level);
- uint8_t blend = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t blend = cfg.channel_mode_args[channel_mode];
calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend);
@@ -144,7 +144,7 @@ void set_level_auto(uint8_t level) {
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level);
PWM_DATATYPE top = PWM_GET(pwm_tops, level);
uint8_t blend = 255 * (uint16_t)level / RAMP_SIZE;
- if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000)
+ if (cfg.channel_mode_args[channel_mode] & 0b01000000)
blend = 255 - blend;
calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend);
@@ -185,7 +185,7 @@ bool gradual_tick_blend(uint8_t gt) {
PWM_DATATYPE ch1_pwm, ch2_pwm;
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt);
PWM_DATATYPE top = PWM_GET(pwm_tops, gt);
- uint8_t blend = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t blend = cfg.channel_mode_args[channel_mode];
calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend);
@@ -197,7 +197,7 @@ bool gradual_tick_auto(uint8_t gt) {
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt);
PWM_DATATYPE top = PWM_GET(pwm_tops, gt);
uint8_t blend = 255 * (uint16_t)gt / RAMP_SIZE;
- if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000)
+ if (cfg.channel_mode_args[channel_mode] & 0b01000000)
blend = 255 - blend;
calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend);
diff --git a/hwdef-noctigon-m44.c b/hwdef-noctigon-m44.c
index 3fc6abe..0c73005 100644
--- a/hwdef-noctigon-m44.c
+++ b/hwdef-noctigon-m44.c
@@ -128,7 +128,7 @@ void set_level_blend(uint8_t level) {
PWM_DATATYPE ch1_pwm, ch2_pwm;
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level);
PWM_DATATYPE top = PWM_GET(pwm_tops, level);
- uint8_t blend = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t blend = cfg.channel_mode_args[channel_mode];
calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend);
@@ -148,7 +148,7 @@ void set_level_auto(uint8_t level) {
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level);
PWM_DATATYPE top = PWM_GET(pwm_tops, level);
uint8_t blend = 255 * (uint16_t)level / RAMP_SIZE;
- if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000)
+ if (cfg.channel_mode_args[channel_mode] & 0b01000000)
blend = 255 - blend;
calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend);
@@ -189,7 +189,7 @@ bool gradual_tick_blend(uint8_t gt) {
PWM_DATATYPE ch1_pwm, ch2_pwm;
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt);
PWM_DATATYPE top = PWM_GET(pwm_tops, gt);
- uint8_t blend = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t blend = cfg.channel_mode_args[channel_mode];
calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend);
@@ -201,7 +201,7 @@ bool gradual_tick_auto(uint8_t gt) {
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt);
PWM_DATATYPE top = PWM_GET(pwm_tops, gt);
uint8_t blend = 255 * (uint16_t)gt / RAMP_SIZE;
- if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000)
+ if (cfg.channel_mode_args[channel_mode] & 0b01000000)
blend = 255 - blend;
calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend);
diff --git a/hwdef-sofirn-lt1s-pro.c b/hwdef-sofirn-lt1s-pro.c
index 6fe0fef..1359c29 100644
--- a/hwdef-sofirn-lt1s-pro.c
+++ b/hwdef-sofirn-lt1s-pro.c
@@ -107,7 +107,7 @@ void set_level_white_blend(uint8_t level) {
PWM_DATATYPE warm_PWM, cool_PWM;
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level);
PWM_DATATYPE top = PWM_GET(pwm_tops, level);
- uint8_t blend = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t blend = cfg.channel_mode_args[channel_mode];
calc_2ch_blend(&warm_PWM, &cool_PWM, brightness, top, blend);
@@ -172,9 +172,9 @@ void set_level_auto_3ch_blend(uint8_t level) {
// "white + red" channel mode
void set_level_red_white_blend(uint8_t level) {
// set the warm+cool white LEDs first
- cfg.channel_mode = CM_WHITE;
+ channel_mode = CM_WHITE;
set_level_white_blend(level);
- cfg.channel_mode = CM_WHITE_RED;
+ channel_mode = CM_WHITE_RED;
if (level == 0) {
RED_PWM_LVL = 0;
@@ -188,7 +188,7 @@ void set_level_red_white_blend(uint8_t level) {
// set the red LED as a ratio of the white output level
// 0 = no red
// 255 = red at 100% of white channel PWM
- uint8_t ratio = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t ratio = cfg.channel_mode_args[channel_mode];
RED_PWM_LVL = (((PWM_DATATYPE2)ratio * (PWM_DATATYPE2)vpwm) + 127) / 255;
if (! actual_level) PWM_CNT = 0; // reset phase
@@ -223,7 +223,7 @@ bool gradual_tick_white_blend(uint8_t gt) {
PWM_DATATYPE warm_PWM, cool_PWM;
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt);
PWM_DATATYPE top = PWM_GET(pwm_tops, gt);
- uint8_t blend = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t blend = cfg.channel_mode_args[channel_mode];
calc_2ch_blend(&warm_PWM, &cool_PWM, brightness, top, blend);
@@ -259,7 +259,7 @@ bool gradual_tick_red_white_blend(uint8_t gt) {
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt);
PWM_DATATYPE top = PWM_GET(pwm_tops, gt);
uint8_t blend = cfg.channel_mode_args[CM_WHITE];
- uint8_t ratio = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t ratio = cfg.channel_mode_args[channel_mode];
red = (((PWM_DATATYPE2)ratio * (PWM_DATATYPE2)brightness) + 127) / 255;
calc_2ch_blend(&warm, &cool, brightness, top, blend);
diff --git a/spaghetti-monster/anduril/channel-modes.c b/spaghetti-monster/anduril/channel-modes.c
index cecf0bf..f7e90bd 100644
--- a/spaghetti-monster/anduril/channel-modes.c
+++ b/spaghetti-monster/anduril/channel-modes.c
@@ -17,7 +17,7 @@ uint8_t channel_mode_state(Event event, uint16_t arg) {
// in addition to changing state... so ignore any tint-ramp events which
// don't look like they were meant to be here
static uint8_t active = 0;
- uint8_t tint = cfg.channel_mode_args[cfg.channel_mode];
+ uint8_t tint = cfg.channel_mode_args[channel_mode];
#endif
// it's possible that a light may need 3H but not 3C,
@@ -25,7 +25,7 @@ uint8_t channel_mode_state(Event event, uint16_t arg) {
#if NUM_CHANNEL_MODES > 1
// 3 clicks: next channel mode
if (event == EV_3clicks) {
- uint8_t next = cfg.channel_mode;
+ uint8_t next = channel_mode;
// go to next channel mode until we find one which is enabled
// (and don't do any infinite loops if the user disabled them all)
uint8_t count = 0;
@@ -36,15 +36,16 @@ uint8_t channel_mode_state(Event event, uint16_t arg) {
//} while ((! channel_modes_enabled[next]) && count < NUM_CHANNEL_MODES);
// undo change if infinite loop detected (redundant?)
- //if (NUM_CHANNEL_MODES == count) next = cfg.channel_mode;
+ //if (NUM_CHANNEL_MODES == count) next = channel_mode;
// if mode hasn't changed, abort
- if (cfg.channel_mode == next)
+ if (channel_mode == next)
return EVENT_NOT_HANDLED;
set_channel_mode(next);
// remember after battery changes
+ cfg.channel_mode = channel_mode;
save_config();
return EVENT_HANDLED;
} else
@@ -52,9 +53,9 @@ uint8_t channel_mode_state(Event event, uint16_t arg) {
#ifdef USE_CUSTOM_CHANNEL_3H_MODES
// defer to mode-specific function if defined
- if (tint_ramp_modes[cfg.channel_mode]) {
- StatePtr tint_func = channel_3H_modes[cfg.channel_mode];
- return tint_func(cfg.channel_mode);
+ if (tint_ramp_modes[channel_mode]) {
+ StatePtr tint_func = channel_3H_modes[channel_mode];
+ return tint_func(channel_mode);
} else
#endif
#ifdef USE_CHANNEL_MODE_ARGS
@@ -95,7 +96,7 @@ uint8_t channel_mode_state(Event event, uint16_t arg) {
past_edge_counter = 1;
}
prev_tint = tint;
- cfg.channel_mode_args[cfg.channel_mode] = tint;
+ cfg.channel_mode_args[channel_mode] = tint;
set_level(actual_level);
return EVENT_HANDLED;
}
@@ -108,7 +109,7 @@ uint8_t channel_mode_state(Event event, uint16_t arg) {
if (0 == tint) tint_ramp_direction = 1;
else if (255 == tint) tint_ramp_direction = -1;
// remember tint after battery change
- cfg.channel_mode_args[cfg.channel_mode] = tint;
+ cfg.channel_mode_args[channel_mode] = tint;
save_config();
// bug?: for some reason, brightness can seemingly change
// from 1/150 to 2/150 without this next line... not sure why
diff --git a/spaghetti-monster/anduril/config-mode.c b/spaghetti-monster/anduril/config-mode.c
index d379cd9..71b0d69 100644
--- a/spaghetti-monster/anduril/config-mode.c
+++ b/spaghetti-monster/anduril/config-mode.c
@@ -13,8 +13,9 @@ volatile uint8_t number_entry_value;
#if defined(USE_CONFIG_COLORS) && (NUM_CHANNEL_MODES > 1)
+// TODO: promote this to fsm-channels.c ?
void set_chan_if(bool cond, uint8_t chan) {
- if ((cond) && (chan != cfg.channel_mode))
+ if ((cond) && (chan != channel_mode))
set_channel_mode(chan);
}
#endif
@@ -41,7 +42,7 @@ uint8_t config_state_base(
#endif
if (event == EV_enter_state) {
#if defined(USE_CONFIG_COLORS) && (NUM_CHANNEL_MODES > 1)
- orig_channel = cfg.channel_mode;
+ orig_channel = channel_mode;
#endif
config_step = 0;
set_level(0);
diff --git a/spaghetti-monster/anduril/load-save-config-fsm.h b/spaghetti-monster/anduril/load-save-config-fsm.h
index 462b41c..7bf87f4 100644
--- a/spaghetti-monster/anduril/load-save-config-fsm.h
+++ b/spaghetti-monster/anduril/load-save-config-fsm.h
@@ -70,6 +70,9 @@ typedef struct Config {
///// strobe / blinky mode settings
#ifdef USE_STROBE_STATE
uint8_t strobe_type;
+ #if NUM_CHANNEL_MODES > 1
+ uint8_t strobe_channels[NUM_STROBES];
+ #endif
#endif
#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
uint8_t strobe_delays[2];
diff --git a/spaghetti-monster/anduril/load-save-config.h b/spaghetti-monster/anduril/load-save-config.h
index 8ae9d96..2dfa8c9 100644
--- a/spaghetti-monster/anduril/load-save-config.h
+++ b/spaghetti-monster/anduril/load-save-config.h
@@ -98,6 +98,12 @@ Config cfg = {
#ifdef USE_STROBE_STATE
.strobe_type = DEFAULT_STROBE,
+ #if NUM_CHANNEL_MODES > 1
+ // channel mode saved per strobe-group mode
+ #ifdef DEFAULT_STROBE_CHANNELS
+ .strobe_channels = { DEFAULT_STROBE_CHANNELS },
+ #endif
+ #endif
#endif
#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
// party / tactical strobe timing
diff --git a/spaghetti-monster/anduril/off-mode.c b/spaghetti-monster/anduril/off-mode.c
index ab67d96..a484f06 100644
--- a/spaghetti-monster/anduril/off-mode.c
+++ b/spaghetti-monster/anduril/off-mode.c
@@ -16,6 +16,10 @@ uint8_t off_state(Event event, uint16_t arg) {
if (event == EV_enter_state) {
set_level(0);
ticks_since_on = 0;
+ #if NUM_CHANNEL_MODES > 1
+ // reset to ramp mode's channel when light turns off
+ channel_mode = cfg.channel_mode;
+ #endif
#ifdef USE_INDICATOR_LED
// redundant, sleep tick does the same thing
//indicator_led_update(cfg.indicator_led_mode & 0x03, 0);
diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c
index 4fef2c2..f21f599 100644
--- a/spaghetti-monster/anduril/ramp-mode.c
+++ b/spaghetti-monster/anduril/ramp-mode.c
@@ -19,6 +19,10 @@ uint8_t steady_state(Event event, uint16_t arg) {
static uint8_t level_before_off = 0;
#endif
+ #if NUM_CHANNEL_MODES > 1
+ channel_mode = cfg.channel_mode;
+ #endif
+
// make sure ramp globals are correct...
// ... but they already are; no need to do it here
//ramp_update_config();
@@ -417,7 +421,7 @@ uint8_t steady_state(Event event, uint16_t arg) {
#ifdef USE_CHANNEL_MODE_ARGS
// ramp tint if tint exists in this mode
if ((event == EV_click3_hold)
- && (channel_has_args(cfg.channel_mode)))
+ && (channel_has_args(channel_mode)))
return EVENT_NOT_HANDLED;
#endif
if (! arg) { // first frame only, to allow thermal regulation to work
@@ -438,7 +442,7 @@ uint8_t steady_state(Event event, uint16_t arg) {
#ifdef USE_CHANNEL_MODE_ARGS
// ramp tint if tint exists in this mode
if ((event == EV_click3_hold_release)
- && (channel_has_args(cfg.channel_mode)))
+ && (channel_has_args(channel_mode)))
return EVENT_NOT_HANDLED;
#endif
set_level_and_therm_target(memorized_level);
@@ -665,7 +669,7 @@ void set_level_and_therm_target(uint8_t level) {
void manual_memory_restore() {
memorized_level = cfg.manual_memory;
#if NUM_CHANNEL_MODES > 1
- cfg.channel_mode = cfg.manual_memory_channel_mode;
+ channel_mode = cfg.channel_mode = cfg.manual_memory_channel_mode;
#endif
#ifdef USE_CHANNEL_MODE_ARGS
for (uint8_t i=0; i<NUM_CHANNEL_MODES; i++)
@@ -676,7 +680,7 @@ void manual_memory_restore() {
void manual_memory_save() {
cfg.manual_memory = actual_level;
#if NUM_CHANNEL_MODES > 1
- cfg.manual_memory_channel_mode = cfg.channel_mode;
+ cfg.manual_memory_channel_mode = channel_mode;
#endif
#ifdef USE_CHANNEL_MODE_ARGS
for (uint8_t i=0; i<NUM_CHANNEL_MODES; i++)
diff --git a/spaghetti-monster/anduril/strobe-modes-fsm.h b/spaghetti-monster/anduril/strobe-modes-fsm.h
index da513a4..4d948ed 100644
--- a/spaghetti-monster/anduril/strobe-modes-fsm.h
+++ b/spaghetti-monster/anduril/strobe-modes-fsm.h
@@ -25,3 +25,31 @@
#define USE_STROBE_STATE
#endif
+// 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_POLICE_COLOR_STROBE_MODE
+ police_color_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;
+#define NUM_STROBES strobe_mode_END
+#endif
+
diff --git a/spaghetti-monster/anduril/strobe-modes.c b/spaghetti-monster/anduril/strobe-modes.c
index 4d06d77..1e6f98c 100644
--- a/spaghetti-monster/anduril/strobe-modes.c
+++ b/spaghetti-monster/anduril/strobe-modes.c
@@ -43,6 +43,16 @@ uint8_t strobe_state(Event event, uint16_t arg) {
save_config();
return EVENT_HANDLED;
}
+ #if NUM_CHANNEL_MODES > 1
+ // 3 clicks: rotate through channel modes for the current strobe
+ else if (event == EV_3clicks) {
+ // TODO: maybe skip aux modes?
+ set_channel_mode((channel_mode + 1) % NUM_CHANNEL_MODES);
+ cfg.strobe_channels[st] = channel_mode;
+ save_config();
+ return EVENT_HANDLED;
+ }
+ #endif
// 4 clicks: rotate backward through strobe/flasher modes
else if (event == EV_4clicks) {
current_strobe_type = cfg.strobe_type = (st - 1 + NUM_STROBES) % NUM_STROBES;
@@ -157,6 +167,11 @@ uint8_t strobe_state(Event event, uint16_t arg) {
inline void strobe_state_iter() {
uint8_t st = current_strobe_type; // can't use switch() on an enum
+ #if NUM_CHANNEL_MODES > 1
+ // remember channel mode for each strobe
+ channel_mode = cfg.strobe_channels[st];
+ #endif
+
switch(st) {
#if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
#ifdef USE_PARTY_STROBE_MODE
@@ -223,7 +238,7 @@ inline void police_color_strobe_iter() {
uint8_t del = 66;
// TODO: make police strobe brightness configurable
uint8_t bright = memorized_level;
- uint8_t channel = cfg.channel_mode;
+ //uint8_t channel = channel_mode;
for (uint8_t i=0; i<10; i++) {
if (0 == i) set_channel_mode(POLICE_COLOR_STROBE_CH1);
@@ -234,8 +249,9 @@ inline void police_color_strobe_iter() {
nice_delay_ms(del);
}
- // restore this when done
- set_channel_mode(channel);
+ // restore the channel when done
+ //set_channel_mode(channel);
+ channel_mode = cfg.channel_mode;
}
#endif
diff --git a/spaghetti-monster/anduril/strobe-modes.h b/spaghetti-monster/anduril/strobe-modes.h
index 127966b..7dc1df4 100644
--- a/spaghetti-monster/anduril/strobe-modes.h
+++ b/spaghetti-monster/anduril/strobe-modes.h
@@ -4,31 +4,7 @@
#pragma once
-// 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_POLICE_COLOR_STROBE_MODE
- police_color_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;
strobe_mode_te current_strobe_type;
@@ -38,7 +14,8 @@ strobe_mode_te current_strobe_type;
#else
#define DEFAULT_STROBE 0
#endif
-#endif
+
+#endif // ifdef USE_STROBE_STATE
// full FET strobe can be a bit much... use max regulated level instead,
diff --git a/spaghetti-monster/anduril/tactical-mode.c b/spaghetti-monster/anduril/tactical-mode.c
index 0bcaaca..0035496 100644
--- a/spaghetti-monster/anduril/tactical-mode.c
+++ b/spaghetti-monster/anduril/tactical-mode.c
@@ -28,6 +28,10 @@ uint8_t tactical_state(Event event, uint16_t arg) {
if ((1 <= lvl) && (lvl <= RAMP_SIZE)) { // steady output
memorized_level = lvl;
momentary_mode = 0;
+ #if NUM_CHANNEL_MODES > 1
+ // use ramp mode's channel
+ channel_mode = cfg.channel_mode;
+ #endif
} else { // momentary strobe mode
momentary_mode = 1;
if (lvl > RAMP_SIZE) {
@@ -40,6 +44,7 @@ uint8_t tactical_state(Event event, uint16_t arg) {
else if ((event & (B_CLICK | B_PRESS)) == (B_CLICK)) {
momentary_active = 0;
set_level(0);
+ interrupt_nice_delays(); // stop animations in progress
}
// delegate to momentary mode while button is pressed
diff --git a/spaghetti-monster/fsm-channels.c b/spaghetti-monster/fsm-channels.c
index 3b30b58..944bdcb 100644
--- a/spaghetti-monster/fsm-channels.c
+++ b/spaghetti-monster/fsm-channels.c
@@ -13,7 +13,7 @@ void set_channel_mode(uint8_t mode) {
set_level(0);
// change the channel
- CH_MODE = mode;
+ channel_mode = mode;
// update the LEDs
set_level(cur_level);
diff --git a/spaghetti-monster/fsm-channels.h b/spaghetti-monster/fsm-channels.h
index ba2d3fa..55fc826 100644
--- a/spaghetti-monster/fsm-channels.h
+++ b/spaghetti-monster/fsm-channels.h
@@ -38,17 +38,10 @@ Channel channels[]; // values are defined in the hwdef-*.c
// TODO: size-optimize the case with only 1 channel mode?
// (the arrays and stuff shouldn't be needed)
-#if defined(USE_CFG) && (NUM_CHANNEL_MODES > 1)
- #define CH_MODE cfg.channel_mode
-#else
+#if NUM_CHANNEL_MODES > 1
+ #define USE_CHANNEL_MODES
// current multi-channel mode
uint8_t channel_mode = DEFAULT_CHANNEL_MODE;
- #define CH_MODE channel_mode
-#endif
-
-// FIXME: remove this?
-#if NUM_CHANNEL_MODES > 1
-#define USE_CHANNEL_MODES
#endif
#ifdef USE_CUSTOM_CHANNEL_3H_MODES
diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c
index 0aeb7c3..bc10ea1 100644
--- a/spaghetti-monster/fsm-misc.c
+++ b/spaghetti-monster/fsm-misc.c
@@ -35,7 +35,7 @@ uint8_t blink_digit(uint8_t num) {
#ifdef BLINK_CHANNEL
// channel is set per blink, to prevent issues
// if another mode interrupts us (like a config menu)
- uint8_t old_channel = CH_MODE;
+ uint8_t old_channel = channel_mode;
#endif
for (; num>0; num--) {
@@ -45,7 +45,7 @@ uint8_t blink_digit(uint8_t num) {
#endif
set_level(BLINK_BRIGHTNESS);
#ifdef BLINK_CHANNEL
- CH_MODE = old_channel;
+ channel_mode = old_channel;
#endif
nice_delay_ms(ontime);
@@ -54,7 +54,7 @@ uint8_t blink_digit(uint8_t num) {
#endif
set_level(0);
#ifdef BLINK_CHANNEL
- CH_MODE = old_channel;
+ channel_mode = old_channel;
#endif
nice_delay_ms(BLINK_SPEED * 3 / 12);
}
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index 6419bfd..a970f0e 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -59,7 +59,7 @@ void set_level(uint8_t level) {
#endif
// call the relevant hardware-specific set_level_*()
- SetLevelFuncPtr set_level_func = channels[CH_MODE].set_level;
+ SetLevelFuncPtr set_level_func = channels[channel_mode].set_level;
set_level_func(level);
if (actual_level != level) prev_level = actual_level;
@@ -217,7 +217,7 @@ void gradual_tick() {
gt --;
// call the relevant hardware-specific function
- GradualTickFuncPtr gradual_tick_func = channels[CH_MODE].gradual_tick;
+ GradualTickFuncPtr gradual_tick_func = channels[channel_mode].gradual_tick;
bool done = gradual_tick_func(gt);
if (done) {