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 0x10, 0x18, 0x20, 0x40, 0x100, 0x400, 0x1000, 0x4000, 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);
28 void ambient_adc(uint16_t adcval)
30 unsigned char newzone;
32 if (!ambient_zone_set)
33 ambient_val = adcval << 4;
35 ambient_val += adcval - (ambient_val >> 4);
38 while (newzone < N_AMBIENT_ZONES-1
39 && ambient_zones[newzone] < ambient_val)
42 if (!ambient_zone_set || newzone != ambient_zone) {
43 ambient_zone = newzone;
45 // ambient_zone_changed();