From 215a56b08586dcf4352b6eb2713f5238a4d5b360 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 13 Sep 2018 03:44:23 -0600 Subject: Added tint ramping. Not tested yet. Also added BLF Lantern build target. --- spaghetti-monster/anduril/anduril.c | 43 +++++++++++++++++++++++++++++++++- spaghetti-monster/anduril/build-all.sh | 1 + spaghetti-monster/fsm-ramping.c | 20 ++++++++++++++++ spaghetti-monster/fsm-ramping.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index c8517af..07d51f5 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -75,6 +75,9 @@ #elif defined(FSM_BLF_GT_MINI_DRIVER) #include "cfg-blf-gt-mini.h" +#elif defined(FSM_BLF_LANTERN_DRIVER) +#include "cfg-blf-lantern.h" + #elif defined(FSM_BLF_Q8_DRIVER) #include "cfg-blf-q8.h" @@ -204,6 +207,10 @@ uint8_t config_state_values[MAX_CONFIG_VALUES]; // ramping mode and its related config mode uint8_t steady_state(EventPtr event, uint16_t arg); uint8_t ramp_config_state(EventPtr event, uint16_t arg); +#ifdef USE_TINT_RAMPING +// not actually a mode, more of a fallback under other modes +uint8_t tint_ramping_state(EventPtr event, uint16_t arg); +#endif // party and tactical strobes #ifdef USE_STROBE_STATE uint8_t strobe_state(EventPtr event, uint16_t arg); @@ -784,6 +791,34 @@ uint8_t steady_state(EventPtr event, uint16_t arg) { } +#ifdef USE_TINT_RAMPING +uint8_t tint_ramping_state(EventPtr event, uint16_t arg) { + static int8_t tint_ramp_direction = 1; + + // click, click, hold: change the tint + if (event == EV_click3_hold) { + if ((arg & 1) == 0) { // ramp slower + if ((tint_ramp_direction > 0) && (tint < 255)) { + tint += 1; + } + else if ((tint_ramp_direction < 0) && (tint > 0)) { + tint -= 1; + } + } + return EVENT_HANDLED; + } + + // click, click, hold, release: reverse direction for next ramp + else if (event == EV_click3_hold_release) { + tint_ramp_direction = -tint_ramp_direction; + return EVENT_HANDLED; + } + + return EVENT_NOT_HANDLED; +} +#endif // ifdef USE_TINT_RAMPING + + #ifdef USE_STROBE_STATE uint8_t strobe_state(EventPtr event, uint16_t arg) { // 'st' reduces ROM size by avoiding access to a volatile var @@ -1786,14 +1821,20 @@ void setup() { load_config(); + #ifdef USE_TINT_RAMPING + // add tint ramping underneath every other state + push_state(tint_ramping_state, 0); + #ifdef USE_MUGGLE_MODE if (muggle_mode_active) push_state(muggle_state, (MUGGLE_FLOOR+MUGGLE_CEILING)/2); else #endif push_state(off_state, 0); - #endif + #endif // ifdef USE_TINT_RAMPING + + #endif // ifdef START_AT_MEMORIZED_LEVEL } diff --git a/spaghetti-monster/anduril/build-all.sh b/spaghetti-monster/anduril/build-all.sh index 794b285..98f95f5 100755 --- a/spaghetti-monster/anduril/build-all.sh +++ b/spaghetti-monster/anduril/build-all.sh @@ -5,6 +5,7 @@ UI=anduril for TARGET in \ BLF_GT \ BLF_GT_MINI \ + BLF_LANTERN \ BLF_Q8 \ EMISAR_D1 \ EMISAR_D1S \ diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 6cdf5e6..0492943 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -25,9 +25,20 @@ void set_level(uint8_t level) { actual_level = level; + + #ifdef USE_TINT_RAMPING + // calculate actual PWM levels based on a single-channel ramp + // and a global tint value + uint8_t brightness = pgm_read_byte(pwm1_levels + level); + uint8_t warm_PWM, cool_PWM; + cool_PWM = (uint16_t)tint * brightness / 255; + warm_PWM = brightness - cool_PWM; + #endif + #ifdef USE_SET_LEVEL_GRADUALLY gradual_target = level; #endif + #ifdef USE_INDICATOR_LED #ifdef USE_INDICATOR_LED_WHILE_RAMPING if (! go_to_standby) @@ -40,6 +51,7 @@ void set_level(uint8_t level) { indicator_led(0); #endif #endif + //TCCR0A = PHASE; if (level == 0) { #if PWM_CHANNELS >= 1 @@ -56,6 +68,12 @@ void set_level(uint8_t level) { #endif } else { level --; + + #ifdef USE_TINT_RAMPING + PWM1_LVL = warm_PWM; + PWM2_LVL = cool_PWM; + #else + #if PWM_CHANNELS >= 1 PWM1_LVL = pgm_read_byte(pwm1_levels + level); #endif @@ -68,6 +86,8 @@ void set_level(uint8_t level) { #if PWM_CHANNELS >= 4 PWM4_LVL = pgm_read_byte(pwm4_levels + level); #endif + + #endif // ifdef USE_TINT_RAMPING } #ifdef USE_DYNAMIC_UNDERCLOCKING auto_clock_speed(); diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h index 14c8dae..9732b9c 100644 --- a/spaghetti-monster/fsm-ramping.h +++ b/spaghetti-monster/fsm-ramping.h @@ -26,6 +26,10 @@ // actual_level: last ramp level set by set_level() volatile uint8_t actual_level = 0; +#ifdef USE_TINT_RAMPING +uint8_t tint = 0; +#endif + #ifdef USE_SET_LEVEL_GRADUALLY // adjust brightness very smoothly volatile uint8_t gradual_target; -- cgit v1.2.3