#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; }