diff options
| author | Selene ToyKeeper | 2020-07-30 03:11:52 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2020-07-30 03:11:52 -0600 |
| commit | fc23a8be7a4db0683f1dc19f196e5051781923ec (patch) | |
| tree | 723a925fd531771f475dadad6367d46ed8547b69 | |
| parent | replaced "goodnight / sunset mode" with sunset timer, which works in both can... (diff) | |
| download | anduril-fc23a8be7a4db0683f1dc19f196e5051781923ec.tar.gz anduril-fc23a8be7a4db0683f1dc19f196e5051781923ec.tar.bz2 anduril-fc23a8be7a4db0683f1dc19f196e5051781923ec.zip | |
moved sunset bump from 3C to 4H, fixed candle sunset behavior (was overflowing / wrapping around)
| -rw-r--r-- | spaghetti-monster/anduril/candle-mode.c | 23 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/sunset-timer.c | 30 |
2 files changed, 28 insertions, 25 deletions
diff --git a/spaghetti-monster/anduril/candle-mode.c b/spaghetti-monster/anduril/candle-mode.c index 70f5e0e..3704ee6 100644 --- a/spaghetti-monster/anduril/candle-mode.c +++ b/spaghetti-monster/anduril/candle-mode.c @@ -21,6 +21,7 @@ #define CANDLE_MODE_C #include "candle-mode.h" + #ifdef USE_SUNSET_TIMER #include "sunset-timer.h" #endif @@ -99,22 +100,22 @@ uint8_t candle_mode_state(Event event, uint16_t arg) { // 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; - #ifdef USE_SUNSET_TIMER - if (sunset_timer == 1) { - subtract = (candle_mode_brightness+CANDLE_AMPLITUDE) - * sunset_ticks / TICKS_PER_MINUTE; - } - #endif // ifdef USE_SUNSET_TIMER - // 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; } + uint16_t brightness = candle_mode_brightness + add; + + // self-timer dims the light during the final minute + #ifdef USE_SUNSET_TIMER + if (1 == sunset_timer) { + brightness = brightness + * ((TICKS_PER_MINUTE>>5) - (sunset_ticks>>5)) + / (TICKS_PER_MINUTE>>5); + } + #endif // ifdef USE_SUNSET_TIMER + set_level(brightness); // wave1: slow random LFO diff --git a/spaghetti-monster/anduril/sunset-timer.c b/spaghetti-monster/anduril/sunset-timer.c index 0687993..4c91723 100644 --- a/spaghetti-monster/anduril/sunset-timer.c +++ b/spaghetti-monster/anduril/sunset-timer.c @@ -30,20 +30,22 @@ uint8_t sunset_timer_state(Event event, uint16_t arg) { sunset_ticks = 0; return MISCHIEF_MANAGED; } - // 3 clicks: add 30m to timer - else if (event == EV_3clicks) { - if (sunset_timer < (255 - SUNSET_TIMER_UNIT)) { - // add 30m to the timer - sunset_timer += SUNSET_TIMER_UNIT; - sunset_timer_peak = sunset_timer; // reset ceiling - sunset_ticks = 0; // reset phase - // blink to confirm - uint8_t brightness = actual_level; - uint8_t bump = actual_level + 32; - if (bump > MAX_LEVEL) bump = 0; - set_level(bump); - delay_4ms(2); - set_level(brightness); + // 4H: add 10m to timer, per second, until released + else if (event == EV_click4_hold) { + if (0 == (arg % TICKS_PER_SECOND)) { + if (sunset_timer < (255 - SUNSET_TIMER_UNIT)) { + // add 30m to the timer + sunset_timer += SUNSET_TIMER_UNIT; + sunset_timer_peak = sunset_timer; // reset ceiling + sunset_ticks = 0; // reset phase + // blink to confirm + uint8_t brightness = actual_level; + uint8_t bump = actual_level + 32; + if (bump > MAX_LEVEL) bump = 0; + set_level(bump); + delay_4ms(2); + set_level(brightness); + } } return MISCHIEF_MANAGED; } |
