5 static uint16_t ambient_val;
6 volatile unsigned char ambient_zone;
7 static unsigned char ambient_zone_set;
9 static uint16_t ambient_zones[] = {
10 0x0b70, 0x0b80, 0x1000, 0x1800, 0x2800, 0x2f80, 0xffff
12 #define N_AMBIENT_ZONES (sizeof(ambient_zones)/sizeof(ambient_zones[0]))
21 void ambient_zone_changed()
24 log_byte(ambient_zone);
25 log_word(ambient_val);
29 void ambient_adc(uint16_t adcval)
31 unsigned char newzone;
33 if (!ambient_zone_set)
34 ambient_val = adcval << 4;
36 ambient_val += adcval - (ambient_val >> 4);
39 while (newzone < N_AMBIENT_ZONES-1
40 && ambient_zones[newzone] < ambient_val)
43 // TODO: implement hysteresis?
44 if (!ambient_zone_set || newzone != ambient_zone) {
45 ambient_zone = newzone;
47 // ambient_zone_changed();