Skip to content

Commit

Permalink
Updating UI of Race week display
Browse files Browse the repository at this point in the history
  • Loading branch information
witnessmenow committed May 6, 2024
1 parent a457e28 commit a91e857
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 95 deletions.
20 changes: 11 additions & 9 deletions F1-Notifications/cheapYellowLCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

// -------------------------------

#define SESSION_TEXT_SIZE 4

TFT_eSPI tft = TFT_eSPI();
PNG png;

Expand Down Expand Up @@ -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<const char *>()));
yValue += 16;
yValue += (SESSION_TEXT_SIZE) * 8;
}

state = raceweek;
Expand Down Expand Up @@ -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);
}
};
184 changes: 99 additions & 85 deletions F1-Notifications/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>());
}

// 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<String>());
}

int roundOffset = 0;
if (json.containsKey(F1_BOT_TOKEN_LABEL))
{
botToken = String(json[F1_BOT_TOKEN_LABEL].as<String>());
}

bool currentRaceNotification = false;
if (json.containsKey(F1_CHAT_ID_LABEL))
{
chatId = String(json[F1_CHAT_ID_LABEL].as<String>());
}

bool isTelegramConfigured(){
return (botToken != "") && (chatId != "");
}
if (json.containsKey(F1_ROUND_OFFSET_LABEL))
{
roundOffset = json[F1_ROUND_OFFSET_LABEL].as<int>();
}

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<String>());
}

if (json.containsKey(F1_TIME_FORMAT_LABEL)) {
timeFormat = String(json[F1_TIME_FORMAT_LABEL].as<String>());
}

if (json.containsKey(F1_BOT_TOKEN_LABEL)) {
botToken = String(json[F1_BOT_TOKEN_LABEL].as<String>());
}

if (json.containsKey(F1_CHAT_ID_LABEL)) {
chatId = String(json[F1_CHAT_ID_LABEL].as<String>());
}

if (json.containsKey(F1_ROUND_OFFSET_LABEL)) {
roundOffset = json[F1_ROUND_OFFSET_LABEL].as<int>();
}

if (json.containsKey(F1_CURRENT_RACE_NOTIFICATION_LABEL)) {
currentRaceNotification = json[F1_CURRENT_RACE_NOTIFICATION_LABEL].as<bool>();
}

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<bool>();
}

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;
}
};
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a91e857

Please sign in to comment.