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=ab28a20faf1ce95719cdd8ff4386ef9b90790af2;hp=9dbf600ea6f9c0bae7dbcccdc91b0c87b4477641;hb=HEAD;hpb=a58c5b9c16ec9060c38a14446e5524b22ad8aea5 diff --git a/firmware/ambient.c b/firmware/ambient.c index 9dbf600..3ae15d3 100644 --- a/firmware/ambient.c +++ b/firmware/ambient.c @@ -11,7 +11,7 @@ volatile unsigned char ambient_zone, ambient_shadow; static unsigned char ambient_min, ambient_max, ambient_drop; /* logging */ -#define AMBIENT_LOG_SIZE 128 +#define AMBIENT_LOG_SIZE 256 static unsigned char ambient_log_offset_stored EEMEM; static unsigned char ambient_log_offset; static unsigned char ambient_log[AMBIENT_LOG_SIZE] EEMEM; @@ -27,15 +27,15 @@ typedef struct { */ static ambient_zone_t ambient_zones[N_AMBIENT_ZONES] = { #ifdef PAVLINA - { 0x0000, 0x0290 }, // dark - { 0x0278, 0x02f8 }, // evening - { 0x02d8, 0x0310 }, // dawn - { 0x0308, 0xffff }, // day + { 0x0000, 0x02d0 }, // dark + { 0x02b0, 0x0318 }, // evening + { 0x0308, 0x032c }, // dawn + { 0x0324, 0xffff }, // day #else { 0x0000, 0x0250 }, // dark - { 0x0240, 0x02e0 }, // evening - { 0x02c0, 0x0300 }, // dawn - { 0x02f8, 0xffff }, // day + { 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;