mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-30 19:45:04 +01:00
Adjust forget commands to respect the direction of engines
Instead of sending the "backwards e-stop" packet to locos the CS will send the e-stop packet with the direction the locos should already have.
This commit is contained in:
parent
f8a19de9fb
commit
420ed7355d
31
DCC.cpp
31
DCC.cpp
|
@ -75,7 +75,7 @@ void DCC::begin(const FSH * motorShieldName) {
|
||||||
|
|
||||||
|
|
||||||
void DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) {
|
void DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) {
|
||||||
byte speedCode = (tSpeed & 0x7F) + tDirection * 128;
|
byte speedCode = calculateSpeedByte(tSpeed,tDirection);
|
||||||
setThrottle2(cab, speedCode);
|
setThrottle2(cab, speedCode);
|
||||||
TrackManager::setDCSignal(cab,speedCode); // in case this is a dcc track on this addr
|
TrackManager::setDCSignal(cab,speedCode); // in case this is a dcc track on this addr
|
||||||
// retain speed for loco reminders
|
// retain speed for loco reminders
|
||||||
|
@ -540,15 +540,24 @@ void DCC::setLocoId(int id,ACK_CALLBACK callback) {
|
||||||
DCCACK::Setup(id | 0xc000,LONG_LOCO_ID_PROG, callback);
|
DCCACK::Setup(id | 0xc000,LONG_LOCO_ID_PROG, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCC::forgetLoco(int cab) { // removes any speed reminders for this loco
|
void DCC::forgetLoco(int cab){ // removes any speed reminders for this loco
|
||||||
setThrottle2(cab,1); // ESTOP this loco if still on track
|
auto direction = getThrottleDirection(cab);
|
||||||
int reg=lookupSpeedTable(cab);
|
setThrottle2(cab, calculateSpeedByte(1, direction)); // ESTOP this loco if still on track
|
||||||
if (reg>=0) speedTable[reg].loco=0;
|
int reg = lookupSpeedTable(cab);
|
||||||
setThrottle2(cab,1); // ESTOP if this loco still on track
|
if (reg >= 0)
|
||||||
|
speedTable[reg].loco = 0;
|
||||||
|
setThrottle2(cab, calculateSpeedByte(1, direction)); // ESTOP if this loco still on track
|
||||||
}
|
}
|
||||||
void DCC::forgetAllLocos() { // removes all speed reminders
|
|
||||||
setThrottle2(0,1); // ESTOP all locos still on track
|
void DCC::forgetAllLocos() { // removes all speed reminders
|
||||||
for (int i=0;i<MAX_LOCOS;i++) speedTable[i].loco=0;
|
for (int i = 0; i < MAX_LOCOS; i++) {
|
||||||
|
auto &locoId = speedTable[i].loco;
|
||||||
|
if (locoId != 0) {
|
||||||
|
auto direction = getThrottleDirection(locoId);
|
||||||
|
setThrottle2(locoId, calculateSpeedByte(1, direction));
|
||||||
|
locoId = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte DCC::loopStatus=0;
|
byte DCC::loopStatus=0;
|
||||||
|
@ -621,6 +630,10 @@ bool DCC::issueReminder(int reg) {
|
||||||
|
|
||||||
///// Private helper functions below here /////////////////////
|
///// Private helper functions below here /////////////////////
|
||||||
|
|
||||||
|
inline byte DCC::calculateSpeedByte(uint8_t tSpeed, bool tDirection) {
|
||||||
|
return (tSpeed & 0x7F) + tDirection * 128;
|
||||||
|
}
|
||||||
|
|
||||||
byte DCC::cv1(byte opcode, int cv) {
|
byte DCC::cv1(byte opcode, int cv) {
|
||||||
cv--;
|
cv--;
|
||||||
return (highByte(cv) & (byte)0x03) | opcode;
|
return (highByte(cv) & (byte)0x03) | opcode;
|
||||||
|
|
1
DCC.h
1
DCC.h
|
@ -102,6 +102,7 @@ public:
|
||||||
static byte cv2(int cv);
|
static byte cv2(int cv);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static byte calculateSpeedByte(uint8_t tSpeed, bool tDirection);
|
||||||
static byte loopStatus;
|
static byte loopStatus;
|
||||||
static void setThrottle2(uint16_t cab, uint8_t speedCode);
|
static void setThrottle2(uint16_t cab, uint8_t speedCode);
|
||||||
static void updateLocoReminder(int loco, byte speedCode);
|
static void updateLocoReminder(int loco, byte speedCode);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user