From c7cf8246a7c78ad0f9b85b9b2c0c6451446ce5be Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 2 Aug 2022 15:57:45 +0200 Subject: [PATCH] make sentResetsSincePacket private to the class and replace all accesses with with methods --- DCCACK.cpp | 6 +++--- DCCWaveform.cpp | 10 +++++----- DCCWaveform.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/DCCACK.cpp b/DCCACK.cpp index de66355..d159383 100644 --- a/DCCACK.cpp +++ b/DCCACK.cpp @@ -81,7 +81,7 @@ void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_C if (ackManagerRejoin ) { // Change from JOIN must zero resets packet. TrackManager::setJoin(false); - DCCWaveform::progTrack.sentResetsSincePacket = 0; + DCCWaveform::progTrack.clearResets(); } autoPowerOff=false; @@ -93,7 +93,7 @@ void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_C /* TODO !!! in MotorDriver surely! if (MotorDriver::commonFaultPin) DCCWaveform::mainTrack.setPowerMode(POWERMODE::ON); - DCCWaveform::progTrack.sentResetsSincePacket = 0; + DCCWaveform::progTrack.clearResets(); **/ } @@ -117,7 +117,7 @@ const byte RESET_MIN=8; // tuning of reset counter before sending message // checkRessets return true if the caller should yield back to loop and try later. bool DCCACK::checkResets(uint8_t numResets) { - return DCCWaveform::progTrack.sentResetsSincePacket < numResets; + return DCCWaveform::progTrack.getResets() < numResets; } // Operations applicable to PROG track ONLY. // (yes I know I could have subclassed the main track but...) diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 7cb59da..e39a61c 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -89,7 +89,7 @@ void DCCWaveform::interruptHandler() { // WAVE_PENDING means we dont yet know what the next bit is if (mainTrack.state==WAVE_PENDING) mainTrack.interrupt2(); if (progTrack.state==WAVE_PENDING) progTrack.interrupt2(); - else DCCACK::checkAck(progTrack.sentResetsSincePacket); + else DCCACK::checkAck(progTrack.getResets()); } #pragma GCC pop_options @@ -160,14 +160,14 @@ void DCCWaveform::interrupt2() { transmitLength = pendingLength; transmitRepeats = pendingRepeats; packetPending = false; - sentResetsSincePacket=0; + clearResets(); } else { // Fortunately reset and idle packets are the same length memcpy( transmitPacket, isMainTrack ? idlePacket : resetPacket, sizeof(idlePacket)); transmitLength = sizeof(idlePacket); transmitRepeats = 0; - if (sentResetsSincePacket<250) sentResetsSincePacket++; + if (getResets() < 250) sentResetsSincePacket++; // only place to increment (private!) } } } @@ -189,7 +189,7 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea pendingLength = byteCount + 1; pendingRepeats = repeats; packetPending = true; - sentResetsSincePacket=0; + clearResets(); } bool DCCWaveform::getPacketPending() { return packetPending; @@ -237,7 +237,7 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea pendingPacket[byteCount] = checksum; pendingLength = byteCount + 1; pendingRepeats = repeats; - sentResetsSincePacket=0; + clearResets(); { int ret; do { diff --git a/DCCWaveform.h b/DCCWaveform.h index cad7861..3ba313a 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -69,12 +69,12 @@ class DCCWaveform { }; #endif void schedulePacket(const byte buffer[], byte byteCount, byte repeats); - volatile byte sentResetsSincePacket; bool getPacketPending(); private: #ifndef ARDUINO_ARCH_ESP32 volatile bool packetPending; + volatile byte sentResetsSincePacket; #else volatile uint32_t resetPacketBase; #endif