Skip to content

Commit 16ea272

Browse files
committed
Remove usage of pgmspace.h header
Remove all Makros and PROGMEM references from the source code. The ESP32 has a memory mapped Flash, so there is no reason to use the Makros. The pgmspace.h is for backward compability to be able to use AVR Arduino libraries.
1 parent f7f70c2 commit 16ea272

28 files changed

+912
-894
lines changed

Diff for: gitVersion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
TEMPLATE = """
2222
#ifndef __GIT_REVISION_H__
2323
#define __GIT_REVISION_H__
24-
constexpr const char gitRevision[] PROGMEM = "Git-revision: {git_revision}";
25-
constexpr const char gitRevShort[] PROGMEM = "\\"{git_revision}\\"";
24+
constexpr const char gitRevision[] = "Git-revision: {git_revision}";
25+
constexpr const char gitRevShort[] = "\\"{git_revision}\\"";
2626
#endif
2727
"""
2828

Diff for: processHtml.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
Use this script for creating PROGMEM header files from html files.
4+
Use this script for creating binary header files from html files.
55
"""
66

77
from pathlib import Path
@@ -40,7 +40,7 @@
4040

4141

4242
class HtmlHeaderProcessor:
43-
"""Create c code PROGMEM header files from HTML files"""
43+
"""Create c code binary header files from HTML files"""
4444

4545
@staticmethod
4646
def _escape_html(data):
@@ -64,7 +64,7 @@ def _process_header_file(cls, html_path, header_path):
6464

6565
with header_path.open(mode="w", encoding="utf-8") as header_file:
6666
header_file.write(
67-
f"static const char {html_path.name.split('.')[0]}_HTML[] PROGMEM = \""
67+
f"static const char {html_path.name.split('.')[0]}_HTML[] = \""
6868
)
6969
header_file.write(content)
7070
header_file.write('";\n')
@@ -88,7 +88,7 @@ def _process_binary_file(cls, binary_path, header_path, info):
8888
with header_path.open(mode="a", encoding="utf-8") as header_file:
8989
varName = binary_path.name.split('.')[0]
9090
header_file.write(
91-
f"static const uint8_t {varName}_BIN[] PROGMEM = {{\n "
91+
f"static const uint8_t {varName}_BIN[] = {{\n "
9292
)
9393
size = 0
9494
for d in data:

Diff for: src/AudioPlayer.cpp

+51-51
Large diffs are not rendered by default.

Diff for: src/Battery.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
if (Battery_IsCritical()) {
2727
Battery_LogStatus();
2828

29-
Log_Println((char *)FPSTR(batteryCriticalMsg), LOGLEVEL_NOTICE);
29+
Log_Println(batteryCriticalMsg, LOGLEVEL_NOTICE);
3030

3131
// Power down and enter deepsleep
3232
Power_PeripheralOff();
@@ -50,13 +50,13 @@
5050
Battery_LogStatus();
5151

5252
if (Battery_IsLow()) {
53-
Log_Println((char *)FPSTR(batteryLowMsg), LOGLEVEL_ERROR);
53+
Log_Println(batteryLowMsg, LOGLEVEL_ERROR);
5454
Led_Indicate(LedIndicatorType::VoltageWarning);
5555
}
5656

5757
#ifdef SHUTDOWN_ON_BAT_CRITICAL
5858
if (Battery_IsCritical()) {
59-
Log_Println((char *)FPSTR(batteryCriticalMsg), LOGLEVEL_ERROR);
59+
Log_Println(batteryCriticalMsg, LOGLEVEL_ERROR);
6060
System_RequestSleep();
6161
}
6262
#endif

Diff for: src/BatteryMax17055.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
bool por = false;
2323
sensor.init(s_batteryCapacity, s_emptyVoltage, s_recoveryVoltage, s_batteryChemistry, s_vCharge, s_resistSensor, por, &i2cBusTwo, &delay);
2424
cycles = gPrefsSettings.getUShort("MAX17055_cycles", 0x0000);
25-
Log_Printf(LOGLEVEL_DEBUG, "%s: %.2f", (char *)"Cycles saved in NVS:", cycles / 100.0);
25+
Log_Printf(LOGLEVEL_DEBUG, "Cycles saved in NVS: %.2f", cycles / 100.0);
2626

2727
// if power was lost, restore model params
2828
if (por) {
@@ -105,11 +105,11 @@
105105
float voltage = Battery_GetVoltage();
106106
char vstr[6];
107107
snprintf(vstr, 6, "%.2f", voltage);
108-
publishMqtt((char *)FPSTR(topicBatteryVoltage), vstr, false);
108+
publishMqtt(topicBatteryVoltage, vstr, false);
109109

110110
float soc = Battery_EstimateLevel() * 100;
111111
snprintf(vstr, 6, "%.2f", soc);
112-
publishMqtt((char *)FPSTR(topicBatterySOC), vstr, false);
112+
publishMqtt(topicBatterySOC, vstr, false);
113113
#endif
114114
}
115115

@@ -120,8 +120,8 @@
120120
Log_Printf(LOGLEVEL_INFO, batteryTempMsg, sensor.getTemperature());
121121

122122
// pretty useless because of low resolution
123-
// Log_Printf(LOGLEVEL_INFO, "Max current to battery since last check: %.4f mA", "Max current to battery since last check", sensor.getMaxCurrent());
124-
// Log_Printf(LOGLEVEL_INFO, "Min current to battery since last check: %.4f mA", "Min current to battery since last check", sensor.getMinCurrent());
123+
// Log_Printf(LOGLEVEL_INFO, "Max current to battery since last check: %.4f mA", sensor.getMaxCurrent());
124+
// Log_Printf(LOGLEVEL_INFO, "Min current to battery since last check: %.4f mA", sensor.getMinCurrent());
125125
// sensor.resetMaxMinCurrent();
126126

127127
Log_Printf(LOGLEVEL_INFO, batteryCyclesMsg, sensor.getCycles() / 100.0);

Diff for: src/BatteryMeasureVoltage.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@
7272
float voltage = Battery_GetVoltage();
7373
char vstr[6];
7474
snprintf(vstr, 6, "%.2f", voltage);
75-
publishMqtt((char *)FPSTR(topicBatteryVoltage), vstr, false);
75+
publishMqtt(topicBatteryVoltage, vstr, false);
7676

7777
float soc = Battery_EstimateLevel() * 100;
7878
snprintf(vstr, 6, "%.2f", soc);
79-
publishMqtt((char *)FPSTR(topicBatterySOC), vstr, false);
79+
publishMqtt(topicBatterySOC, vstr, false);
8080
#endif
8181
}
8282

Diff for: src/Bluetooth.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ void Bluetooth_Init(void) {
182182
a2dp_sink->set_rssi_active(true);
183183
a2dp_sink->set_rssi_callback(rssi);
184184
// start bluetooth sink
185-
a2dp_sink->start((char *)FPSTR(nameBluetoothSinkDevice));
186-
Log_Printf(LOGLEVEL_INFO, "Bluetooth sink started, Device: %s", PSTR(nameBluetoothSinkDevice));
185+
a2dp_sink->start(nameBluetoothSinkDevice);
186+
Log_Printf(LOGLEVEL_INFO, "Bluetooth sink started, Device: %s", nameBluetoothSinkDevice);
187187
// connect events after startup
188188
a2dp_sink->set_on_connection_state_changed(connection_state_changed);
189189
a2dp_sink->set_on_audio_state_changed(audio_state_changed);

Diff for: src/Cmd.cpp

+34-34
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ void Cmd_Action(const uint16_t mod) {
1616
case CMD_LOCK_BUTTONS_MOD: { // Locks/unlocks all buttons
1717
System_ToggleLockControls();
1818
if (System_AreControlsLocked()) {
19-
Log_Println((char *) FPSTR(modificatorAllButtonsLocked), LOGLEVEL_NOTICE);
19+
Log_Println(modificatorAllButtonsLocked, LOGLEVEL_NOTICE);
2020
#ifdef MQTT_ENABLE
21-
publishMqtt((char *) FPSTR(topicLockControlsState), "ON", false);
21+
publishMqtt(topicLockControlsState, "ON", false);
2222
#endif
2323
} else {
24-
Log_Println((char *) FPSTR(modificatorAllButtonsUnlocked), LOGLEVEL_NOTICE);
24+
Log_Println(modificatorAllButtonsUnlocked, LOGLEVEL_NOTICE);
2525
#ifdef MQTT_ENABLE
26-
publishMqtt((char *) FPSTR(topicLockControlsState), "OFF", false);
26+
publishMqtt(topicLockControlsState, "OFF", false);
2727
#endif
2828
}
2929
System_IndicateOk();
@@ -72,7 +72,7 @@ void Cmd_Action(const uint16_t mod) {
7272

7373
case CMD_SLEEP_AFTER_END_OF_TRACK: { // Puts uC to sleep after end of current track
7474
if (gPlayProperties.playMode == NO_PLAYLIST) {
75-
Log_Println((char *) FPSTR(modificatorNotallowedWhenIdle), LOGLEVEL_NOTICE);
75+
Log_Println(modificatorNotallowedWhenIdle, LOGLEVEL_NOTICE);
7676
System_IndicateError();
7777
return;
7878
}
@@ -82,63 +82,63 @@ void Cmd_Action(const uint16_t mod) {
8282

8383
if (gPlayProperties.sleepAfterCurrentTrack) {
8484
gPlayProperties.sleepAfterCurrentTrack = false;
85-
Log_Println((char *) FPSTR(modificatorSleepAtEOTd), LOGLEVEL_NOTICE);
85+
Log_Println(modificatorSleepAtEOTd, LOGLEVEL_NOTICE);
8686
#ifdef MQTT_ENABLE
87-
publishMqtt((char *) FPSTR(topicSleepTimerState), "0", false);
87+
publishMqtt(topicSleepTimerState, "0", false);
8888
#endif
8989
Led_ResetToInitialBrightness();
9090
} else {
9191
System_DisableSleepTimer();
9292
gPlayProperties.sleepAfterCurrentTrack = true;
93-
Log_Println((char *) FPSTR(modificatorSleepAtEOT), LOGLEVEL_NOTICE);
93+
Log_Println(modificatorSleepAtEOT, LOGLEVEL_NOTICE);
9494
#ifdef MQTT_ENABLE
95-
publishMqtt((char *) FPSTR(topicSleepTimerState), "EOT", false);
95+
publishMqtt(topicSleepTimerState, "EOT", false);
9696
#endif
9797
Led_ResetToNightBrightness();
9898
}
9999

100100
#ifdef MQTT_ENABLE
101-
publishMqtt((char *) FPSTR(topicLedBrightnessState), Led_GetBrightness(), false);
101+
publishMqtt(topicLedBrightnessState, Led_GetBrightness(), false);
102102
#endif
103103
System_IndicateOk();
104104
break;
105105
}
106106

107107
case CMD_SLEEP_AFTER_END_OF_PLAYLIST: { // Puts uC to sleep after end of whole playlist (can take a while :->)
108108
if (gPlayProperties.playMode == NO_PLAYLIST) {
109-
Log_Println((char *) FPSTR(modificatorNotallowedWhenIdle), LOGLEVEL_NOTICE);
109+
Log_Println(modificatorNotallowedWhenIdle, LOGLEVEL_NOTICE);
110110
System_IndicateError();
111111
return;
112112
}
113113
if (gPlayProperties.sleepAfterPlaylist) {
114114
System_DisableSleepTimer();
115115
gPlayProperties.sleepAfterPlaylist = false;
116116
#ifdef MQTT_ENABLE
117-
publishMqtt((char *) FPSTR(topicSleepTimerState), "0", false);
117+
publishMqtt(topicSleepTimerState, "0", false);
118118
#endif
119119
Led_ResetToInitialBrightness();
120-
Log_Println((char *) FPSTR(modificatorSleepAtEOPd), LOGLEVEL_NOTICE);
120+
Log_Println(modificatorSleepAtEOPd, LOGLEVEL_NOTICE);
121121
} else {
122122
gPlayProperties.sleepAfterPlaylist = true;
123123
Led_ResetToNightBrightness();
124-
Log_Println((char *) FPSTR(modificatorSleepAtEOP), LOGLEVEL_NOTICE);
124+
Log_Println(modificatorSleepAtEOP, LOGLEVEL_NOTICE);
125125
#ifdef MQTT_ENABLE
126-
publishMqtt((char *) FPSTR(topicSleepTimerState), "EOP", false);
126+
publishMqtt(topicSleepTimerState, "EOP", false);
127127
#endif
128128
}
129129

130130
gPlayProperties.sleepAfterCurrentTrack = false;
131131
gPlayProperties.playUntilTrackNumber = 0;
132132
#ifdef MQTT_ENABLE
133-
publishMqtt((char *) FPSTR(topicLedBrightnessState), Led_GetBrightness(), false);
133+
publishMqtt(topicLedBrightnessState, Led_GetBrightness(), false);
134134
#endif
135135
System_IndicateOk();
136136
break;
137137
}
138138

139139
case CMD_SLEEP_AFTER_5_TRACKS: {
140140
if (gPlayProperties.playMode == NO_PLAYLIST) {
141-
Log_Println((char *) FPSTR(modificatorNotallowedWhenIdle), LOGLEVEL_NOTICE);
141+
Log_Println(modificatorNotallowedWhenIdle, LOGLEVEL_NOTICE);
142142
System_IndicateError();
143143
return;
144144
}
@@ -151,47 +151,47 @@ void Cmd_Action(const uint16_t mod) {
151151
gPlayProperties.sleepAfter5Tracks = false;
152152
gPlayProperties.playUntilTrackNumber = 0;
153153
#ifdef MQTT_ENABLE
154-
publishMqtt((char *) FPSTR(topicSleepTimerState), "0", false);
154+
publishMqtt(topicSleepTimerState, "0", false);
155155
#endif
156156
Led_ResetToInitialBrightness();
157-
Log_Println((char *) FPSTR(modificatorSleepd), LOGLEVEL_NOTICE);
157+
Log_Println(modificatorSleepd, LOGLEVEL_NOTICE);
158158
} else {
159159
gPlayProperties.sleepAfter5Tracks = true;
160160
if (gPlayProperties.currentTrackNumber + 5 > gPlayProperties.numberOfTracks) { // If currentTrack + 5 exceeds number of tracks in playlist, sleep after end of playlist
161161
gPlayProperties.sleepAfterPlaylist = true;
162162
#ifdef MQTT_ENABLE
163-
publishMqtt((char *) FPSTR(topicSleepTimerState), "EOP", false);
163+
publishMqtt(topicSleepTimerState, "EOP", false);
164164
#endif
165165
} else {
166166
gPlayProperties.playUntilTrackNumber = gPlayProperties.currentTrackNumber + 5;
167167
#ifdef MQTT_ENABLE
168-
publishMqtt((char *) FPSTR(topicSleepTimerState), "EO5T", false);
168+
publishMqtt(topicSleepTimerState, "EO5T", false);
169169
#endif
170170
}
171171
Led_ResetToNightBrightness();
172-
Log_Println((char *) FPSTR(sleepTimerEO5), LOGLEVEL_NOTICE);
172+
Log_Println(sleepTimerEO5, LOGLEVEL_NOTICE);
173173
}
174174

175175
#ifdef MQTT_ENABLE
176-
publishMqtt((char *) FPSTR(topicLedBrightnessState), Led_GetBrightness(), false);
176+
publishMqtt(topicLedBrightnessState, Led_GetBrightness(), false);
177177
#endif
178178
System_IndicateOk();
179179
break;
180180
}
181181

182182
case CMD_REPEAT_PLAYLIST: {
183183
if (gPlayProperties.playMode == NO_PLAYLIST) {
184-
Log_Println((char *) FPSTR(modificatorNotallowedWhenIdle), LOGLEVEL_NOTICE);
184+
Log_Println(modificatorNotallowedWhenIdle, LOGLEVEL_NOTICE);
185185
System_IndicateError();
186186
} else {
187187
if (gPlayProperties.repeatPlaylist) {
188-
Log_Println((char *) FPSTR(modificatorPlaylistLoopDeactive), LOGLEVEL_NOTICE);
188+
Log_Println(modificatorPlaylistLoopDeactive, LOGLEVEL_NOTICE);
189189
} else {
190-
Log_Println((char *) FPSTR(modificatorPlaylistLoopActive), LOGLEVEL_NOTICE);
190+
Log_Println(modificatorPlaylistLoopActive, LOGLEVEL_NOTICE);
191191
}
192192
gPlayProperties.repeatPlaylist = !gPlayProperties.repeatPlaylist;
193193
#ifdef MQTT_ENABLE
194-
publishMqtt((char *) FPSTR(topicRepeatModeState), AudioPlayer_GetRepeatMode(), false);
194+
publishMqtt(topicRepeatModeState, AudioPlayer_GetRepeatMode(), false);
195195
#endif
196196
System_IndicateOk();
197197
}
@@ -200,17 +200,17 @@ void Cmd_Action(const uint16_t mod) {
200200

201201
case CMD_REPEAT_TRACK: { // Introduces looping for track-mode
202202
if (gPlayProperties.playMode == NO_PLAYLIST) {
203-
Log_Println((char *) FPSTR(modificatorNotallowedWhenIdle), LOGLEVEL_NOTICE);
203+
Log_Println(modificatorNotallowedWhenIdle, LOGLEVEL_NOTICE);
204204
System_IndicateError();
205205
} else {
206206
if (gPlayProperties.repeatCurrentTrack) {
207-
Log_Println((char *) FPSTR(modificatorTrackDeactive), LOGLEVEL_NOTICE);
207+
Log_Println(modificatorTrackDeactive, LOGLEVEL_NOTICE);
208208
} else {
209-
Log_Println((char *) FPSTR(modificatorTrackActive), LOGLEVEL_NOTICE);
209+
Log_Println(modificatorTrackActive, LOGLEVEL_NOTICE);
210210
}
211211
gPlayProperties.repeatCurrentTrack = !gPlayProperties.repeatCurrentTrack;
212212
#ifdef MQTT_ENABLE
213-
publishMqtt((char *) FPSTR(topicRepeatModeState), AudioPlayer_GetRepeatMode(), false);
213+
publishMqtt(topicRepeatModeState, AudioPlayer_GetRepeatMode(), false);
214214
#endif
215215
System_IndicateOk();
216216
}
@@ -219,9 +219,9 @@ void Cmd_Action(const uint16_t mod) {
219219

220220
case CMD_DIMM_LEDS_NIGHTMODE: {
221221
#ifdef MQTT_ENABLE
222-
publishMqtt((char *) FPSTR(topicLedBrightnessState), Led_GetBrightness(), false);
222+
publishMqtt(topicLedBrightnessState, Led_GetBrightness(), false);
223223
#endif
224-
Log_Println((char *) FPSTR(ledsDimmedToNightmode), LOGLEVEL_INFO);
224+
Log_Println(ledsDimmedToNightmode, LOGLEVEL_INFO);
225225
Led_ResetToNightBrightness();
226226
System_IndicateOk();
227227
break;
@@ -265,7 +265,7 @@ void Cmd_Action(const uint16_t mod) {
265265
if (millis() <= 30000) { // Only allow to enable FTP within the first 30s after start (to prevent children it mess it up)
266266
Ftp_EnableServer();
267267
} else {
268-
Log_Println((char *) FPSTR(ftpEnableTooLate), LOGLEVEL_ERROR);
268+
Log_Println(ftpEnableTooLate, LOGLEVEL_ERROR);
269269
System_IndicateError();
270270
}
271271
break;

Diff for: src/Ftp.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void Ftp_Init(void) {
3131
String nvsFtpUser = gPrefsSettings.getString("ftpuser", "-1");
3232
if (!nvsFtpUser.compareTo("-1")) {
3333
gPrefsSettings.putString("ftpuser", (String)Ftp_User);
34-
Log_Println((char *) FPSTR(wroteFtpUserToNvs), LOGLEVEL_ERROR);
34+
Log_Println(wroteFtpUserToNvs, LOGLEVEL_ERROR);
3535
} else {
3636
Ftp_User = nvsFtpUser;
3737
Log_Printf(LOGLEVEL_INFO, restoredFtpUserFromNvs, nvsFtpUser.c_str());
@@ -41,7 +41,7 @@ void Ftp_Init(void) {
4141
String nvsFtpPassword = gPrefsSettings.getString("ftppassword", "-1");
4242
if (!nvsFtpPassword.compareTo("-1")) {
4343
gPrefsSettings.putString("ftppassword", (String)Ftp_Password);
44-
Log_Println((char *) FPSTR(wroteFtpPwdToNvs), LOGLEVEL_ERROR);
44+
Log_Println(wroteFtpPwdToNvs, LOGLEVEL_ERROR);
4545
} else {
4646
Ftp_Password = nvsFtpPassword;
4747
Log_Printf(LOGLEVEL_INFO, restoredFtpPwdFromNvs, nvsFtpPassword.c_str());
@@ -76,7 +76,7 @@ void Ftp_EnableServer(void) {
7676

7777
System_IndicateOk();
7878
} else {
79-
Log_Println((char *) FPSTR(unableToStartFtpServer), LOGLEVEL_ERROR);
79+
Log_Println(unableToStartFtpServer, LOGLEVEL_ERROR);
8080
System_IndicateError();
8181
}
8282
}
@@ -89,7 +89,7 @@ void ftpManager(void) {
8989
ftpEnableCurrentStatus = true;
9090
ftpSrv = new FtpServer();
9191
ftpSrv->begin(gFSystem, Ftp_User, Ftp_Password);
92-
Log_Printf(LOGLEVEL_DEBUG, "%s: %u", PSTR(freeHeapWithFtp), ESP.getFreeHeap());
92+
Log_Printf(LOGLEVEL_DEBUG, freeHeapWithFtp, ESP.getFreeHeap());
9393
Log_Println(ftpServerStarted, LOGLEVEL_NOTICE);
9494
}
9595
#endif

0 commit comments

Comments
 (0)