From 044b467085ebe60532ac9c91d4d1b0bcceacb6dc Mon Sep 17 00:00:00 2001 From: Asbelos Date: Wed, 15 Jun 2022 11:44:46 +0100 Subject: [PATCH] Implement HAL macro in exrail --- EXRAIL2MacroReset.h | 2 ++ EXRAILMacros.h | 9 +++++++++ IODevice.cpp | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index 80e82af..bdd6682 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -58,6 +58,7 @@ #undef FREE #undef FWD #undef GREEN +#undef HAL #undef IF #undef IFAMBER #undef IFCLOSED @@ -161,6 +162,7 @@ #define FREE(blockid) #define FWD(speed) #define GREEN(signal_id) +#define HAL(haltype,params...) #define IF(sensor_id) #define IFAMBER(signal_id) #define IFCLOSED(turnout_id) diff --git a/EXRAILMacros.h b/EXRAILMacros.h index cff0753..e953936 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -61,6 +61,14 @@ #define ALIAS(name,value...) const int name= 1##value##0 ==10 ? -__COUNTER__ : value##0/10; #include "myAutomation.h" +// Pass 1h Implements HAL macro by creating exrailHalSetup function +#include "EXRAIL2MacroReset.h" +#undef HAL +#define HAL(haltype,params...) haltype::create(params); +void exrailHalSetup() { + #include "myAutomation.h" +} + // Pass 2 create throttle route list #include "EXRAIL2MacroReset.h" #undef ROUTE @@ -234,6 +242,7 @@ const FLASH int16_t RMFT2::SignalDefinitions[] = { #define FREE(blockid) OPCODE_FREE,V(blockid), #define FWD(speed) OPCODE_FWD,V(speed), #define GREEN(signal_id) OPCODE_GREEN,V(signal_id), +#define HAL(haltype,params...) #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 3b6094b..b292195 100644 --- a/IODevice.cpp +++ b/IODevice.cpp @@ -32,6 +32,7 @@ // Link to halSetup function. If not defined, the function reference will be NULL. extern __attribute__((weak)) void halSetup(); +extern __attribute__((weak)) void exrailHalSetup(); //================================================================================================================== // Static methods @@ -55,6 +56,10 @@ void IODevice::begin() { if (halSetup) halSetup(); + // include any HAL devices defined in exrail. + if (exrailHalSetup) + exrailHalSetup(); + // Initialise the IO subsystem defaults ArduinoPins::create(2, NUM_DIGITAL_PINS-2); // Reserve pins for direct access // Predefine two PCA9685 modules 0x40-0x41