From ead6e5afa11d526d9a366eeb6013e7eaa16bcb76 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Tue, 3 Sep 2024 09:55:36 +0100 Subject: [PATCH] NEOPIXEL EXRAIL --- EXRAIL2.cpp | 13 +++++++++++++ EXRAIL2.h | 5 ++++- EXRAIL2MacroReset.h | 6 ++++++ EXRAILMacros.h | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index 9f1075c..4b2a0e4 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -969,6 +969,10 @@ void RMFT2::loop2() { } break; + case OPCODE_NEOPIXEL: // OPCODE_NEOPIXEL,V(vpin),OPCODE_PAD,V(rgbcolour) + IODevice::writeAnalogue(operand,getOperand(1)); + break; + #ifndef IO_NO_HAL case OPCODE_WAITFORTT: // OPCODE_WAITFOR,V(turntable_id) if (Turntable::ttMoving(operand)) { @@ -1154,6 +1158,15 @@ int16_t RMFT2::getSignalSlot(int16_t id) { return; } +if (sigtype== NEOPIXEL_SIGNAL_FLAG) { + // redpin,amberpin,greenpin are the 3 rgbs + VPIN colour=redpin; + if (rag==SIGNAL_AMBER) colour=amberpin; + if (rag==SIGNAL_GREEN) colour=greenpin; + IODevice::writeAnalogue(sigid, colour); + return; + } + // LED or similar 3 pin signal, (all pins zero would be a virtual signal) // If amberpin is zero, synthesise amber from red+green diff --git a/EXRAIL2.h b/EXRAIL2.h index b4a06da..19d89ad 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -71,7 +71,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN, OPCODE_ROUTE_DISABLED, OPCODE_STASH,OPCODE_CLEAR_STASH,OPCODE_CLEAR_ALL_STASH,OPCODE_PICKUP_STASH, - + OPCODE_NEOPIXEL, // OPcodes below this point are skip-nesting IF operations // placed here so that they may be skipped as a group // see skipIfBlock() @@ -160,7 +160,10 @@ class LookList { static const int16_t ACTIVE_HIGH_SIGNAL_FLAG=0x2000; static const int16_t DCC_SIGNAL_FLAG=0x1000; static const int16_t DCCX_SIGNAL_FLAG=0x3000; + static const int16_t NEOPIXEL_SIGNAL_FLAG=0x5000; static const int16_t SIGNAL_ID_MASK=0x0FFF; + // Neopixel has last bit 1 for colour on, otherwise black (to allow for blinking etc with SET/RESET) + static const int16_t NEOPIXEL_FLAG_ON=0x0001; // Throttle Info Access functions built by exrail macros static const byte rosterNameCount; static const int16_t HIGHFLASH routeIdList[]; diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index 2428a09..db075a4 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -97,6 +97,9 @@ #undef LCCX #undef LCN #undef MOVETT +#undef NEOPIXEL +#undef NEOPIXEL_OFF +#undef NEOPIXEL_SIGNAL #undef ONACTIVATE #undef ONACTIVATEL #undef ONAMBER @@ -254,6 +257,9 @@ #define SCREEN(display,row,msg) #define LCN(msg) #define MOVETT(id,steps,activity) +#define NEOPIXEL(id,colour) +#define NEOPIXEL_OFF(id,colour) +#define NEOPIXEL_SIGNAL(sigid,redcolour,ambercolour,greencolour) #define ONACTIVATE(addr,subaddr) #define ONACTIVATEL(linear) #define ONAMBER(signal_id) diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 825ce02..3b97171 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -174,6 +174,7 @@ bool exrailHalSetup() { #define DCC_SIGNAL(id,addr,subaddr) | FEATURE_SIGNAL #undef DCCX_SIGNAL #define DCCX_SIGNAL(id,redAspect,amberAspect,greenAspect) | FEATURE_SIGNAL +#define NEOPIXEL_SIGNAL(sigid,redcolour,ambercolour,greencolour) | FEATURE_SIGNAL #undef VIRTUAL_SIGNAL #define VIRTUAL_SIGNAL(id) | FEATURE_SIGNAL @@ -405,6 +406,8 @@ const FSH * RMFT2::getRosterFunctions(int16_t id) { #define DCC_SIGNAL(id,addr,subaddr) id | RMFT2::DCC_SIGNAL_FLAG,addr,subaddr,0, #undef DCCX_SIGNAL #define DCCX_SIGNAL(id,redAspect,amberAspect,greenAspect) id | RMFT2::DCCX_SIGNAL_FLAG,redAspect,amberAspect,greenAspect, +#undef NEOPIXEL_SIGNAL +#define NEOPIXEL_SIGNAL(sigid,redcolour,ambercolour,greencolour) id | RMFT2::NEOPIXEL_SIGNAL_FLAG,redcolour | NEOPIXEL_FLAG_ON, ambercolour | NEOPIXEL_FLAG_ON, greencolour | NEOPIXEL_FLAG_ON, #undef VIRTUAL_SIGNAL #define VIRTUAL_SIGNAL(id) id,0,0,0, @@ -515,6 +518,9 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; #define STEALTH(code...) PRINT(dummy) #define LCN(msg) PRINT(msg) #define MOVETT(id,steps,activity) OPCODE_SERVO,V(id),OPCODE_PAD,V(steps),OPCODE_PAD,V(EXTurntable::activity),OPCODE_PAD,V(0), +#define NEOPIXEL(id,colour) OPCODE_NEOPIXEL,V(id),OPCODE_PAD,V(colour| NEOPIXEL_FLAG_ON), +#define NEOPIXEL_OFF(id,colour) OPCODE_NEOPIXEL,V(id),OPCODE_PAD,V(colour& ^NEOPIXEL_FLAG_ON), +#define NEOPIXEL_SIGNAL(sigid,redcolour,ambercolour,greencolour) #define ONACTIVATE(addr,subaddr) OPCODE_ONACTIVATE,V(addr<<2|subaddr), #define ONACTIVATEL(linear) OPCODE_ONACTIVATE,V(linear+3), #define ONAMBER(signal_id) OPCODE_ONAMBER,V(signal_id),