use Serial.print for important info like wifi stuff

.. and for other important info.
Will be muted automatically in case that serial is in used for other purposes.
This commit is contained in:
Frank
2022-12-04 17:52:10 +01:00
parent 1a9a1cbbbe
commit 676cc26171
10 changed files with 93 additions and 41 deletions

View File

@@ -164,7 +164,7 @@ class UsermodTemperature : public Usermod {
temperature = -127.0f; // default to -127, DS18B20 only goes down to -50C
if (enabled) {
// config says we are enabled
DEBUG_PRINTLN(F("Allocating temperature pin..."));
USER_PRINTLN(F("Finding temperature pin..."));
// pin retrieved from cfg.json (readFromConfig()) prior to running setup()
if (temperaturePin >= 0 && pinManager.allocatePin(temperaturePin, true, PinOwner::UM_Temperature)) {
oneWire = new OneWire(temperaturePin);
@@ -175,13 +175,14 @@ class UsermodTemperature : public Usermod {
}
} else {
if (temperaturePin >= 0) {
DEBUG_PRINTLN(F("Temperature pin allocation failed."));
USER_PRINTLN(F("Temperature pin allocation failed."));
}
temperaturePin = -1; // allocation failed
}
}
lastMeasurement = millis() - readingInterval + 10000;
initDone = true;
USER_PRINTLN(F("temperature usermod initialized."));
}
void loop() {

View File

@@ -1302,9 +1302,11 @@ class AudioReactive : public Usermod {
#ifdef WLED_DEBUG
DEBUG_PRINTLN(F("AR: Failed to initialize sound input driver. Please check input PIN settings."));
#else
ERRORSR_PRINTLN(F("AR: Failed to initialize sound input driver. Please check input PIN settings."));
USER_PRINTLN(F("AR: Failed to initialize sound input driver. Please check input PIN settings."));
#endif
disableSoundProcessing = true;
} else {
USER_PRINTLN(F("AR: sound input driver initialized successfully."));
}
if (enabled) connectUDPSoundSync();

View File

@@ -177,9 +177,9 @@ class FourLineDisplayUsermod : public Usermod {
isHW = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda);
//isHW = true;
if (isHW) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
if (ioPin[0] < 0 || ioPin[1] < 0) { type=NONE; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
if (ioPin[0] < 0 || ioPin[1] < 0) { type=NONE; enabled = false; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } };
if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; return; }
if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; enabled = false; return; }
}
DEBUG_PRINTLN(F("Allocating display."));
@@ -224,14 +224,14 @@ class FourLineDisplayUsermod : public Usermod {
}
if (nullptr == u8x8) {
DEBUG_PRINTLN(F("Display init failed."));
USER_PRINTLN(F("Display init failed."));
pinManager.deallocateMultiplePins((const uint8_t*)ioPin, (type == SSD1306_SPI || type == SSD1306_SPI64) ? 5 : 2, po);
type = NONE;
return;
}
initDone = true;
DEBUG_PRINTLN(F("Starting display."));
USER_PRINTLN(F("Starting display."));
/*if (!(type == SSD1306_SPI || type == SSD1306_SPI64))*/ u8x8->setBusClock(ioFrequency); // can be used for SPI too
u8x8->begin();
setFlipMode(flip);

View File

@@ -339,8 +339,8 @@ class FourLineDisplayUsermod : public Usermod {
// isHW = true;
if (isHW) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
PinManagerPinType pins[2] = { {ioPin[0], true }, { ioPin[1], true } };
if (ioPin[0] < 0 || ioPin[1] < 0) { type=NONE; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; return; }
if (ioPin[0] < 0 || ioPin[1] < 0) { type=NONE; enabled=false; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; enabled=false; return; }
}
DEBUG_PRINTLN(F("Allocating display."));
@@ -418,14 +418,14 @@ class FourLineDisplayUsermod : public Usermod {
}
if (nullptr == u8x8) {
DEBUG_PRINTLN(F("Display init failed."));
USER_PRINTLN(F("Display init failed."));
pinManager.deallocateMultiplePins((const uint8_t*)ioPin, isSPI ? 5 : 2, po);
type = NONE;
return;
}
lineHeight = u8x8->getRows() > 4 ? 2 : 1;
DEBUG_PRINTLN(F("Starting display."));
USER_PRINTLN(F("Starting display."));
u8x8->setBusClock(ioFrequency); // can be used for SPI too
u8x8->begin();
setFlipMode(flip);

