Skip to content

Commit a91e857

Browse files
committed
Updating UI of Race week display
1 parent a457e28 commit a91e857

File tree

3 files changed

+111
-95
lines changed

3 files changed

+111
-95
lines changed

F1-Notifications/cheapYellowLCD.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
// -------------------------------
2222

23+
#define SESSION_TEXT_SIZE 4
24+
2325
TFT_eSPI tft = TFT_eSPI();
2426
PNG png;
2527

@@ -110,20 +112,20 @@ class CheapYellowDisplay : public F1Display
110112
Serial.println("prts");
111113
tft.fillRect(0, 0, screenWidth, screenHeight, TFT_BLACK);
112114

113-
// It's race week!
114-
String tempStr = "Next Race: ";
115-
tempStr += String(convertRaceName(raceName));
116-
117-
tft.drawString(tempStr, 5, 5, 2);
115+
tft.setTextColor(TFT_WHITE, TFT_BLACK);
116+
int yPos = 5;
117+
String gpStartDateStr = String(getConvertedTime(races_sessions["gp"], "M d"));
118+
String displayMessage = String(convertRaceName(raceName)) + " | " + gpStartDateStr;
119+
tft.drawCentreString(displayMessage, screenCenterX, yPos, 4);
118120

119-
int yValue = 21;
121+
int yValue = 46;
120122
for (JsonPair kv : races_sessions)
121123
{
122-
printSession(5,
124+
printSession(4,
123125
yValue,
124126
sessionCodeToString(kv.key().c_str()),
125127
getConvertedTime(kv.value().as<const char *>()));
126-
yValue += 16;
128+
yValue += (SESSION_TEXT_SIZE) * 8;
127129
}
128130

129131
state = raceweek;
@@ -182,6 +184,6 @@ class CheapYellowDisplay : public F1Display
182184
String tempStr = String(sessionName);
183185
tempStr += " ";
184186
tempStr += sessionStartTime;
185-
tft.drawString(tempStr, x, y, 2);
187+
tft.drawString(tempStr, x, y, SESSION_TEXT_SIZE);
186188
}
187189
};

F1-Notifications/config.h

Lines changed: 99 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,102 +7,116 @@
77
#define F1_ROUND_OFFSET_LABEL "roundOffset"
88
#define F1_CURRENT_RACE_NOTIFICATION_LABEL "currentRaceNotification"
99

