Skip to content

Commit 20444ee

Browse files
committed
Debug optimisations
1 parent 340a9f8 commit 20444ee

File tree

15 files changed

+84
-114
lines changed

15 files changed

+84
-114
lines changed

wled00/button.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,23 @@ void handleSwitch(uint8_t b)
125125
{
126126
// isButtonPressed() handles inverted/noninverted logic
127127
if (buttonPressedBefore[b] != isButtonPressed(b)) {
128-
DEBUG_PRINT(F("Switch: State changed ")); DEBUG_PRINTLN(b);
128+
DEBUG_PRINTF_P(PSTR("Switch: State changed %u\n"), b);
129129
buttonPressedTime[b] = millis();
130130
buttonPressedBefore[b] = !buttonPressedBefore[b];
131131
}
132132

133133
if (buttonLongPressed[b] == buttonPressedBefore[b]) return;
134134

135135
if (millis() - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce)
136-
DEBUG_PRINT(F("Switch: Activating ")); DEBUG_PRINTLN(b);
136+
DEBUG_PRINTF_P(PSTR("Switch: Activating %u\n"), b);
137137
if (!buttonPressedBefore[b]) { // on -> off
138-
DEBUG_PRINT(F("Switch: On -> Off ")); DEBUG_PRINTLN(b);
138+
DEBUG_PRINTF_P(PSTR("Switch: On -> Off (%u)\n"), b);
139139
if (macroButton[b]) applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
140140
else { //turn on
141141
if (!bri) {toggleOnOff(); stateUpdated(CALL_MODE_BUTTON);}
142142
}
143143
} else { // off -> on
144-
DEBUG_PRINT(F("Switch: Off -> On ")); DEBUG_PRINTLN(b);
144+
DEBUG_PRINTF_P(PSTR("Switch: Off -> On (%u)\n"), b);
145145
if (macroLongPress[b]) applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET);
146146
else { //turn off
147147
if (bri) {toggleOnOff(); stateUpdated(CALL_MODE_BUTTON);}
@@ -173,7 +173,7 @@ void handleAnalog(uint8_t b)
173173
static float filteredReading[WLED_MAX_BUTTONS] = {0.0f};
174174
unsigned rawReading; // raw value from analogRead, scaled to 12bit
175175

176-
DEBUG_PRINT(F("Analog: Reading button ")); DEBUG_PRINTLN(b);
176+
DEBUG_PRINTF_P(PSTR("Analog: Reading button %u\n"), b);
177177

178178
#ifdef ESP8266
179179
rawReading = analogRead(A0) << 2; // convert 10bit read to 12bit
@@ -193,8 +193,8 @@ void handleAnalog(uint8_t b)
193193
// remove noise & reduce frequency of UI updates
194194
if (abs(int(aRead) - int(oldRead[b])) <= POT_SENSITIVITY) return; // no significant change in reading
195195

196-
DEBUG_PRINT(F("Analog: Raw = ")); DEBUG_PRINT(rawReading);
197-
DEBUG_PRINT(F(" Filtered = ")); DEBUG_PRINTLN(aRead);
196+
DEBUG_PRINTF_P(PSTR("Analog: Raw = %u\n"), rawReading);
197+
DEBUG_PRINTF_P(PSTR(" Filtered = %u\n"), aRead);
198198

199199
// Unomment the next lines if you still see flickering related to potentiometer
200200
// This waits until strip finishes updating (why: strip was not updating at the start of handleButton() but may have started during analogRead()?)
@@ -207,7 +207,7 @@ void handleAnalog(uint8_t b)
207207

208208
// if no macro for "short press" and "long press" is defined use brightness control
209209
if (!macroButton[b] && !macroLongPress[b]) {
210-
DEBUG_PRINT(F("Analog: Action = ")); DEBUG_PRINTLN(macroDoublePress[b]);
210+
DEBUG_PRINTF_P(PSTR("Analog: Action = %u\n"), macroDoublePress[b]);
211211
// if "double press" macro defines which option to change
212212
if (macroDoublePress[b] >= 250) {
213213
// global brightness

wled00/cfg.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
277277
if ((buttonType[s] == BTN_TYPE_ANALOG) || (buttonType[s] == BTN_TYPE_ANALOG_INVERTED)) {
278278
if (digitalPinToAnalogChannel(btnPin[s]) < 0) {
279279
// not an ADC analog pin
280-
DEBUG_PRINT(F("PIN ALLOC error: GPIO")); DEBUG_PRINT(btnPin[s]);
281-
DEBUG_PRINT(F("for analog button #")); DEBUG_PRINT(s);
282-
DEBUG_PRINTLN(F(" is not an analog pin!"));
280+
DEBUG_PRINTF_P(PSTR("PIN ALLOC error: GPIO%d for analog button #%d is not an analog pin!\n"), btnPin[s], s);
283281
btnPin[s] = -1;
284282
pinManager.deallocatePin(pin,PinOwner::Button);
285283
} else {
@@ -290,7 +288,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
290288
{
291289
if (digitalPinToTouchChannel(btnPin[s]) < 0) {
292290
// not a touch pin
293-
DEBUG_PRINTF_P(PSTR("PIN ALLOC error: GPIO%d for touch button #%d is not an touch pin!\n"), btnPin[s], s);
291+
DEBUG_PRINTF_P(PSTR("PIN ALLOC error: GPIO%d for touch button #%d is not a touch pin!\n"), btnPin[s], s);
294292
btnPin[s] = -1;
295293
pinManager.deallocatePin(pin,PinOwner::Button);
296294
}

wled00/e131.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
108108

109109
if (e131SkipOutOfSequence)
110110
if (seq < e131LastSequenceNumber[previousUniverses] && seq > 20 && e131LastSequenceNumber[previousUniverses] < 250){
111-
DEBUG_PRINT(F("skipping E1.31 frame (last seq="));
112-
DEBUG_PRINT(e131LastSequenceNumber[previousUniverses]);
113-
DEBUG_PRINT(F(", current seq="));
114-
DEBUG_PRINT(seq);
115-
DEBUG_PRINT(F(", universe="));
116-
DEBUG_PRINT(uni);
117-
DEBUG_PRINTLN(")");
111+
DEBUG_PRINTF_P(PSTR("skipping E1.31 frame (last seq=%d, current seq=%d, universe=%d)\n"), e131LastSequenceNumber[previousUniverses], seq, uni);
118112
return;
119113
}
120114
e131LastSequenceNumber[previousUniverses] = seq;

wled00/json.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,11 +1144,8 @@ void serveJson(AsyncWebServerRequest* request)
11441144

11451145
DEBUG_PRINTF_P(PSTR("JSON buffer size: %u for request: %d\n"), lDoc.memoryUsage(), subJson);
11461146

1147-
#ifdef WLED_DEBUG
1148-
size_t len =
1149-
#endif
1150-
response->setLength();
1151-
DEBUG_PRINT(F("JSON content length: ")); DEBUG_PRINTLN(len);
1147+
[[maybe_unused]] size_t len = response->setLength();
1148+
DEBUG_PRINTF_P(PSTR("JSON content length: %u\n"), len);
11521149

11531150
request->send(response);
11541151
}

wled00/mqtt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ static void onMqttConnect(bool sessionPresent)
5555
static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
5656
static char *payloadStr;
5757

58-
DEBUG_PRINT(F("MQTT msg: "));
59-
DEBUG_PRINTLN(topic);
58+
DEBUG_PRINTF_P(PSTR("MQTT msg: %s\n"), topic);
6059

6160
// paranoia check to avoid npe if no payload
6261
if (payload==nullptr) {

wled00/ntp.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ bool checkNTPResponse()
246246
}
247247

248248
uint32_t ntpPacketReceivedTime = millis();
249-
DEBUG_PRINT(F("NTP recv, l="));
250-
DEBUG_PRINTLN(cb);
249+
DEBUG_PRINTF_P(PSTR("NTP recv, l=%d\n"), cb);
251250
byte pbuf[NTP_PACKET_SIZE];
252251
ntpUdp.read(pbuf, NTP_PACKET_SIZE); // read the packet into the buffer
253252
if (!isValidNtpResponse(pbuf)) return false; // verify we have a valid response to client
@@ -493,7 +492,7 @@ void calculateSunriseAndSunset() {
493492
do {
494493
time_t theDay = localTime - retryCount * 86400; // one day back = 86400 seconds
495494
minUTC = getSunriseUTC(year(theDay), month(theDay), day(theDay), latitude, longitude, false);
496-
DEBUG_PRINT(F("* sunrise (minutes from UTC) = ")); DEBUG_PRINTLN(minUTC);
495+
DEBUG_PRINTF_P(PSTR("* sunrise (minutes from UTC) = %d\n"), minUTC);
497496
retryCount ++;
498497
} while ((abs(minUTC) > SUNSET_MAX) && (retryCount <= 3));
499498

@@ -512,7 +511,7 @@ void calculateSunriseAndSunset() {
512511
do {
513512
time_t theDay = localTime - retryCount * 86400; // one day back = 86400 seconds
514513
minUTC = getSunriseUTC(year(theDay), month(theDay), day(theDay), latitude, longitude, true);
515-
DEBUG_PRINT(F("* sunset (minutes from UTC) = ")); DEBUG_PRINTLN(minUTC);
514+
DEBUG_PRINTF_P(PSTR("* sunset (minutes from UTC) = %d\n"), minUTC);
516515
retryCount ++;
517516
} while ((abs(minUTC) > SUNSET_MAX) && (retryCount <= 3));
518517

wled00/presets.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ void initPresetsFile()
117117

118118
bool applyPresetFromPlaylist(byte index)
119119
{
120-
DEBUG_PRINT(F("Request to apply preset: "));
121-
DEBUG_PRINTLN(index);
120+
DEBUG_PRINTF_P(PSTR("Request to apply preset: %d\n"), index);
122121
presetToApply = index;
123122
callModeToApply = CALL_MODE_DIRECT_CHANGE;
124123
return true;
@@ -127,8 +126,7 @@ bool applyPresetFromPlaylist(byte index)
127126
bool applyPreset(byte index, byte callMode)
128127
{
129128
unloadPlaylist(); // applying a preset unloads the playlist (#3827)
130-
DEBUG_PRINT(F("Request to apply preset: "));
131-
DEBUG_PRINTLN(index);
129+
DEBUG_PRINTF_P(PSTR("Request to apply preset: %u\n"), index);
132130
presetToApply = index;
133131
callModeToApply = callMode;
134132
return true;
@@ -163,8 +161,7 @@ void handlePresets()
163161
presetToApply = 0; //clear request for preset
164162
callModeToApply = 0;
165163

166-
DEBUG_PRINT(F("Applying preset: "));
167-
DEBUG_PRINTLN(tmpPreset);
164+
DEBUG_PRINTF_P(PSTR("Applying preset: %u\n"), (unsigned)tmpPreset);
168165

169166
#ifdef ARDUINO_ARCH_ESP32
170167
if (tmpPreset==255 && tmpRAMbuffer!=nullptr) {
@@ -222,7 +219,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
222219
else sprintf_P(saveName, PSTR("Preset %d"), index);
223220
}
224221

225-
DEBUG_PRINT(F("Saving preset (")); DEBUG_PRINT(index); DEBUG_PRINT(F(") ")); DEBUG_PRINTLN(saveName);
222+
DEBUG_PRINTF_P(PSTR("Saving preset (%d) %s\n"), index, saveName);
226223

227224
presetToSave = index;
228225
playlistSave = false;

wled00/remote.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ void handleRemote(uint8_t *incomingData, size_t len) {
186186
}
187187

188188
if (len != sizeof(message_structure_t)) {
189-
DEBUG_PRINT(F("Unknown incoming ESP Now message received of length "));
190-
DEBUG_PRINTLN(len);
189+
DEBUG_PRINTF_P(PSTR("Unknown incoming ESP Now message received of length %u\n"), len);
191190
return;
192191
}
193192

wled00/set.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
157157
char la[4] = "LA"; la[2] = offset+s; la[3] = 0; //LED mA
158158
char ma[4] = "MA"; ma[2] = offset+s; ma[3] = 0; //max mA
159159
if (!request->hasArg(lp)) {
160-
DEBUG_PRINT(F("No data for "));
161-
DEBUG_PRINTLN(s);
160+
DEBUG_PRINTF_P(PSTR("No data for %d\n"), s);
162161
break;
163162
}
164163
for (int i = 0; i < 5; i++) {
@@ -729,7 +728,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
729728
else subObj[name].add(value.toInt()); // we may have an int
730729
j++;
731730
}
732-
DEBUG_PRINT(F("[")); DEBUG_PRINT(j); DEBUG_PRINT(F("] = ")); DEBUG_PRINTLN(value);
731+
DEBUG_PRINTF_P(PSTR("[%d] = %s\n"), j, value.c_str());
733732
} else {
734733
// we are using a hidden field with the same name as our parameter (!before the actual parameter!)
735734
// to describe the type of parameter (text,float,int), for boolean parameters the first field contains "off"
@@ -748,7 +747,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
748747
} else if (type == "int") subObj[name] = value.toInt();
749748
else subObj[name] = value; // text fields
750749
}
751-
DEBUG_PRINT(F(" = ")); DEBUG_PRINTLN(value);
750+
DEBUG_PRINTF_P(PSTR(" = %s\n"), value.c_str());
752751
}
753752
}
754753
usermods.readFromConfig(um); // force change of usermod parameters
@@ -809,8 +808,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
809808
if (!(req.indexOf("win") >= 0)) return false;
810809

811810
int pos = 0;
812-
DEBUG_PRINT(F("API req: "));
813-
DEBUG_PRINTLN(req);
811+
DEBUG_PRINTF_P(PSTR("API req: %s\n"), req.c_str());
814812

815813
//segment select (sets main segment)
816814
pos = req.indexOf(F("SM="));

wled00/src/dependencies/toki/Toki.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class Toki {
155155
return (tick == TickT::active);
156156
}
157157

158-
void printTime(const Time& t) {
159-
Serial.printf_P(PSTR("%u,%03u\n"),t.sec,t.ms);
158+
void printTime(const Time& t, Print &dest = Serial) {
159+
dest.printf_P(PSTR("%u,%03u\n"),t.sec,t.ms);
160160
}
161161
};

0 commit comments

Comments
 (0)