From 25bbfa4c6805bf03cdb188d6d7d3457eec9b642b Mon Sep 17 00:00:00 2001 From: Colin Murdoch Date: Wed, 27 Sep 2023 14:46:48 +0100 Subject: [PATCH] Fix <1 JOIN> Fixed <1 JOIN> issue in TrackManager --- DCCEXParser.cpp | 15 +++++++++------ EXRAIL2.cpp | 4 ++-- TrackManager.cpp | 18 ++++++++++-------- TrackManager.h | 9 +++++---- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index aee7e05..c82175b 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -589,8 +589,8 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) prog=false; } singletrack=true; - if (main) TrackManager::setTrackPower(false, POWERMODE::ON, t); - if (prog) TrackManager::setTrackPower(true, POWERMODE::ON, t); + if (main) TrackManager::setTrackPower(false, false, POWERMODE::ON, t); + if (prog) TrackManager::setTrackPower(true, false, POWERMODE::ON, t); //CommandDistributor::broadcastPower(); //TrackManager::streamTrackState(stream, t); TrackManager::streamTrackState(NULL,t); @@ -603,8 +603,11 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) if (!singletrack) { TrackManager::setJoin(join); - if (main) TrackManager::setMainPower(POWERMODE::ON); - if (prog) TrackManager::setProgPower(POWERMODE::ON); + if (join) TrackManager::setJoinPower(POWERMODE::ON); + else { + if (main) TrackManager::setMainPower(POWERMODE::ON); + if (prog) TrackManager::setProgPower(POWERMODE::ON); + } CommandDistributor::broadcastPower(); return; @@ -646,10 +649,10 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) } singletrack=true; TrackManager::setJoin(false); - if (main) TrackManager::setTrackPower(false, POWERMODE::OFF, t); + if (main) TrackManager::setTrackPower(false, false, POWERMODE::OFF, t); if (prog) { TrackManager::progTrackBoosted=false; // Prog track boost mode will not outlive prog track off - TrackManager::setTrackPower(true, POWERMODE::OFF, t); + TrackManager::setTrackPower(true, false, POWERMODE::OFF, t); CommandDistributor::broadcastPower(); } StringFormatter::send(stream, F("Track %d OFF\n"), t); diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index 8fd9532..321872d 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -786,10 +786,10 @@ void RMFT2::loop2() { //byte thistrack=getOperand(1); switch (operand) { case TRACK_POWER_0: - TrackManager::setTrackPower(TrackManager::isProg(getOperand(1)), POWERMODE::OFF, getOperand(1)); + TrackManager::setTrackPower(TrackManager::isProg(getOperand(1)), false, POWERMODE::OFF, getOperand(1)); break; case TRACK_POWER_1: - TrackManager::setTrackPower(TrackManager::isProg(getOperand(1)), POWERMODE::ON, getOperand(1)); + TrackManager::setTrackPower(TrackManager::isProg(getOperand(1)), false, POWERMODE::ON, getOperand(1)); break; } diff --git a/TrackManager.cpp b/TrackManager.cpp index f66fb4d..dd27d85 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -417,17 +417,17 @@ std::vectorTrackManager::getMainDrivers() { } #endif -void TrackManager::setPower2(bool setProg,POWERMODE mode) { +void TrackManager::setPower2(bool setProg,bool setJoin, POWERMODE mode) { if (!setProg) mainPowerGuess=mode; FOR_EACH_TRACK(t) { - TrackManager::setTrackPower(setProg, mode, t); + TrackManager::setTrackPower(setProg, setJoin, mode, t); } return; } -void TrackManager::setTrackPower(bool setProg, POWERMODE mode, byte thistrack) { +void TrackManager::setTrackPower(bool setProg, bool setJoin, POWERMODE mode, byte thistrack) { //DIAG(F("SetTrackPower Processing Track %d"), thistrack); MotorDriver * driver=track[thistrack]; @@ -445,21 +445,23 @@ void TrackManager::setTrackPower(bool setProg, POWERMODE mode, byte thistrack) { break; case TRACK_MODE_DC: case TRACK_MODE_DCX: - if (setProg) break; + DIAG(F("Processing track - %d setProg %d"), thistrack, setProg); + if (setProg || setJoin) {DIAG(F("Nowt to do")); break;} driver->setBrake(true); // DC starts with brake on applyDCSpeed(thistrack); // speed match DCC throttles driver->setPower(mode); + DIAG(F("Doing it anyway")); break; case TRACK_MODE_PROG: - if (!setProg) break; + if (!setProg && !setJoin) break; driver->setBrake(true); driver->setBrake(false); driver->setPower(mode); break; case TRACK_MODE_EXT: - driver->setBrake(true); - driver->setBrake(false); - driver->setPower(mode); + driver->setBrake(true); + driver->setBrake(false); + driver->setPower(mode); break; case TRACK_MODE_NONE: break; diff --git a/TrackManager.h b/TrackManager.h index cf2d54b..21b8d59 100644 --- a/TrackManager.h +++ b/TrackManager.h @@ -65,11 +65,12 @@ class TrackManager { static std::vectorgetMainDrivers(); #endif - static void setPower2(bool progTrack,POWERMODE mode); + static void setPower2(bool progTrack,bool joinTrack,POWERMODE mode); static void setPower(POWERMODE mode) {setMainPower(mode); setProgPower(mode);} - static void setMainPower(POWERMODE mode) {setPower2(false,mode);} - static void setProgPower(POWERMODE mode) {setPower2(true,mode);} - static void setTrackPower(bool setProg, POWERMODE mode, byte thistrack); + static void setMainPower(POWERMODE mode) {setPower2(false,false,mode);} + static void setProgPower(POWERMODE mode) {setPower2(true,false,mode);} + static void setJoinPower(POWERMODE mode) {setPower2(false,true,mode);} + static void setTrackPower(bool setProg, bool setJoin, POWERMODE mode, byte thistrack); static const int16_t MAX_TRACKS=8;