mirror of
https://github.com/zzzzDev4/IAS-Better-Tea.git
synced 2025-04-21 07:31:20 +02:00
Display improvements and QOL tweaks
This commit is contained in:
parent
6ffd5f4332
commit
c558338b63
5 changed files with 121 additions and 68 deletions
|
@ -90,9 +90,17 @@ void SmartDisplay::printTeaConfigScreen(TeaData tea)
|
||||||
m_display->println(tea.m_teaName);
|
m_display->println(tea.m_teaName);
|
||||||
|
|
||||||
m_display->setCursor(128 - 35, m_display->getCursorY());
|
m_display->setCursor(128 - 35, m_display->getCursorY());
|
||||||
m_display->print(tea.m_waterTemp);
|
|
||||||
m_display->drawCircle(m_display->getCursorX() + 4, m_display->getCursorY(), 1, WHITE);
|
if (tea.m_waterTemp > 0)
|
||||||
m_display->println(" C");
|
{
|
||||||
|
m_display->print(tea.m_waterTemp);
|
||||||
|
m_display->drawCircle(m_display->getCursorX() + 4, m_display->getCursorY(), 1, WHITE);
|
||||||
|
m_display->println(" C");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_display->println("");
|
||||||
|
}
|
||||||
|
|
||||||
m_display->setTextSize(2);
|
m_display->setTextSize(2);
|
||||||
String steepingTime = SmartTime::formatSeconds(tea.m_steepingSeconds);
|
String steepingTime = SmartTime::formatSeconds(tea.m_steepingSeconds);
|
||||||
|
@ -130,23 +138,38 @@ void SmartDisplay::printRequestFeedbackScreen(TeaData tea)
|
||||||
{
|
{
|
||||||
resetDisplay();
|
resetDisplay();
|
||||||
|
|
||||||
m_display->println("Feedback on brew intensity");
|
m_display->println(" Feedback ");
|
||||||
m_display->println();
|
m_display->setCursor(0, m_display->getCursorY() + 4);
|
||||||
m_display->println("|less| perfect |more|");
|
m_display->println("< >");
|
||||||
|
m_display->setCursor(0, m_display->getCursorY() + 4);
|
||||||
|
m_display->println("shorter ok longer");
|
||||||
|
|
||||||
m_display->display();
|
m_display->display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmartDisplay::printAddNewTeaConfigScreen(TeaData tea)
|
void SmartDisplay::printAddNewTeaConfigScreen(TeaData tea, u_int *flicker)
|
||||||
{
|
{
|
||||||
resetDisplay();
|
resetDisplay();
|
||||||
|
|
||||||
m_display->println("Add initial config for new tea");
|
m_display->println(" New Tea");
|
||||||
m_display->println();
|
m_display->println("Steeping time:");
|
||||||
m_display->print("Steeping time:");
|
|
||||||
|
if (*flicker % 12 == 0)
|
||||||
|
{
|
||||||
|
toggle = !toggle;
|
||||||
|
}
|
||||||
|
if (toggle)
|
||||||
|
{
|
||||||
|
m_display->display();
|
||||||
|
*flicker += 3;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_display->setTextSize(2);
|
||||||
String steepingTime = SmartTime::formatSeconds(tea.m_steepingSeconds);
|
String steepingTime = SmartTime::formatSeconds(tea.m_steepingSeconds);
|
||||||
m_display->print(steepingTime);
|
m_display->print(steepingTime);
|
||||||
m_display->setTextSize(1);
|
m_display->setTextSize(1);
|
||||||
|
m_display->setCursor(m_display->getCursorX(), m_display->getCursorY() + 7);
|
||||||
m_display->println(" min");
|
m_display->println(" min");
|
||||||
|
|
||||||
m_display->display();
|
m_display->display();
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// special screens
|
// special screens
|
||||||
void printAddNewTeaConfigScreen(TeaData tea);
|
void printAddNewTeaConfigScreen(TeaData tea, u_int *flicker);
|
||||||
|
|
||||||
// animations
|
// animations
|
||||||
void playTeaAnimation();
|
void playTeaAnimation();
|
||||||
|
@ -37,4 +37,5 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Adafruit_SSD1306 *m_display;
|
Adafruit_SSD1306 *m_display;
|
||||||
|
bool toggle = false;
|
||||||
};
|
};
|
|
@ -12,6 +12,7 @@ void SmartStrip::reset()
|
||||||
{
|
{
|
||||||
FastLED.clear(true);
|
FastLED.clear(true);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmartStrip::setGreen(int led)
|
void SmartStrip::setGreen(int led)
|
||||||
|
@ -21,6 +22,7 @@ void SmartStrip::setGreen(int led)
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SmartStrip::animateBottomToTop(int r, int g, int b)
|
void SmartStrip::animateBottomToTop(int r, int g, int b)
|
||||||
{
|
{
|
||||||
for (int i = 0; i <= 14; i++)
|
for (int i = 0; i <= 14; i++)
|
||||||
|
@ -28,9 +30,8 @@ void SmartStrip::animateBottomToTop(int r, int g, int b)
|
||||||
leds[i].setRGB(r, g, b);
|
leds[i].setRGB(r, g, b);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
delay(100);
|
delay(50);
|
||||||
}
|
}
|
||||||
FastLED.clear(true);
|
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@ void SmartStrip::progressBar(int min, int max, int val)
|
||||||
leds[i].setRGB(3, 3, 3);
|
leds[i].setRGB(3, 3, 3);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
|
FastLED.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
135
src/main.cpp
135
src/main.cpp
|
@ -93,6 +93,7 @@ void setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
u_int frame = 0;
|
u_int frame = 0;
|
||||||
|
u_int flicker = 0;
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -147,15 +148,7 @@ void loop()
|
||||||
}
|
}
|
||||||
case PROCESS_RFID_SCAN:
|
case PROCESS_RFID_SCAN:
|
||||||
{
|
{
|
||||||
smartDisplay.resetDisplay();
|
smartDisplay.playTeaAnimationPartOne(32, "", "Loading...", "", "");
|
||||||
display.println("Detected!");
|
|
||||||
display.display();
|
|
||||||
delay(200);
|
|
||||||
display.println(currentTea.m_rfidCode);
|
|
||||||
delay(200);
|
|
||||||
|
|
||||||
display.println("Sync...");
|
|
||||||
display.display();
|
|
||||||
|
|
||||||
JSONVar result = teaNet.httpsGETRequest(shuttleServer + "/teabyrfid/" + currentTea.m_rfidCode);
|
JSONVar result = teaNet.httpsGETRequest(shuttleServer + "/teabyrfid/" + currentTea.m_rfidCode);
|
||||||
Serial.print("Result:");
|
Serial.print("Result:");
|
||||||
|
@ -165,30 +158,25 @@ void loop()
|
||||||
if (result == JSON.parse("{}"))
|
if (result == JSON.parse("{}"))
|
||||||
{
|
{
|
||||||
smartDisplay.printMsg("GET FAILED");
|
smartDisplay.printMsg("GET FAILED");
|
||||||
delay(1000);
|
delay(500);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (JSONVar::stringify(result) == "null")
|
if (JSONVar::stringify(result) == "null")
|
||||||
{
|
{
|
||||||
Serial.print("TEA DOES NOT EXIST YET!");
|
Serial.print("TEA DOES NOT EXIST YET!");
|
||||||
String payload = teaNet.createTeaData("Unnamed Tea", currentTea.m_rfidCode, 90, 180);
|
|
||||||
result = teaNet.httpsPOSTRequest(shuttleServer + "/addtea", payload);
|
|
||||||
// catch possible failure
|
|
||||||
if (result == JSON.parse("{}"))
|
|
||||||
{
|
|
||||||
smartDisplay.printMsg("POST FAILED");
|
|
||||||
delay(1000);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
state = State::DISPLAY_ADD_NEW_TEA_CONFIG;
|
state = State::DISPLAY_ADD_NEW_TEA_CONFIG;
|
||||||
|
currentTea = TeaData("New Tea", currentTea.m_rfidCode, -1, 120);
|
||||||
|
smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", "");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
state = State::DISPLAY_SCANNED_TEA_CONFIG;
|
state = State::DISPLAY_SCANNED_TEA_CONFIG;
|
||||||
|
currentTea = TeaData(result["teaname"], currentTea.m_rfidCode, result["watertemp"], result["steepingseconds"]);
|
||||||
|
smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTea = TeaData(result["teaname"], currentTea.m_rfidCode, result["watertemp"], result["steepingseconds"]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DISPLAY_SCANNED_TEA_CONFIG:
|
case DISPLAY_SCANNED_TEA_CONFIG:
|
||||||
|
@ -213,7 +201,7 @@ void loop()
|
||||||
}
|
}
|
||||||
smartDisplay.printTeaConfigScreen(currentTea);
|
smartDisplay.printTeaConfigScreen(currentTea);
|
||||||
|
|
||||||
if (isBtnPressed() && currentTea.m_steepingSeconds <= 0)
|
if (isTouchBtnPressed() && currentTea.m_steepingSeconds <= 0)
|
||||||
{
|
{
|
||||||
// rickroll
|
// rickroll
|
||||||
Serial.println("Easter");
|
Serial.println("Easter");
|
||||||
|
@ -222,21 +210,8 @@ void loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// change state if start pressed
|
// change state if start pressed
|
||||||
if (isBtnPressed())
|
if (isTouchBtnPressed())
|
||||||
{
|
{
|
||||||
String payload = teaNet.createTeaData(currentTea);
|
|
||||||
Serial.println(payload);
|
|
||||||
smartDisplay.playTeaAnimationPartOne(32, "", "Sync...", "", "");
|
|
||||||
JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/updatetea", payload);
|
|
||||||
// catch possible failure
|
|
||||||
if (res == JSON.parse("{}"))
|
|
||||||
{
|
|
||||||
smartDisplay.printMsg("POST FAILED");
|
|
||||||
delay(1000);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", "");
|
|
||||||
delay(250);
|
|
||||||
teaTimer.beginSteeping(currentTea.m_steepingSeconds * 1000);
|
teaTimer.beginSteeping(currentTea.m_steepingSeconds * 1000);
|
||||||
state = State::STEEPING_IN_PROGRESS;
|
state = State::STEEPING_IN_PROGRESS;
|
||||||
smartStrip.reset();
|
smartStrip.reset();
|
||||||
|
@ -252,7 +227,7 @@ void loop()
|
||||||
if (buttonLeft.isJustPressed())
|
if (buttonLeft.isJustPressed())
|
||||||
{
|
{
|
||||||
teaTimer.endSteeping();
|
teaTimer.endSteeping();
|
||||||
smartDisplay.printMsg("DONE");
|
smartDisplay.printMsg("Ready!");
|
||||||
smartStrip.animateBottomToTop(0, 1, 0);
|
smartStrip.animateBottomToTop(0, 1, 0);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
state = State::REQUEST_FEEDBACK;
|
state = State::REQUEST_FEEDBACK;
|
||||||
|
@ -267,9 +242,8 @@ void loop()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
smartDisplay.printMsg("DONE");
|
smartDisplay.printMsg("Ready!");
|
||||||
smartStrip.animateBottomToTop(0, 1, 0);
|
smartStrip.animateBottomToTop(0, 1, 0);
|
||||||
delay(1000);
|
|
||||||
state = State::REQUEST_FEEDBACK;
|
state = State::REQUEST_FEEDBACK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -281,38 +255,89 @@ void loop()
|
||||||
String uid = smartRFID.readTag(50); // just enough time to detect tag
|
String uid = smartRFID.readTag(50); // just enough time to detect tag
|
||||||
if (uid != "no_tag_detected" && uid != "")
|
if (uid != "no_tag_detected" && uid != "")
|
||||||
{
|
{
|
||||||
|
// we still want to save the last configuration (treated as perfect, no steeping time change)
|
||||||
|
String payload = teaNet.createTeaData(currentTea);
|
||||||
|
Serial.println(payload);
|
||||||
|
smartDisplay.playTeaAnimationPartOne(32, "", "Loading...", "", "");
|
||||||
|
JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/updatetea", payload);
|
||||||
|
// catch possible failure
|
||||||
|
if (res == JSON.parse("{}"))
|
||||||
|
{
|
||||||
|
smartDisplay.printMsg("TRY AGAIN");
|
||||||
|
delay(500);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
currentTea.m_rfidCode = uid;
|
currentTea.m_rfidCode = uid;
|
||||||
smartDisplay.resetDisplay();
|
smartDisplay.resetDisplay();
|
||||||
|
smartStrip.reset();
|
||||||
state = PROCESS_RFID_SCAN;
|
state = PROCESS_RFID_SCAN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBtnPressed())
|
if (isTouchBtnPressed())
|
||||||
{
|
{
|
||||||
// keep steeping time for next brew
|
// keep steeping time for next brew
|
||||||
smartDisplay.printMsg("Feedback accepted (perfect)");
|
|
||||||
delay(1000);
|
|
||||||
state = State::WAIT_FOR_RFID_SCAN;
|
state = State::WAIT_FOR_RFID_SCAN;
|
||||||
|
|
||||||
|
String payload = teaNet.createTeaData(currentTea);
|
||||||
|
Serial.println(payload);
|
||||||
|
smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(perfect)", "", "saving...");
|
||||||
|
JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/updatetea", payload);
|
||||||
|
// catch possible failure
|
||||||
|
if (res == JSON.parse("{}"))
|
||||||
|
{
|
||||||
|
smartDisplay.printMsg("POST FAILED");
|
||||||
|
delay(1000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", "");
|
||||||
|
smartStrip.reset();
|
||||||
}
|
}
|
||||||
if (buttonLeft.isJustPressed())
|
if (buttonLeft.isJustPressed())
|
||||||
{
|
{
|
||||||
// decrease steeping time for next brew
|
// decrease steeping time for next brew
|
||||||
smartDisplay.printMsg("Feedback accepted (-)");
|
|
||||||
delay(1000);
|
|
||||||
state = State::WAIT_FOR_RFID_SCAN;
|
state = State::WAIT_FOR_RFID_SCAN;
|
||||||
|
|
||||||
|
String payload = teaNet.createTeaData(currentTea);
|
||||||
|
Serial.println(payload);
|
||||||
|
smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(shorter)", "", "saving...");
|
||||||
|
JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/updatetea", payload);
|
||||||
|
// catch possible failure
|
||||||
|
if (res == JSON.parse("{}"))
|
||||||
|
{
|
||||||
|
smartDisplay.printMsg("POST FAILED");
|
||||||
|
delay(1000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", "");
|
||||||
|
smartStrip.reset();
|
||||||
}
|
}
|
||||||
if (buttonRight.isJustPressed())
|
if (buttonRight.isJustPressed())
|
||||||
{
|
{
|
||||||
// increase steeping time for next brew
|
// increase steeping time for next brew
|
||||||
smartDisplay.printMsg("Feedback accepted (+)");
|
|
||||||
delay(1000);
|
|
||||||
state = State::WAIT_FOR_RFID_SCAN;
|
state = State::WAIT_FOR_RFID_SCAN;
|
||||||
|
|
||||||
|
String payload = teaNet.createTeaData(currentTea);
|
||||||
|
Serial.println(payload);
|
||||||
|
smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(longer)", "", "saving...");
|
||||||
|
JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/updatetea", payload);
|
||||||
|
// catch possible failure
|
||||||
|
if (res == JSON.parse("{}"))
|
||||||
|
{
|
||||||
|
smartDisplay.printMsg("POST FAILED");
|
||||||
|
delay(1000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", "");
|
||||||
|
smartStrip.reset();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DISPLAY_ADD_NEW_TEA_CONFIG:
|
case DISPLAY_ADD_NEW_TEA_CONFIG:
|
||||||
{
|
{
|
||||||
smartDisplay.printAddNewTeaConfigScreen(currentTea);
|
flicker++;
|
||||||
|
smartDisplay.printAddNewTeaConfigScreen(currentTea, &flicker);
|
||||||
|
|
||||||
String uid = smartRFID.readTag(50); // just enough time to detect tag
|
String uid = smartRFID.readTag(50); // just enough time to detect tag
|
||||||
if (uid != "no_tag_detected" && uid != "")
|
if (uid != "no_tag_detected" && uid != "")
|
||||||
|
@ -332,19 +357,21 @@ void loop()
|
||||||
currentTea.m_steepingSeconds += 10;
|
currentTea.m_steepingSeconds += 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBtnPressed())
|
if (isTouchBtnPressed())
|
||||||
{
|
{
|
||||||
smartDisplay.printMsg("Accepted");
|
smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "", "", "saving...");
|
||||||
delay(500);
|
|
||||||
smartDisplay.printMsg("sync...");
|
String payload = teaNet.createTeaData("Unnamed Tea", currentTea.m_rfidCode, -1, currentTea.m_steepingSeconds);
|
||||||
JSONVar res = teaNet.httpsPOSTRequest(shuttleServer + "/updatetea", teaNet.createTeaData(currentTea));
|
JSONVar result = teaNet.httpsPOSTRequest(shuttleServer + "/addtea", payload);
|
||||||
// catch possible failure
|
// catch possible failure
|
||||||
if (res == JSON.parse("{}"))
|
if (result == JSON.parse("{}"))
|
||||||
{
|
{
|
||||||
smartDisplay.printMsg("POST FAILED");
|
smartDisplay.printMsg("POST FAILED");
|
||||||
delay(1000);
|
delay(500);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", "");
|
||||||
state = State::DISPLAY_SCANNED_TEA_CONFIG;
|
state = State::DISPLAY_SCANNED_TEA_CONFIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +380,7 @@ void loop()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBtnPressed()
|
bool isTouchBtnPressed()
|
||||||
{
|
{
|
||||||
return digitalRead(TOUCH_BTN_PIN) == HIGH;
|
return digitalRead(TOUCH_BTN_PIN) == HIGH;
|
||||||
}
|
}
|
|
@ -20,4 +20,4 @@
|
||||||
#include "SmartButton.hpp"
|
#include "SmartButton.hpp"
|
||||||
#include "SmartSound.hpp"
|
#include "SmartSound.hpp"
|
||||||
|
|
||||||
bool isBtnPressed();
|
bool isTouchBtnPressed();
|
Loading…
Add table
Reference in a new issue