attempt to fix issue #21
set.cpp: introduce "-2" => "no value" in addition to "-1" => disable 4LD_ALT: do not copy "global" pins into UM specific setting; just use them directly.
This commit is contained in:
@@ -347,19 +347,21 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (ioPin[0] < 0 || ioPin[1] < 0) {
|
||||
ioPin[0] = i2c_scl;
|
||||
ioPin[1] = i2c_sda;
|
||||
}
|
||||
//if (ioPin[0] < 0 || ioPin[1] < 0) { //WLEDMM do _not_ copy global pins !!
|
||||
// ioPin[0] = i2c_scl;
|
||||
// ioPin[1] = i2c_sda;
|
||||
//}
|
||||
isHW = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda);
|
||||
if ((ioPin[0] == -1) || (ioPin[1] == -1)) isHW = true; // WLEDMM "use global" = hardware
|
||||
// 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) { typeOK=false; strcpy(errorMessage, PSTR("I2C No Pins defined")); return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
|
||||
if ((ioPin[0] < 0 || ioPin[1] < 0) && (i2c_scl < 0 || i2c_sda < 0)) { // invalid pins, or "use global" and global pins not defined
|
||||
typeOK=false; strcpy(errorMessage, PSTR("I2C No Pins defined")); return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
|
||||
|
||||
if (isHW) {
|
||||
if (!pinManager.joinWire(ioPin[1], ioPin[0])) { typeOK=false; strcpy(errorMessage, PSTR("I2C init failed")); return; } // WLEDMM join the HW bus
|
||||
if (!pinManager.joinWire(i2c_sda, i2c_scl)) { typeOK=false; strcpy(errorMessage, PSTR("I2C HW init failed")); return; } // WLEDMM join the HW bus
|
||||
} else {
|
||||
if (!pinManager.allocateMultiplePins(pins, 2, po)) { typeOK=false; strcpy(errorMessage, PSTR("I2C Alloc pins failed")); return; } // WLEDMM use software bus
|
||||
}
|
||||
@@ -442,7 +444,7 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
|
||||
if (nullptr == u8x8) {
|
||||
USER_PRINTLN(F("Display init failed."));
|
||||
pinManager.deallocateMultiplePins((const uint8_t*)ioPin, isSPI ? 5 : 2, po);
|
||||
if (!isHW || !isSPI) pinManager.deallocateMultiplePins((const uint8_t*)ioPin, isSPI ? 5 : 2, po); // WLEDMM do not de-alloc global pins
|
||||
typeOK=false;
|
||||
strcpy(errorMessage, PSTR("Display init failed"));
|
||||
return;
|
||||
@@ -1285,8 +1287,9 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
bool isHW = (oldPin[0]==spi_sclk && oldPin[1]==spi_mosi);
|
||||
if (isHW) po = PinOwner::HW_SPI;
|
||||
} else {
|
||||
bool isHW = (oldPin[0]==i2c_scl && oldPin[1]==i2c_sda);
|
||||
if (isHW) po = PinOwner::HW_I2C;
|
||||
//bool isHW = (oldPin[0]==i2c_scl && oldPin[1]==i2c_sda);
|
||||
//if ((ioPin[0] == -1) || (ioPin[1] == -1)) isHW = true; // WLEDMM "use global" = hardware
|
||||
//if (isHW) po = PinOwner::HW_I2C; // WLEDMM don't try to de-alloc HW pins.
|
||||
}
|
||||
pinManager.deallocateMultiplePins((const uint8_t *)oldPin, 2, po);
|
||||
type = newType;
|
||||
|
||||
@@ -523,12 +523,12 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
||||
if (!requestJSONBufferLock(5)) return;
|
||||
|
||||
// global I2C & SPI pins
|
||||
int8_t hw_sda_pin = -1;//!request->arg(F("SDApin")).length() ? -1 : (int)request->arg(F("SDApin")).toInt();
|
||||
int8_t hw_scl_pin = -1;//!request->arg(F("SCLpin")).length() ? -1 : (int)request->arg(F("SCLpin")).toInt();
|
||||
int8_t hw_sda_pin = -2;//!request->arg(F("SDApin")).length() ? -1 : (int)request->arg(F("SDApin")).toInt(); // WLEDMM: -2 = no value
|
||||
int8_t hw_scl_pin = -2;//!request->arg(F("SCLpin")).length() ? -1 : (int)request->arg(F("SCLpin")).toInt(); // WLEDMM: -2 = no value
|
||||
|
||||
int8_t hw_mosi_pin = -1;//!request->arg(F("MOSIpin")).length() ? -1 : (int)request->arg(F("MOSIpin")).toInt();
|
||||
int8_t hw_miso_pin = -1;//!request->arg(F("MISOpin")).length() ? -1 : (int)request->arg(F("MISOpin")).toInt();
|
||||
int8_t hw_sclk_pin = -1;//!request->arg(F("SCLKpin")).length() ? -1 : (int)request->arg(F("SCLKpin")).toInt();
|
||||
int8_t hw_mosi_pin = -2;//!request->arg(F("MOSIpin")).length() ? -1 : (int)request->arg(F("MOSIpin")).toInt();
|
||||
int8_t hw_miso_pin = -2;//!request->arg(F("MISOpin")).length() ? -1 : (int)request->arg(F("MISOpin")).toInt();
|
||||
int8_t hw_sclk_pin = -2;//!request->arg(F("SCLKpin")).length() ? -1 : (int)request->arg(F("SCLKpin")).toInt();
|
||||
|
||||
//WLEDMM: :pin values have 2 occurrences: the type and the value, we need the value
|
||||
int paramsNr = request->params();
|
||||
@@ -556,17 +556,19 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
||||
if (hw_sda_pin >= 0 && hw_scl_pin >= 0 && pinManager.allocateMultiplePins(i2c, 2, PinOwner::HW_I2C)) {
|
||||
i2c_sda = hw_sda_pin;
|
||||
i2c_scl = hw_scl_pin;
|
||||
DEBUG_PRINTF("handleSettingsSet(): reserved I2C pins SDA=%d SCL=%d.\n", i2c_sda, i2c_scl);
|
||||
#ifdef ESP32
|
||||
Wire.setPins(i2c_sda, i2c_scl); // this will fail if Wire is initilised (Wire.begin() called)
|
||||
#endif
|
||||
// Wire.begin(); // WLEDMM moved into pinManager
|
||||
} else {
|
||||
// there is no Wire.end()
|
||||
if (hw_sda_pin < 0 || hw_scl_pin < 0) { // WLEDMM bugfix allow pin = -1
|
||||
if (hw_sda_pin == -1 || hw_scl_pin == -1) { // WLEDMM bugfix allow pin = -1
|
||||
i2c_sda = -1;
|
||||
i2c_scl = -1;
|
||||
DEBUG_PRINTLN(F("handleSettingsSet(): reset I2C pins to -1"));
|
||||
}
|
||||
DEBUG_PRINTLN(F("Could not allocate I2C pins."));
|
||||
DEBUG_PRINTLN(F("handleSettingsSet(): Could not allocate I2C pins - deallocating."));
|
||||
uint8_t i2c[2] = { static_cast<uint8_t>(i2c_scl), static_cast<uint8_t>(i2c_sda) };
|
||||
pinManager.deallocateMultiplePins(i2c, 2, PinOwner::HW_I2C); // just in case deallocation of old pins
|
||||
Serial.printf("pinmgr not success for global i2c %d %d\n", i2c_sda, i2c_scl);
|
||||
@@ -592,7 +594,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
||||
#endif
|
||||
} else {
|
||||
//SPI.end();
|
||||
if (hw_mosi_pin < 0 || hw_sclk_pin < 0) { // WLEDMM bugfix allow pin = -1
|
||||
if (hw_mosi_pin == -1 || hw_sclk_pin == -1) { // WLEDMM bugfix allow pin = -1
|
||||
spi_mosi = hw_mosi_pin;
|
||||
spi_miso = hw_miso_pin;
|
||||
spi_sclk = hw_sclk_pin;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
// version code in format yymmddb (b = daily build)
|
||||
#define VERSION 2303080
|
||||
#define VERSION 2303081
|
||||
|
||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||
//#define WLED_USE_MY_CONFIG
|
||||
|
||||
Reference in New Issue
Block a user