From a91e857b49c518723055c32dd674eb826c3f5463 Mon Sep 17 00:00:00 2001 From: witnessmenow Date: Mon, 6 May 2024 21:08:53 +0100 Subject: [PATCH] Updating UI of Race week display --- F1-Notifications/cheapYellowLCD.h | 20 ++-- F1-Notifications/config.h | 184 ++++++++++++++++-------------- platformio.ini | 2 +- 3 files changed, 111 insertions(+), 95 deletions(-) diff --git a/F1-Notifications/cheapYellowLCD.h b/F1-Notifications/cheapYellowLCD.h index 0ba1763..10aba21 100644 --- a/F1-Notifications/cheapYellowLCD.h +++ b/F1-Notifications/cheapYellowLCD.h @@ -20,6 +20,8 @@ // ------------------------------- +#define SESSION_TEXT_SIZE 4 + TFT_eSPI tft = TFT_eSPI(); PNG png; @@ -110,20 +112,20 @@ class CheapYellowDisplay : public F1Display Serial.println("prts"); tft.fillRect(0, 0, screenWidth, screenHeight, TFT_BLACK); - // It's race week! - String tempStr = "Next Race: "; - tempStr += String(convertRaceName(raceName)); - - tft.drawString(tempStr, 5, 5, 2); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + int yPos = 5; + String gpStartDateStr = String(getConvertedTime(races_sessions["gp"], "M d")); + String displayMessage = String(convertRaceName(raceName)) + " | " + gpStartDateStr; + tft.drawCentreString(displayMessage, screenCenterX, yPos, 4); - int yValue = 21; + int yValue = 46; for (JsonPair kv : races_sessions) { - printSession(5, + printSession(4, yValue, sessionCodeToString(kv.key().c_str()), getConvertedTime(kv.value().as())); - yValue += 16; + yValue += (SESSION_TEXT_SIZE) * 8; } state = raceweek; @@ -182,6 +184,6 @@ class CheapYellowDisplay : public F1Display String tempStr = String(sessionName); tempStr += " "; tempStr += sessionStartTime; - tft.drawString(tempStr, x, y, 2); + tft.drawString(tempStr, x, y, SESSION_TEXT_SIZE); } }; diff --git a/F1-Notifications/config.h b/F1-Notifications/config.h index cbb2a9a..6f9b4ac 100644 --- a/F1-Notifications/config.h +++ b/F1-Notifications/config.h @@ -7,102 +7,116 @@ #define F1_ROUND_OFFSET_LABEL "roundOffset" #define F1_CURRENT_RACE_NOTIFICATION_LABEL "currentRaceNotification" -class F1Config { - public: - //How the time will be displayed, see here for more info: https://github.com/ropg/ezTime#datetime - String timeFormat = "l, d-M-Y H:i"; // Friday, 17-Mar-2023 00:30 - String timeZone = "Europe/London"; //seems to be something wrong with Europe/Dublin - - // Telegram BOT Token (Get from Botfather) - String botToken = ""; +class F1Config +{ +public: + // How the time will be displayed, see here for more info: https://github.com/ropg/ezTime#datetime + String timeFormat = "l, H:i"; // Friday, 00:30 + String timeZone = "Europe/London"; // seems to be something wrong with Europe/Dublin + + // Telegram BOT Token (Get from Botfather) + String botToken = ""; + + // Use @myidbot (IDBot) to find out the chat ID of an individual or a group + // Also note that you need to click "start" on a bot before it can + // message you + String chatId = ""; + + int roundOffset = 0; + + bool currentRaceNotification = false; + + bool isTelegramConfigured() + { + return (botToken != "") && (chatId != ""); + } + + bool fetchConfigFile() + { + if (SPIFFS.exists(F1_CONFIG_JSON)) + { + // file exists, reading and loading + Serial.println("reading config file"); + File configFile = SPIFFS.open(F1_CONFIG_JSON, "r"); + if (configFile) + { + Serial.println("opened config file"); + StaticJsonDocument<1024> json; + DeserializationError error = deserializeJson(json, configFile); + serializeJsonPretty(json, Serial); + if (!error) + { + Serial.println("\nparsed json"); + + if (json.containsKey(F1_TIME_ZONE_LABEL)) + { + timeZone = String(json[F1_TIME_ZONE_LABEL].as()); + } - // Use @myidbot (IDBot) to find out the chat ID of an individual or a group - // Also note that you need to click "start" on a bot before it can - // message you - String chatId = ""; + if (json.containsKey(F1_TIME_FORMAT_LABEL)) + { + timeFormat = String(json[F1_TIME_FORMAT_LABEL].as()); + } - int roundOffset = 0; + if (json.containsKey(F1_BOT_TOKEN_LABEL)) + { + botToken = String(json[F1_BOT_TOKEN_LABEL].as()); + } - bool currentRaceNotification = false; + if (json.containsKey(F1_CHAT_ID_LABEL)) + { + chatId = String(json[F1_CHAT_ID_LABEL].as()); + } - bool isTelegramConfigured(){ - return (botToken != "") && (chatId != ""); - } + if (json.containsKey(F1_ROUND_OFFSET_LABEL)) + { + roundOffset = json[F1_ROUND_OFFSET_LABEL].as(); + } - bool fetchConfigFile() { - if (SPIFFS.exists(F1_CONFIG_JSON)) { - //file exists, reading and loading - Serial.println("reading config file"); - File configFile = SPIFFS.open(F1_CONFIG_JSON, "r"); - if (configFile) { - Serial.println("opened config file"); - StaticJsonDocument<1024> json; - DeserializationError error = deserializeJson(json, configFile); - serializeJsonPretty(json, Serial); - if (!error) { - Serial.println("\nparsed json"); - - if (json.containsKey(F1_TIME_ZONE_LABEL)) { - timeZone = String(json[F1_TIME_ZONE_LABEL].as()); - } - - if (json.containsKey(F1_TIME_FORMAT_LABEL)) { - timeFormat = String(json[F1_TIME_FORMAT_LABEL].as()); - } - - if (json.containsKey(F1_BOT_TOKEN_LABEL)) { - botToken = String(json[F1_BOT_TOKEN_LABEL].as()); - } - - if (json.containsKey(F1_CHAT_ID_LABEL)) { - chatId = String(json[F1_CHAT_ID_LABEL].as()); - } - - if (json.containsKey(F1_ROUND_OFFSET_LABEL)) { - roundOffset = json[F1_ROUND_OFFSET_LABEL].as(); - } - - if (json.containsKey(F1_CURRENT_RACE_NOTIFICATION_LABEL)) { - currentRaceNotification = json[F1_CURRENT_RACE_NOTIFICATION_LABEL].as(); - } - - return true; - - } else { - Serial.println("failed to load json config"); - return false; + if (json.containsKey(F1_CURRENT_RACE_NOTIFICATION_LABEL)) + { + currentRaceNotification = json[F1_CURRENT_RACE_NOTIFICATION_LABEL].as(); } + + return true; + } + else + { + Serial.println("failed to load json config"); + return false; } } + } - - Serial.println("Config file does not exist"); + Serial.println("Config file does not exist"); + return false; + } + + bool saveConfigFile() + { + Serial.println(F("Saving config")); + StaticJsonDocument<1024> json; + json[F1_TIME_ZONE_LABEL] = timeZone; + json[F1_TIME_FORMAT_LABEL] = timeFormat; + json[F1_BOT_TOKEN_LABEL] = botToken; + json[F1_CHAT_ID_LABEL] = chatId; + json[F1_ROUND_OFFSET_LABEL] = roundOffset; + json[F1_CURRENT_RACE_NOTIFICATION_LABEL] = currentRaceNotification; + + File configFile = SPIFFS.open(F1_CONFIG_JSON, "w"); + if (!configFile) + { + Serial.println("failed to open config file for writing"); return false; - } - bool saveConfigFile() { - Serial.println(F("Saving config")); - StaticJsonDocument<1024> json; - json[F1_TIME_ZONE_LABEL] = timeZone; - json[F1_TIME_FORMAT_LABEL] = timeFormat; - json[F1_BOT_TOKEN_LABEL] = botToken; - json[F1_CHAT_ID_LABEL] = chatId; - json[F1_ROUND_OFFSET_LABEL] = roundOffset; - json[F1_CURRENT_RACE_NOTIFICATION_LABEL] = currentRaceNotification; - - File configFile = SPIFFS.open(F1_CONFIG_JSON, "w"); - if (!configFile) { - Serial.println("failed to open config file for writing"); - return false; - } - - serializeJsonPretty(json, Serial); - if (serializeJson(json, configFile) == 0) { - Serial.println(F("Failed to write to file")); - return false; - } - configFile.close(); - return true; + serializeJsonPretty(json, Serial); + if (serializeJson(json, configFile) == 0) + { + Serial.println(F("Failed to write to file")); + return false; } + configFile.close(); + return true; + } }; diff --git a/platformio.ini b/platformio.ini index 3f65b88..e9088e7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,7 +19,7 @@ framework = arduino lib_deps = khoih-prog/ESP_DoubleResetDetector@^1.3.2 bblanchon/ArduinoJson@^6.21.3 - wnatth3/WiFiManager@^2.0.16-rc.2 + https://github.com/tzapu/WiFiManager.git#v2.0.17 ropg/ezTime@^0.8.3 witnessmenow/UniversalTelegramBot@^1.3.0 https://github.com/witnessmenow/file-fetcher-arduino.git