diff --git a/usermods/BH1750_v2/usermod_bh1750.h b/usermods/BH1750_v2/usermod_bh1750.h index 820aa578..1e7ae48b 100644 --- a/usermods/BH1750_v2/usermod_bh1750.h +++ b/usermods/BH1750_v2/usermod_bh1750.h @@ -223,10 +223,10 @@ public: void appendConfigData() { oappend(SET_F("addHB('")); oappend(SET_F(_name)); oappend("');"); - oappend(SET_F("addInfo('BH1750:pin[]',1,'','I2C SDA');")); - oappend(SET_F("rOption('BH1750:pin[]',1,'use global (")); oappendi(i2c_sda); oappend(")',-1);"); oappend(SET_F("addInfo('BH1750:pin[]',0,'','I2C SCL');")); oappend(SET_F("rOption('BH1750:pin[]',0,'use global (")); oappendi(i2c_scl); oappend(")',-1);"); + oappend(SET_F("addInfo('BH1750:pin[]',1,'','I2C SDA');")); + oappend(SET_F("rOption('BH1750:pin[]',1,'use global (")); oappendi(i2c_sda); oappend(")',-1);"); } // (called from set.cpp) stores persistent properties to cfg.json @@ -240,7 +240,10 @@ public: top[FPSTR(_HomeAssistantDiscovery)] = HomeAssistantDiscovery; top[FPSTR(_offset)] = offset; JsonArray io_pin = top.createNestedArray(F("pin")); - for (byte i=0; i<2; i++) io_pin.add(ioPin[i]); + //WLEDMM: Only save if not same as global + io_pin.add((ioPin[0]==i2c_scl)?-1:ioPin[0]); + io_pin.add((ioPin[1]==i2c_sda)?-1:ioPin[1]); + // top[F("help4Pins")] = F("SCL,SDA"); // help for Settings page DEBUG_PRINTLN(F("BH1750 config saved.")); diff --git a/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h b/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h index 5b348f39..a110794a 100644 --- a/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h +++ b/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h @@ -112,6 +112,8 @@ class FourLineDisplayUsermod : public Usermod { bool initDone = false; volatile bool drawing = false; + char errorMessage[100] = "No errors"; //WLEDMM: show error in um settings if occurred + // HW interface & configuration U8X8 *u8x8 = nullptr; // pointer to U8X8 display object @@ -124,6 +126,7 @@ class FourLineDisplayUsermod : public Usermod { #endif DisplayType type = FLD_TYPE; // display type + bool typeOK = true; //WLEDMM: instead of type == NULL and type=NULL bool flip = false; // flip display 180° uint8_t contrast = 10; // screen contrast uint8_t lineHeight = 1; // 1 row or 2 rows @@ -198,32 +201,32 @@ class FourLineDisplayUsermod : public Usermod { * Wrappers for screen drawing */ void setFlipMode(uint8_t mode) { - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; u8x8->setFlipMode(mode); } void setContrast(uint8_t contrast) { - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; u8x8->setContrast(contrast); } void drawString(uint8_t col, uint8_t row, const char *string, bool ignoreLH=false) { - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; u8x8->setFont(u8x8_font_chroma48medium8_r); if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string); else u8x8->drawString(col, row, string); } void draw2x2String(uint8_t col, uint8_t row, const char *string) { - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; u8x8->setFont(u8x8_font_chroma48medium8_r); u8x8->draw2x2String(col, row, string); } void drawGlyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font, bool ignoreLH=false) { - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; u8x8->setFont(font); if (!ignoreLH && lineHeight==2) u8x8->draw1x2Glyph(col, row, glyph); else u8x8->drawGlyph(col, row, glyph); } void draw2x2Glyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font) { - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; u8x8->setFont(font); u8x8->draw2x2Glyph(col, row, glyph); } @@ -232,11 +235,11 @@ class FourLineDisplayUsermod : public Usermod { return u8x8->getCols(); } void clear() { - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; u8x8->clear(); } void setPowerSave(uint8_t save) { - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; u8x8->setPowerSave(save); } @@ -268,7 +271,7 @@ class FourLineDisplayUsermod : public Usermod { * the useAMPM configuration. */ void showTime() { - if (type == NONE || !enabled || !displayTurnedOff) return; + if (!typeOK || !enabled || !displayTurnedOff) return; unsigned long now = millis(); while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing @@ -316,40 +319,37 @@ class FourLineDisplayUsermod : public Usermod { // gets called once at boot. Do all initialization that doesn't depend on // network here void setup() { - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; bool isHW, isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64); PinOwner po = PinOwner::UM_FourLineDisplay; if (isSPI) { - int8_t hw_sclk = spi_sclk; - int8_t hw_mosi = spi_mosi; if (ioPin[0] < 0 || ioPin[1] < 0) { - ioPin[0] = hw_sclk; - ioPin[1] = hw_mosi; + ioPin[0] = spi_sclk; + ioPin[1] = spi_mosi; } - isHW = (ioPin[0]==hw_sclk && ioPin[1]==hw_mosi); + isHW = (ioPin[0]==spi_sclk && ioPin[1]==spi_mosi); PinManagerPinType cspins[3] = { { ioPin[2], true }, { ioPin[3], true }, { ioPin[4], true } }; - if (!pinManager.allocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay)) { type=NONE; return; } + if (!pinManager.allocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay)) { typeOK=false; strcpy(errorMessage, PSTR("SPI3 alloc pins failed")); return; } if (isHW) po = PinOwner::HW_SPI; // allow multiple allocations of HW I2C bus pins PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } }; if (!pinManager.allocateMultiplePins(pins, 2, po)) { pinManager.deallocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay); - type = NONE; + typeOK=false; + strcpy(errorMessage, PSTR("SPI2 alloc pins failed")); return; } } else { - int8_t hw_scl = i2c_scl; - int8_t hw_sda = i2c_sda; if (ioPin[0] < 0 || ioPin[1] < 0) { - ioPin[0] = hw_scl; - ioPin[1] = hw_sda; + ioPin[0] = i2c_scl; + ioPin[1] = i2c_sda; } - isHW = (ioPin[0]==hw_scl && ioPin[1]==hw_sda); + 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 PinManagerPinType pins[2] = { {ioPin[0], true }, { ioPin[1], true } }; - 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; } + if (ioPin[0] < 0 || ioPin[1] < 0) { typeOK=false; strcpy(errorMessage, PSTR("I2C No Pins defined")); return; } //WLEDMM bugfix - ensure that "final" GPIO are valid + if (!pinManager.allocateMultiplePins(pins, 2, po)) { typeOK=false; strcpy(errorMessage, PSTR("I2C Alloc pins failed")); return; } } DEBUG_PRINTLN(F("Allocating display.")); @@ -380,7 +380,8 @@ class FourLineDisplayUsermod : public Usermod { u8x8_Setup(u8x8.getU8x8(), u8x8_d_ssd1306_128x64_noname, u8x8_cad_001, u8x8_byte_arduino_4wire_sw_spi, u8x8_gpio_and_delay_arduino); break; default: - type = NONE; + typeOK=false; + strcpy(errorMessage, PSTR("No valid type")); return; } if (isSPI) { @@ -429,7 +430,8 @@ class FourLineDisplayUsermod : public Usermod { if (nullptr == u8x8) { USER_PRINTLN(F("Display init failed.")); pinManager.deallocateMultiplePins((const uint8_t*)ioPin, isSPI ? 5 : 2, po); - type = NONE; + typeOK=false; + strcpy(errorMessage, PSTR("Display init failed")); return; } @@ -481,7 +483,7 @@ class FourLineDisplayUsermod : public Usermod { bool needRedraw = false; unsigned long now = millis(); - if (type == NONE || !enabled) return; + if (!typeOK || !enabled) return; if (overlayUntil > 0) { if (now >= overlayUntil) { // Time to display the overlay has elapsed. @@ -713,7 +715,7 @@ class FourLineDisplayUsermod : public Usermod { * to wake up the screen. */ bool wakeDisplay() { - if (type == NONE || !enabled) return false; + if (!typeOK || !enabled) return false; if (displayTurnedOff) { unsigned long now = millis(); while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing @@ -1047,20 +1049,34 @@ class FourLineDisplayUsermod : public Usermod { oappend(SET_F("addOption(dd,'SSD1305 128x64',5);")); oappend(SET_F("addOption(dd,'SSD1306 SPI',6);")); oappend(SET_F("addOption(dd,'SSD1306 SPI 128x64',7);")); + bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64); // WLEDMM add defaults oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'','I2C/SPI CLK');")); #ifdef FLD_PIN_SCL oappend(SET_F("xOption('4LineDisplay:pin[]',0,' ⎌',")); oappendi(FLD_PIN_SCL); oappend(");"); #endif - oappend(SET_F("rOption('4LineDisplay:pin[]',0,'use global (")); oappendi(i2c_scl); oappend(")',-1);"); + if (isSPI) { + oappend(SET_F("rOption('4LineDisplay:pin[]',0,'use global (")); oappendi(spi_sclk); oappend(")',-1);"); + } else { + oappend(SET_F("rOption('4LineDisplay:pin[]',0,'use global (")); oappendi(i2c_scl); oappend(")',-1);"); + } oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'','I2C/SPI DTA');")); #ifdef FLD_PIN_SDA oappend(SET_F("xOption('4LineDisplay:pin[]',1,' ⎌',")); oappendi(FLD_PIN_SDA); oappend(");"); #endif - oappend(SET_F("rOption('4LineDisplay:pin[]',1,'use global (")); oappendi(i2c_sda); oappend(")',-1);"); + if (isSPI) { + oappend(SET_F("rOption('4LineDisplay:pin[]',1,'use global (")); oappendi(spi_mosi); oappend(")',-1);"); + } else { + oappend(SET_F("rOption('4LineDisplay:pin[]',1,'use global (")); oappendi(i2c_sda); oappend(")',-1);"); + } oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'','SPI CS');")); oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'','SPI DC');")); oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'','SPI RST');")); + + //WLEDMM add errorMessage to um settings + if (strcmp(errorMessage, "") != 0) { + oappend(SET_F("addInfo('errorMessage', 0, 'error: ")); oappend(SET_F(errorMessage)); oappend("!');"); + } } /* @@ -1167,9 +1183,7 @@ class FourLineDisplayUsermod : public Usermod { bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64); if (isSPI) { pinManager.deallocateMultiplePins((const uint8_t *)(&oldPin[2]), 3, po); - uint8_t hw_sclk = spi_sclk; - uint8_t hw_mosi = spi_mosi; - bool isHW = (oldPin[0]==hw_sclk && oldPin[1]==hw_mosi); + bool isHW = (oldPin[0]==spi_sclk && oldPin[1]==spi_mosi); if (isHW) po = PinOwner::HW_SPI; } else { uint8_t hw_scl = i2c_scl; diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index ed2f5990..23f3dcea 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -311,8 +311,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { #endif Wire.begin(); } else { - i2c_sda = -1; - i2c_scl = -1; + Serial.printf("pinmgr not success i2c %d %d\n", i2c_sda, i2c_scl); } JsonArray hw_if_spi = hw[F("if")][F("spi-pin")]; CJSON(spi_mosi, hw_if_spi[0]); @@ -326,9 +325,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { SPI.begin(); #endif } else { - spi_mosi = -1; - spi_miso = -1; - spi_sclk = -1; + Serial.printf("pinmgr not success spi %d %d %d\n", spi_mosi, spi_miso, spi_sclk); } //int hw_status_pin = hw[F("status")]["pin"]; // -1 diff --git a/wled00/data/settings.htm b/wled00/data/settings.htm index 72e52cc5..cf23d81d 100644 --- a/wled00/data/settings.htm +++ b/wled00/data/settings.htm @@ -98,7 +98,7 @@