From: Jan "Yenya" Kasprzak Date: Fri, 18 Apr 2014 16:24:06 +0000 (+0200) Subject: ambient.c: fixup, disable shadow code X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=commitdiff_plain;h=dc4a8b74e6bd5ecfd139fabbb1f5bd8dad3b624e ambient.c: fixup, disable shadow code --- diff --git a/firmware/ambient.c b/firmware/ambient.c index c932320..3ae15d3 100644 --- a/firmware/ambient.c +++ b/firmware/ambient.c @@ -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;