// TFT_eSPI - Version: Latest
#include <TFT_eSPI.h>
#include "FS.h"
#include <string.h>
#include <Wire.h>
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
//include libraries for wifi connection and time
#include <WiFi.h>
#include "time.h"
// log into the internet
const char* ssid = "ssid";
const char* password = "password";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 3600;
const int daylightOffset_sec = 3600;
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
// This is the file name used to store the calibration data
// You can change this to create new calibration files.
// The SPIFFS file name must start with "/".
#define CALIBRATION_FILE "/TouchCalData2"
// Set REPEAT_CAL to true instead of false to run calibration
// again, otherwise it will only be done once.
// Repeat calibration if you change the screen rotation.
// changed this bool val to true (was false)
#define REPEAT_CAL true
// the input button specification
#define INPUT_X 10 //center of numeric display
#define INPUT_Y 130
#define INPUT_W 145 //width and height
#define INPUT_H 100
#define INPUT_TSIZE 3 //bbz kas cia vps text size
#define INPUT_TCOLOR TFT_CYAN //text color
#define INPUT_FONT &FreeMono12pt7b //edit this in the future
// define input text
char input_button_string1[] = "INPUT";
char input_button_string2[] = "PRODUCT";
// the check_prod button specification
#define CHECK_X 160 //center of numeric display
#define CHECK_Y 130
#define CHECK_W 145 //width and height
#define CHECK_H 100
#define CHECK_TSIZE 3 //bbz kas cia vps text size
#define CHECK_TCOLOR TFT_CYAN //text color
#define CHECK_FONT &FreeMono12pt7b //edit this in the future
// define check_prod string
char check_button_string1[] = "CHECK";
char check_button_string2[] = "PRODUCT";
char check_button_string3[] = "STATUS";
// the time display box specification
// time display properties in pixels: X: [85:235] Y: [10:70]
#define TIME_X 85
#define TIME_Y 10
#define TIME_W 150
#define TIME_H 60
#define TIME_TSIZE 1
#define TIME_TCOLOR TFT_CYAN
#define TIME_FONT &FreeSans18pt7b
// the time_to_expire display box specification
#define EXPIREIN_X 85
#define EXPIREIN_Y 10
#define EXPIREIN_W 150
#define EXPIREIN_H 60
#define EXPIREIN_TSIZE 1
#define EXPIREIN_TCOLOR TFT_CYAN
#define EXPIREIN_FONT &FreeSans18pt7b
// the time_to_expire display box specification
#define EXPIREIN_X 120
#define EXPIREIN_Y 60
#define EXPIREIN_W 80
#define EXPIREIN_H 120
#define EXPIREIN_TSIZE 1
#define EXPIREIN_TCOLOR TFT_CYAN
#define EXPIREIN_FONT &FreeSans18pt7b
// the INCREMENT display box specification
#define INCREMENT_X 220
#define INCREMENT_Y 60
#define INCREMENT_W 80
#define INCREMENT_H 120
#define INCREMENT_TSIZE 1
#define INCREMENT_TCOLOR TFT_CYAN
#define INCREMENT_FONT &FreeSans18pt7b
// the DECREMENT display box specification
#define DECREMENT_X 20
#define DECREMENT_Y 60
#define DECREMENT_W 80
#define DECREMENT_H 120
#define DECREMENT_TSIZE 1
#define DECREMENT_TCOLOR TFT_CYAN
#define DECREMENT_FONT &FreeSans18pt7b
// the date display box specification
// date display properties in pixels: X: [64:256] Y: [80:120]
#define DATE_X 32
#define DATE_Y 80
#define DATE_W 256
#define DATE_H 40
#define DATE_TSIZE 0.25
#define DATE_TCOLOR TFT_CYAN
#define DATE_FONT &FreeMono9pt7b
// back button specification
#define BACK_X 10
#define BACK_Y 10
#define BACK_W 70
#define BACK_H 40
#define BACK_TCOLOR TFT_CYAN
#define BACK_FONT &FreeMono18pt7b
char backString[] = "<==";
// forward button specification
#define FORWARD_X 240
#define FORWARD_Y 10
#define FORWARD_W 70
#define FORWARD_H 40
#define FORWARD_TCOLOR TFT_CYAN
#define FORWARD_FONT &FreeMono18pt7b
char forwardString[] = "==>";
// product button spec
#define PRODBUT_X 10
#define PRODBUT_Y 60
#define PRODBUT_W 93
#define PRODBUT_H 50
#define PRODBUT_TCOLOR TFT_CYAN
#define PRODBUT_FONT &FreeMono9pt7b
// confirm button spec
#define CONFIRM_X 80
#define CONFIRM_Y 190
#define CONFIRM_W 160
#define CONFIRM_H 50
#define CONFIRM_TCOLOR TFT_CYAN
#define CONFIRM_FONT &FreeMono9pt7b
char confirmString[] = "CONFIRM";
// product display spec
#define PRODISP_X 20
#define PRODISP_Y 60
#define PRODISP_W 280
#define PRODISP_H 30
#define PRODISP_TCOLOR TFT_CYAN
#define PRODISP_FONT &FreeMono9pt7b
char noProductString[] = "No product Added";
// define list of weekdays
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
char monthsOfTheYear[12][10] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
char usualProducts[9][15] = {"Bread", "Milk", "Meat", "Cheese", "Pesto", "Rucola", "Eggs", "Yoghurt", "Fruit"};
char productInputName[15];
tm productInputExpiry;
int currentsize = 0;
// define a new variable type
struct FoodItem {
char name[20];
tm expiryDate;
int daysLeft;
// Method to set the product name
void setProductName(const char* newName) {
// Use strncpy to safely copy the new name into the name field
strncpy(name, newName, sizeof(name));
// Ensure the name is null-terminated
name[sizeof(name) - 1] = '\0';
}
// Method to set the product expiry date
void setProductExpiry(tm newExpiryDate) {
expiryDate = newExpiryDate;
}
};
// make an empty list of food items storing the name and the expiry date of the product
FoodItem foodList[] = {
// for example
//{"milk", DateTime(2023, 10, 12)}, // Example date
};
const int foodCount = sizeof(foodList) / sizeof(foodList[0]);
// integer to indicate the screen state
int page = 0;
// integer to state in how many days a prod expires
int expiresIn = 0;
int prodNumber = 0;
void setup() {
Serial.begin(9600);
//connect to WiFi
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");
//init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
//disconnect WiFi as it's no longer needed
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
// initialize tft screen
tft.init();
// set rotation before calibration
tft.setRotation(3);
// calibrate the touchscreen and retrieve the scaling factors
touch_calibrate();
// clear the screen
tft.fillScreen(TFT_WHITE);
// draw home screen
drawHome();
currentsize = 0;
delay(2000);
}
void loop() {
// initialize the touch function and create variables to store the coordinates in
uint16_t x, y;
int pressed = tft.getTouch(&x,&y);
if (page == 1) {
// get real time from ntp
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
String timeString = String(timeinfo.tm_hour) + ":" + String(timeinfo.tm_min);
String dateString = String(timeinfo.tm_wday) + ", " + monthsOfTheYear[timeinfo.tm_mon+1] + String(timeinfo.tm_mday);
setRealTime(timeString);
setRealDate(dateString);
if(pressed) {
if((x > CHECK_X) && (x < CHECK_X+CHECK_W)){
if((y > CHECK_Y) && (y < CHECK_Y+CHECK_H)){
delay(150);
checkMenu();
pressed = false;
}
}
}
if(pressed) {
if((x > INPUT_X) && (x < INPUT_X+INPUT_W)){
if((y > INPUT_Y) && (y < INPUT_Y+INPUT_H)){
delay(150);
inputMenu();
pressed = false;
}
}
}
delay(100);
}
if (page == 2) {
if (pressed) {
if ((x > BACK_X) && (x < BACK_X + BACK_W) && (y > BACK_Y) && (y < BACK_Y + BACK_H)) {
delay(150);
drawHome();
pressed = false;
} else {
// calculate row and col based on x and y coordinates
int col = (x - PRODBUT_X) / (PRODBUT_W + 13.3);
int row = (y - PRODBUT_Y) / (PRODBUT_H + 13.3);
// check if the click was within a product button
if (col >= 0 && col < 3 && row >= 0 && row < 3) {
prodNumber = col + row * 3;
delay(150);
expirySelectionMenu(expiresIn);
pressed = false;
}
}
}
}
if (page == 3) {
if(pressed) {
if((x > BACK_X) && (x < BACK_X+BACK_W)) {
if((y > BACK_Y) && (y < BACK_Y+BACK_H)) {
delay(150);
drawHome();
pressed = false;
}
}
}
}
if (page == 4) {
if(pressed) {
if((x > BACK_X) && (x < BACK_X+BACK_W)) {
if((y > BACK_Y) && (y < BACK_Y+BACK_H)) {
delay(150);
drawHome();
pressed = false;
}
}
if((x > DECREMENT_X) && (x < DECREMENT_X+DECREMENT_W) && (expiresIn > 0)) {
if((y > DECREMENT_Y) && (y < DECREMENT_Y+DECREMENT_H)) {
expiresIn = expiresIn - 1;
delay(150);
expirySelectionMenu(expiresIn);
pressed = false;
}
}
if((x > INCREMENT_X) && (x < INCREMENT_X+INCREMENT_W)) {
if((y > INCREMENT_Y) && (y < INCREMENT_Y+INCREMENT_H)) {
expiresIn = expiresIn + 1;
delay(150);
expirySelectionMenu(expiresIn);
pressed = false;
}
}
if((x > CONFIRM_X) && (x < CONFIRM_X+CONFIRM_W)) {
if((y > CONFIRM_Y) && (y < CONFIRM_Y+CONFIRM_H)) {
addExpirySelection(expiresIn, prodNumber);
delay(150);
drawHome();
pressed = false;
}
}
}
}
}
// ---------------------------------------------------------------------------------------------
void touch_calibrate(){
uint16_t calData[5];
uint8_t calDataOK = 0;
// check file system exists
if (!SPIFFS.begin()) {
Serial.println("Formating file system");
SPIFFS.format();
SPIFFS.begin();
}
// check if calibration file exists and size is correct
if (SPIFFS.exists(CALIBRATION_FILE)) {
if (REPEAT_CAL)
{
// Delete if we want to re-calibrate
SPIFFS.remove(CALIBRATION_FILE);
}
else
{
File f = SPIFFS.open(CALIBRATION_FILE, "r");
if (f) {
if (f.readBytes((char *)calData, 14) == 14)
calDataOK = 1;
f.close();
}
}
}
if (calDataOK && !REPEAT_CAL) {
// calibration data valid
tft.setTouch(calData);
}
else {
// data not valid so recalibrate
tft.fillScreen(TFT_BLACK);
tft.setCursor(20, 0);
tft.setTextFont(2);
tft.setTextSize(1);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.println("Touch corners as indicated");
tft.setTextFont(1);
tft.println();
if (REPEAT_CAL) {
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.println("Set REPEAT_CAL to false to stop this running again!");
}
tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.println("Calibration complete!");
// store data
File f = SPIFFS.open(CALIBRATION_FILE, "w");
if (f) {
f.write((const unsigned char *)calData, 14);
f.close();
}
}
}
//--------------------------------------------------------------------------------------------------------------------
void drawHome() {
// draw the background of the home screen
tft.fillRect(0, 0, 320, 240, TFT_LIGHTGREY);
//draw the buttons on the homescreen
// draw the input button box
tft.fillRect(INPUT_X, INPUT_Y, INPUT_W, INPUT_H, TFT_DARKGREEN);
tft.drawRect(INPUT_X, INPUT_Y, INPUT_W, INPUT_H, TFT_CYAN);
// draw the check_prod button box
tft.fillRect(CHECK_X, CHECK_Y, CHECK_W, CHECK_H, TFT_DARKGREEN);
tft.drawRect(CHECK_X, CHECK_Y, CHECK_W, CHECK_H, TFT_CYAN);
// draw the time box
tft.fillRect(TIME_X, TIME_Y, TIME_W, TIME_H, TFT_NAVY);
tft.drawRect(TIME_X, TIME_Y, TIME_W, TIME_H, TFT_CYAN);
// draw the date box
tft.fillRect(DATE_X, DATE_Y, DATE_W, DATE_H, TFT_NAVY);
tft.drawRect(DATE_X, DATE_Y, DATE_W, DATE_H, TFT_CYAN);
// draw the text on both of the buttons check_prod and input
//INPUT BUTTON:
tft.setFreeFont(INPUT_FONT); // Choose a nicefont that fits box
tft.setTextColor(INPUT_TCOLOR); // Set the font colour
int input_shiftx1 = (INPUT_W - tft.textWidth(input_button_string1)) / 2; //automatically centers the text in the middle of the box
int input_shiftx2 = (INPUT_W - tft.textWidth(input_button_string2)) / 2;
int input_shifty = (INPUT_H - tft.fontHeight()) / 2; //automatically centers the text in the middle of the box
int input_button_text1 = tft.drawString(input_button_string1, INPUT_X + input_shiftx1, INPUT_Y + input_shifty/1.5);
int input_button_text2 = tft.drawString(input_button_string2, INPUT_X + input_shiftx2, INPUT_Y + 1.5*input_shifty);
//CHECK product BUTTON
tft.setFreeFont(CHECK_FONT); // Choose a nicefont that fits box
tft.setTextColor(CHECK_TCOLOR); // Set the font colour
int check_shiftx1 = (CHECK_W - tft.textWidth(check_button_string1)) / 2; //automatically centers the text in the middle of the box
int check_shiftx2 = (CHECK_W - tft.textWidth(check_button_string2)) / 2;
int check_shiftx3 = (CHECK_W - tft.textWidth(check_button_string3)) / 2;
int check_shifty = (CHECK_H - tft.fontHeight()) / 2; //automatically centers the text in the middle of the box
int checkButtonText1 = tft.drawString(check_button_string1, CHECK_X + check_shiftx1, CHECK_Y + check_shifty/1.7);
int checkButtonText2 = tft.drawString(check_button_string2, CHECK_X + check_shiftx2, CHECK_Y + check_shifty);
int checkButtonText3 = tft.drawString(check_button_string3, CHECK_X + check_shiftx3, CHECK_Y + 1.7*check_shifty);
page = 1;
}
//-------------------------------------------------------------------------------------------------------------------------------
void inputMenu() {
// draw the background of the input menu screen
tft.fillRect(0, 0, 320, 240, TFT_LIGHTGREY);
// draw the BACK button box
tft.fillRect(BACK_X, BACK_Y, BACK_W, BACK_H, TFT_RED);
tft.drawRect(BACK_X, BACK_Y, BACK_W, BACK_H, TFT_CYAN);
// back button text
tft.setFreeFont(BACK_FONT); // Choose a nicefont that fits box
tft.setTextColor(BACK_TCOLOR); // Set the font colour
int backShiftx = (BACK_W - tft.textWidth(backString)) / 2;
int backShifty = (BACK_H - tft.fontHeight()) / 2;
int backButtonText = tft.drawString(backString, BACK_X+backShiftx, BACK_Y+backShifty);
// draw the FORWARD button box
tft.fillRect(FORWARD_X, FORWARD_Y, FORWARD_W, FORWARD_H, TFT_RED);
tft.drawRect(FORWARD_X, FORWARD_Y, FORWARD_W, FORWARD_H, TFT_CYAN);
// back button text
tft.setFreeFont(FORWARD_FONT); // Choose a nicefont that fits box
tft.setTextColor(FORWARD_TCOLOR); // Set the font colour
int forwardShiftx = (FORWARD_W - tft.textWidth(forwardString)) / 2;
int forwardShifty = (FORWARD_H - tft.fontHeight()) / 2;
int forwardButtonText = tft.drawString(forwardString, FORWARD_X+forwardShiftx, FORWARD_Y+forwardShifty);
// draw the hujna buttons
tft.setFreeFont(PRODBUT_FONT);
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
int boxNumber = col + row*3;
tft.fillRect(PRODBUT_X+(PRODBUT_W+10)*col, PRODBUT_Y+(PRODBUT_H+10)*row, PRODBUT_W, PRODBUT_H, TFT_RED);
tft.drawRect(PRODBUT_X+(PRODBUT_W+10)*col, PRODBUT_Y+(PRODBUT_H+10)*row, PRODBUT_W, PRODBUT_H, TFT_CYAN);
int productShiftx = (PRODBUT_W - tft.textWidth(usualProducts[boxNumber])) / 2;
int productShifty = (PRODBUT_H - tft.fontHeight()) / 2;
tft.drawString(usualProducts[boxNumber],PRODBUT_X+(PRODBUT_W+10)*col+productShiftx,PRODBUT_Y+(PRODBUT_H+10)*row+productShifty);
}
}
page = 2;
}
//-------------------------------------------------------------------------------------------------------------------------------
void checkMenu() {
// draw the background of the home screen
tft.fillRect(0, 0, 320, 240, TFT_LIGHTGREY);
// draw the BACK button box
tft.fillRect(BACK_X, BACK_Y, BACK_W, BACK_H, TFT_RED);
tft.drawRect(BACK_X, BACK_Y, BACK_W, BACK_H, TFT_CYAN);
// back button text
tft.setFreeFont(BACK_FONT); // Choose a nicefont that fits box
tft.setTextColor(BACK_TCOLOR); // Set the font colour
int backShiftx = (BACK_W - tft.textWidth(backString)) / 2;
int backShifty = (BACK_H - tft.fontHeight()) / 2;
int backButtonText = tft.drawString(backString, BACK_X+backShiftx, BACK_Y+backShifty);
// draw the hujna button
tft.fillRect(PRODISP_X, PRODISP_Y, PRODISP_W, PRODISP_H, TFT_RED);
tft.drawRect(PRODISP_X, PRODISP_Y, PRODISP_W, PRODISP_H, TFT_CYAN);
// back button text
tft.setFreeFont(PRODISP_FONT); // Choose a nicefont that fits box
tft.setTextColor(PRODISP_TCOLOR); // Set the font colour
int prodDispShiftx = (PRODISP_W - tft.textWidth(noProductString)) / 2;
int prodDispShifty = (PRODISP_H - tft.fontHeight()) / 2;
int noProdButtonText = tft.drawString(noProductString, PRODISP_X+prodDispShiftx, PRODISP_Y+prodDispShifty);
page = 3;
}
//-------------------------------------------------------------------------------------------------------------------------------
void expirySelectionMenu(int expire_in_days) {
// draw the background of the home screen
tft.fillRect(0, 0, 320, 240, TFT_LIGHTGREY);
// draw the BACK button box
tft.fillRect(BACK_X, BACK_Y, BACK_W, BACK_H, TFT_RED);
tft.drawRect(BACK_X, BACK_Y, BACK_W, BACK_H, TFT_CYAN);
// back button text
tft.setFreeFont(BACK_FONT); // Choose a nicefont that fits box
tft.setTextColor(BACK_TCOLOR); // Set the font colour
int backShiftx = (BACK_W - tft.textWidth(backString)) / 2;
int backShifty = (BACK_H - tft.fontHeight()) / 2;
int backButtonText = tft.drawString(backString, BACK_X+backShiftx, BACK_Y+backShifty);
// draw the increment button
tft.fillRect(INCREMENT_X, INCREMENT_Y, INCREMENT_W, INCREMENT_H, TFT_RED);
tft.drawRect(INCREMENT_X, INCREMENT_Y, INCREMENT_W, INCREMENT_H, TFT_CYAN);
tft.setFreeFont(INCREMENT_FONT); // Choose a nicefont that fits box
tft.setTextColor(INCREMENT_TCOLOR);
int incrementShiftx = (INCREMENT_W - tft.textWidth("+")) / 2;
int incrementShifty = (INCREMENT_H - tft.fontHeight()) / 2;
int incrementButtonText = tft.drawString("+", INCREMENT_X+incrementShiftx, INCREMENT_Y+incrementShifty);
// draw the decrement button
tft.fillRect(DECREMENT_X, DECREMENT_Y, DECREMENT_W, DECREMENT_H, TFT_RED);
tft.drawRect(DECREMENT_X, DECREMENT_Y, DECREMENT_W, DECREMENT_H, TFT_CYAN);
tft.setFreeFont(DECREMENT_FONT); // Choose a nicefont that fits box
tft.setTextColor(DECREMENT_TCOLOR);
int decrementShiftx = (DECREMENT_W - tft.textWidth("-")) / 2;
int decrementShifty = (DECREMENT_H - tft.fontHeight()) / 2;
int decrementButtonText = tft.drawString("-", DECREMENT_X+decrementShiftx, DECREMENT_Y+decrementShifty);
// draw the expire_in display
tft.fillRect(EXPIREIN_X, EXPIREIN_Y, EXPIREIN_W, EXPIREIN_H, TFT_RED);
tft.drawRect(EXPIREIN_X, EXPIREIN_Y, EXPIREIN_W, EXPIREIN_H, TFT_CYAN);
tft.setFreeFont(EXPIREIN_FONT); // Choose a nicefont that fits box
tft.setTextColor(EXPIREIN_TCOLOR);
int expireShiftx = (EXPIREIN_W - tft.textWidth(String(expire_in_days))) / 2;
int expireShifty = (EXPIREIN_H - tft.fontHeight()) / 2;
int expireButtonText = tft.drawString(String(expire_in_days), EXPIREIN_X+expireShiftx, EXPIREIN_Y+expireShifty);
// button to confirm selection
tft.fillRect(CONFIRM_X, CONFIRM_Y, CONFIRM_W, CONFIRM_H, TFT_RED);
tft.drawRect(CONFIRM_X, CONFIRM_Y, CONFIRM_W, CONFIRM_H, TFT_CYAN);
tft.setFreeFont(CONFIRM_FONT); // Choose a nicefont that fits box
tft.setTextColor(CONFIRM_TCOLOR);
int confirmShiftx = (CONFIRM_W - tft.textWidth(String(confirmString))) / 2;
int confirmShifty = (CONFIRM_H - tft.fontHeight()) / 2;
int confirmButtonText = tft.drawString(String(confirmString), CONFIRM_X+confirmShiftx, CONFIRM_Y+confirmShifty);
page = 4;
}
//-------------------------------------------------------------------------------------------------------------------------------
// void checkExpiryDates(adjtime now) {
// for (int i = 0; i < 10; i++) {
// foodList[i].daysLeft = (foodList[i].expiryDate - now).days();
// if (foodList[i].daysLeft == 0) {
// }
// }
// }
//-----------------------------------------------------------------------------------------------------------------------------------------
void setRealTime(String timestring) {
tft.fillRect(TIME_X, TIME_Y, TIME_W, TIME_H, TFT_NAVY);
tft.setFreeFont(TIME_FONT);
tft.setTextColor(TIME_TCOLOR);
int time_shiftx = (TIME_W - tft.textWidth(timestring)) / 2;
int time_shifty = (TIME_H - tft.fontHeight()) / 2;
int time_text = tft.drawString(timestring, TIME_X + time_shiftx, TIME_Y + time_shifty);
//avoid flicker
}
//------------------------------------------------------------------------------------------------------------------------------------------
void setRealDate(String datestring) {
tft.fillRect(DATE_X, DATE_Y, DATE_W, DATE_H, TFT_NAVY);
tft.setTextSize(DATE_TSIZE);
tft.setFreeFont(DATE_FONT);
tft.setTextColor(DATE_TCOLOR);
int date_shiftx = (DATE_W - tft.textWidth(datestring)) / 2;
int date_shifty = (DATE_H - tft.fontHeight()) / 2;
int date_text = tft.drawString(datestring, DATE_X + date_shiftx, DATE_Y + date_shifty);
}
//-----------------------------------------------------------------------------------------------------------------------------------------
void addExpirySelection(int expireInDays, int productNumber) {
// if (currentsize < 27) {
// DateTime now = rtc.now();
// strcpy(productInputName, usualProducts[productNumber]);
// productInputExpiry = DateTime(now.year(), now.month(), now.day() + expireInDays);
// Serial.println(productInputName);
// Serial.println(currentsize);
// foodList[currentsize].setProductName(productInputName);
// foodList[currentsize].setProductExpiry(productInputExpiry);
// currentsize++;
// }
// else {
// Serial.println("Food list is full");
// Serial.println(currentsize);
//}
prodNumber = 0;
expiresIn = 0;
}
//-----------------------------------------------------------------------------------------------------------------------------------------
void printLocalTime()
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
String timeString = String(timeinfo.tm_hour) + ":" + String(timeinfo.tm_min);
String dateString = String(daysOfTheWeek[timeinfo.tm_wday]) + ", " + monthsOfTheYear[timeinfo.tm_mon] + " " + String(timeinfo.tm_mday);
setRealTime(timeString);
setRealDate(dateString);
}
//-------------------------------------------------------------------------------------------------------------------------------------------