1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

IODevice.cpp: Fix error in overlap checking.

The checkNoOverlap() function didn't work correctly in the case where one device has nPins=0.  All devices configured after that were rejected, even when no overlap was present.
This commit is contained in:
Neil McKechnie 2023-01-16 23:03:53 +00:00
parent abf62dfd85
commit ccf463b507

View File

@ -292,16 +292,17 @@ bool IODevice::checkNoOverlap(VPIN firstPin, uint8_t nPins, uint8_t i2cAddress)
VPIN lastPin=firstPin+nPins-1; VPIN lastPin=firstPin+nPins-1;
for (IODevice *dev = _firstDevice; dev != 0; dev = dev->_nextDevice) { for (IODevice *dev = _firstDevice; dev != 0; dev = dev->_nextDevice) {
// check for pin range overlaps (verbose but compiler will fix that) if (nPins > 0 && dev->_nPins > 0) {
VPIN firstDevPin=dev->_firstVpin; // check for pin range overlaps (verbose but compiler will fix that)
VPIN lastDevPin=firstDevPin+dev->_nPins-1; VPIN firstDevPin=dev->_firstVpin;
bool noOverlap= firstPin>lastDevPin || lastPin<firstDevPin; VPIN lastDevPin=firstDevPin+dev->_nPins-1;
if (!noOverlap) { bool noOverlap= firstPin>lastDevPin || lastPin<firstDevPin;
DIAG(F("WARNING HAL Overlap definition of pins %d to %d ignored."), if (!noOverlap) {
firstPin, lastPin); DIAG(F("WARNING HAL Overlap definition of pins %d to %d ignored."),
return false; firstPin, lastPin);
return false;
}
} }
// Check for overlapping I2C address // Check for overlapping I2C address
if (i2cAddress && dev->_I2CAddress==i2cAddress) { if (i2cAddress && dev->_I2CAddress==i2cAddress) {
DIAG(F("WARNING HAL Overlap. i2c Addr 0x%x ignored."),i2cAddress); DIAG(F("WARNING HAL Overlap. i2c Addr 0x%x ignored."),i2cAddress);