X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=blobdiff_plain;f=firmware%2Fambient.c;h=3ae15d3c0e97080e1ac56957f06b67a883275305;hp=5627dba2a88ab3b5ec1fd246793cd699e7e1c726;hb=dc4a8b74e6bd5ecfd139fabbb1f5bd8dad3b624e;hpb=bd8e93c9a8a74602aa856a2d7c53dfbc2522af07 diff --git a/firmware/ambient.c b/firmware/ambient.c index 5627dba..3ae15d3 100644 --- a/firmware/ambient.c +++ b/firmware/ambient.c @@ -27,14 +27,14 @@ typedef struct { */ static ambient_zone_t ambient_zones[N_AMBIENT_ZONES] = { #ifdef PAVLINA - { 0x0000, 0x02b0 }, // dark - { 0x0298, 0x0308 }, // evening - { 0x02e8, 0x0320 }, // dawn - { 0x0318, 0xffff }, // day + { 0x0000, 0x02d0 }, // dark + { 0x02b0, 0x0318 }, // evening + { 0x0308, 0x032c }, // dawn + { 0x0324, 0xffff }, // day #else - { 0x0000, 0x0240 }, // dark - { 0x0230, 0x02e0 }, // evening - { 0x02c0, 0x0304 }, // dawn + { 0x0000, 0x0250 }, // dark + { 0x0230, 0x02e8 }, // evening + { 0x02d0, 0x0302 }, // dawn { 0x02fc, 0xffff }, // day #endif }; @@ -102,6 +102,9 @@ static unsigned char val_to_zone(uint16_t ambient_val) { unsigned char new_zone = ambient_zone; + if (new_zone >= N_AMBIENT_ZONES) + new_zone = N_AMBIENT_ZONES-1; + while (ambient_zones[new_zone].lo > ambient_val) new_zone--; @@ -129,8 +132,8 @@ void ambient_adc(uint16_t adcval) slow_10bit = ambient_slow >> AMBIENT_SLOW_SHIFT; - if (new_zone > 1 && ( - new_zone == ambient_zone-1 || new_zone > ambient_zone)) { + if ((new_zone > ambient_zone) + || (new_zone > 1 && new_zone == ambient_zone - 1)) { // but change to the neighbouring zone is governed by _slow, // except to the darkest zone, where we want fast reaction. new_zone = val_to_zone(slow_10bit); @@ -140,6 +143,7 @@ void ambient_adc(uint16_t adcval) if ((user_zone = get_user_param(0)) > 0) new_zone = user_zone - 1; +#if 0 // ignore shadow-entering code altogether for now // are we entering the shadow? if (!user_zone && new_zone < ambient_zone && ambient_zone >= 2 && slow_10bit > fast_10bit @@ -163,6 +167,7 @@ void ambient_adc(uint16_t adcval) new_zone = ambient_zone; // don't change while entering shadow ambient_zone_changed(); // notify others the first time } +#endif // TODO: maybe use these values instead of 10-bit? byte_fast = fast_10bit >> 2;