diff --git a/DCC.cpp b/DCC.cpp index f8ca7b1..0993f4c 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -587,7 +587,7 @@ void DCC::loop() { void DCC::issueReminders() { // if the main track transmitter still has a pending packet, skip this time around. - if ( DCCWaveform::mainTrack.packetPending) return; + if ( DCCWaveform::mainTrack.getPacketPending()) return; // This loop searches for a loco in the speed table starting at nextLoco and cycling back around for (int reg=0;reg MAX_PACKET_SIZE) return; // allow for chksum + + byte checksum = 0; + for (byte b = 0; b < byteCount; b++) { + checksum ^= buffer[b]; + pendingPacket[b] = buffer[b]; + } + // buffer is MAX_PACKET_SIZE but pendingPacket is one bigger + pendingPacket[byteCount] = checksum; + pendingLength = byteCount + 1; + pendingRepeats = repeats; + sentResetsSincePacket=0; + { + int ret; + do { + if(isMainTrack) + ret = rmtMainChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats); + else + ret = rmtProgChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats); + } while(ret > 0); + } +} + +bool DCCWaveform::getPacketPending() { + if(isMainTrack) + return rmtMainChannel->busy(); + else + return rmtProgChannel->busy(); } void DCCWaveform::loop() { } diff --git a/DCCWaveform.h b/DCCWaveform.h index d530b70..2a55189 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -54,11 +54,13 @@ class DCCWaveform { static DCCWaveform progTrack; inline void clearRepeats() { transmitRepeats=0; } void schedulePacket(const byte buffer[], byte byteCount, byte repeats); - volatile bool packetPending; volatile byte sentResetsSincePacket; + bool getPacketPending(); private: - +#ifndef ARDUINO_ARCH_ESP32 + volatile bool packetPending; +#endif static void interruptHandler(); void interrupt2();