aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spaghetti-monster/fsm-ramping.c23
-rw-r--r--spaghetti-monster/fsm-ramping.h1
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
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.