View File

@@ -369,6 +369,7 @@ void clearEEPROM();
//wled_serial.cpp
void handleSerial();
void updateBaudRate(uint32_t rate);
bool canUseSerial(void); // WLEDMM returns true if Serial can be used for debug output (i.e. not configured for other purpose)
//wled_server.cpp
bool isIp(String str);

View File

@@ -300,6 +300,8 @@ bool PinManagerClass::allocateMultiplePins(const managed_pin_type * mptArray, by
DEBUG_PRINT(gpio);
DEBUG_PRINT(" as "); DEBUG_PRINT(mptArray[i].isOutput ? "output": "input"); // WLEDMM
DEBUG_PRINTLN(F(""));
#else // WLEDMM
USER_PRINTF("PIN ALLOC: cannot use GPIO%d for %s.\n", gpio, mptArray[i].isOutput ? "output": "input");
#endif
if ((gpio < WLED_NUM_PINS) && (gpio >= 0) && (tag != PinOwner::None)) {
ownerConflict[gpio] = tag; // WLEDMM record conflict
@@ -317,6 +319,8 @@ bool PinManagerClass::allocateMultiplePins(const managed_pin_type * mptArray, by
DEBUG_PRINT(F(" already allocated by "));
DebugPrintOwnerTag(ownerTag[gpio]);
DEBUG_PRINTLN(F(""));
#else // WLEDMM
USER_PRINTF("PIN ALLOC: failed to assign GPIO%d to %s.\n", gpio, getOwnerText(tag).c_str());
#endif
shouldFail = true;
}
@@ -375,6 +379,10 @@ bool PinManagerClass::allocatePin(byte gpio, bool output, PinOwner tag)
DEBUG_PRINTLN(F(" - HW I2C & SPI pins have to be allocated using allocateMultiplePins()"));
}
}
#else // WLEDMM
if (gpio < 255) {
USER_PRINTF("PIN ALLOC: cannot use GPIO%d for %s.\n", gpio, output ? "output": "input");
}
#endif
return false;
}
@@ -386,6 +394,8 @@ bool PinManagerClass::allocatePin(byte gpio, bool output, PinOwner tag)
DEBUG_PRINT(F(" already allocated by "));
DebugPrintOwnerTag(ownerTag[gpio]);
DEBUG_PRINTLN(F(""));
#else // WLEDMM
USER_PRINTF("PIN ALLOC: failed to assign GPIO%d to %s.\n", gpio, getOwnerText(tag).c_str());
#endif
return false;
}

View File

