Skip to content

Commit 6a2241c

Browse files
authored
Store more messages in flash (#299)
1 parent 1095a8f commit 6a2241c

File tree

8 files changed

+29
-28
lines changed

8 files changed

+29
-28
lines changed

src/display/core/Controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void Controller::setup() {
1818
mode = settings.getStartupMode();
1919

2020
if (!SPIFFS.begin(true)) {
21-
Serial.println("An Error has occurred while mounting LittleFS");
21+
Serial.println(F("An Error has occurred while mounting LittleFS"));
2222
}
2323

2424
pluginManager = new PluginManager();

src/display/core/zones.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#define ZONES_H
33

44
#include "Arduino.h"
5+
#include <pgmspace.h>
56

67
typedef struct {
7-
String name;
8-
String zones;
8+
const char *name;
9+
const char *zones;
910
} zones_t;
1011

11-
const zones_t zones[] = {
12+
static const zones_t zones[] PROGMEM = {
1213
{"Africa/Abidjan", "GMT0"},
1314
{"Africa/Accra", "GMT0"},
1415
{"Africa/Addis_Ababa", "EAT-3"},
@@ -472,12 +473,12 @@ const zones_t zones[] = {
472473
{"Pacific/Wallis", "<+12>-12"},
473474
};
474475

475-
inline char const *FALLBACK_TZ = "GMT0";
476+
static const char FALLBACK_TZ[] PROGMEM = "GMT0";
476477

477-
inline const char *resolve_timezone(String time_zone_label) {
478-
for (int i = 0; i < sizeof(zones); i++) {
479-
if (zones[i].name == time_zone_label) {
480-
return zones[i].zones.c_str();
478+
inline const char *resolve_timezone(const String &time_zone_label) {
479+
for (size_t i = 0; i < sizeof(zones) / sizeof(zones[0]); i++) {
480+
if (time_zone_label == zones[i].name) {
481+
return zones[i].zones;
481482
}
482483
}
483484
return FALLBACK_TZ;

src/display/drivers/LilyGo-T-RGB/LilyGo_RGBPanel.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool LilyGo_RGBPanel::begin(LilyGo_RGBPanel_Color_Order order) {
4545

4646
// Initialize the XL9555 expansion chip
4747
if (!extension.init(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL)) {
48-
Serial.println("External GPIO expansion chip does not exist.");
48+
Serial.println(F("External GPIO expansion chip does not exist."));
4949
assert(false);
5050
}
5151

@@ -57,7 +57,7 @@ bool LilyGo_RGBPanel::begin(LilyGo_RGBPanel_Color_Order order) {
5757
extension.digitalWrite(power_enable, HIGH);
5858

5959
if (!initTouch()) {
60-
Serial.println("Touch chip not found.");
60+
Serial.println(F("Touch chip not found."));
6161
}
6262

6363
initBUS();
@@ -76,15 +76,15 @@ bool LilyGo_RGBPanel::installSD() {
7676
if (SD_MMC.begin("/sdcard", true, false)) {
7777
uint8_t cardType = SD_MMC.cardType();
7878
if (cardType != CARD_NONE) {
79-
Serial.print("SD Card Type: ");
79+
Serial.print(F("SD Card Type: "));
8080
if (cardType == CARD_MMC)
81-
Serial.println("MMC");
81+
Serial.println(F("MMC"));
8282
else if (cardType == CARD_SD)
83-
Serial.println("SDSC");
83+
Serial.println(F("SDSC"));
8484
else if (cardType == CARD_SDHC)
85-
Serial.println("SDHC");
85+
Serial.println(F("SDHC"));
8686
else
87-
Serial.println("UNKNOWN");
87+
Serial.println(F("UNKNOWN"));
8888
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
8989
Serial.printf("SD Card Size: %lluMB\n", cardSize);
9090
}

src/display/drivers/LilyGoDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void LilyGoDriver::init() {
1313
printf("Initializing LilyGo driver\n");
1414
if (!panel.begin()) {
1515
for (uint8_t i = 0; i < 20; i++) {
16-
Serial.println("Error, failed to initialize T-RGB");
16+
Serial.println(F("Error, failed to initialize T-RGB"));
1717
delay(1000);
1818
}
1919
ESP.restart();

src/display/drivers/Waveshare/WavesharePanel.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool WavesharePanel::begin(WS_RGBPanel_Color_Order order) {
5858
Set_EXIO(EXIO_PIN8, Low);
5959

6060
if (!initTouch()) {
61-
Serial.println("Touch chip not found.");
61+
Serial.println(F("Touch chip not found."));
6262
return false;
6363
}
6464

@@ -78,15 +78,15 @@ bool WavesharePanel::installSD() {
7878
if (SD_MMC.begin("/sdcard", true, false)) {
7979
uint8_t cardType = SD_MMC.cardType();
8080
if (cardType != CARD_NONE) {
81-
Serial.print("SD Card Type: ");
81+
Serial.print(F("SD Card Type: "));
8282
if (cardType == CARD_MMC)
83-
Serial.println("MMC");
83+
Serial.println(F("MMC"));
8484
else if (cardType == CARD_SD)
85-
Serial.println("SDSC");
85+
Serial.println(F("SDSC"));
8686
else if (cardType == CARD_SDHC)
87-
Serial.println("SDHC");
87+
Serial.println(F("SDHC"));
8888
else
89-
Serial.println("UNKNOWN");
89+
Serial.println(F("UNKNOWN"));
9090
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
9191
Serial.printf("SD Card Size: %lluMB\n", cardSize);
9292
}

src/display/drivers/WaveshareDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void WaveshareDriver::init() {
77
printf("WaveshareDriver initialzing\n");
88
if (!panel.begin()) {
99
for (uint8_t i = 0; i < 20; i++) {
10-
Serial.println("Error, failed to initialize T-RGB");
10+
Serial.println(F("Error, failed to initialize T-RGB"));
1111
delay(1000);
1212
}
1313
ESP.restart();

src/display/plugins/WebUIPlugin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,21 @@ void WebUIPlugin::handleProfileRequest(uint32_t clientId, JsonDocument &request)
221221
auto obj = response["profile"].to<JsonObject>();
222222
writeProfile(obj, profile);
223223
} else {
224-
response["error"] = "Profile not found";
224+
response["error"] = F("Profile not found");
225225
}
226226
} else if (type == "req:profiles:save") {
227227
auto obj = request["profile"].as<JsonObject>();
228228
Profile profile;
229229
parseProfile(obj, profile);
230230
if (!profileManager->saveProfile(profile)) {
231-
response["error"] = "Save failed";
231+
response["error"] = F("Save failed");
232232
}
233233
auto respObj = response["profile"].to<JsonObject>();
234234
writeProfile(respObj, profile);
235235
} else if (type == "req:profiles:delete") {
236236
auto id = request["id"].as<String>();
237237
if (!profileManager->deleteProfile(id)) {
238-
response["error"] = "Delete failed";
238+
response["error"] = F("Delete failed");
239239
}
240240
} else if (type == "req:profiles:select") {
241241
auto id = request["id"].as<String>();

src/display/plugins/mDNSPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ void mDNSPlugin::start(Event const &event) const {
1313
if (apMode)
1414
return;
1515
if (!MDNS.begin(controller->getSettings().getMdnsName().c_str())) {
16-
Serial.println("Error setting up MDNS responder!");
16+
Serial.println(F("Error setting up MDNS responder!"));
1717
}
1818
}

0 commit comments

Comments
 (0)