5 static uint16_t ambient_val;
6 volatile unsigned char ambient_zone;
8 /* My photodiode reads 0x00C5 .. 0x033B */
14 * Note: these have to be sorted, starting with 0, ending with 0xFFFF
15 * and having small overlaps in order to provide a bit of hysteresis.
17 static ambient_zone_t ambient_zones[] = {
18 { 0x0000, 0xa400 }, // dark
23 #define N_AMBIENT_ZONES (sizeof(ambient_zones)/sizeof(ambient_zones[0]))
31 void ambient_zone_changed()
35 log_byte(ambient_zone);
36 log_word(ambient_val);
40 // led_set_pattern(N_PWMLEDS, status_led_pattern_select());
41 // led_set_pattern(N_PWMLEDS+1, illumination_led_pattern_select());
45 void ambient_adc(uint16_t adcval)
47 unsigned char old_zone = ambient_zone;
49 ambient_val += adcval - (ambient_val >> 3);
51 while (ambient_zones[ambient_zone].lo > ambient_val)
54 while (ambient_zones[ambient_zone].hi < ambient_val)
58 if (old_zone != ambient_zone) {
60 log_byte(ambient_zone);
64 // ambient_zone_changed();