@@ -171,7 +171,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
#ifdef ESP32
if (((buttonType[i] == BTN_TYPE_ANALOG) || (buttonType[i] == BTN_TYPE_ANALOG_INVERTED)) && (digitalPinToAnalogChannel(btnPin[i]) < 0)) { // WLEDMM
// not an ADC analog pin
DEBUG_PRINTF("PIN ALLOC error: GPIO%d for analog button #%d is not an analog pin!\n", btnPin[i], i);
USER_PRINTF("PIN ALLOC error: GPIO%d for analog button #%d is not an analog pin!\n", btnPin[i], i);
btnPin[i] = -1;
pinManager.deallocatePin(hw_btn_pin,PinOwner::Button);
} else { // WLEDMM end

View File

@@ -279,12 +279,16 @@ 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
DEBUG_PRINTLN();
DEBUG_PRINT(F("---WLED "));
DEBUG_PRINT(versionString);
DEBUG_PRINT(" ");
DEBUG_PRINT(VERSION);
DEBUG_PRINTLN(F(" INIT---"));
USER_PRINTLN();
USER_PRINT(F("---WLED "));
USER_PRINT(versionString);
USER_PRINT(" ");
USER_PRINT(VERSION);
USER_PRINTLN(F(" INIT---"));
#ifdef WLED_RELEASE_NAME
USER_PRINTF("WLEDMM_%s %s\n", versionString, releaseString); // WLEDMM specific
#endif
#ifdef ARDUINO_ARCH_ESP32
DEBUG_PRINT(F("esp32 "));
DEBUG_PRINTLN(ESP.getSdkVersion());
@@ -354,20 +358,21 @@ void WLED::setup()
pinManager.allocatePin(2, true, PinOwner::DMX);
#endif
USER_PRINTLN();
DEBUG_PRINTLN(F("Registering usermods ..."));
registerUsermods();
for (uint8_t i=1; i<WLED_MAX_BUTTONS; i++) btnPin[i] = -1;
bool fsinit = false;
DEBUGFS_PRINTLN(F("Mount FS"));
DEBUG_PRINTLN(F("Mount FS"));
#ifdef ARDUINO_ARCH_ESP32
fsinit = WLED_FS.begin(true);
#else
fsinit = WLED_FS.begin();
#endif
if (!fsinit) {
DEBUGFS_PRINTLN(F("FS failed!"));
DEBUG_PRINTLN(F("FS failed!"));
errorFlag = ERR_FS_BEGIN;
}
#ifdef WLED_ADD_EEPROM_SUPPORT
@@ -398,7 +403,7 @@ void WLED::setup()
DEBUG_PRINTLN(F("Initializing strip"));
beginStrip();
DEBUG_PRINTLN(F("Usermods setup"));
USER_PRINTLN(F("Usermods setup ..."));
userSetup();
usermods.setup();
@@ -472,15 +477,14 @@ void WLED::setup()
#endif
// WLEDMM : dump GPIO infos (experimental, UI integration pending)
#ifdef WLED_DEBUG
Serial.println(F("WLED initialization completed."));
Serial.println(F("\nGPIO\t| Assigned to\t\t| Info"));
Serial.println(F("--------|-----------------------|------------"));
//#ifdef WLED_DEBUG
USER_PRINTLN(F("\nGPIO\t| Assigned to\t\t| Info"));
USER_PRINTLN(F("--------|-----------------------|------------"));
for(int pinNr = 0; pinNr < WLED_NUM_PINS; pinNr++) { // 49 = highest PIN on ESP32-S3
if(pinManager.isPinOk(pinNr, false)) {
if ((!pinManager.isPinAllocated(pinNr)) && (pinManager.getPinSpecialText(pinNr).length() == 0)) continue; // comment out to include no-name,unused GPIO pins
//if ((!pinManager.isPinAllocated(pinNr)) && (pinManager.getPinSpecialText(pinNr).length() == 0)) continue; // un-comment to hide no-name,unused GPIO pins
bool is_inOut = pinManager.isPinOk(pinNr, true);
Serial.printf("%s %2d\t %-17s %s\t %s\n",
USER_PRINTF("%s %2d\t %-17s %s\t %s\n",
(is_inOut?"i/o":"in "),
pinNr,
pinManager.getPinOwnerText(pinNr).c_str(),
@@ -489,8 +493,16 @@ void WLED::setup()
);
}
}
Serial.println();
USER_PRINTLN(F("WLED initialization done.\n"));
delay(50);
// repeat Ada prompt
#ifdef WLED_ENABLE_ADALIGHT
if (!pinManager.isPinAllocated(hardwareRX) && !pinManager.isPinAllocated(hardwareTX)) {
Serial.println(F("Ada"));
}
#endif
//#endif
// WLEDMM end
}
@@ -527,8 +539,8 @@ void WLED::initAP(bool resetAP)
WLED_SET_AP_SSID();
strcpy_P(apPass, PSTR(WLED_AP_PASS));
}
DEBUG_PRINT(F("Opening access point "));
DEBUG_PRINTLN(apSSID);
USER_PRINT(F("Opening access point ")); // WLEDMM
USER_PRINTLN(apSSID); // WLEDMM
WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0));
WiFi.softAP(apSSID, apPass, apChannel, apHide);
@@ -631,7 +643,7 @@ bool WLED::initEthernet()
}
successfullyConfiguredEthernet = true;
DEBUG_PRINTLN(F("initC: *** Ethernet successfully configured! ***"));
USER_PRINTLN(F("initC: *** Ethernet successfully configured! ***")); // WLEDMM
return true;
#else
return false; // Ethernet not enabled for build
@@ -660,7 +672,7 @@ void WLED::initConnection()
lastReconnectAttempt = millis();
if (!WLED_WIFI_CONFIGURED) {
DEBUG_PRINTLN(F("No connection configured."));
USER_PRINTLN(F("No WiFi connection configured.")); // WLEDMM
if (!apActive) initAP(); // instantly go to ap mode
return;
} else if (!apActive) {
@@ -675,9 +687,9 @@ void WLED::initConnection()
}
showWelcomePage = false;
DEBUG_PRINT(F("Connecting to "));
DEBUG_PRINT(clientSSID);
DEBUG_PRINTLN("...");
USER_PRINT(F("Connecting to "));
USER_PRINT(clientSSID);
USER_PRINTLN("...");
// convert the "serverDescription" into a valid DNS hostname (alphanumeric)
char hostname[25];
@@ -728,7 +740,7 @@ void WLED::initInterfaces()
MDNS.end();
MDNS.begin(cmDNS);
DEBUG_PRINTLN(F("mDNS started"));
USER_PRINTLN(F("mDNS started."));
MDNS.addService("http", "tcp", 80);
MDNS.addService("wled", "tcp", 80);
MDNS.addServiceTxt("wled", "tcp", "mac", escapedMac.c_str());
@@ -807,7 +819,7 @@ void WLED::handleConnection()
}
}
if (forceReconnect) {
DEBUG_PRINTLN(F("Forcing reconnect."));
USER_PRINTLN(F("Forcing reconnect."));
initConnection();
interfacesInited = false;
forceReconnect = false;
@@ -816,7 +828,7 @@ void WLED::handleConnection()
}
if (!Network.isConnected()) {
if (interfacesInited) {
DEBUG_PRINTLN(F("Disconnected!"));
USER_PRINTLN(F("Disconnected!"));
interfacesInited = false;
initConnection();
}
@@ -836,8 +848,8 @@ void WLED::handleConnection()
}
} else if (!interfacesInited) { //newly connected
DEBUG_PRINTLN("");
DEBUG_PRINT(F("Connected! IP address: "));
DEBUG_PRINTLN(Network.localIP());
USER_PRINT(F("Connected! IP address: "));
USER_PRINTLN(Network.localIP());
if (improvActive) {
if (improvError == 3) sendImprovStateResponse(0x00, true);
sendImprovStateResponse(0x04);
@@ -853,7 +865,7 @@ void WLED::handleConnection()
dnsServer.stop();
WiFi.softAPdisconnect(true);
apActive = false;
DEBUG_PRINTLN(F("Access point disabled (handle)."));
USER_PRINTLN(F("Access point disabled (handle)."));
}
}
}

