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

Basic process loop working

This commit is contained in:
zzzz 2024-05-02 21:53:47 +02:00
parent 52d7a57dc5
commit fd16803d2a
5 changed files with 102 additions and 67 deletions

View file

@ -5,14 +5,14 @@ SmartDisplay::SmartDisplay(Adafruit_SSD1306 *display)
m_display = display; m_display = display;
} }
void SmartDisplay::printTeaConfigScreen(int steepingSeconds, int editDir) void SmartDisplay::printTeaConfigScreen(const char *teaName, int steepingSeconds, int editDir)
{ {
m_display->clearDisplay(); m_display->clearDisplay();
m_display->setTextColor(WHITE); m_display->setTextColor(WHITE);
m_display->setTextSize(1); m_display->setTextSize(1);
m_display->setCursor(0, 0); m_display->setCursor(0, 0);
m_display->println("Premium Earl Grey"); m_display->println(teaName);
m_display->println(" "); m_display->println(" ");
m_display->setTextSize(2); m_display->setTextSize(2);
@ -35,3 +35,31 @@ void SmartDisplay::printTeaConfigScreen(int steepingSeconds, int editDir)
} }
m_display->display(); m_display->display();
} }
void SmartDisplay::printTeaSteepingProgressScreen(const char *teaName, int steepingSeconds)
{
m_display->clearDisplay();
m_display->setTextColor(WHITE);
m_display->setTextSize(1);
m_display->setCursor(0, 0);
m_display->println(teaName);
m_display->println("(Steeping)");
m_display->setTextSize(2);
m_display->println(steepingSeconds);
m_display->display();
}
void SmartDisplay::printWaitForRFIDScreen()
{
m_display->clearDisplay();
m_display->setTextColor(WHITE);
m_display->setTextSize(1);
m_display->setCursor(0, 0);
m_display->println("Waiting for RFID scan...");
m_display->display();
}

View file

@ -5,9 +5,10 @@
class SmartDisplay { class SmartDisplay {
public: public:
SmartDisplay(Adafruit_SSD1306 *display); SmartDisplay(Adafruit_SSD1306 *display);
void printTeaConfigScreen(int steepingSeconds, int editDir); void printTeaConfigScreen(const char* teaName, int steepingSeconds, int editDir);
void printAddNewTeaScreen(); void printAddNewTeaScreen();
void printSteepingInProgressScreen(); void printTeaSteepingProgressScreen(const char *teaName, int steepingSeconds);
void printWaitForRFIDScreen();
private: private:
Adafruit_SSD1306 *m_display; Adafruit_SSD1306 *m_display;
}; };

View file

