From d077e3a2ffae500d5b097bb6f3a51f26f097f9ad Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 16 Sep 2021 16:47:47 +0100 Subject: [PATCH] Auto power on and POWEROFF macro --- RMFT2.cpp | 10 ++++++++++ RMFT2.h | 2 +- RMFTMacros.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/RMFT2.cpp b/RMFT2.cpp index 842b460..9ab89f6 100644 --- a/RMFT2.cpp +++ b/RMFT2.cpp @@ -19,6 +19,7 @@ #include #include "RMFT2.h" #include "DCC.h" +#include "DCCWaveform.h" #include "DIAG.h" #include "WiThrottle.h" #include "DCCEXParser.h" @@ -326,6 +327,8 @@ int RMFT2::locateRouteStart(int16_t _route) { void RMFT2::driveLoco(byte speed) { if (loco<=0) return; // Prevent broadcast! if (diag) DIAG(F("EXRAIL drive %d %d %d"),loco,speed,forward^invert); + if (DCCWaveform::mainTrack.getPowerMode()==POWERMODE::OFF) + DCCWaveform::mainTrack.setPowerMode(POWERMODE::ON); DCC::setThrottle(loco,speed, forward^invert); speedo=speed; } @@ -477,6 +480,11 @@ void RMFT2::loop2() { if (loco) DCC::writeCVByteMain(loco, operand, GET_OPERAND(1)); break; + case OPCODE_POWEROFF: + DCCWaveform::mainTrack.setPowerMode(POWERMODE::OFF); + DCCWaveform::progTrack.setPowerMode(POWERMODE::OFF); + break; + case OPCODE_RESUME: pausingTask=NULL; driveLoco(speedo); @@ -572,6 +580,8 @@ void RMFT2::loop2() { return; case OPCODE_JOIN: + DCCWaveform::mainTrack.setPowerMode(POWERMODE::ON); + DCCWaveform::progTrack.setPowerMode(POWERMODE::ON); DCC::setProgTrackSyncMain(true); break; diff --git a/RMFT2.h b/RMFT2.h index a254070..90080b7 100644 --- a/RMFT2.h +++ b/RMFT2.h @@ -40,7 +40,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, OPCODE_PAD,OPCODE_FOLLOW,OPCODE_CALL,OPCODE_RETURN, OPCODE_JOIN,OPCODE_UNJOIN,OPCODE_READ_LOCO1,OPCODE_READ_LOCO2,OPCODE_POM, OPCODE_START,OPCODE_SETLOCO,OPCODE_SENDLOCO, - OPCODE_PAUSE, OPCODE_RESUME, + OPCODE_PAUSE, OPCODE_RESUME,OPCODE_POWEROFF, OPCODE_ONCLOSE, OPCODE_ONTHROW, OPCODE_SERVOTURNOUT, OPCODE_PINTURNOUT, OPCODE_PRINT, OPCODE_ROUTE,OPCODE_AUTOMATION,OPCODE_SEQUENCE,OPCODE_ENDTASK,OPCODE_ENDEXRAIL diff --git a/RMFTMacros.h b/RMFTMacros.h index c66dc3c..9fd1c22 100644 --- a/RMFTMacros.h +++ b/RMFTMacros.h @@ -90,6 +90,7 @@ #define PAUSE #define PRINT(msg) #define POM(cv,value) +#define POWEROFF #define READ_LOCO #define RED(signal_id) #define RESERVE(blockid) @@ -188,6 +189,7 @@ const int StringMacroTracker1=__COUNTER__; #undef ONTHROW #undef PAUSE #undef POM +#undef POWEROFF #undef PRINT #undef READ_LOCO #undef RED @@ -265,6 +267,7 @@ const int StringMacroTracker1=__COUNTER__; #define ONTHROW(turnout_id) OPCODE_ONTHROW,V(turnout_id), #define PAUSE OPCODE_PAUSE,NOP, #define POM(cv,value) OPCODE_POM,V(cv),OPCODE_PAD,V(value), +#define POWEROFF OPCODE_POWEROFF,NOP, #define PRINT(msg) OPCODE_PRINT,V(__COUNTER__ - StringMacroTracker2), #define READ_LOCO OPCODE_READ_LOCO1,NOP,OPCODE_READ_LOCO2,NOP, #define RED(signal_id) OPCODE_RED,V(signal_id),