View File

@@ -715,6 +715,20 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
#define DEBUG_PRINTF(x...)
#endif
// WLEDMM: macros to print "user messages" to Serial
#ifdef WLED_DEBUG
// use DEBUG_PRINT
#define USER_PRINT(x) DEBUG_PRINT(x)
#define USER_PRINTLN(x) DEBUG_PRINTLN(x)
#define USER_PRINTF(x...) DEBUG_PRINTF(x)
#else
// check if serial is availeable, then use Serial.print directly
#define USER_PRINT(x) { if (canUseSerial()) {Serial.print(x); Serial.flush();}}
#define USER_PRINTLN(x) { if (canUseSerial()) {Serial.println(x); Serial.flush();}}
#define USER_PRINTF(x...) { if (canUseSerial()) {Serial.printf(x); Serial.flush();}}
#endif
// WLEDMM end
#ifdef WLED_DEBUG_FS
#define DEBUGFS_PRINT(x) DEBUGOUT.print(x)
#define DEBUGFS_PRINTLN(x) DEBUGOUT.println(x)

View File

@@ -67,6 +67,18 @@ void sendBytes(){
}
}
bool canUseSerial(void) { // WLEDMM returns true if Serial can be used for debug output (i.e. not configured for other purpose)
if (pinManager.isPinAllocated(hardwareTX) && (pinManager.getPinOwner(hardwareTX) != PinOwner::DebugOut))
return false; // TX allocated to LEDs or other functions
if ((realtimeMode == REALTIME_MODE_GENERIC) || (realtimeMode == REALTIME_MODE_ADALIGHT) || (realtimeMode == REALTIME_MODE_TPM2NET))
return false; // Serial in use for adaLight or other serial communication
//if ((improvActive == 1) || (improvActive == 2)) return false; // don't interfere when IMPROV communication is ongoing
if (improvActive > 0) return false; // don't interfere when IMPROV communication is ongoing
if (continuousSendLED == true) return false; // Continuous Serial Streaming
return true;
} // WLEDMM end
void handleSerial()
{
if (pinManager.isPinAllocated(hardwareRX)) return;