@ -1,6 +1,6 @@
#include "TeaTimer.hpp" #include "TeaTimer.hpp"
void TeaTimer::init(ContinuousServo *t_servo) TeaTimer::TeaTimer(ContinuousServo *t_servo)
{ {
m_servo = t_servo; m_servo = t_servo;
} }
@ -10,7 +10,7 @@ void TeaTimer::beginSteeping(unsigned long t_steepingDuration)
{ {
if (m_isSteeping) if (m_isSteeping)
return; return;
m_servo->moveServoForMillisClockwise(2000); m_servo->moveServoForMillisClockwise(m_servoTurningTime);
m_endSteepingTime = millis() + t_steepingDuration; m_endSteepingTime = millis() + t_steepingDuration;
m_isSteeping = true; m_isSteeping = true;
} }
@ -18,14 +18,13 @@ void TeaTimer::beginSteeping(unsigned long t_steepingDuration)
// Move servo up, stop timer immediately. // Move servo up, stop timer immediately.
void TeaTimer::end_steeping() void TeaTimer::end_steeping()
{ {
m_servo->moveServoForMillisCounterClockwise(2000); m_servo->moveServoForMillisCounterClockwise(m_servoTurningTime);
m_isSteeping = false; m_isSteeping = false;
} }
// Called at start of update. // Called at start of update.
void TeaTimer::tick() void TeaTimer::tick()
{ {
m_servo->tick();
if (millis() >= m_endSteepingTime && m_isSteeping) if (millis() >= m_endSteepingTime && m_isSteeping)
{ {
end_steeping(); end_steeping();

View file

@ -6,7 +6,7 @@
class TeaTimer class TeaTimer
{ {
public: public:
void init(ContinuousServo *t_servo); TeaTimer(ContinuousServo *t_servo);
// Move servo down, start timer. // Move servo down, start timer.
void beginSteeping(unsigned long t_steepingDuration); void beginSteeping(unsigned long t_steepingDuration);
// Move servo up, stop timer immediately. // Move servo up, stop timer immediately.
@ -20,5 +20,6 @@ private:
bool m_isSteeping = false; bool m_isSteeping = false;
// The time in millis when steeping is done. // The time in millis when steeping is done.
unsigned long m_endSteepingTime; unsigned long m_endSteepingTime;
unsigned long m_servoTurningTime = 1000;
ContinuousServo *m_servo; ContinuousServo *m_servo;
}; };

View file

@ -4,6 +4,9 @@
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#include <MFRC522.h> #include <MFRC522.h>
#include <FS.h>
#include <LittleFS.h>
#include <time.h>
#include "TeaTimer.hpp" #include "TeaTimer.hpp"
#include "ContinuousServo.hpp" #include "ContinuousServo.hpp"
@ -27,7 +30,7 @@ MFRC522::MIFARE_Key key;
auto display = Adafruit_SSD1306(128, 32, &WIRE); auto display = Adafruit_SSD1306(128, 32, &WIRE);
ContinuousServo contServo(SERVO_PIN); ContinuousServo contServo(SERVO_PIN);
TeaTimer teaTimer; TeaTimer teaTimer(&contServo);
SmartDial smartDial(POTENTIOMETER_PIN); SmartDial smartDial(POTENTIOMETER_PIN);
SmartDisplay smartDisplay(&display); SmartDisplay smartDisplay(&display);
@ -54,14 +57,16 @@ void setup()
Serial.println("Initializing RFID..."); Serial.println("Initializing RFID...");
mfrc522.PCD_Init(); mfrc522.PCD_Init();
Serial.print(F("Ver: 0x")); /*Serial.print(F("Ver: 0x"));
byte readReg = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); byte readReg = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.println(readReg, HEX); Serial.println(readReg, HEX);*/
mfrc522.PICC_HaltA();
Serial.println("Initializing OLED..."); Serial.println("Initializing OLED...");
display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false); // Address 0x3C for 128x32 display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false); // Address 0x3C for 128x32
printMsg("Tea is Great!"); printMsg("Tea is Great!");
delay(3000);
delay(1000);
// Prepare the key (used both as key A and key B) // Prepare the key (used both as key A and key B)
for (byte i = 0; i < 6; i++) for (byte i = 0; i < 6; i++)
@ -101,8 +106,6 @@ void printMsg(unsigned long l)
bool isBtnPressed() bool isBtnPressed()
{ {
if (millis() < 10000)
return false;
return digitalRead(TOUCH_BTN_PIN) == HIGH; return digitalRead(TOUCH_BTN_PIN) == HIGH;
} }
@ -110,16 +113,55 @@ int steepingSeconds = 60;
void loop() void loop()
{ {
contServo.tick();
switch (state) switch (state)
{ {
case WAIT_FOR_RFID_SCAN: case WAIT_FOR_RFID_SCAN:
{ {
smartDisplay.printWaitForRFIDScreen();
// Look for new cards
if (!mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if (!mfrc522.PICC_ReadCardSerial())
return;
// Show some details of the PICC (that is: the tag/card)
// UID is a unique four hex pairs, e.g. E6 67 2A 12
Serial.print(F("Card UID:"));
oled_dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
display.println();
display.display();
delay(1000);
// PICC type, e.g. "MIFARE 1K0"
// Serial.print(F("PICC type: "));
// MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
// Serial.println(mfrc522.PICC_GetTypeName(piccType));
// Halt PICC
mfrc522.PICC_HaltA();
display.println("Success!");
display.display();
delay(1000);
state = State::DISPLAY_SCANNED_TEA_CONFIG;
break; break;
} }
case DISPLAY_SCANNED_TEA_CONFIG: case DISPLAY_SCANNED_TEA_CONFIG:
{ {
int dir = smartDial.smoothEdit(&steepingSeconds, 0, 120); int dir = smartDial.smoothEdit(&steepingSeconds, 0, 120);
smartDisplay.printTeaConfigScreen(steepingSeconds, dir); smartDisplay.printTeaConfigScreen("Premium Earl Grey", steepingSeconds, dir);
// change state if start pressed
if (isBtnPressed())
{
teaTimer.beginSteeping(10000);
state = State::STEEPING_IN_PROGRESS;
}
break; break;
} }
case ADD_NEW_TEA_CONFIG: case ADD_NEW_TEA_CONFIG:
@ -128,60 +170,24 @@ void loop()
} }
case STEEPING_IN_PROGRESS: case STEEPING_IN_PROGRESS:
{ {
teaTimer.tick();
if (teaTimer.isSteeping())
{
auto r = teaTimer.remainingSteepTimeSeconds();
smartDisplay.printTeaSteepingProgressScreen("Premium Earl Grey", r);
}
else
{
printMsg("DONE");
if (!contServo.isTurning())
{
delay(3000);
state = State::WAIT_FOR_RFID_SCAN;
}
}
break; break;
} }
}; };
// Look for new cards
if (!mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if (!mfrc522.PICC_ReadCardSerial())
return;
// Show some details of the PICC (that is: the tag/card)
// UID is a unique four hex pairs, e.g. E6 67 2A 12
Serial.print(F("Card UID:"));
serial_dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0, 10);
display.println("Card UID: ");
// oled_dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
// display.println();
// display.display();
// PICC type, e.g. "MIFARE 1K0"
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
// Halt PICC
mfrc522.PICC_HaltA();
Serial.print("Delay scanning...");
delay(scanDelay * 1000); // Turn seconds into milliseconds
Serial.println(" ...Ready to scan again!");
/*
teaTimer.tick();
if (isBtnPressed() && !teaTimer.isSteeping())
{
teaTimer.beginSteeping(5000);
}
if (teaTimer.isSteeping())
{
auto r = teaTimer.remainingSteepTimeSeconds();
printMsg(r);
}
else
{
printMsg("Default");
}*/
} }
void toggle_led() void toggle_led()