From: Jan "Yenya" Kasprzak Date: Thu, 18 Jul 2013 21:29:32 +0000 (+0200) Subject: ambient.c: rewrite X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=5a5088f09ea11dd3c36f3bb6833a0c5d85715641;hp=5a5088f09ea11dd3c36f3bb6833a0c5d85715641;p=bike-lights.git ambient.c: rewrite We now measure two running averages - ambient_slow and ambient_fast. The _fast is computed based on the ADC readings and few bits of averaging. The _slow is computed based on _fast and few bits of averaging. We don't want to change the zone too often, but on the other hand, we want fast reaction to the strong ambient light level changes. So we compute the new ambient zone based on _fast, and when the new one is current one +1 or -1, we retry using the _slow value. Only when even the _slow suggests that the ambient zone has changed, we permit the change to the neighbouring level. Changes to the more distant zone are permitted immediately. Also the logging rewritten to accomodate minimum, a few bits of max-min, and a few bits of level drop. ---