From: Jan "Yenya" Kasprzak Date: Wed, 29 Aug 2012 14:25:00 +0000 (+0200) Subject: pwmled.c: enabling/disabling functions X-Git-Tag: gedasymbols-20120913~39 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=4dcd70de690010bdf0a3489d06508f2ab624b474;p=bike-lights.git pwmled.c: enabling/disabling functions --- diff --git a/pwmled.c b/pwmled.c index df8bc07..5c816b3 100644 --- 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;