#include #include "lights.h" #define AMBIENT_VAL_SHIFT 2 static uint16_t ambient_val; volatile unsigned char ambient_zone; /* My photodiode reads 0x00C5 .. 0x033B */ typedef struct { uint16_t lo, hi; } ambient_zone_t; /* * Note: these have to be sorted, starting with 0, ending with 0xFFFF * and having small overlaps in order to provide a bit of hysteresis. */ static ambient_zone_t ambient_zones[] = { { 0x0000 , 0x0290<> (AMBIENT_VAL_SHIFT - AMBIENT_ADC_SHIFT)); while (ambient_zones[ambient_zone].lo > ambient_val) ambient_zone--; while (ambient_zones[ambient_zone].hi < ambient_val) ambient_zone++; #if 0 if (old_zone != ambient_zone) { log_byte(0xab); log_byte(ambient_zone); log_word(adcval); log_flush(); } // ambient_zone_changed(); #endif }