update for usermessages

wled.h:
- Don't use Serial directly -S2 as S2 serial driver is buggy.
- added USER_FLUSH macro
wled.cpp
- replace fluh with FLUSH
- print ArduionoOTA info (if enabled)
wled_server.cpp:
- added userlog info after file upload.
pinn_manager:
- don't show "(default)" is the PIN is actually assigned to HW drivers
- bugfix for getPinOwner()
This commit is contained in:
Frank
2022-12-05 12:48:03 +01:00
parent 6a96963ab1
commit 58688d25ae
4 changed files with 37 additions and 11 deletions

View File

@@ -89,12 +89,16 @@ String PinManagerClass::getPinSpecialText(int gpio) { // special purpose PIN in
#endif
#endif
// hardware special purpose PINS. part1
// hardware special purpose PINS. part1 - assigned pins
if (gpio == hardwareTX) return(F("Serial TX")); // Serial (debug monitor) TX pin (usually GPIO1)
if (gpio == hardwareRX) return(F("Serial RX")); // Serial (debug monitor) RX pin (usually GPIO3)
if ((gpio == i2c_sda) || ((gpio == HW_PIN_SDA) && (i2c_sda < 0))) return(F("(default) I2C SDA"));
if ((gpio == i2c_scl) || ((gpio == HW_PIN_SCL) && (i2c_scl < 0))) return(F("(default) I2C SCL"));
if (isPinAllocated(gpio)) {
if ((gpio == i2c_sda) && (getPinOwner(gpio) == PinOwner::HW_I2C)) return(F("I2C SDA"));
if ((gpio == i2c_scl) && (getPinOwner(gpio) == PinOwner::HW_I2C)) return(F("I2C SCL"));
if ((gpio == spi_sclk) && (getPinOwner(gpio) == PinOwner::HW_SPI)) return(F("SPI SLK / SCK"));
if ((gpio == spi_mosi) && (getPinOwner(gpio) == PinOwner::HW_SPI)) return(F("SPI PICO / MOSI"));
if ((gpio == spi_miso) && (getPinOwner(gpio) == PinOwner::HW_SPI)) return(F("SPI POCI / MISO"));
}
// MCU special PINS
#ifdef ARDUINO_ARCH_ESP32
#if defined(CONFIG_IDF_TARGET_ESP32S3)
@@ -138,7 +142,9 @@ String PinManagerClass::getPinSpecialText(int gpio) { // special purpose PIN in
if (gpio == STATUSLED) return(F("WLED Status LED"));
#endif
// hardware special purpose PINS. part2
// hardware special purpose PINS. part2 - default pins
if ((gpio == i2c_sda) || ((gpio == HW_PIN_SDA) && (i2c_sda < 0))) return(F("(default) I2C SDA"));
if ((gpio == i2c_scl) || ((gpio == HW_PIN_SCL) && (i2c_scl < 0))) return(F("(default) I2C SCL"));
if ((gpio == spi_sclk) || ((gpio == HW_PIN_CLOCKSPI) && (spi_sclk < 0))) return(F("(default) SPI SLK / SCK"));
if ((gpio == spi_mosi) || ((gpio == HW_PIN_DATASPI) && (spi_mosi < 0))) return(F("(default) SPI PICO / MOSI"));
if ((gpio == spi_miso) || ((gpio == HW_PIN_MISOSPI) && (spi_miso < 0))) return(F("(default) SPI POCI / MISO"));
@@ -490,6 +496,7 @@ bool PinManagerClass::isPinOk(byte gpio, bool output)
PinOwner PinManagerClass::getPinOwner(byte gpio) {
if (!isPinOk(gpio, false)) return PinOwner::None;
if (gpio >= WLED_NUM_PINS) return PinOwner::None; // WLEDMM: catch error cases
return ownerTag[gpio];
}

View File

@@ -32,8 +32,8 @@ void WLED::reset()
yield(); // enough time to send response to client
}
applyBri();
USER_PRINTLN(F("WLED RESET"));
if (canUseSerial()) Serial.flush(); // WLEDMM: wait until Serial has completed sending its buffer
USER_PRINTLN(F("\nWLED RESTART\n"));
USER_FLUSH(); // WLEDMM: wait until Serial has completed sending buffered data
ESP.restart();
}
@@ -280,6 +280,8 @@ void WLED::setup()
#if defined(WLED_DEBUG) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3))
delay(2500); // allow CDC USB serial to initialise
#endif
//Serial.setDebugOutput(true);
USER_FLUSH(); delay(100);
USER_PRINTLN();
USER_PRINT(F("---WLED "));
USER_PRINT(versionString);
@@ -351,6 +353,7 @@ void WLED::setup()
//DEBUG_PRINT(F("LEDs inited. heap usage ~"));
//DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap());
USER_FLUSH(); // WLEDMM flush buffer now, before anything time-critial is started.
#ifdef WLED_DEBUG
pinManager.allocatePin(hardwareTX, true, PinOwner::DebugOut); // TX (GPIO1 on ESP32) reserved for debug output
@@ -492,7 +495,7 @@ void WLED::setup()
pinManager.getPinConflicts(pinNr).c_str(),
pinManager.getPinSpecialText(pinNr).c_str()
);
if (canUseSerial()) Serial.flush(); // avoid lost lines (buffer overflow?)
USER_FLUSH(); // avoid lost lines (Serial buffer overflow)
}
}
USER_PRINTLN(F("WLED initialization done.\n"));
@@ -768,6 +771,13 @@ void WLED::initInterfaces()
initMqtt();
interfacesInited = true;
wasConnected = true;
#ifndef WLED_DISABLE_OTA // WLEDMM
if (aOtaEnabled) {
USER_PRINT(F(" ArduinoOTA: "));
USER_PRINTLN(ArduinoOTA.getHostname());
}
#endif // WLEDMM end
}
void WLED::handleConnection()

View File

@@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2212043
#define VERSION 2212051
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG
@@ -716,16 +716,23 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
#endif
// WLEDMM: macros to print "user messages" to Serial
#ifdef WLED_DEBUG
// cannot do this on -S2, due to buggy USBCDC serial driver
#if defined(WLED_DEBUG) || defined(WLED_DEBUG_HOST) || defined(CONFIG_IDF_TARGET_ESP32S2)
// use DEBUG_PRINT
#define USER_PRINT(x) DEBUG_PRINT(x)
#define USER_PRINTLN(x) DEBUG_PRINTLN(x)
#define USER_PRINTF(x...) DEBUG_PRINTF(x)
#ifdef WLED_DEBUG_HOST
#define USER_FLUSH() {}
#else
#define USER_FLUSH() {DEBUGOUT.flush();}
#endif
#else
// check if serial is availeable, then use Serial.print directly
// if serial is availeable, we use Serial.print directly
#define USER_PRINT(x) { if (canUseSerial()) Serial.print(x); }
#define USER_PRINTLN(x) { if (canUseSerial()) Serial.println(x); }
#define USER_PRINTF(x...) { if (canUseSerial()) Serial.printf(x); }
#define USER_FLUSH() {Serial.flush();}
#endif
// WLEDMM end

View File

@@ -52,6 +52,8 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t
}
if (final) {
request->_tempFile.close();
USER_PRINT(F("File uploaded: ")); // WLEDMM
USER_PRINTLN(filename); // WLEDMM
if (filename.equalsIgnoreCase("/cfg.json") || filename.equalsIgnoreCase("cfg.json")) { // WLEDMM
request->send(200, "text/plain", F("Configuration restore successful.\nRebooting..."));
doReboot = true;