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(-) 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 From 90d4d514851192f74819a141b81cf515089209c7 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 13 Sep 2018 04:02:40 -0600 Subject: oops, forgot to add lantern config file --- spaghetti-monster/anduril/cfg-blf-lantern.h | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 spaghetti-monster/anduril/cfg-blf-lantern.h diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h new file mode 100644 index 0000000..05b89ca --- /dev/null +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -0,0 +1,59 @@ +// BLF Lantern config options for Anduril + +// basically the same as a Q8... sort of +#define FSM_BLF_Q8_DRIVER + +// the button lights up +#define USE_INDICATOR_LED +// the button is visible while main LEDs are on +#define USE_INDICATOR_LED_WHILE_RAMPING +// enable blinking indicator LED while off +#define TICK_DURING_STANDBY + +// the lantern has two PWM channels, but they drive different sets of emitters +// (one channel for warm emitters, one channel for cold) +// so enable a special ramping mode which changes tint instead of brightness +#define USE_TINT_RAMPING + +#ifdef RAMP_LENGTH +#undef RAMP_LENGTH +#endif + +// level_calc.py 1 150 7135 1 30 800 +#define RAMP_LENGTH 150 +#define PWM1_LEVELS 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,11,11,12,13,13,14,15,15,16,17,18,18,19,20,21,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,46,48,49,50,51,53,54,56,57,58,60,61,63,64,66,67,69,70,72,74,75,77,79,80,82,84,85,87,89,91,93,95,97,98,100,102,104,106,108,111,113,115,117,119,121,124,126,128,130,133,135,137,140,142,145,147,150,152,155,157,160,163,165,168,171,173,176,179,182,185,188,190,193,196,199,202,205,209,212,215,218,221,224,228,231,234,238,241,245,248,251,255 +#define MAX_1x7135 65 +#define HALFSPEED_LEVEL 14 +#define QUARTERSPEED_LEVEL 5 + +// set floor and ceiling as far apart as possible +// because this lantern isn't overpowered +#define RAMP_SMOOTH_FLOOR 1 +#define RAMP_SMOOTH_CEILING 150 +#define RAMP_DISCRETE_FLOOR RAMP_SMOOTH_FLOOR +#define RAMP_DISCRETE_CEILING RAMP_SMOOTH_CEILING + +// the sensor (attiny85) is nowhere near the emitters +// so thermal regulation can't work +#ifdef USE_THERMAL_REGULATION +#undef USE_THERMAL_REGULATION +#endif + +// also, the set_level_gradually() thing isn't compatible with tint ramping +// (but unsetting it here doesn't actually do anything, because the thermal +// regulation define enables it later... so this is mostly just a note to +// make this compatibility issue explicit) +#ifdef USE_SET_LEVEL_GRADUALLY +#undef USE_SET_LEVEL_GRADUALLY +#endif + +// don't blink while ramping +#ifdef BLINK_AT_CHANNEL_BOUNDARIES +#undef BLINK_AT_CHANNEL_BOUNDARIES +#endif +#ifdef BLINK_AT_RAMP_CEILING +#undef BLINK_AT_RAMP_CEILING +#endif +#ifdef BLINK_AT_RAMP_FLOOR +#undef BLINK_AT_RAMP_FLOOR +#endif -- cgit v1.2.3 From 999ea108106aa95553032a524310e7adac05ea23 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 13 Sep 2018 04:03:39 -0600 Subject: made tint ramping actually work (needed to set_level() again after changing tint) also, made sure ramp ends will go the right direction (may be reduntant though) --- spaghetti-monster/anduril/anduril.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 07d51f5..250e3d7 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -804,6 +804,7 @@ uint8_t tint_ramping_state(EventPtr event, uint16_t arg) { else if ((tint_ramp_direction < 0) && (tint > 0)) { tint -= 1; } + set_level(actual_level); } return EVENT_HANDLED; } @@ -811,6 +812,8 @@ uint8_t tint_ramping_state(EventPtr event, uint16_t arg) { // click, click, hold, release: reverse direction for next ramp else if (event == EV_click3_hold_release) { tint_ramp_direction = -tint_ramp_direction; + if (tint == 0) tint_ramp_direction = 1; + else if (tint == 255) tint_ramp_direction = -1; return EVENT_HANDLED; } -- cgit v1.2.3 From 4b93b02d6d966f4bda4ea90499601b52430c62f8 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 13 Sep 2018 04:30:02 -0600 Subject: fixed tint ramp brightness being off by one level, and eliminated bias toward first PWM channel --- spaghetti-monster/fsm-ramping.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 0492943..ee816dd 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -26,15 +26,6 @@ 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 @@ -70,6 +61,13 @@ void set_level(uint8_t 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 * (uint16_t)brightness) + 127) / 255; + warm_PWM = brightness - cool_PWM; + PWM1_LVL = warm_PWM; PWM2_LVL = cool_PWM; #else -- cgit v1.2.3 From b6adac8b6b949f2f573f18063858a0728df39f02 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 13 Sep 2018 04:49:50 -0600 Subject: ramp tint faster, remember after battery change also, fixed typo while setting default ramp values --- spaghetti-monster/anduril/anduril.c | 15 +++++++++++++-- spaghetti-monster/anduril/cfg-blf-lantern.h | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 250e3d7..7217f87 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -158,6 +158,9 @@ typedef enum { ramp_discrete_floor_e, ramp_discrete_ceil_e, ramp_discrete_steps_e, + #ifdef USE_TINT_RAMPING + tint_e, + #endif #ifdef USE_STROBE_STATE strobe_type_e, #endif @@ -797,7 +800,7 @@ uint8_t tint_ramping_state(EventPtr event, uint16_t arg) { // click, click, hold: change the tint if (event == EV_click3_hold) { - if ((arg & 1) == 0) { // ramp slower + //if ((arg & 1) == 0) { // ramp slower if ((tint_ramp_direction > 0) && (tint < 255)) { tint += 1; } @@ -805,7 +808,7 @@ uint8_t tint_ramping_state(EventPtr event, uint16_t arg) { tint -= 1; } set_level(actual_level); - } + //} return EVENT_HANDLED; } @@ -814,6 +817,8 @@ uint8_t tint_ramping_state(EventPtr event, uint16_t arg) { tint_ramp_direction = -tint_ramp_direction; if (tint == 0) tint_ramp_direction = 1; else if (tint == 255) tint_ramp_direction = -1; + // remember tint after battery change + save_config(); return EVENT_HANDLED; } @@ -1696,6 +1701,9 @@ void load_config() { ramp_discrete_floor = eeprom[ramp_discrete_floor_e]; ramp_discrete_ceil = eeprom[ramp_discrete_ceil_e]; ramp_discrete_steps = eeprom[ramp_discrete_steps_e]; + #ifdef USE_TINT_RAMPING + tint = eeprom[tint_e]; + #endif #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE) strobe_type = eeprom[strobe_type_e]; // TODO: move this to eeprom_wl? strobe_delays[0] = eeprom[strobe_delays_0_e]; @@ -1730,6 +1738,9 @@ void save_config() { eeprom[ramp_discrete_floor_e] = ramp_discrete_floor; eeprom[ramp_discrete_ceil_e] = ramp_discrete_ceil; eeprom[ramp_discrete_steps_e] = ramp_discrete_steps; + #ifdef USE_TINT_RAMPING + eeprom[tint_e] = tint; + #endif #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE) eeprom[strobe_type_e] = strobe_type; // TODO: move this to eeprom_wl? eeprom[strobe_delays_0_e] = strobe_delays[0]; diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index 05b89ca..709bca9 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -29,9 +29,9 @@ // set floor and ceiling as far apart as possible // because this lantern isn't overpowered #define RAMP_SMOOTH_FLOOR 1 -#define RAMP_SMOOTH_CEILING 150 +#define RAMP_SMOOTH_CEIL 150 #define RAMP_DISCRETE_FLOOR RAMP_SMOOTH_FLOOR -#define RAMP_DISCRETE_CEILING RAMP_SMOOTH_CEILING +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL // the sensor (attiny85) is nowhere near the emitters // so thermal regulation can't work -- cgit v1.2.3 From 2019f64e39f1b61ea0dcb6facdf9b93955b4e8b7 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 10 Oct 2018 21:28:09 -0600 Subject: Fixed location of an #endif --- spaghetti-monster/anduril/anduril.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 7217f87..a3d5c69 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -1838,6 +1838,7 @@ void setup() { #ifdef USE_TINT_RAMPING // add tint ramping underneath every other state push_state(tint_ramping_state, 0); + #endif // ifdef USE_TINT_RAMPING #ifdef USE_MUGGLE_MODE if (muggle_mode_active) @@ -1846,8 +1847,6 @@ void setup() { #endif push_state(off_state, 0); - #endif // ifdef USE_TINT_RAMPING - #endif // ifdef START_AT_MEMORIZED_LEVEL } -- cgit v1.2.3 From 01833c6f5618dc24d7cd3eefb559352f6d95b28c Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 8 Nov 2018 17:35:13 -0700 Subject: added lantern pin layout --- spaghetti-monster/anduril/cfg-blf-lantern.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index 709bca9..26e5b5a 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -1,4 +1,12 @@ // BLF Lantern config options for Anduril +/* BLF Lantern pinout + * ---- + * Reset -|1 8|- VCC + * eswitch -|2 7|- powerbank enable? + * aux LED -|3 6|- PWM (5000K) + * GND -|4 5|- PWM (3000K) + * ---- + */ // basically the same as a Q8... sort of #define FSM_BLF_Q8_DRIVER -- cgit v1.2.3 From c08e69271078a2d1807fa8b2f905490692befbec Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 19 Dec 2018 15:36:53 -0700 Subject: configured lantern stepped ramp and button LED mode, set default tint to 128 (balanced) --- spaghetti-monster/anduril/cfg-blf-lantern.h | 8 +++++++- spaghetti-monster/fsm-ramping.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index de593d4..a1bda7d 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -17,6 +17,11 @@ #define USE_INDICATOR_LED_WHILE_RAMPING // enable blinking indicator LED while off #define TICK_DURING_STANDBY +#define STANDBY_TICK_SPEED 3 // every 0.128 s +#define USE_FANCIER_BLINKING_INDICATOR +// off mode: high (2) +// lockout: blinking (3) +#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 2) // the lantern has two PWM channels, but they drive different sets of emitters // (one channel for warm emitters, one channel for cold) @@ -38,8 +43,9 @@ // because this lantern isn't overpowered #define RAMP_SMOOTH_FLOOR 1 #define RAMP_SMOOTH_CEIL 150 -#define RAMP_DISCRETE_FLOOR RAMP_SMOOTH_FLOOR +#define RAMP_DISCRETE_FLOOR 20 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 5 // the sensor (attiny85) is nowhere near the emitters // so thermal regulation can't work diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h index 9732b9c..4ce8015 100644 --- a/spaghetti-monster/fsm-ramping.h +++ b/spaghetti-monster/fsm-ramping.h @@ -27,7 +27,7 @@ volatile uint8_t actual_level = 0; #ifdef USE_TINT_RAMPING -uint8_t tint = 0; +uint8_t tint = 128; #endif #ifdef USE_SET_LEVEL_GRADUALLY -- cgit v1.2.3 From 680c2b723f5ebe259741bf34f25a09957ddc8a0b Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 10 May 2019 02:13:13 -0600 Subject: made candle mode amplitude configurable at compile time, and increased the magnitude for the lantern build --- spaghetti-monster/anduril/anduril.c | 27 ++++++++++++++++----------- spaghetti-monster/anduril/cfg-blf-lantern.h | 3 +++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index ea3c06a..675062f 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -383,6 +383,9 @@ volatile uint8_t bike_flasher_brightness = MAX_1x7135; #ifdef USE_CANDLE_MODE uint8_t candle_mode_state(Event event, uint16_t arg); uint8_t triangle_wave(uint8_t phase); +#ifndef CANDLE_AMPLITUDE +#define CANDLE_AMPLITUDE 20 +#endif #endif #ifdef USE_BEACON_MODE @@ -1100,17 +1103,14 @@ inline void bike_flasher_iter() { #ifdef USE_CANDLE_MODE uint8_t candle_mode_state(Event event, uint16_t arg) { - // FIXME: make candle variance magnitude a compile-time option, - // since 20 is sometimes too much or too little, - // depending on the driver type and ramp shape - //#define MAX_CANDLE_LEVEL (RAMP_SIZE-8-6-4) - #define MAX_CANDLE_LEVEL (RAMP_SIZE/2) + #define MAX_CANDLE_LEVEL (RAMP_LENGTH-CANDLE_AMPLITUDE-20) 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; - static uint8_t candle_wave2_depth = 7; - static uint8_t candle_wave3_depth = 4; + static const uint8_t candle_wave1_depth = 8 * CANDLE_AMPLITUDE / 20; + static uint8_t candle_wave2_depth = 7 * CANDLE_AMPLITUDE / 20; + static uint8_t candle_wave3_depth = 5 * CANDLE_AMPLITUDE / 20; static uint8_t candle_mode_brightness = 24; static uint8_t candle_mode_timer = 0; #define TICKS_PER_CANDLE_MINUTE 4096 // about 65 seconds @@ -1155,7 +1155,7 @@ uint8_t candle_mode_state(Event event, uint16_t arg) { // self-timer dims the light during the final minute uint8_t subtract = 0; if (candle_mode_timer == 1) { - subtract = ((candle_mode_brightness+20) + subtract = ((candle_mode_brightness+CANDLE_AMPLITUDE) * ((arg & (TICKS_PER_CANDLE_MINUTE-1)) >> 4)) >> 8; } @@ -1172,7 +1172,7 @@ uint8_t candle_mode_state(Event event, uint16_t arg) { } // 3-oscillator synth for a relatively organic pattern uint8_t add; - add = ((triangle_wave(candle_wave1) * 8) >> 8) + 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; @@ -1180,6 +1180,7 @@ uint8_t candle_mode_state(Event event, uint16_t arg) { 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; @@ -1192,16 +1193,20 @@ uint8_t candle_mode_state(Event event, uint16_t arg) { if ((candle_wave2_depth > 0) && ((pseudo_rand() & 0b00111111) == 0)) candle_wave2_depth --; // random sawtooth retrigger + // TODO: trigger less often? if ((pseudo_rand()) == 0) { - candle_wave2_depth = 7; + // TODO: random amplitude with higher maximum? + candle_wave2_depth = 7 * CANDLE_AMPLITUDE / 20; //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 --; + // TODO: trigger less often? if ((pseudo_rand() & 0b01111111) == 0) - candle_wave3_depth = 5; + // TODO: random amplitude with higher maximum? + candle_wave3_depth = 5 * CANDLE_AMPLITUDE / 20; return MISCHIEF_MANAGED; } return EVENT_NOT_HANDLED; diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index 71e7021..f4c2d1c 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -39,6 +39,9 @@ #define HALFSPEED_LEVEL 14 #define QUARTERSPEED_LEVEL 5 +// the default of 20 looks a bit flat, so increase it +#define CANDLE_AMPLITUDE 33 + // set floor and ceiling as far apart as possible // because this lantern isn't overpowered #define RAMP_SMOOTH_FLOOR 1 -- cgit v1.2.3 From 396b4a95abf7a6d5466e9f089993144b203e6b0e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 10 May 2019 22:41:45 -0600 Subject: reworked candle mode a bit more, now specifies the amplitude of each wave in percent, with a higher potential brightness but more of a low bias overall (looks good on the lantern; haven't tried it elsewhere yet) --- spaghetti-monster/anduril/anduril.c | 26 +++++++++++++++----------- spaghetti-monster/anduril/cfg-blf-lantern.h | 4 ++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 675062f..376c27a 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -1103,14 +1103,18 @@ inline void bike_flasher_iter() { #ifdef USE_CANDLE_MODE uint8_t candle_mode_state(Event event, uint16_t arg) { - #define MAX_CANDLE_LEVEL (RAMP_LENGTH-CANDLE_AMPLITUDE-20) + #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; - static const uint8_t candle_wave1_depth = 8 * CANDLE_AMPLITUDE / 20; - static uint8_t candle_wave2_depth = 7 * CANDLE_AMPLITUDE / 20; - static uint8_t candle_wave3_depth = 5 * CANDLE_AMPLITUDE / 20; + // 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 @@ -1193,20 +1197,20 @@ uint8_t candle_mode_state(Event event, uint16_t arg) { if ((candle_wave2_depth > 0) && ((pseudo_rand() & 0b00111111) == 0)) candle_wave2_depth --; // random sawtooth retrigger - // TODO: trigger less often? - if ((pseudo_rand()) == 0) { - // TODO: random amplitude with higher maximum? - candle_wave2_depth = 7 * CANDLE_AMPLITUDE / 20; + 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 --; - // TODO: trigger less often? if ((pseudo_rand() & 0b01111111) == 0) - // TODO: random amplitude with higher maximum? - candle_wave3_depth = 5 * CANDLE_AMPLITUDE / 20; + // 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; diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index f4c2d1c..3d4c762 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -39,8 +39,8 @@ #define HALFSPEED_LEVEL 14 #define QUARTERSPEED_LEVEL 5 -// the default of 20 looks a bit flat, so increase it -#define CANDLE_AMPLITUDE 33 +// the default of 26 looks a bit flat, so increase it +#define CANDLE_AMPLITUDE 40 // set floor and ceiling as far apart as possible // because this lantern isn't overpowered -- cgit v1.2.3 From ec7334dc722376e3507570e24035da0fc198229e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 10 May 2019 23:25:35 -0600 Subject: Increased default candle magnitude to better fit recent changes (but it still uses less power than the old version, despite the larger amplitude, because it has more of a low bias now) --- spaghetti-monster/anduril/anduril.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 376c27a..e3ff0cb 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -384,7 +384,7 @@ volatile uint8_t bike_flasher_brightness = MAX_1x7135; uint8_t candle_mode_state(Event event, uint16_t arg); uint8_t triangle_wave(uint8_t phase); #ifndef CANDLE_AMPLITUDE -#define CANDLE_AMPLITUDE 20 +#define CANDLE_AMPLITUDE 25 #endif #endif -- cgit v1.2.3 From a4dff7596a9a83b4c3b1f837e8cbe291ed3c4580 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 13 May 2019 23:23:00 -0600 Subject: made tint ramping blink at ends of ramp, made lantern default to stepped mode, lowered lantern floor, made beacon blink shorter --- spaghetti-monster/anduril/anduril.c | 18 +++++++++++++++--- spaghetti-monster/anduril/cfg-blf-lantern.h | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index e3ff0cb..a9fb234 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -262,6 +262,9 @@ void save_config_wl(); #endif // default ramp options if not overridden earlier per-driver +#ifndef RAMP_STYLE +#define RAMP_STYLE 0 // smooth default +#endif #ifndef RAMP_SMOOTH_FLOOR #define RAMP_SMOOTH_FLOOR 1 #endif @@ -305,7 +308,7 @@ void save_config_wl(); #endif uint8_t memorized_level = DEFAULT_LEVEL; // smooth vs discrete ramping -volatile uint8_t ramp_style = 0; // 0 = smooth, 1 = discrete +volatile uint8_t ramp_style = RAMP_STYLE; // 0 = smooth, 1 = discrete volatile uint8_t ramp_smooth_floor = RAMP_SMOOTH_FLOOR; volatile uint8_t ramp_smooth_ceil = RAMP_SMOOTH_CEIL; volatile uint8_t ramp_discrete_floor = RAMP_DISCRETE_FLOOR; @@ -873,6 +876,7 @@ uint8_t steady_state(Event event, uint16_t arg) { #ifdef USE_TINT_RAMPING uint8_t tint_ramping_state(Event event, uint16_t arg) { static int8_t tint_ramp_direction = 1; + static uint8_t prev_tint = 0; // click, click, hold: change the tint if (event == EV_click3_hold) { @@ -883,6 +887,14 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { else if ((tint_ramp_direction < 0) && (tint > 0)) { tint -= 1; } + if ((prev_tint != tint) && + ( (tint == 0) || (tint == 255) )) { + uint8_t foo = actual_level; + set_level(0); + delay_4ms(3); + set_level(foo); + } + prev_tint = tint; set_level(actual_level); //} return EVENT_HANDLED; @@ -1816,9 +1828,9 @@ uint8_t beacon_config_state(Event event, uint16_t arg) { inline void beacon_mode_iter() { // one iteration of main loop() set_level(memorized_level); - nice_delay_ms(500); + nice_delay_ms(100); set_level(0); - nice_delay_ms(((beacon_seconds) * 1000) - 500); + nice_delay_ms(((beacon_seconds) * 1000) - 100); } #endif // #ifdef USE_BEACON_MODE diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index 3d4c762..0372aa0 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -44,9 +44,10 @@ // set floor and ceiling as far apart as possible // because this lantern isn't overpowered +#define RAMP_STYLE 1 // 0 = smooth, 1 = stepped #define RAMP_SMOOTH_FLOOR 1 #define RAMP_SMOOTH_CEIL 150 -#define RAMP_DISCRETE_FLOOR 20 +#define RAMP_DISCRETE_FLOOR 10 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 5 -- cgit v1.2.3 From a337ca16cf33f9e7e0747a1ea0af53930ec47318 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 14 May 2019 00:25:18 -0600 Subject: added auto-tint modes, refactored some indicator blinks into "blip()", enabled blink at ceiling for lantern --- spaghetti-monster/anduril/anduril.c | 79 +++++++++++++++-------------- spaghetti-monster/anduril/cfg-blf-lantern.h | 7 +-- spaghetti-monster/fsm-ramping.c | 14 ++++- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index a9fb234..1d7ecbd 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -250,6 +250,7 @@ uint8_t number_entry_state(Event event, uint16_t arg); volatile uint8_t number_entry_value; void blink_confirm(uint8_t num); +void blip(); #if defined(USE_INDICATOR_LED) && defined(TICK_DURING_STANDBY) void indicator_blink(uint8_t arg); #endif @@ -437,10 +438,7 @@ uint8_t off_state(Event event, uint16_t arg) { #ifdef MOON_TIMING_HINT if (arg == 0) { // let the user know they can let go now to stay at moon - uint8_t temp = actual_level; - set_level(0); - delay_4ms(3); - set_level(temp); + blip(); } else #endif // don't start ramping immediately; @@ -618,8 +616,7 @@ uint8_t steady_state(Event event, uint16_t arg) { #ifdef START_AT_MEMORIZED_LEVEL save_config_wl(); #endif - set_level(0); - delay_4ms(20/4); + blip(); set_level(memorized_level); return MISCHIEF_MANAGED; } @@ -670,8 +667,7 @@ uint8_t steady_state(Event event, uint16_t arg) { || (memorized_level == mode_min) #endif )) { - set_level(0); - delay_4ms(8/4); + blip(); } #endif #if defined(BLINK_AT_STEPS) @@ -685,8 +681,7 @@ uint8_t steady_state(Event event, uint16_t arg) { (memorized_level == nearest) ) { - set_level(0); - delay_4ms(8/4); + blip(); } #endif set_level(memorized_level); @@ -732,8 +727,7 @@ uint8_t steady_state(Event event, uint16_t arg) { || (memorized_level == mode_min) #endif )) { - set_level(0); - delay_4ms(8/4); + blip(); } #endif #if defined(BLINK_AT_STEPS) @@ -747,8 +741,7 @@ uint8_t steady_state(Event event, uint16_t arg) { (memorized_level == nearest) ) { - set_level(0); - delay_4ms(8/4); + blip(); } #endif set_level(memorized_level); @@ -819,10 +812,7 @@ uint8_t steady_state(Event event, uint16_t arg) { // overheating: drop by an amount proportional to how far we are above the ceiling else if (event == EV_temperature_high) { #if 0 - uint8_t foo = actual_level; - set_level(0); - delay_4ms(2); - set_level(foo); + blip(); #endif #ifdef THERM_HARD_TURBO_DROP if (actual_level > THERM_FASTER_LEVEL) { @@ -850,10 +840,7 @@ uint8_t steady_state(Event event, uint16_t arg) { // (proportional to how low we are) else if (event == EV_temperature_low) { #if 0 - uint8_t foo = actual_level; - set_level(0); - delay_4ms(2); - set_level(foo); + blip(); #endif if (actual_level < target_level) { //int16_t stepup = actual_level + (arg>>1); @@ -877,26 +864,32 @@ uint8_t steady_state(Event event, uint16_t arg) { uint8_t tint_ramping_state(Event event, uint16_t arg) { static int8_t tint_ramp_direction = 1; static uint8_t prev_tint = 0; + static uint8_t past_edge_counter = 0; // 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; - } - if ((prev_tint != tint) && - ( (tint == 0) || (tint == 255) )) { - uint8_t foo = actual_level; - set_level(0); - delay_4ms(3); - set_level(foo); - } - prev_tint = tint; - set_level(actual_level); - //} + // reset at beginning of movement + if (! arg) { past_edge_counter = 0; } + // change normal tints + if ((tint_ramp_direction > 0) && (tint < 254)) { + tint += 1; + } + else if ((tint_ramp_direction < 0) && (tint > 1)) { + tint -= 1; + } + // if the user kept pressing long enough, go the final step + if (past_edge_counter == 64) { + past_edge_counter ++; + tint ^= 1; + blip(); + } + else if (prev_tint == tint) { + if (past_edge_counter == 0) blip(); + // count up but don't wrap back to zero + if (past_edge_counter < 255) past_edge_counter ++; + } + prev_tint = tint; + set_level(actual_level); return EVENT_HANDLED; } @@ -1962,6 +1955,14 @@ void blink_confirm(uint8_t num) { } } +// Just go dark for a moment to indicate to user that something happened +void blip() { + uint8_t temp = actual_level; + set_level(0); + delay_4ms(3); + set_level(temp); +} + #if defined(USE_INDICATOR_LED) && defined(TICK_DURING_STANDBY) // beacon-like mode for the indicator LED diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index 0372aa0..9467397 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -69,9 +69,10 @@ #ifdef BLINK_AT_RAMP_MIDDLE #undef BLINK_AT_RAMP_MIDDLE #endif -#ifdef BLINK_AT_RAMP_CEILING -#undef BLINK_AT_RAMP_CEILING -#endif #ifdef BLINK_AT_RAMP_FLOOR #undef BLINK_AT_RAMP_FLOOR #endif +// except the top... blink at the top +#ifndef BLINK_AT_RAMP_CEILING +#define BLINK_AT_RAMP_CEILING +#endif diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index ee816dd..27e3876 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -65,7 +65,19 @@ void set_level(uint8_t level) { // 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 * (uint16_t)brightness) + 127) / 255; + + // auto-tint modes + uint8_t mytint; + // linear with power level + //if (tint == 0) { mytint = brightness; } + //else if (tint == 255) { mytint = 255 - brightness; } + // perceptual by ramp level + if (tint == 0) { mytint = 255 * (uint16_t)level / RAMP_SIZE; } + else if (tint == 255) { mytint = 255 - (255 * (uint16_t)level / RAMP_SIZE); } + // stretch 1-254 to fit 0-255 range + else { mytint = (tint * 100 / 99) - 1; } + + cool_PWM = (((uint16_t)mytint * (uint16_t)brightness) + 127) / 255; warm_PWM = brightness - cool_PWM; PWM1_LVL = warm_PWM; -- cgit v1.2.3 From 5a46280fcad8f8f6f3da46195de835545ad48fbd Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 14 May 2019 00:40:26 -0600 Subject: fixed bug where click-click-hold from off to strobes would also activate tint ramping when it shouldn't --- spaghetti-monster/anduril/anduril.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 1d7ecbd..6057bf0 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -864,12 +864,24 @@ uint8_t steady_state(Event event, uint16_t arg) { uint8_t tint_ramping_state(Event event, uint16_t arg) { static int8_t tint_ramp_direction = 1; static uint8_t prev_tint = 0; + // don't activate auto-tint modes unless the user hits the edge + // and keeps pressing for a while static uint8_t past_edge_counter = 0; + // bugfix: click-click-hold from off to strobes would invoke tint ramping + // 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; // click, click, hold: change the tint if (event == EV_click3_hold) { // reset at beginning of movement - if (! arg) { past_edge_counter = 0; } + if (! arg) { + active = 1; // first frame means this is for us + past_edge_counter = 0; // doesn't start until user hits the edge + } + // ignore event if we weren't the ones who handled the first frame + if (! active) return EVENT_HANDLED; + // change normal tints if ((tint_ramp_direction > 0) && (tint < 254)) { tint += 1; @@ -880,9 +892,10 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { // if the user kept pressing long enough, go the final step if (past_edge_counter == 64) { past_edge_counter ++; - tint ^= 1; + tint ^= 1; // 0 -> 1, 254 -> 255 blip(); } + // if tint change stalled, let user know we hit the edge else if (prev_tint == tint) { if (past_edge_counter == 0) blip(); // count up but don't wrap back to zero @@ -895,6 +908,8 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { // click, click, hold, release: reverse direction for next ramp else if (event == EV_click3_hold_release) { + active = 0; // ignore next hold if it wasn't meant for us + // reverse tint_ramp_direction = -tint_ramp_direction; if (tint == 0) tint_ramp_direction = 1; else if (tint == 255) tint_ramp_direction = -1; -- cgit v1.2.3 From 6adfea8f7c4b7b37ce79153ce4873baf73e627d5 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 14 May 2019 01:41:32 -0600 Subject: moved triangle_wave into fsm-misc, because I need it for power correction in tint ramping --- spaghetti-monster/anduril/anduril.c | 12 ++++++------ spaghetti-monster/fsm-misc.c | 7 +++++++ spaghetti-monster/fsm-misc.h | 3 +++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 6057bf0..75c22e3 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -185,6 +185,12 @@ typedef enum { #define USE_PSEUDO_RAND #endif +#if defined(USE_CANDLE_MODE) +#ifndef USE_TRIANGLE_WAVE +#define USE_TRIANGLE_WAVE +#endif +#endif + #include "spaghetti-monster.h" @@ -1235,12 +1241,6 @@ uint8_t candle_mode_state(Event event, uint16_t arg) { } return EVENT_NOT_HANDLED; } - -uint8_t triangle_wave(uint8_t phase) { - uint8_t result = phase << 1; - if (phase > 127) result = 255 - result; - return result; -} #endif // #ifdef USE_CANDLE_MODE diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c index e61fe00..9f953fa 100644 --- a/spaghetti-monster/fsm-misc.c +++ b/spaghetti-monster/fsm-misc.c @@ -146,5 +146,12 @@ void indicator_led_auto() { */ #endif // USE_INDICATOR_LED +#ifdef USE_TRIANGLE_WAVE +uint8_t triangle_wave(uint8_t phase) { + uint8_t result = phase << 1; + if (phase > 127) result = 255 - result; + return result; +} +#endif #endif diff --git a/spaghetti-monster/fsm-misc.h b/spaghetti-monster/fsm-misc.h index 4e0eb4f..6e41b6c 100644 --- a/spaghetti-monster/fsm-misc.h +++ b/spaghetti-monster/fsm-misc.h @@ -46,5 +46,8 @@ uint8_t blink(uint8_t num, uint8_t speed); void indicator_led(uint8_t lvl); #endif +#ifdef USE_TRIANGLE_WAVE +uint8_t triangle_wave(uint8_t phase); +#endif #endif -- cgit v1.2.3 From 310074c6cf46f3e76873c027b2235457ca35c151 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 14 May 2019 01:42:44 -0600 Subject: added tint ramping power correction for middle tints (it actually needs a surprisingly large correction factor) --- spaghetti-monster/fsm-ramping.c | 23 +++++++++++++++++------ spaghetti-monster/fsm-ramping.h | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 27e3876..1dbb969 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -68,17 +68,28 @@ void set_level(uint8_t level) { // auto-tint modes uint8_t mytint; - // linear with power level - //if (tint == 0) { mytint = brightness; } - //else if (tint == 255) { mytint = 255 - brightness; } + #if 1 // perceptual by ramp level if (tint == 0) { mytint = 255 * (uint16_t)level / RAMP_SIZE; } else if (tint == 255) { mytint = 255 - (255 * (uint16_t)level / RAMP_SIZE); } - // stretch 1-254 to fit 0-255 range + #else + // linear with power level + //if (tint == 0) { mytint = brightness; } + //else if (tint == 255) { mytint = 255 - brightness; } + #endif + // stretch 1-254 to fit 0-255 range (hits every value except 98 and 198) else { mytint = (tint * 100 / 99) - 1; } - cool_PWM = (((uint16_t)mytint * (uint16_t)brightness) + 127) / 255; - warm_PWM = brightness - cool_PWM; + // middle tints sag, so correct for that effect + uint16_t base_PWM = brightness; + // correction is only necessary when PWM is fast + if (level > HALFSPEED_LEVEL) { + base_PWM = brightness + + ((brightness>>1) * triangle_wave(mytint) / 255); + } + + cool_PWM = (((uint16_t)mytint * (uint16_t)base_PWM) + 127) / 255; + warm_PWM = base_PWM - cool_PWM; PWM1_LVL = warm_PWM; PWM2_LVL = cool_PWM; diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h index 4ce8015..dcc3b74 100644 --- a/spaghetti-monster/fsm-ramping.h +++ b/spaghetti-monster/fsm-ramping.h @@ -28,6 +28,7 @@ volatile uint8_t actual_level = 0; #ifdef USE_TINT_RAMPING uint8_t tint = 128; +#define USE_TRIANGLE_WAVE #endif #ifdef USE_SET_LEVEL_GRADUALLY -- cgit v1.2.3 From 1961c3a6950cefa05cdb6e4b0d1967371f7da9f4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 14 May 2019 03:16:33 -0600 Subject: the lantern middle-tint power correction factor wasn't quite right... ... so I adjusted it to make the result closer to a flat curve --- spaghetti-monster/fsm-ramping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 1dbb969..082f8c9 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -85,7 +85,7 @@ void set_level(uint8_t level) { // correction is only necessary when PWM is fast if (level > HALFSPEED_LEVEL) { base_PWM = brightness - + ((brightness>>1) * triangle_wave(mytint) / 255); + + ((((uint16_t)brightness) * 26 / 64) * triangle_wave(mytint) / 255); } cool_PWM = (((uint16_t)mytint * (uint16_t)base_PWM) + 127) / 255; -- cgit v1.2.3