From 7a2fd90bfce236f446aaa62b23dfc3b8995e763d Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 30 Apr 2022 23:24:51 +0200 Subject: [PATCH] set the reset packet counter of the prog track to 0 every time the track is turned on --- DCCACK.cpp | 1 + MotorDriver.cpp | 2 ++ MotorDriver.h | 4 ++++ TrackManager.cpp | 2 ++ 4 files changed, 9 insertions(+) diff --git a/DCCACK.cpp b/DCCACK.cpp index de66355..83ce359 100644 --- a/DCCACK.cpp +++ b/DCCACK.cpp @@ -76,6 +76,7 @@ void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_C callback(-2); // our prog track cant measure current return; } + progDriver->setResetCounterPointer(&(DCCWaveform::progTrack.sentResetsSincePacket)); ackManagerRejoin=TrackManager::isJoined(); if (ackManagerRejoin ) { diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 517e2dd..b26161e 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -98,6 +98,8 @@ void MotorDriver::setPower(POWERMODE mode) { bool on=mode==POWERMODE::ON; if (on) { IODevice::write(powerPin,HIGH); + if (resetsCounterP != NULL) + *resetsCounterP = 0; } else IODevice::write(powerPin,LOW); powerMode=mode; diff --git a/MotorDriver.h b/MotorDriver.h index 981b259..d0dd999 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -73,8 +73,12 @@ class MotorDriver { inline byte getFaultPin() { return faultPin; } + inline void setResetCounterPointer(byte *bp) { // load resetPacketCounter pointer + resetsCounterP = bp; + } void checkPowerOverload(bool useProgLimit, byte trackno); private: + byte *resetsCounterP = NULL; // points to the resetPacketCounter if this is a prog track void getFastPin(const FSH* type,int pin, bool input, FASTPIN & result); void getFastPin(const FSH* type,int pin, FASTPIN & result) { getFastPin(type, pin, 0, result); diff --git a/TrackManager.cpp b/TrackManager.cpp index 5618644..58f10f7 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -124,6 +124,8 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr track[t]->setPower(POWERMODE::OFF); trackMode[t]=TRACK_MODE_OFF; } + } else { + track[trackToSet]->setResetCounterPointer(NULL); // only the prog track has this pointer set } trackMode[trackToSet]=mode; trackDCAddr[trackToSet]=dcAddr;