4
0
Fork 0
mirror of https://github.com/zzzzDev4/IAS-Better-Tea.git synced 2025-04-21 07:31:20 +02:00

implemented timeout

This commit is contained in:
zzzz 2024-06-14 14:35:49 +02:00
parent d9753564b9
commit b87d97e2be

View file

@ -40,6 +40,13 @@ String shuttleServer = "https://ias-tea-axum.shuttleapp.rs";
TeaData currentTea(-1, "Teafault", "c0derfid", "", -1, 30); TeaData currentTea(-1, "Teafault", "c0derfid", "", -1, 30);
// config
long feedbackTimeout = 15;
int defaultSteepingTime = 120;
// timeout
unsigned long timeoutTime;
enum State enum State
{ {
// lifecycle states // lifecycle states
@ -80,7 +87,20 @@ void setup()
teaNet.init(ssid, password); teaNet.init(ssid, password);
smartDisplay.playTeaAnimationPartTwo(32, "", "Success!", "", ""); smartDisplay.playTeaAnimationPartTwo(32, "", "Success!", "", "");
delay(250);
// load config
JSONVar result = teaNet.httpsGETRequest(shuttleServer + "/configuration");
// catch possible failure
if (result == JSON.parse("{}"))
{
smartDisplay.printMsg("failed loading config");
delay(500);
}
else
{
defaultSteepingTime = result["default_steeping_time"];
feedbackTimeout = result["feedback_timeout"];
}
smartDisplay.playTeaAnimation(); smartDisplay.playTeaAnimation();
delay(250); delay(250);
@ -166,7 +186,7 @@ void loop()
{ {
Serial.print("TEA DOES NOT EXIST YET!"); Serial.print("TEA DOES NOT EXIST YET!");
state = State::DISPLAY_ADD_NEW_TEA_CONFIG; state = State::DISPLAY_ADD_NEW_TEA_CONFIG;
currentTea = TeaData(-1, "New Tea", currentTea.m_rfidCode, "", -1, 120); currentTea = TeaData(-1, "New Tea", currentTea.m_rfidCode, "", -1, defaultSteepingTime);
smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", ""); smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", "");
break; break;
} }
@ -235,6 +255,7 @@ void loop()
smartStrip.animateBottomToTop(0, 1, 0); smartStrip.animateBottomToTop(0, 1, 0);
delay(1000); delay(1000);
state = State::REQUEST_FEEDBACK; state = State::REQUEST_FEEDBACK;
timeoutTime = millis() + (feedbackTimeout * 1000 * 60);
break; break;
} }
@ -249,11 +270,33 @@ void loop()
smartDisplay.printMsg("Ready!"); smartDisplay.printMsg("Ready!");
smartStrip.animateBottomToTop(0, 1, 0); smartStrip.animateBottomToTop(0, 1, 0);
state = State::REQUEST_FEEDBACK; state = State::REQUEST_FEEDBACK;
timeoutTime = millis() + (feedbackTimeout * 1000 * 60);
} }
break; break;
} }
case REQUEST_FEEDBACK: case REQUEST_FEEDBACK:
{ {
// timeout
if (millis() >= timeoutTime)
{
// we still want to save the last configuration (treated as perfect, no steeping time change)
String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds);
Serial.println(payload);
smartDisplay.playTeaAnimationPartOne(32, "", "Loading...", "", "");
JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/tea-steeping-time/" + currentTea.m_id, payload);
// catch possible failure
if (res == JSON.parse("{}"))
{
smartDisplay.printMsg("TRY AGAIN");
delay(500);
break;
}
state = State::WAIT_FOR_RFID_SCAN;
smartStrip.reset();
break;
}
smartDisplay.printRequestFeedbackScreen(currentTea); smartDisplay.printRequestFeedbackScreen(currentTea);
String uid = smartRFID.readTag(50); // just enough time to detect tag String uid = smartRFID.readTag(50); // just enough time to detect tag
@ -282,8 +325,6 @@ void loop()
if (isTouchBtnPressed()) if (isTouchBtnPressed())
{ {
// keep steeping time for next brew // keep steeping time for next brew
state = State::WAIT_FOR_RFID_SCAN;
String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds); String payload = teaNet.bundleSteepingTimeChange(currentTea.m_steepingSeconds);
Serial.println(payload); Serial.println(payload);
smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(perfect)", "", "saving..."); smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(perfect)", "", "saving...");
@ -295,6 +336,7 @@ void loop()
delay(1000); delay(1000);
break; break;
} }
state = State::WAIT_FOR_RFID_SCAN;
smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", ""); smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", "");
smartStrip.reset(); smartStrip.reset();
} }