diff --git a/DCC.cpp b/DCC.cpp index 01c2309..b4b6fc1 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -158,7 +158,7 @@ void DCC::setThrottle2( uint16_t cab, byte speedCode) { b[nB++] = speedCode; // for encoding see setThrottle } - if (speedCode==1) DCCQueue::scheduleEstopPacket(b, nB, 4, cab); // highest priority + if ((speedCode & 0x7F) == 1) DCCQueue::scheduleEstopPacket(b, nB, 4, cab); // highest priority else DCCQueue::scheduleDCCSpeedPacket( b, nB, 4, cab); } diff --git a/DCCQueue.cpp b/DCCQueue.cpp index 1186bd5..8330e74 100644 --- a/DCCQueue.cpp +++ b/DCCQueue.cpp @@ -20,8 +20,10 @@ #include "Arduino.h" +#include "defines.h" #include "DCCQueue.h" #include "DCCWaveform.h" +#include "DIAG.h" // create statics DCCQueue* DCCQueue::lowPriorityQueue=new DCCQueue(); @@ -80,7 +82,8 @@ PendingSlot* DCCQueue::recycleList=nullptr; void DCCQueue::scheduleEstopPacket(byte* packet, byte length, byte repeats,uint16_t loco) { - + // DIAG(F("DCC ESTOP loco=%d"),loco); + // kill any existing throttle packets for this loco PendingSlot * previous=nullptr; auto p=highPriorityQueue->head; @@ -130,6 +133,7 @@ PendingSlot* DCCQueue::recycleList=nullptr; // remove this slot from the queue if (previous) previous->next=p->next; else highPriorityQueue->head=p->next; + if (!highPriorityQueue->head) highPriorityQueue->tail=nullptr; // and recycle it. recycle(p); @@ -166,6 +170,7 @@ PendingSlot* DCCQueue::recycleList=nullptr; recycleList=p->next; } else { + DIAG(F("New DCC queue slot")); p=new PendingSlot; // need a queue entry } p->next=nullptr;