Use averaged brightness for limit calculation

This commit is contained in:
fruchti 2020-07-15 22:44:20 +02:00
parent ccfdd7aeab
commit fe246bfa6d
2 changed files with 10 additions and 11 deletions

View file

@ -1 +1 @@
264 277

View file

@ -67,19 +67,18 @@ void LightSensor_Poll(void)
unsigned int measurement = LightSensor_Measurement; unsigned int measurement = LightSensor_Measurement;
LightSensor_NewMeasurement = false; LightSensor_NewMeasurement = false;
float brightness = 1.0f - measurement / 65535.0f; float brightness = 1.0f - measurement / 65535.0f;
if(measurement != 65535 && brightness < LightSensor_MinimumBrightness)
{
LightSensor_MinimumBrightness = brightness;
}
if(brightness > LightSensor_MaximumBrightness)
{
LightSensor_MaximumBrightness = brightness;
}
LightSensor_AbsoluteBrightness = LIGHTSENSOR_LAMBDA * LightSensor_AbsoluteBrightness LightSensor_AbsoluteBrightness = LIGHTSENSOR_LAMBDA * LightSensor_AbsoluteBrightness
+ (1.0f - LIGHTSENSOR_LAMBDA) * brightness; + (1.0f - LIGHTSENSOR_LAMBDA) * brightness;
if(LightSensor_AbsoluteBrightness < LightSensor_MinimumBrightness)
{
LightSensor_MinimumBrightness = LightSensor_AbsoluteBrightness;
}
if(LightSensor_AbsoluteBrightness > LightSensor_MaximumBrightness)
{
LightSensor_MaximumBrightness = LightSensor_AbsoluteBrightness;
}
// Scale and saturate to get relative brightness value // Scale and saturate to get relative brightness value
float range = LightSensor_MaximumBrightness float range = LightSensor_MaximumBrightness
- LightSensor_MinimumBrightness; - LightSensor_MinimumBrightness;