From 421d00b3fbe81ab518bdcdfd7817a826ef99a5c2 Mon Sep 17 00:00:00 2001 From: zzzz Date: Tue, 14 May 2024 20:21:01 +0200 Subject: [PATCH] added time formatting --- src/SmartDisplay.cpp | 25 ++++++++++++++++++------- src/SmartDisplay.hpp | 8 ++++---- src/SmartTime.cpp | 14 ++++++++++++++ src/SmartTime.hpp | 7 +++++++ src/main.cpp | 10 ++++++++-- 5 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 src/SmartTime.cpp create mode 100644 src/SmartTime.hpp diff --git a/src/SmartDisplay.cpp b/src/SmartDisplay.cpp index da83504..30f219c 100644 --- a/src/SmartDisplay.cpp +++ b/src/SmartDisplay.cpp @@ -1,4 +1,5 @@ #include "SmartDisplay.hpp" +#include "SmartTime.hpp" SmartDisplay::SmartDisplay(Adafruit_SSD1306 *display) { @@ -12,11 +13,15 @@ void SmartDisplay::printTeaConfigScreen(TeaData tea) m_display->println(tea.m_teaName); m_display->print(tea.m_waterTemp); + m_display->drawCircle(m_display->getCursorX() + 4, m_display->getCursorY(), 1, WHITE); m_display->println(" C"); m_display->setTextSize(2); - m_display->print(tea.m_steepingSeconds); - m_display->print(" "); + String steepingTime = SmartTime::formatSeconds(tea.m_steepingSeconds); + m_display->print(steepingTime); + m_display->setTextSize(1); + m_display->setCursor(m_display->getCursorX(), m_display->getCursorY() + 7); + m_display->println(" min"); m_display->display(); } @@ -29,7 +34,11 @@ void SmartDisplay::printTeaSteepingProgressScreen(TeaData tea, int remainingSeco m_display->println(" (Steeping)"); m_display->setTextSize(2); - m_display->println(remainingSeconds); + String remainingTime = SmartTime::formatSeconds(remainingSeconds); + m_display->print(remainingTime); + m_display->setTextSize(1); + m_display->setCursor(m_display->getCursorX(), m_display->getCursorY() + 7); + m_display->println(" min"); m_display->display(); } @@ -42,7 +51,7 @@ void SmartDisplay::printWaitForRFIDScreen() m_display->display(); } -void SmartDisplay::printRequestFeedbackScreen(TeaData teaData) +void SmartDisplay::printRequestFeedbackScreen(TeaData tea) { resetDisplay(); @@ -53,15 +62,17 @@ void SmartDisplay::printRequestFeedbackScreen(TeaData teaData) m_display->display(); } -void SmartDisplay::printAddNewTeaConfigScreen(TeaData teaData) +void SmartDisplay::printAddNewTeaConfigScreen(TeaData tea) { resetDisplay(); m_display->println("Add initial config for new tea"); m_display->println(); m_display->print("Steeping time:"); - m_display->print(teaData.m_steepingSeconds); - m_display->println("s"); + String steepingTime = SmartTime::formatSeconds(tea.m_steepingSeconds); + m_display->print(steepingTime); + m_display->setTextSize(1); + m_display->println(" min"); m_display->display(); } diff --git a/src/SmartDisplay.hpp b/src/SmartDisplay.hpp index 02504fe..e3389e7 100644 --- a/src/SmartDisplay.hpp +++ b/src/SmartDisplay.hpp @@ -11,13 +11,13 @@ public: public: // lifecycle screens void printWaitForRFIDScreen(); - void printTeaConfigScreen(TeaData teaData); - void printTeaSteepingProgressScreen(TeaData teaData, int remainingSeconds); - void printRequestFeedbackScreen(TeaData teaData); + void printTeaConfigScreen(TeaData tea); + void printTeaSteepingProgressScreen(TeaData tea, int remainingSeconds); + void printRequestFeedbackScreen(TeaData tea); public: // special screens - void printAddNewTeaConfigScreen(TeaData teaData); + void printAddNewTeaConfigScreen(TeaData tea); public: // helper methods diff --git a/src/SmartTime.cpp b/src/SmartTime.cpp new file mode 100644 index 0000000..bd2bd72 --- /dev/null +++ b/src/SmartTime.cpp @@ -0,0 +1,14 @@ +#include "SmartTime.hpp" + +String SmartTime::formatSeconds(int seconds) +{ + int m = seconds / 60; + int s = seconds % 60; + String str = ""; + str += m; + str += ":"; + if (s < 10) + str += "0"; + str += s; + return str; +} \ No newline at end of file diff --git a/src/SmartTime.hpp b/src/SmartTime.hpp new file mode 100644 index 0000000..6fd6f4c --- /dev/null +++ b/src/SmartTime.hpp @@ -0,0 +1,7 @@ +#pragma once +#include + +class SmartTime { + public: + static String formatSeconds(int seconds); +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0475bdc..ec6a270 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -242,18 +242,24 @@ void loop() break; } + if (isBtnPressed()) { + // keep steeping time for next brew + smartDisplay.printMsg("Feedback accepted (perfect)"); + delay(1000); + state = State::WAIT_FOR_RFID_SCAN; + } if (buttonLeft.isJustPressed()) { // decrease steeping time for next brew smartDisplay.printMsg("Feedback accepted (-)"); - delay(3000); + delay(1000); state = State::WAIT_FOR_RFID_SCAN; } if (buttonRight.isJustPressed()) { // increase steeping time for next brew smartDisplay.printMsg("Feedback accepted (+)"); - delay(3000); + delay(1000); state = State::WAIT_FOR_RFID_SCAN; } break;