]> www.fi.muni.cz Git - bike-lights.git/blobdiff - firmware/ambient.c
ambient.c: user-settable ambient light zone
[bike-lights.git] / firmware / ambient.c
index caeca14a242430923ffc1ec0dfe47e4cedf00459..19b7a13cd86003bc4ec0407f9aa42ecbe287719d 100644 (file)
@@ -23,13 +23,12 @@ typedef struct {
  * 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[] = {
+static ambient_zone_t ambient_zones[N_AMBIENT_ZONES] = {
        { 0x0000                   , 0x0270<<AMBIENT_VAL_SHIFT }, // dark
        { 0x0260<<AMBIENT_VAL_SHIFT, 0x02e0<<AMBIENT_VAL_SHIFT }, // evening
        { 0x02d0<<AMBIENT_VAL_SHIFT, 0x0306<<AMBIENT_VAL_SHIFT }, // dawn
        { 0x0300<<AMBIENT_VAL_SHIFT, 0xffff                    }, // day
 };
-#define N_AMBIENT_ZONES (sizeof(ambient_zones)/sizeof(ambient_zones[0]))
 
 void init_ambient()
 {
@@ -108,6 +107,11 @@ void ambient_adc(uint16_t adcval)
 
        if (ambient_max < byte_val)
                ambient_max = byte_val;
+
+       // user_param ambient zone override
+       if ((byte_val = get_user_param(0)) > 0)
+               ambient_zone = byte_val - 1;
+
        if (old_zone != ambient_zone) {
 #if 0
                log_byte(0xab);