10-
class F1Config {
11-
public:
12-
//How the time will be displayed, see here for more info: https://github.com/ropg/ezTime#datetime
13-
String timeFormat = "l, d-M-Y H:i"; // Friday, 17-Mar-2023 00:30
14-
String timeZone = "Europe/London"; //seems to be something wrong with Europe/Dublin
15-
16-
// Telegram BOT Token (Get from Botfather)
17-
String botToken = "";
10+
class F1Config
11+
{
12+
public:
13+
// How the time will be displayed, see here for more info: https://github.com/ropg/ezTime#datetime
14+
String timeFormat = "l, H:i"; // Friday, 00:30
15+
String timeZone = "Europe/London"; // seems to be something wrong with Europe/Dublin
16+
17+
// Telegram BOT Token (Get from Botfather)
18+
String botToken = "";
19+
20+
// Use @myidbot (IDBot) to find out the chat ID of an individual or a group
21+
// Also note that you need to click "start" on a bot before it can
22+
// message you
23+
String chatId = "";
24+
25+
int roundOffset = 0;
26+
27+
bool currentRaceNotification = false;
28+
29+
bool isTelegramConfigured()
30+
{
31+
return (botToken != "") && (chatId != "");
32+
}
33+
34+
bool fetchConfigFile()
35+
{
36+
if (SPIFFS.exists(F1_CONFIG_JSON))
37+
{
38+
// file exists, reading and loading
39+
Serial.println("reading config file");
40+
File configFile = SPIFFS.open(F1_CONFIG_JSON, "r");
41+
if (configFile)
42+
{
43+
Serial.println("opened config file");
44+
StaticJsonDocument<1024> json;
45+
DeserializationError error = deserializeJson(json, configFile);
46+
serializeJsonPretty(json, Serial);
47+
if (!error)
48+
{
49+
Serial.println("\nparsed json");
50+
51+
if (json.containsKey(F1_TIME_ZONE_LABEL))
52+
{
53+
timeZone = String(json[F1_TIME_ZONE_LABEL].as<String>());
54+
}
1855

19-
// Use @myidbot (IDBot) to find out the chat ID of an individual or a group
20-
// Also note that you need to click "start" on a bot before it can
21-
// message you
22-
String chatId = "";
56+
if (json.containsKey(F1_TIME_FORMAT_LABEL))
57+
{
58+
timeFormat = String(json[F1_TIME_FORMAT_LABEL].as<String>());
59+
}
2360

24-
int roundOffset = 0;
61+
if (json.containsKey(F1_BOT_TOKEN_LABEL))
62+
{
63+
botToken = String(json[F1_BOT_TOKEN_LABEL].as<String>());
64+
}
2565

26-
bool currentRaceNotification = false;
66+
if (json.containsKey(F1_CHAT_ID_LABEL))
67+
{
68+
chatId = String(json[F1_CHAT_ID_LABEL].as<String>());
69+
}
2770

28-
bool isTelegramConfigured(){
29-
return (botToken != "") && (chatId != "");
30-
}
71+
if (json.containsKey(F1_ROUND_OFFSET_LABEL))
72+
{
73+
roundOffset = json[F1_ROUND_OFFSET_LABEL].as<int>();
74+
}
3175

32-
bool fetchConfigFile() {
33-
if (SPIFFS.exists(F1_CONFIG_JSON)) {
34-
//file exists, reading and loading
35-
Serial.println("reading config file");
36-
File configFile = SPIFFS.open(F1_CONFIG_JSON, "r");
37-
if (configFile) {
38-
Serial.println("opened config file");
39-
StaticJsonDocument<1024> json;
40-
DeserializationError error = deserializeJson(json, configFile);
41-
serializeJsonPretty(json, Serial);
42-
if (!error) {
43-
Serial.println("\nparsed json");
44-
45-
if (json.containsKey(F1_TIME_ZONE_LABEL)) {
46-
timeZone = String(json[F1_TIME_ZONE_LABEL].as<String>());
47-
}
48-
49-
if (json.containsKey(F1_TIME_FORMAT_LABEL)) {
50-
timeFormat = String(json[F1_TIME_FORMAT_LABEL].as<String>());
51-
}
52-
53-
if (json.containsKey(F1_BOT_TOKEN_LABEL)) {
54-
botToken = String(json[F1_BOT_TOKEN_LABEL].as<String>());
55-
}
56-
57-
if (json.containsKey(F1_CHAT_ID_LABEL)) {
58-
chatId = String(json[F1_CHAT_ID_LABEL].as<String>());
59-
}
60-
61-
if (json.containsKey(F1_ROUND_OFFSET_LABEL)) {
62-
roundOffset = json[F1_ROUND_OFFSET_LABEL].as<int>();
63-
}
64-
65-
if (json.containsKey(F1_CURRENT_RACE_NOTIFICATION_LABEL)) {
66-
currentRaceNotification = json[F1_CURRENT_RACE_NOTIFICATION_LABEL].as<bool>();
67-
}
68-
69-
return true;
70-
71-
} else {
72-
Serial.println("failed to load json config");
73-
return false;
76+
if (json.containsKey(F1_CURRENT_RACE_NOTIFICATION_LABEL))
77+
{
78+
currentRaceNotification = json[F1_CURRENT_RACE_NOTIFICATION_LABEL].as<bool>();
7479
}
80+
81+
return true;
82+
}
83+
else
84+
{
85+
Serial.println("failed to load json config");
86+
return false;
7587
}
7688
}
89+
}
7790

78-
79-
Serial.println("Config file does not exist");
91+
Serial.println("Config file does not exist");
92+
return false;
93+
}
94+
95+
bool saveConfigFile()
96+
{
97+
Serial.println(F("Saving config"));
98+
StaticJsonDocument<1024> json;
99+
json[F1_TIME_ZONE_LABEL] = timeZone;
100+
json[F1_TIME_FORMAT_LABEL] = timeFormat;
101+
json[F1_BOT_TOKEN_LABEL] = botToken;
102+
json[F1_CHAT_ID_LABEL] = chatId;
103+
json[F1_ROUND_OFFSET_LABEL] = roundOffset;
104+
json[F1_CURRENT_RACE_NOTIFICATION_LABEL] = currentRaceNotification;
105+
106+
File configFile = SPIFFS.open(F1_CONFIG_JSON, "w");
107+
if (!configFile)
108+
{
109+
Serial.println("failed to open config file for writing");
80110
return false;
81-
82111
}
83112

84-
bool saveConfigFile() {
85-
Serial.println(F("Saving config"));
86-
StaticJsonDocument<1024> json;
87-
json[F1_TIME_ZONE_LABEL] = timeZone;
88-
json[F1_TIME_FORMAT_LABEL] = timeFormat;
89-
json[F1_BOT_TOKEN_LABEL] = botToken;
90-
json[F1_CHAT_ID_LABEL] = chatId;
91-
json[F1_ROUND_OFFSET_LABEL] = roundOffset;
92-
json[F1_CURRENT_RACE_NOTIFICATION_LABEL] = currentRaceNotification;
93-
94-
File configFile = SPIFFS.open(F1_CONFIG_JSON, "w");
95-
if (!configFile) {
96-
Serial.println("failed to open config file for writing");
97-
return false;
98-
}
99-
100-
serializeJsonPretty(json, Serial);
101-
if (serializeJson(json, configFile) == 0) {
102-
Serial.println(F("Failed to write to file"));
103-
return false;
104-
}
105-
configFile.close();
106-
return true;
113+
serializeJsonPretty(json, Serial);
114+
if (serializeJson(json, configFile) == 0)
115+
{
116+
Serial.println(F("Failed to write to file"));
117+
return false;
107118
}
119+
configFile.close();
120+
return true;
121+
}
108122
};

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ framework = arduino
1919
lib_deps =
2020
khoih-prog/ESP_DoubleResetDetector@^1.3.2
2121
bblanchon/ArduinoJson@^6.21.3
22-
wnatth3/WiFiManager@^2.0.16-rc.2
22+
https://github.com/tzapu/WiFiManager.git#v2.0.17
2323
ropg/ezTime@^0.8.3
2424
witnessmenow/UniversalTelegramBot@^1.3.0
2525
https://github.com/witnessmenow/file-fetcher-arduino.git

0 commit comments

Comments
 (0)