mirror of
https://github.com/zzzzDev4/IAS-Better-Tea.git
synced 2025-04-21 07:31:20 +02:00
44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#include "SmartFeedback.hpp"
|
|
|
|
// bool: false => feedback less brewtime; true => feedback more brewtime
|
|
int SmartFeedback::calculateNewTime(bool feedback, JSONVar steepingLog, int currentSteepingTime)
|
|
{
|
|
int numLogEntries = steepingLog.length();
|
|
int steepingTimes[numLogEntries];
|
|
for (int i = 0; i < numLogEntries; i++)
|
|
{
|
|
steepingTimes[i] = steepingLog[i]["steeping_seconds"];
|
|
}
|
|
|
|
// if there is no log yet, we just add/substract MAX_STEP
|
|
if (numLogEntries == 0)
|
|
return feedback ? currentSteepingTime + MAX_STEP : currentSteepingTime - MAX_STEP;
|
|
|
|
// check the last brewing time
|
|
int lastSteepingTime = steepingTimes[numLogEntries-1];
|
|
Serial.print("last steeping time: ");
|
|
Serial.println(lastSteepingTime);
|
|
if (feedback)
|
|
{
|
|
// we want a longer brewing time
|
|
|
|
if (lastSteepingTime >= currentSteepingTime)
|
|
return currentSteepingTime + MIDDLE_STEP;
|
|
|
|
if (lastSteepingTime < currentSteepingTime)
|
|
return currentSteepingTime + MAX_STEP;
|
|
}
|
|
else
|
|
{
|
|
// we want a shorter brewing time
|
|
|
|
if (lastSteepingTime > currentSteepingTime)
|
|
return currentSteepingTime - MAX_STEP;
|
|
|
|
if (lastSteepingTime <= currentSteepingTime)
|
|
return currentSteepingTime - MIDDLE_STEP;
|
|
}
|
|
|
|
// something went wrong
|
|
return 0;
|
|
}
|