aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-ramping.c
diff options
context:
space:
mode:
Diffstat (limited to 'spaghetti-monster/fsm-ramping.c')
-rw-r--r--spaghetti-monster/fsm-ramping.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index c3ad8b4..3791030 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -76,16 +76,25 @@ void set_level(uint8_t level) {
LED_ENABLE2_PORT &= ~(1 << LED_ENABLE2_PIN);
#endif
} else {
- level --;
-
// enable the power channel, if relevant
#ifdef LED_ENABLE_PIN
- LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN);
+ #ifndef LED_ENABLE_PIN_LEVEL_MIN
+ LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN);
+ #else
+ // only enable during part of the ramp
+ if ((level >= LED_ENABLE_PIN_LEVEL_MIN)
+ && (level <= LED_ENABLE_PIN_LEVEL_MAX))
+ LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN);
+ else // disable during other parts of the ramp
+ LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN);
+ #endif
#endif
#ifdef LED_ENABLE2_PIN
LED_ENABLE2_PORT |= (1 << LED_ENABLE2_PIN);
#endif
+ level --;
+
#ifdef USE_TINT_RAMPING
#ifndef TINT_RAMPING_CORRECTION
#define TINT_RAMPING_CORRECTION 26 // 140% brightness at middle tint
@@ -156,6 +165,15 @@ void gradual_tick() {
if (gt < actual_level) gt = actual_level - 1;
else if (gt > actual_level) gt = actual_level + 1;
+ #ifdef LED_ENABLE_PIN_LEVEL_MIN
+ // only enable during part of the ramp
+ if ((gt >= LED_ENABLE_PIN_LEVEL_MIN)
+ && (gt <= LED_ENABLE_PIN_LEVEL_MAX))
+ LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN);
+ else // disable during other parts of the ramp
+ LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN);
+ #endif
+
gt --; // convert 1-based number to 0-based
PWM_DATATYPE target;