]> www.fi.muni.cz Git - bike-lights.git/commitdiff
pwmled.c: enabling/disabling functions
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 29 Aug 2012 14:25:00 +0000 (16:25 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 29 Aug 2012 14:25:00 +0000 (16:25 +0200)
pwmled.c

index df8bc07635ddb1545f899e88b1b93a04443b37f3..5c816b3351e4b3077f46084baa6cdb5d3045f6da 100644 (file)
--- a/pwmled.c
+++ b/pwmled.c
@@ -12,6 +12,7 @@ static unsigned char adc_vals[N_PWMLEDS*N_PWMLED_MODES] = {
        0x04, 0x14, 0x24, 0x38,
 };
 
+// TODO: maybe convert this to bitmask to simplify pwmled_needs_adc() ?
 static unsigned char pwmled_state[N_PWMLEDS];
 #define ST_DISABLED 0
 #define ST_PROBING  1
@@ -51,6 +52,34 @@ unsigned char pwmled_needs_adc(unsigned char n)
                return 0;
 }
 
+unsigned char pwmled_enabled(unsigned char n)
+{
+       unsigned char st = pwmled_state[n];
+       if (st == ST_OFF || st == ST_ON)
+               return 1;
+       else
+               return 0;
+}
+
+void pwmled_set_mode(unsigned char n, unsigned char mode)
+{
+       if (!pwmled_enabled(n))
+               return;
+
+       if (mode == 0) {
+               pwm_off(n);
+               pwmled_state[n] = ST_OFF;
+               return;
+       }
+
+       if (mode <= N_PWMLED_MODES) {
+               mode--;
+               pwm_set(n, pwm_vals[n*N_PWMLED_MODES+mode]);
+               pwmled_state[n] = ST_ON;
+               pwmled_mode[n] = mode;
+       }
+}
+
 static void inline probing_adc(unsigned char n, uint16_t adcval)
 {
        unsigned char need_bigger = 0, i;