diff --git a/wled00/button.cpp b/wled00/button.cpp index 8b366e055..b5a4e9436 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -125,7 +125,7 @@ void handleSwitch(uint8_t b) { // isButtonPressed() handles inverted/noninverted logic if (buttonPressedBefore[b] != isButtonPressed(b)) { - DEBUG_PRINT(F("Switch: State changed ")); DEBUG_PRINTLN(b); + DEBUG_PRINTF_P(PSTR("Switch: State changed %u\n"), b); buttonPressedTime[b] = millis(); buttonPressedBefore[b] = !buttonPressedBefore[b]; } @@ -133,15 +133,15 @@ void handleSwitch(uint8_t b) if (buttonLongPressed[b] == buttonPressedBefore[b]) return; if (millis() - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce) - DEBUG_PRINT(F("Switch: Activating ")); DEBUG_PRINTLN(b); + DEBUG_PRINTF_P(PSTR("Switch: Activating %u\n"), b); if (!buttonPressedBefore[b]) { // on -> off - DEBUG_PRINT(F("Switch: On -> Off ")); DEBUG_PRINTLN(b); + DEBUG_PRINTF_P(PSTR("Switch: On -> Off (%u)\n"), b); if (macroButton[b]) applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET); else { //turn on if (!bri) {toggleOnOff(); stateUpdated(CALL_MODE_BUTTON);} } } else { // off -> on - DEBUG_PRINT(F("Switch: Off -> On ")); DEBUG_PRINTLN(b); + DEBUG_PRINTF_P(PSTR("Switch: Off -> On (%u)\n"), b); if (macroLongPress[b]) applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET); else { //turn off if (bri) {toggleOnOff(); stateUpdated(CALL_MODE_BUTTON);} @@ -173,7 +173,7 @@ void handleAnalog(uint8_t b) static float filteredReading[WLED_MAX_BUTTONS] = {0.0f}; unsigned rawReading; // raw value from analogRead, scaled to 12bit - DEBUG_PRINT(F("Analog: Reading button ")); DEBUG_PRINTLN(b); + DEBUG_PRINTF_P(PSTR("Analog: Reading button %u\n"), b); #ifdef ESP8266 rawReading = analogRead(A0) << 2; // convert 10bit read to 12bit @@ -193,8 +193,8 @@ void handleAnalog(uint8_t b) // remove noise & reduce frequency of UI updates if (abs(int(aRead) - int(oldRead[b])) <= POT_SENSITIVITY) return; // no significant change in reading - DEBUG_PRINT(F("Analog: Raw = ")); DEBUG_PRINT(rawReading); - DEBUG_PRINT(F(" Filtered = ")); DEBUG_PRINTLN(aRead); + DEBUG_PRINTF_P(PSTR("Analog: Raw = %u\n"), rawReading); + DEBUG_PRINTF_P(PSTR(" Filtered = %u\n"), aRead); // Unomment the next lines if you still see flickering related to potentiometer // 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) // if no macro for "short press" and "long press" is defined use brightness control if (!macroButton[b] && !macroLongPress[b]) { - DEBUG_PRINT(F("Analog: Action = ")); DEBUG_PRINTLN(macroDoublePress[b]); + DEBUG_PRINTF_P(PSTR("Analog: Action = %u\n"), macroDoublePress[b]); // if "double press" macro defines which option to change if (macroDoublePress[b] >= 250) { // global brightness diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 89076efab..a6c3ab74d 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -277,9 +277,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { if ((buttonType[s] == BTN_TYPE_ANALOG) || (buttonType[s] == BTN_TYPE_ANALOG_INVERTED)) { if (digitalPinToAnalogChannel(btnPin[s]) < 0) { // not an ADC analog pin - DEBUG_PRINT(F("PIN ALLOC error: GPIO")); DEBUG_PRINT(btnPin[s]); - DEBUG_PRINT(F("for analog button #")); DEBUG_PRINT(s); - DEBUG_PRINTLN(F(" is not an analog pin!")); + DEBUG_PRINTF_P(PSTR("PIN ALLOC error: GPIO%d for analog button #%d is not an analog pin!\n"), btnPin[s], s); btnPin[s] = -1; pinManager.deallocatePin(pin,PinOwner::Button); } else { @@ -290,7 +288,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { { if (digitalPinToTouchChannel(btnPin[s]) < 0) { // not a touch pin - DEBUG_PRINTF_P(PSTR("PIN ALLOC error: GPIO%d for touch button #%d is not an touch pin!\n"), btnPin[s], s); + DEBUG_PRINTF_P(PSTR("PIN ALLOC error: GPIO%d for touch button #%d is not a touch pin!\n"), btnPin[s], s); btnPin[s] = -1; pinManager.deallocatePin(pin,PinOwner::Button); } diff --git a/wled00/e131.cpp b/wled00/e131.cpp index e28750db3..7c074759e 100644 --- a/wled00/e131.cpp +++ b/wled00/e131.cpp @@ -108,13 +108,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){ if (e131SkipOutOfSequence) if (seq < e131LastSequenceNumber[previousUniverses] && seq > 20 && e131LastSequenceNumber[previousUniverses] < 250){ - DEBUG_PRINT(F("skipping E1.31 frame (last seq=")); - DEBUG_PRINT(e131LastSequenceNumber[previousUniverses]); - DEBUG_PRINT(F(", current seq=")); - DEBUG_PRINT(seq); - DEBUG_PRINT(F(", universe=")); - DEBUG_PRINT(uni); - DEBUG_PRINTLN(")"); + DEBUG_PRINTF_P(PSTR("skipping E1.31 frame (last seq=%d, current seq=%d, universe=%d)\n"), e131LastSequenceNumber[previousUniverses], seq, uni); return; } e131LastSequenceNumber[previousUniverses] = seq; diff --git a/wled00/json.cpp b/wled00/json.cpp index 01acc7ba3..596bd780e 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -1144,11 +1144,8 @@ void serveJson(AsyncWebServerRequest* request) DEBUG_PRINTF_P(PSTR("JSON buffer size: %u for request: %d\n"), lDoc.memoryUsage(), subJson); - #ifdef WLED_DEBUG - size_t len = - #endif - response->setLength(); - DEBUG_PRINT(F("JSON content length: ")); DEBUG_PRINTLN(len); + [[maybe_unused]] size_t len = response->setLength(); + DEBUG_PRINTF_P(PSTR("JSON content length: %u\n"), len); request->send(response); } diff --git a/wled00/mqtt.cpp b/wled00/mqtt.cpp index 775a4fe58..833e6eb7d 100644 --- a/wled00/mqtt.cpp +++ b/wled00/mqtt.cpp @@ -55,8 +55,7 @@ static void onMqttConnect(bool sessionPresent) static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) { static char *payloadStr; - DEBUG_PRINT(F("MQTT msg: ")); - DEBUG_PRINTLN(topic); + DEBUG_PRINTF_P(PSTR("MQTT msg: %s\n"), topic); // paranoia check to avoid npe if no payload if (payload==nullptr) { diff --git a/wled00/ntp.cpp b/wled00/ntp.cpp index 056110a58..7b7dac96e 100644 --- a/wled00/ntp.cpp +++ b/wled00/ntp.cpp @@ -246,8 +246,7 @@ bool checkNTPResponse() } uint32_t ntpPacketReceivedTime = millis(); - DEBUG_PRINT(F("NTP recv, l=")); - DEBUG_PRINTLN(cb); + DEBUG_PRINTF_P(PSTR("NTP recv, l=%d\n"), cb); byte pbuf[NTP_PACKET_SIZE]; ntpUdp.read(pbuf, NTP_PACKET_SIZE); // read the packet into the buffer if (!isValidNtpResponse(pbuf)) return false; // verify we have a valid response to client @@ -493,7 +492,7 @@ void calculateSunriseAndSunset() { do { time_t theDay = localTime - retryCount * 86400; // one day back = 86400 seconds minUTC = getSunriseUTC(year(theDay), month(theDay), day(theDay), latitude, longitude, false); - DEBUG_PRINT(F("* sunrise (minutes from UTC) = ")); DEBUG_PRINTLN(minUTC); + DEBUG_PRINTF_P(PSTR("* sunrise (minutes from UTC) = %d\n"), minUTC); retryCount ++; } while ((abs(minUTC) > SUNSET_MAX) && (retryCount <= 3)); @@ -512,7 +511,7 @@ void calculateSunriseAndSunset() { do { time_t theDay = localTime - retryCount * 86400; // one day back = 86400 seconds minUTC = getSunriseUTC(year(theDay), month(theDay), day(theDay), latitude, longitude, true); - DEBUG_PRINT(F("* sunset (minutes from UTC) = ")); DEBUG_PRINTLN(minUTC); + DEBUG_PRINTF_P(PSTR("* sunset (minutes from UTC) = %d\n"), minUTC); retryCount ++; } while ((abs(minUTC) > SUNSET_MAX) && (retryCount <= 3)); diff --git a/wled00/presets.cpp b/wled00/presets.cpp index 2916d337a..20edfd91e 100644 --- a/wled00/presets.cpp +++ b/wled00/presets.cpp @@ -117,8 +117,7 @@ void initPresetsFile() bool applyPresetFromPlaylist(byte index) { - DEBUG_PRINT(F("Request to apply preset: ")); - DEBUG_PRINTLN(index); + DEBUG_PRINTF_P(PSTR("Request to apply preset: %d\n"), index); presetToApply = index; callModeToApply = CALL_MODE_DIRECT_CHANGE; return true; @@ -127,8 +126,7 @@ bool applyPresetFromPlaylist(byte index) bool applyPreset(byte index, byte callMode) { unloadPlaylist(); // applying a preset unloads the playlist (#3827) - DEBUG_PRINT(F("Request to apply preset: ")); - DEBUG_PRINTLN(index); + DEBUG_PRINTF_P(PSTR("Request to apply preset: %u\n"), index); presetToApply = index; callModeToApply = callMode; return true; @@ -163,8 +161,7 @@ void handlePresets() presetToApply = 0; //clear request for preset callModeToApply = 0; - DEBUG_PRINT(F("Applying preset: ")); - DEBUG_PRINTLN(tmpPreset); + DEBUG_PRINTF_P(PSTR("Applying preset: %u\n"), (unsigned)tmpPreset); #ifdef ARDUINO_ARCH_ESP32 if (tmpPreset==255 && tmpRAMbuffer!=nullptr) { @@ -222,7 +219,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj) else sprintf_P(saveName, PSTR("Preset %d"), index); } - DEBUG_PRINT(F("Saving preset (")); DEBUG_PRINT(index); DEBUG_PRINT(F(") ")); DEBUG_PRINTLN(saveName); + DEBUG_PRINTF_P(PSTR("Saving preset (%d) %s\n"), index, saveName); presetToSave = index; playlistSave = false; diff --git a/wled00/remote.cpp b/wled00/remote.cpp index 9d8b94df0..9bc5430c0 100644 --- a/wled00/remote.cpp +++ b/wled00/remote.cpp @@ -186,8 +186,7 @@ void handleRemote(uint8_t *incomingData, size_t len) { } if (len != sizeof(message_structure_t)) { - DEBUG_PRINT(F("Unknown incoming ESP Now message received of length ")); - DEBUG_PRINTLN(len); + DEBUG_PRINTF_P(PSTR("Unknown incoming ESP Now message received of length %u\n"), len); return; } diff --git a/wled00/set.cpp b/wled00/set.cpp index 2811d7088..7814e55d9 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -157,8 +157,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) char la[4] = "LA"; la[2] = offset+s; la[3] = 0; //LED mA char ma[4] = "MA"; ma[2] = offset+s; ma[3] = 0; //max mA if (!request->hasArg(lp)) { - DEBUG_PRINT(F("No data for ")); - DEBUG_PRINTLN(s); + DEBUG_PRINTF_P(PSTR("No data for %d\n"), s); break; } for (int i = 0; i < 5; i++) { @@ -729,7 +728,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) else subObj[name].add(value.toInt()); // we may have an int j++; } - DEBUG_PRINT(F("[")); DEBUG_PRINT(j); DEBUG_PRINT(F("] = ")); DEBUG_PRINTLN(value); + DEBUG_PRINTF_P(PSTR("[%d] = %s\n"), j, value.c_str()); } else { // we are using a hidden field with the same name as our parameter (!before the actual parameter!) // 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) } else if (type == "int") subObj[name] = value.toInt(); else subObj[name] = value; // text fields } - DEBUG_PRINT(F(" = ")); DEBUG_PRINTLN(value); + DEBUG_PRINTF_P(PSTR(" = %s\n"), value.c_str()); } } usermods.readFromConfig(um); // force change of usermod parameters @@ -809,8 +808,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply) if (!(req.indexOf("win") >= 0)) return false; int pos = 0; - DEBUG_PRINT(F("API req: ")); - DEBUG_PRINTLN(req); + DEBUG_PRINTF_P(PSTR("API req: %s\n"), req.c_str()); //segment select (sets main segment) pos = req.indexOf(F("SM=")); diff --git a/wled00/src/dependencies/toki/Toki.h b/wled00/src/dependencies/toki/Toki.h index e7f12a453..0e849d3c2 100644 --- a/wled00/src/dependencies/toki/Toki.h +++ b/wled00/src/dependencies/toki/Toki.h @@ -155,7 +155,7 @@ class Toki { return (tick == TickT::active); } - void printTime(const Time& t) { - Serial.printf_P(PSTR("%u,%03u\n"),t.sec,t.ms); + void printTime(const Time& t, Print &dest = Serial) { + dest.printf_P(PSTR("%u,%03u\n"),t.sec,t.ms); } }; \ No newline at end of file diff --git a/wled00/udp.cpp b/wled00/udp.cpp index c2221e2cf..d030b6655 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -213,7 +213,7 @@ void parseNotifyPacket(uint8_t *udpIn) { //compatibilityVersionByte: byte version = udpIn[11]; - DEBUG_PRINT(F("UDP packet version: ")); DEBUG_PRINTLN(version); + DEBUG_PRINTF_P(PSTR("UDP packet version: %d\n"), (int)version); // if we are not part of any sync group ignore message if (version < 9) { @@ -256,7 +256,7 @@ void parseNotifyPacket(uint8_t *udpIn) { if (applyEffects && currentPlaylist >= 0) unloadPlaylist(); if (version > 10 && (receiveSegmentOptions || receiveSegmentBounds)) { unsigned numSrcSegs = udpIn[39]; - DEBUG_PRINT(F("UDP segments: ")); DEBUG_PRINTLN(numSrcSegs); + DEBUG_PRINTF_P(PSTR("UDP segments: %d\n"), numSrcSegs); // are we syncing bounds and slave has more active segments than master? if (receiveSegmentBounds && numSrcSegs < strip.getActiveSegmentsNum()) { DEBUG_PRINTLN(F("Removing excessive segments.")); @@ -270,13 +270,13 @@ void parseNotifyPacket(uint8_t *udpIn) { for (size_t i = 0; i < numSrcSegs && i < strip.getMaxSegments(); i++) { unsigned ofs = 41 + i*udpIn[40]; //start of segment offset byte unsigned id = udpIn[0 +ofs]; - DEBUG_PRINT(F("UDP segment received: ")); DEBUG_PRINTLN(id); + DEBUG_PRINTF_P(PSTR("UDP segment received: %u\n"), id); if (id > strip.getSegmentsNum()) break; else if (id == strip.getSegmentsNum()) { if (receiveSegmentBounds && id < strip.getMaxSegments()) strip.appendSegment(); else break; } - DEBUG_PRINT(F("UDP segment check: ")); DEBUG_PRINTLN(id); + DEBUG_PRINTF_P(PSTR("UDP segment check: %u\n"), id); Segment& selseg = strip.getSegment(id); // if we are not syncing bounds skip unselected segments if (selseg.isActive() && !(selseg.isSelected() || receiveSegmentBounds)) continue; @@ -290,7 +290,7 @@ void parseNotifyPacket(uint8_t *udpIn) { id += inactiveSegs; // adjust id } } - DEBUG_PRINT(F("UDP segment processing: ")); DEBUG_PRINTLN(id); + DEBUG_PRINTF_P(PSTR("UDP segment processing: %u\n"), id); uint16_t start = (udpIn[1+ofs] << 8 | udpIn[2+ofs]); uint16_t stop = (udpIn[3+ofs] << 8 | udpIn[4+ofs]); @@ -307,14 +307,14 @@ void parseNotifyPacket(uint8_t *udpIn) { selseg.options = (selseg.options & 0x0071U) | (udpIn[9 +ofs] & 0x0E); // ignore selected, freeze, reset & transitional selseg.setOpacity(udpIn[10+ofs]); if (applyEffects) { - DEBUG_PRINT(F("Apply effect: ")); DEBUG_PRINTLN(id); + DEBUG_PRINTF_P(PSTR("Apply effect: %u\n"), id); selseg.setMode(udpIn[11+ofs]); selseg.speed = udpIn[12+ofs]; selseg.intensity = udpIn[13+ofs]; selseg.palette = udpIn[14+ofs]; } if (receiveNotificationColor || !someSel) { - DEBUG_PRINT(F("Apply color: ")); DEBUG_PRINTLN(id); + DEBUG_PRINTF_P(PSTR("Apply color: %u\n"), id); selseg.setColor(0, RGBW32(udpIn[15+ofs],udpIn[16+ofs],udpIn[17+ofs],udpIn[18+ofs])); selseg.setColor(1, RGBW32(udpIn[19+ofs],udpIn[20+ofs],udpIn[21+ofs],udpIn[22+ofs])); selseg.setColor(2, RGBW32(udpIn[23+ofs],udpIn[24+ofs],udpIn[25+ofs],udpIn[26+ofs])); @@ -324,10 +324,10 @@ void parseNotifyPacket(uint8_t *udpIn) { // when applying synced options ignore selected as it may be used as indicator of which segments to sync // freeze, reset should never be synced // LSB to MSB: select, reverse, on, mirror, freeze, reset, reverse_y, mirror_y, transpose, map1d2d (3), ssim (2), set (2) - DEBUG_PRINT(F("Apply options: ")); DEBUG_PRINTLN(id); + DEBUG_PRINTF_P(PSTR("Apply options: %u\n"), id); selseg.options = (selseg.options & 0b0000000000110001U) | (udpIn[28+ofs]<<8) | (udpIn[9 +ofs] & 0b11001110U); // ignore selected, freeze, reset if (applyEffects) { - DEBUG_PRINT(F("Apply sliders: ")); DEBUG_PRINTLN(id); + DEBUG_PRINTF_P(PSTR("Apply sliders: %u\n"), id); selseg.custom1 = udpIn[29+ofs]; selseg.custom2 = udpIn[30+ofs]; selseg.custom3 = udpIn[31+ofs] & 0x1F; @@ -561,7 +561,7 @@ void handleNotifications() //wled notifier, ignore if realtime packets active if (udpIn[0] == 0 && !realtimeMode && receiveGroups) { - DEBUG_PRINT(F("UDP notification from: ")); DEBUG_PRINTLN(notifierUdp.remoteIP()); + DEBUG_PRINTF_P(PSTR("UDP notification from: %d.%d.%d.%d\n"), notifierUdp.remoteIP()[0], notifierUdp.remoteIP()[1], notifierUdp.remoteIP()[2], notifierUdp.remoteIP()[3]); parseNotifyPacket(udpIn); return; } diff --git a/wled00/wled.cpp b/wled00/wled.cpp index a6143eee6..840c06bf7 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -159,7 +159,7 @@ void WLED::loop() if (millis() - heapTime > 15000) { uint32_t heap = ESP.getFreeHeap(); if (heap < MIN_HEAP_SIZE && lastHeap < MIN_HEAP_SIZE) { - DEBUG_PRINT(F("Heap too low! ")); DEBUG_PRINTLN(heap); + DEBUG_PRINTF_P(PSTR("Heap too low! %u\n"), heap); forceReconnect = true; strip.resetSegments(); // remove all but one segments from memory } else if (heap < MIN_HEAP_SIZE) { @@ -264,9 +264,9 @@ void WLED::loop() if (loopMillis > maxLoopMillis) maxLoopMillis = loopMillis; if (millis() - debugTime > 29999) { DEBUG_PRINTLN(F("---DEBUG INFO---")); - DEBUG_PRINT(F("Runtime: ")); DEBUG_PRINTLN(millis()); - DEBUG_PRINT(F("Unix time: ")); toki.printTime(toki.getTime()); - DEBUG_PRINT(F("Free heap: ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("Runtime: %u\n"), millis()); + DEBUG_PRINTF_P(PSTR("Unix time: %u,%03u\n"), toki.getTime().sec, toki.getTime().ms); + DEBUG_PRINTF_P(PSTR("Free heap: %u\n"), ESP.getFreeHeap()); #if defined(ARDUINO_ARCH_ESP32) if (psramFound()) { DEBUG_PRINTF_P(PSTR("PSRAM: %dkB/%dkB\n"), ESP.getFreePsram()/1024, ESP.getPsramSize()/1024); @@ -276,21 +276,21 @@ void WLED::loop() #endif DEBUG_PRINTF_P(PSTR("Wifi state: %d\n"), WiFi.status()); #ifndef WLED_DISABLE_ESPNOW - DEBUG_PRINT(F("ESP-NOW state: ")); DEBUG_PRINTLN(statusESPNow); + DEBUG_PRINTF_P(PSTR("ESP-NOW state: %u\n"), statusESPNow); #endif if (WiFi.status() != lastWifiState) { wifiStateChangedTime = millis(); } lastWifiState = WiFi.status(); - DEBUG_PRINT(F("State time: ")); DEBUG_PRINTLN(wifiStateChangedTime); - DEBUG_PRINT(F("NTP last sync: ")); DEBUG_PRINTLN(ntpLastSyncTime); - DEBUG_PRINT(F("Client IP: ")); DEBUG_PRINTLN(Network.localIP()); + DEBUG_PRINTF_P(PSTR("State time: %u\n"), wifiStateChangedTime); + DEBUG_PRINTF_P(PSTR("NTP last sync: %u\n"), ntpLastSyncTime); + DEBUG_PRINTF_P(PSTR("Client IP: %u.%u.%u.%u\n"), Network.localIP()[0], Network.localIP()[1], Network.localIP()[2], Network.localIP()[3]); if (loops > 0) { // avoid division by zero - DEBUG_PRINT(F("Loops/sec: ")); DEBUG_PRINTLN(loops / 30); - DEBUG_PRINT(F("Loop time[ms]: ")); DEBUG_PRINT(avgLoopMillis/loops); DEBUG_PRINT("/");DEBUG_PRINTLN(maxLoopMillis); - DEBUG_PRINT(F("UM time[ms]: ")); DEBUG_PRINT(avgUsermodMillis/loops); DEBUG_PRINT("/");DEBUG_PRINTLN(maxUsermodMillis); - DEBUG_PRINT(F("Strip time[ms]: ")); DEBUG_PRINT(avgStripMillis/loops); DEBUG_PRINT("/"); DEBUG_PRINTLN(maxStripMillis); + DEBUG_PRINTF_P(PSTR("Loops/sec: %u\n"), loops / 30); + DEBUG_PRINTF_P(PSTR("Loop time[ms]: %u/%u\n"), avgLoopMillis/loops, maxLoopMillis); + DEBUG_PRINTF_P(PSTR("UM time[ms]: %u/%u\n"), avgUsermodMillis/loops, maxUsermodMillis); + DEBUG_PRINTF_P(PSTR("Strip time[ms]:%u/%u\n"), avgStripMillis/loops, maxStripMillis); } strip.printSize(); loops = 0; @@ -358,45 +358,38 @@ void WLED::setup() Serial.setDebugOutput(false); // switch off kernel messages when using USBCDC #endif DEBUG_PRINTLN(); - DEBUG_PRINT(F("---WLED ")); - DEBUG_PRINT(versionString); - DEBUG_PRINT(F(" ")); - DEBUG_PRINT(VERSION); - DEBUG_PRINTLN(F(" INIT---")); + DEBUG_PRINTF_P(PSTR("---WLED %s %u INIT---\n"), versionString, VERSION); + DEBUG_PRINTLN(); #ifdef ARDUINO_ARCH_ESP32 - DEBUG_PRINT(F("esp32 ")); - DEBUG_PRINTLN(ESP.getSdkVersion()); + DEBUG_PRINTF_P(PSTR("esp32 %s\n"), ESP.getSdkVersion()); #if defined(ESP_ARDUINO_VERSION) - //DEBUG_PRINTF_P(PSTR("arduino-esp32 0x%06x\n"), ESP_ARDUINO_VERSION); - DEBUG_PRINTF_P(PSTR("arduino-esp32 v%d.%d.%d\n"), int(ESP_ARDUINO_VERSION_MAJOR), int(ESP_ARDUINO_VERSION_MINOR), int(ESP_ARDUINO_VERSION_PATCH)); // availeable since v2.0.0 + DEBUG_PRINTF_P(PSTR("arduino-esp32 v%d.%d.%d\n"), int(ESP_ARDUINO_VERSION_MAJOR), int(ESP_ARDUINO_VERSION_MINOR), int(ESP_ARDUINO_VERSION_PATCH)); // available since v2.0.0 #else DEBUG_PRINTLN(F("arduino-esp32 v1.0.x\n")); // we can't say in more detail. #endif - DEBUG_PRINT(F("CPU: ")); DEBUG_PRINT(ESP.getChipModel()); - DEBUG_PRINT(F(" rev.")); DEBUG_PRINT(ESP.getChipRevision()); - DEBUG_PRINT(F(", ")); DEBUG_PRINT(ESP.getChipCores()); DEBUG_PRINT(F(" core(s)")); - DEBUG_PRINT(F(", ")); DEBUG_PRINT(ESP.getCpuFreqMHz()); DEBUG_PRINTLN(F("MHz.")); - DEBUG_PRINT(F("FLASH: ")); DEBUG_PRINT((ESP.getFlashChipSize()/1024)/1024); - DEBUG_PRINT(F("MB, Mode ")); DEBUG_PRINT(ESP.getFlashChipMode()); + DEBUG_PRINTF_P(PSTR("CPU: "), ESP.getChipModel()); + DEBUG_PRINTF_P(PSTR(" rev."), ESP.getChipRevision()); + DEBUG_PRINTF_P(PSTR(", %d core(s)"), ESP.getChipCores()); + DEBUG_PRINTF_P(PSTR(", %d MHz.\n"), ESP.getCpuFreqMHz()); + DEBUG_PRINTF_P(PSTR("FLASH: %dMB, Mode %d "), (ESP.getFlashChipSize()/1024)/1024, ESP.getFlashChipMode()); #ifdef WLED_DEBUG switch (ESP.getFlashChipMode()) { // missing: Octal modes - case FM_QIO: DEBUG_PRINT(F(" (QIO)")); break; - case FM_QOUT: DEBUG_PRINT(F(" (QOUT)"));break; - case FM_DIO: DEBUG_PRINT(F(" (DIO)")); break; - case FM_DOUT: DEBUG_PRINT(F(" (DOUT)"));break; + case FM_QIO: DEBUG_PRINT(F("(QIO)")); break; + case FM_QOUT: DEBUG_PRINT(F("(QOUT)"));break; + case FM_DIO: DEBUG_PRINT(F("(DIO)")); break; + case FM_DOUT: DEBUG_PRINT(F("(DOUT)"));break; default: break; } #endif - DEBUG_PRINT(F(", speed ")); DEBUG_PRINT(ESP.getFlashChipSpeed()/1000000);DEBUG_PRINTLN(F("MHz.")); + DEBUG_PRINTF_P(PSTR(", speed %u MHz.\n"), ESP.getFlashChipSpeed()/1000000); #else - DEBUG_PRINT(F("esp8266 @ ")); DEBUG_PRINT(ESP.getCpuFreqMHz()); DEBUG_PRINT(F("MHz.\nCore: ")); - DEBUG_PRINTLN(ESP.getCoreVersion()); - DEBUG_PRINT(F("FLASH: ")); DEBUG_PRINT((ESP.getFlashChipSize()/1024)/1024); DEBUG_PRINTLN(F(" MB")); + DEBUG_PRINTF_P(PSTR("esp8266 @ %u MHz.\nCore: %s\n"), ESP.getCpuFreqMHz(), ESP.getCoreVersion()); + DEBUG_PRINTF_P(PSTR("FLASH: %u MB\n"), (ESP.getFlashChipSize()/1024)/1024); #endif - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("heap %u\n"), ESP.getFreeHeap()); #if defined(ARDUINO_ARCH_ESP32) // BOARD_HAS_PSRAM also means that a compiler flag "-mfix-esp32-psram-cache-issue" was used and so PSRAM is safe to use on rev.1 ESP32 @@ -405,7 +398,7 @@ void WLED::setup() if (!psramSafe) DEBUG_PRINTLN(F("Not using PSRAM.")); #endif pDoc = new PSRAMDynamicJsonDocument((psramSafe && psramFound() ? 2 : 1)*JSON_BUFFER_SIZE); - DEBUG_PRINT(F("JSON buffer allocated: ")); DEBUG_PRINTLN((psramSafe && psramFound() ? 2 : 1)*JSON_BUFFER_SIZE); + DEBUG_PRINTF_P(PSTR("JSON buffer allocated: %u\n"), (psramSafe && psramFound() ? 2 : 1)*JSON_BUFFER_SIZE); // if the above fails requestJsonBufferLock() will always return false preventing crashes if (psramFound()) { DEBUG_PRINTF_P(PSTR("PSRAM: %dkB/%dkB\n"), ESP.getFreePsram()/1024, ESP.getPsramSize()/1024); @@ -427,7 +420,7 @@ void WLED::setup() DEBUG_PRINTLN(F("Registering usermods ...")); registerUsermods(); - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("heap %u\n"), ESP.getFreeHeap()); bool fsinit = false; DEBUGFS_PRINTLN(F("Mount FS")); @@ -457,7 +450,7 @@ void WLED::setup() DEBUG_PRINTLN(F("Reading config")); deserializeConfigFromFS(); - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("heap %u\n"), ESP.getFreeHeap()); #if defined(STATUSLED) && STATUSLED>=0 if (!pinManager.isPinAllocated(STATUSLED)) { @@ -469,12 +462,12 @@ void WLED::setup() DEBUG_PRINTLN(F("Initializing strip")); beginStrip(); - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("heap %u\n"), ESP.getFreeHeap()); DEBUG_PRINTLN(F("Usermods setup")); userSetup(); usermods.setup(); - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("heap %u\n"), ESP.getFreeHeap()); if (strcmp(multiWiFi[0].clientSSID, DEFAULT_CLIENT_SSID) == 0) showWelcomePage = true; @@ -537,13 +530,13 @@ void WLED::setup() // HTTP server page init DEBUG_PRINTLN(F("initServer")); initServer(); - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("heap %u\n"), ESP.getFreeHeap()); #ifndef WLED_DISABLE_INFRARED // init IR DEBUG_PRINTLN(F("initIR")); initIR(); - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("heap %u\n"), ESP.getFreeHeap()); #endif // Seed FastLED random functions with an esp random value, which already works properly at this point. @@ -654,11 +647,11 @@ bool WLED::initEthernet() return false; } if (ethernetType >= WLED_NUM_ETH_TYPES) { - DEBUG_PRINT(F("initE: Ignoring attempt for invalid ethernetType ")); DEBUG_PRINTLN(ethernetType); + DEBUG_PRINTF_P(PSTR("initE: Ignoring attempt for invalid ethernetType (%d)\n"), ethernetType); return false; } - DEBUG_PRINT(F("initE: Attempting ETH config: ")); DEBUG_PRINTLN(ethernetType); + DEBUG_PRINTF_P(PSTR("initE: Attempting ETH config: %d\n"), ethernetType); // Ethernet initialization should only succeed once -- else reboot required ethernet_settings es = ethernetBoards[ethernetType]; @@ -689,9 +682,7 @@ bool WLED::initEthernet() pinsToAllocate[9].pin = 17; pinsToAllocate[9].isOutput = true; } else { - DEBUG_PRINT(F("initE: Failing due to invalid eth_clk_mode (")); - DEBUG_PRINT(es.eth_clk_mode); - DEBUG_PRINTLN(")"); + DEBUG_PRINTF_P(PSTR("initE: Failing due to invalid eth_clk_mode (%d)\n"), es.eth_clk_mode); return false; } diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index d184e9878..291f6f5fc 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -163,8 +163,7 @@ static void handleUpload(AsyncWebServerRequest *request, const String& filename, } request->_tempFile = WLED_FS.open(finalname, "w"); - DEBUG_PRINT(F("Uploading ")); - DEBUG_PRINTLN(finalname); + DEBUG_PRINTF_P(PSTR("Uploading %s\n"), finalname.c_str()); if (finalname.equals(FPSTR(getPresetsFileName()))) presetsModifiedTime = toki.second(); } if (len) { @@ -466,7 +465,7 @@ void initServer() //called when the url is not defined here, ajax-in; get-settings server.onNotFound([](AsyncWebServerRequest *request){ - DEBUG_PRINT(F("Not-Found HTTP call: ")); DEBUG_PRINTLN(request->url()); + DEBUG_PRINTF_P(PSTR("Not-Found HTTP call: %s\n"), request->url().c_str()); if (captivePortal(request)) return; //make API CORS compatible diff --git a/wled00/ws.cpp b/wled00/ws.cpp index 3dec548f4..45640b68c 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -125,7 +125,7 @@ void sendDataWs(AsyncWebSocketClient * client) // the following may no longer be necessary as heap management has been fixed by @willmmiles in AWS size_t heap1 = ESP.getFreeHeap(); - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("heap %u\n"), ESP.getFreeHeap()); #ifdef ESP8266 if (len>heap1) { DEBUG_PRINTLN(F("Out of memory (WS)!")); @@ -135,7 +135,7 @@ void sendDataWs(AsyncWebSocketClient * client) AsyncWebSocketBuffer buffer(len); #ifdef ESP8266 size_t heap2 = ESP.getFreeHeap(); - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); + DEBUG_PRINTF_P(PSTR("heap %u\n"), ESP.getFreeHeap()); #else size_t heap2 = 0; // ESP32 variants do not have the same issue and will work without checking heap allocation #endif @@ -150,11 +150,11 @@ void sendDataWs(AsyncWebSocketClient * client) DEBUG_PRINT(F("Sending WS data ")); if (client) { - client->text(std::move(buffer)); DEBUG_PRINTLN(F("to a single client.")); + client->text(std::move(buffer)); } else { - ws.textAll(std::move(buffer)); DEBUG_PRINTLN(F("to multiple clients.")); + ws.textAll(std::move(buffer)); } releaseJSONBufferLock(); diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 25c0c6298..6c3ee83dc 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -224,8 +224,7 @@ void appendGPIOinfo() { void getSettingsJS(byte subPage, char* dest) { //0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec - DEBUG_PRINT(F("settings resp")); - DEBUG_PRINTLN(subPage); + DEBUG_PRINTF_P(PSTR("settings resp %u\n"), (unsigned)subPage); obuf = dest; olen = 0;