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:
parent
52d7a57dc5
commit
fd16803d2a
5 changed files with 102 additions and 67 deletions
|
@ -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();
|
||||||
|
}
|
|
@ -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;
|
||||||
};
|
};
|
|
@ -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();
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
116
src/main.cpp
116
src/main.cpp
|
@ -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,28 +113,13 @@ int steepingSeconds = 60;
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
contServo.tick();
|
||||||
|
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case WAIT_FOR_RFID_SCAN:
|
case WAIT_FOR_RFID_SCAN:
|
||||||
{
|
{
|
||||||
break;
|
smartDisplay.printWaitForRFIDScreen();
|
||||||
}
|
|
||||||
case DISPLAY_SCANNED_TEA_CONFIG:
|
|
||||||
{
|
|
||||||
int dir = smartDial.smoothEdit(&steepingSeconds, 0, 120);
|
|
||||||
smartDisplay.printTeaConfigScreen(steepingSeconds, dir);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ADD_NEW_TEA_CONFIG:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case STEEPING_IN_PROGRESS:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Look for new cards
|
// Look for new cards
|
||||||
if (!mfrc522.PICC_IsNewCardPresent())
|
if (!mfrc522.PICC_IsNewCardPresent())
|
||||||
return;
|
return;
|
||||||
|
@ -143,45 +131,63 @@ void loop()
|
||||||
// Show some details of the PICC (that is: the tag/card)
|
// Show some details of the PICC (that is: the tag/card)
|
||||||
// UID is a unique four hex pairs, e.g. E6 67 2A 12
|
// UID is a unique four hex pairs, e.g. E6 67 2A 12
|
||||||
Serial.print(F("Card UID:"));
|
Serial.print(F("Card UID:"));
|
||||||
serial_dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
|
oled_dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
|
||||||
|
display.println();
|
||||||
display.clearDisplay();
|
display.display();
|
||||||
display.setTextColor(WHITE);
|
delay(1000);
|
||||||
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"
|
// PICC type, e.g. "MIFARE 1K0"
|
||||||
Serial.print(F("PICC type: "));
|
// Serial.print(F("PICC type: "));
|
||||||
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
// MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||||
Serial.println(mfrc522.PICC_GetTypeName(piccType));
|
// Serial.println(mfrc522.PICC_GetTypeName(piccType));
|
||||||
|
|
||||||
// Halt PICC
|
// Halt PICC
|
||||||
mfrc522.PICC_HaltA();
|
mfrc522.PICC_HaltA();
|
||||||
|
|
||||||
Serial.print("Delay scanning...");
|
display.println("Success!");
|
||||||
delay(scanDelay * 1000); // Turn seconds into milliseconds
|
display.display();
|
||||||
Serial.println(" ...Ready to scan again!");
|
delay(1000);
|
||||||
|
|
||||||
/*
|
state = State::DISPLAY_SCANNED_TEA_CONFIG;
|
||||||
teaTimer.tick();
|
break;
|
||||||
|
}
|
||||||
|
case DISPLAY_SCANNED_TEA_CONFIG:
|
||||||
|
{
|
||||||
|
int dir = smartDial.smoothEdit(&steepingSeconds, 0, 120);
|
||||||
|
smartDisplay.printTeaConfigScreen("Premium Earl Grey", steepingSeconds, dir);
|
||||||
|
|
||||||
if (isBtnPressed() && !teaTimer.isSteeping())
|
// change state if start pressed
|
||||||
{
|
if (isBtnPressed())
|
||||||
teaTimer.beginSteeping(5000);
|
{
|
||||||
}
|
teaTimer.beginSteeping(10000);
|
||||||
if (teaTimer.isSteeping())
|
state = State::STEEPING_IN_PROGRESS;
|
||||||
{
|
}
|
||||||
auto r = teaTimer.remainingSteepTimeSeconds();
|
break;
|
||||||
printMsg(r);
|
}
|
||||||
}
|
case ADD_NEW_TEA_CONFIG:
|
||||||
else
|
{
|
||||||
{
|
break;
|
||||||
printMsg("Default");
|
}
|
||||||
}*/
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggle_led()
|
void toggle_led()
|
||||||
|
|
Loading…
Add table
Reference in a new issue