Skip to content

Commit

Permalink
strobe/candle: refactoring and fix 7C bug for indicator
Browse files Browse the repository at this point in the history
Refactoring code and fix a bug where when configured to use indicator
LED in candle mode, 2C or 3C to the next/prev strobe mode and back to
candle, the indicator LED won't turn on and 7C stops working.

This was due to the aux_led_reset flag was not properly cleared in 2C or
3C.

See issue #28
  • Loading branch information
starryalley committed Aug 9, 2023
1 parent 243185e commit 7fbe7a3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
17 changes: 2 additions & 15 deletions spaghetti-monster/anduril/candle-mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ static inline void reset_parameters() {
candle_wave1_depth = candle_wave1_maxdepth * candle_amplitude / 100;
candle_wave2_depth = candle_wave2_maxdepth * candle_amplitude / 100;
#ifdef USE_AUX_RGB_LEDS
aux_led_reset = 0;
rgb_led_update(RGB_RED|RGB_HIGH, 0);
#elif defined(USE_INDICATOR_LED)
aux_led_reset = 0;
indicator_led(candle_indicator_mode);
#endif
break;
case fireplace_fast_wobble_e:
Expand All @@ -66,11 +62,7 @@ static inline void reset_parameters() {
candle_wave2_depth = candle_wave2_maxdepth * candle_amplitude / 100;
candle_wave3_depth = candle_wave3_maxdepth * candle_amplitude / 100;
#ifdef USE_AUX_RGB_LEDS
aux_led_reset = 0;
rgb_led_update(RGB_YELLOW|RGB_HIGH, 0);
#elif defined(USE_INDICATOR_LED)
aux_led_reset = 0;
indicator_led(candle_indicator_mode);
#endif
break;
default:
Expand All @@ -81,11 +73,7 @@ static inline void reset_parameters() {
candle_wave2_depth = candle_wave2_maxdepth * candle_amplitude / 100;
candle_wave3_depth = candle_wave3_maxdepth * candle_amplitude / 100;
#ifdef USE_AUX_RGB_LEDS
aux_led_reset = !candle_use_aux;
rgb_led_update(RGB_OFF, 0);
#elif defined(USE_INDICATOR_LED)
aux_led_reset = 0;
indicator_led(candle_indicator_mode);
#endif
}
}
Expand Down Expand Up @@ -119,9 +107,6 @@ uint8_t candle_mode_state(Event event, uint16_t arg) {
if (event == EV_enter_state) {
ramp_direction = 1;
reset_parameters();
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 0;
#endif
#ifdef PWM_TOP_CANDLE
#ifdef USE_DYN_PWM
use_static_pwm = 1;
Expand Down Expand Up @@ -226,7 +211,9 @@ uint8_t candle_mode_state(Event event, uint16_t arg) {
#elif defined(USE_INDICATOR_LED)
else if (event == EV_7clicks) {
candle_indicator_mode = (candle_indicator_mode + 1) % 3;
#ifdef USE_INDICATOR_LED
indicator_led(candle_indicator_mode);
#endif
save_config();
blip();
}
Expand Down
41 changes: 24 additions & 17 deletions spaghetti-monster/anduril/strobe-modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ static inline void undo_global_setting() {
PWM1_TOP = PWM_TOP;
#endif
restore_tint();
// always reset aux LED (default behaviour)
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 1;
#endif
}

// for some strobe modes we need to enable/disable some global settings:
Expand All @@ -70,6 +74,13 @@ static void strobe_global_setup(strobe_mode_te type) {
PWM1_TOP = PWM_TOP_CANDLE;
#endif
restore_tint();
// aux LED will not be reset in each set_level in candle mode
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 0;
#endif
#ifdef USE_INDICATOR_LED
indicator_led(candle_indicator_mode);
#endif
break;
#endif

Expand All @@ -82,13 +93,19 @@ static void strobe_global_setup(strobe_mode_te type) {
#ifdef USE_TINT_RAMPING
tint_locked = 0;
#endif
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 1;
#endif
break;
#endif

#ifdef USE_TINT_RAMPING
case tint_alternating_strobe_e:
case tint_smooth_ramp_e:
tint_locked = 0;
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 1;
#endif
break;
#endif

Expand All @@ -107,40 +124,30 @@ uint8_t strobe_state(Event event, uint16_t arg) {
momentary_mode = 1; // 0 = ramping, 1 = strobes
#endif

if (event == EV_enter_state) {
#ifdef USE_TINT_RAMPING
saved_tint = tint;
#endif
strobe_global_setup(st);
}

#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);
} else {
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 1;
#endif
}
#endif
// use static PWM in firework mode
#if defined(USE_FIREWORK_MODE) && defined(PWM_TOP_FIREWORK)
if (st == firework_mode_e && event == EV_enter_state) {
strobe_global_setup(st);
}
#endif

if (0) {} // placeholder
// init anything which needs to be initialized
else if (event == EV_enter_state) {
ramp_direction = 1;
#ifdef USE_TINT_RAMPING
tint_locked = 0;
saved_tint = tint;
#endif
return MISCHIEF_MANAGED;
}
// 1 click: off
else if (event == EV_1click) {
set_state(off_state, 0);
#if defined(USE_AUX_RGB_LEDS) || defined(USE_INDICATOR_LED)
aux_led_reset = 1;
#endif
undo_global_setting();
return MISCHIEF_MANAGED;
}
Expand Down

0 comments on commit 7fbe7a3

Please sign in to comment.