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=72e13323a9d6124ba863a70a71dc676af916a876;hp=59c85a79b2e17bb11b65b54d0d3fb79f170e3154;hb=c30006aaf666f7cff3a6ab949c613c2f8cc6163b;hpb=b0572d0cae20a9fd351b197a0ea9b01fc658ee77 diff --git a/firmware/ambient.c b/firmware/ambient.c index 59c85a7..72e1332 100644 --- a/firmware/ambient.c +++ b/firmware/ambient.c @@ -2,6 +2,7 @@ #include "lights.h" +#define AMBIENT_VAL_SHIFT 2 static uint16_t ambient_val; volatile unsigned char ambient_zone; @@ -15,10 +16,10 @@ typedef struct { * and having small overlaps in order to provide a bit of hysteresis. */ static ambient_zone_t ambient_zones[] = { - { 0x0000, 0xb000 }, // dark - { 0xa800, 0xc400 }, - { 0xc200, 0xcb00 }, - { 0xca80, 0xffff } + { 0x0000 , 0x0290<> 3); + ambient_val += adcval - (ambient_val + >> (AMBIENT_VAL_SHIFT - AMBIENT_ADC_SHIFT)); while (ambient_zones[ambient_zone].lo > ambient_val) ambient_zone--;