From 95bf5aae3887b7dd1865614e14e66093032906c7 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sun, 14 Jan 2024 20:20:22 +0000 Subject: [PATCH] HAL defaults control --- EXRAIL2MacroReset.h | 2 ++ EXRAILMacros.h | 7 ++++++- IODevice.cpp | 44 ++++++++++++++++++++++---------------------- IODevice.h | 3 ++- version.h | 4 +++- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index 7811a0d..3554f6c 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -67,6 +67,7 @@ #undef FWD #undef GREEN #undef HAL +#undef HAL_IGNORE_DEFAULTS #undef IF #undef IFAMBER #undef IFCLOSED @@ -218,6 +219,7 @@ #define FWD(speed) #define GREEN(signal_id) #define HAL(haltype,params...) +#define HAL_IGNORE_DEFAULTS #define IF(sensor_id) #define IFAMBER(signal_id) #define IFCLOSED(turnout_id) diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 2c18ae0..8ed2b82 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -143,8 +143,12 @@ static_assert(!hasdup(compileTimeSequenceList[0],1),"Duplicate SEQUENCE/ROUTE/AU #include "EXRAIL2MacroReset.h" #undef HAL #define HAL(haltype,params...) haltype::create(params); -void exrailHalSetup() { +#undef HAL_IGNORE_DEFAULTS +#define HAL_IGNORE_DEFAULTS ignore_defaults=true; +bool exrailHalSetup() { + bool ignore_defaults=false; #include "myAutomation.h" + return ignore_defaults; } // Pass 1c detect compile time featurtes @@ -460,6 +464,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; #define FWD(speed) OPCODE_FWD,V(speed), #define GREEN(signal_id) OPCODE_GREEN,V(signal_id), #define HAL(haltype,params...) +#define HAL_IGNORE_DEFAULTS #define IF(sensor_id) OPCODE_IF,V(sensor_id), #define IFAMBER(signal_id) OPCODE_IFAMBER,V(signal_id), #define IFCLOSED(turnout_id) OPCODE_IFCLOSED,V(turnout_id), diff --git a/IODevice.cpp b/IODevice.cpp index e811fff..99199aa 100644 --- a/IODevice.cpp +++ b/IODevice.cpp @@ -33,7 +33,7 @@ // Link to halSetup function. If not defined, the function reference will be NULL. extern __attribute__((weak)) void halSetup(); -extern __attribute__((weak)) void exrailHalSetup(); +extern __attribute__((weak)) bool exrailHalSetup(); //================================================================================================================== // Static methods @@ -60,34 +60,31 @@ void IODevice::begin() { halSetup(); // include any HAL devices defined in exrail. + bool ignoreDefaults=false; if (exrailHalSetup) - exrailHalSetup(); - + ignoreDefaults=exrailHalSetup(); + if (ignoreDefaults) return; + // Predefine two PCA9685 modules 0x40-0x41 if no conflicts // Allocates 32 pins 100-131 - if (checkNoOverlap(100, 16, 0x40)) { + const bool silent=true; // no message if these conflict + if (checkNoOverlap(100, 16, 0x40, silent)) { PCA9685::create(100, 16, 0x40); - } else { - DIAG(F("Default PCA9685 at I2C 0x40 disabled due to configured user device")); - } - if (checkNoOverlap(116, 16, 0x41)) { + } + + if (checkNoOverlap(116, 16, 0x41, silent)) { PCA9685::create(116, 16, 0x41); - } else { - DIAG(F("Default PCA9685 at I2C 0x41 disabled due to configured user device")); - } + } // Predefine two MCP23017 module 0x20/0x21 if no conflicts // Allocates 32 pins 164-195 - if (checkNoOverlap(164, 16, 0x20)) { + if (checkNoOverlap(164, 16, 0x20, silent)) { MCP23017::create(164, 16, 0x20); - } else { - DIAG(F("Default MCP23017 at I2C 0x20 disabled due to configured user device")); - } - if (checkNoOverlap(180, 16, 0x21)) { + } + + if (checkNoOverlap(180, 16, 0x21, silent)) { MCP23017::create(180, 16, 0x21); - } else { - DIAG(F("Default MCP23017 at I2C 0x21 disabled due to configured user device")); - } + } } // reset() function to reinitialise all devices @@ -339,7 +336,10 @@ IODevice *IODevice::findDeviceFollowing(VPIN vpin) { // returns true if pins DONT overlap with existing device // TODO: Move the I2C address reservation and checks into the I2CManager code. // That will enable non-HAL devices to reserve I2C addresses too. -bool IODevice::checkNoOverlap(VPIN firstPin, uint8_t nPins, I2CAddress i2cAddress) { +// Silent is used by the default setup so that there is no message if the default +// device has already been handled by the user setup. +bool IODevice::checkNoOverlap(VPIN firstPin, uint8_t nPins, + I2CAddress i2cAddress, bool silent) { #ifdef DIAG_IO DIAG(F("Check no overlap %u %u %s"), firstPin,nPins,i2cAddress.toString()); #endif @@ -352,14 +352,14 @@ bool IODevice::checkNoOverlap(VPIN firstPin, uint8_t nPins, I2CAddress i2cAddres VPIN lastDevPin=firstDevPin+dev->_nPins-1; bool noOverlap= firstPin>lastDevPin || lastPin_I2CAddress==i2cAddress) { - DIAG(F("WARNING HAL Overlap. i2c Addr %s ignored."),i2cAddress.toString()); + if (!silent) DIAG(F("WARNING HAL Overlap. i2c Addr %s ignored."),i2cAddress.toString()); return false; } } diff --git a/IODevice.h b/IODevice.h index d12fafd..6c70f5f 100644 --- a/IODevice.h +++ b/IODevice.h @@ -166,7 +166,8 @@ public: void setGPIOInterruptPin(int16_t pinNumber); // Method to check if pins will overlap before creating new device. - static bool checkNoOverlap(VPIN firstPin, uint8_t nPins=1, I2CAddress i2cAddress=0); + static bool checkNoOverlap(VPIN firstPin, uint8_t nPins=1, + I2CAddress i2cAddress=0, bool silent=false); // Method used by IODevice filters to locate slave pins that may be overlayed by their own // pin range. diff --git a/version.h b/version.h index 33c6164..8c8ef68 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,9 @@ #include "StringFormatter.h" -#define VERSION "5.2.25" +#define VERSION "5.2.26" +// 5.2.26 - Silently ignore overridden HAL defaults +// - include HAL_IGNORE_DEFAULTS macro in EXRAIL // 5.2.25 - Fix bug causing after working