-static uint16_t ambient_zones[] = {
- 0x0c00, 0x0d00, 0x1000, 0x1800, 0x2800, 0x2f80, 0xffff
+/* logging */
+#define AMBIENT_LOG_SIZE 128
+static unsigned char ambient_log_offset_stored EEMEM;
+static unsigned char ambient_log_offset;
+static unsigned char ambient_log[AMBIENT_LOG_SIZE] EEMEM;
+
+/* 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 , 0x0280<<AMBIENT_VAL_SHIFT }, // dark
+ { 0x0270<<AMBIENT_VAL_SHIFT, 0x02f0<<AMBIENT_VAL_SHIFT }, // evening
+ { 0x02e8<<AMBIENT_VAL_SHIFT, 0x030a<<AMBIENT_VAL_SHIFT }, // dawn
+ { 0x0308<<AMBIENT_VAL_SHIFT, 0xffff }, // day