FIx lighting maths

This commit is contained in:
Robert Marshall 2018-09-22 07:09:43 +01:00
parent f383baae95
commit 1b18919543

View file

@ -182,18 +182,13 @@ float getIndexMultiplier(int now, int startTime, int endTime, bool swap){
float indexMultiplier = 1;
int a = swap ? endTime - now : now - startTime;
int b = endTime - startTime;
indexMultiplier = a > 0 ? b / a : 0;
if (indexMultiplier < 1)
indexMultiplier = 1;
return indexMultiplier;
return constrain(a / b, 0, 1);
}
float getHeatIndex() {
time_t now = time(nullptr);
float indexMultiplier = now >= _lightsOffStartTime ? getIndexMultiplier(now, _lightsOffStartTime, _lightsOffEndTime, true) : getIndexMultiplier(now, _lightsOnStartTime, _lightsOnEndTime, false);
return HEAT_INDEX_MAX / indexMultiplier;
return HEAT_INDEX_MAX * indexMultiplier;
}
void doLighting() {