Ethernet configuration fix, improve PinManager (#2123)

* Improved pin manager, ethernet config

* Ethernet is configured prior even to LED pins
* Pin Manager allocation / deallocation functions
   now take an "ownership" tag parameter, helping
   avoid accidentally free'ing pins that were allocated
   by other code
* Pin Manager now has ability to allocate multiple
  pins at once; Simplifies error handling

* Fix operator precedence error

Bitwise AND has lower precedence than the
relational "greater than" operator.

* PinManager update for some user modules

* don't build everything...

* Final step to reduce RAM overhead

* update comment

* remove macros

* Remove leftover allocated

* Init ethernet after settings saved

Co-authored-by: Christian Schwinne <dev.aircoookie@gmail.com>
This commit is contained in:
Henry Gabryjelski
2021-08-23 05:14:48 -07:00
committed by GitHub
parent ff8145b745
commit 1d4487b6cd
19 changed files with 450 additions and 206 deletions

View File

@@ -115,14 +115,19 @@ class UsermodTemperature : public Usermod {
// config says we are enabled
DEBUG_PRINTLN(F("Allocating temperature pin..."));
// pin retrieved from cfg.json (readFromConfig()) prior to running setup()
if (temperaturePin >= 0 && pinManager.allocatePin(temperaturePin)) {
if (temperaturePin >= 0 && pinManager.allocatePin(temperaturePin, true, PinOwner::UM_Temperature)) {
oneWire = new OneWire(temperaturePin);
if (!oneWire->reset())
if (!oneWire->reset()) {
sensorFound = false; // resetting 1-Wire bus yielded an error
else
while ((sensorFound=findSensor()) && retries--) delay(25); // try to find sensor
} else {
while ((sensorFound=findSensor()) && retries--) {
delay(25); // try to find sensor
}
}
} else {
if (temperaturePin >= 0) DEBUG_PRINTLN(F("Temperature pin allocation failed."));
if (temperaturePin >= 0) {
DEBUG_PRINTLN(F("Temperature pin allocation failed."));
}
temperaturePin = -1; // allocation failed
sensorFound = false;
}
@@ -273,7 +278,7 @@ class UsermodTemperature : public Usermod {
DEBUG_PRINTLN(F("Re-init temperature."));
// deallocate pin and release memory
delete oneWire;
pinManager.deallocatePin(temperaturePin);
pinManager.deallocatePin(temperaturePin, PinOwner::UM_Temperature);
temperaturePin = newTemperaturePin;
// initialise
setup();