]> www.fi.muni.cz Git - bike-lights.git/commitdiff
pwmled.c: do not regulate just after mode change
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sun, 16 Dec 2012 16:28:39 +0000 (17:28 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sun, 16 Dec 2012 16:28:39 +0000 (17:28 +0100)
firmware/pwmled.c

index 9a8deac4658bae6ddbb349c0196d4935d13f248e..70cbcf1429ca6d71bc0c6d432111d9ae72bbeca3 100644 (file)
@@ -5,7 +5,10 @@
 typedef struct {
        uint16_t target, pwm;
        int16_t err_sum;
-       unsigned char mode, state, probe_steady;
+       unsigned char mode, state;
+       union {
+               unsigned char probe_steady, mode_changed;
+       };
        uint16_t mode_pwm[N_PWMLED_MODES];
        int16_t err_sums[N_PWMLED_MODES];
 } pwmled_t;
@@ -122,6 +125,7 @@ void pwmled_set_mode(unsigned char n, unsigned char mode)
                led->state = ST_ON;
                led->pwm = led->mode_pwm[mode - 1];
                led->err_sum = led->err_sums[mode - 1];
+               led->mode_changed = 1;
                pwm_set(n, led->pwm);
        } else {
                led->state = ST_OFF;
@@ -202,6 +206,10 @@ void pwmled_adc(unsigned char n, uint16_t adcval)
        if (!ST_IS_ON(led->state))
                return;
 
+       if (led->state == ST_ON && led->mode_changed) {
+               led->mode_changed--;
+               return;
+       }
        // FIXME: test for maximum adcval value (adc_max[n])
 
        old_pwm = led->pwm;