1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 21:21:24 +01:00

autopower on/off merged into BASELINE and exit codes

This commit is contained in:
Harald Barth 2020-09-08 22:14:05 +02:00
parent ad4928043c
commit 7a008938ec
2 changed files with 19 additions and 13 deletions

26
DCC.cpp
View File

@ -518,7 +518,13 @@ void DCC::ackManagerLoop(bool blocking) {
// if blocking then we must ONLY return AFTER callback issued // if blocking then we must ONLY return AFTER callback issued
switch (opcode) { switch (opcode) {
case BASELINE: case BASELINE:
if (checkResets(blocking, 3)) return; if (DCCWaveform::progTrack.getPowerMode() == POWERMODE::OFF) {
DCCWaveform::progTrack.setPowerMode(POWERMODE::ON);
DCCWaveform::progTrack.sentResetsSincePacket = 0;
DCCWaveform::progTrack.autoPowerOff=true;
return;
}
if (checkResets(blocking, DCCWaveform::progTrack.autoPowerOff ? 20 : 3)) return;
DCCWaveform::progTrack.setAckBaseline(debugMode); DCCWaveform::progTrack.setAckBaseline(debugMode);
break; break;
case W0: // write 0 bit case W0: // write 0 bit
@ -582,6 +588,7 @@ void DCC::ackManagerLoop(bool blocking) {
case ITC1: // If True Callback(0 or 1) (if prevous WACK got an ACK) case ITC1: // If True Callback(0 or 1) (if prevous WACK got an ACK)
if (ackReceived) { if (ackReceived) {
ackManagerProg = NULL; // all done now ackManagerProg = NULL; // all done now
DCCWaveform::progTrack.doAutoPowerOff();
callback(opcode==ITC0?0:1); callback(opcode==ITC0?0:1);
return; return;
} }
@ -590,6 +597,7 @@ void DCC::ackManagerLoop(bool blocking) {
case ITCB: // If True callback(byte) case ITCB: // If True callback(byte)
if (ackReceived) { if (ackReceived) {
ackManagerProg = NULL; // all done now ackManagerProg = NULL; // all done now
DCCWaveform::progTrack.doAutoPowerOff();
callback(ackManagerByte); callback(ackManagerByte);
return; return;
} }
@ -598,6 +606,7 @@ void DCC::ackManagerLoop(bool blocking) {
case NAKFAIL: // If nack callback(-1) case NAKFAIL: // If nack callback(-1)
if (!ackReceived) { if (!ackReceived) {
ackManagerProg = NULL; // all done now ackManagerProg = NULL; // all done now
DCCWaveform::progTrack.doAutoPowerOff();
callback(-1); callback(-1);
return; return;
} }
@ -605,7 +614,8 @@ void DCC::ackManagerLoop(bool blocking) {
case FAIL: // callback(-1) case FAIL: // callback(-1)
ackManagerProg = NULL; ackManagerProg = NULL;
callback(-1); DCCWaveform::progTrack.doAutoPowerOff();
callback(-1);
return; return;
case STARTMERGE: case STARTMERGE:
@ -637,6 +647,7 @@ void DCC::ackManagerLoop(bool blocking) {
case COMBINELOCOID: case COMBINELOCOID:
// ackManagerStash is cv17, ackManagerByte is CV 18 // ackManagerStash is cv17, ackManagerByte is CV 18
ackManagerProg=NULL; ackManagerProg=NULL;
DCCWaveform::progTrack.doAutoPowerOff();
callback( ackManagerByte + ((ackManagerStash - 192) << 8)); callback( ackManagerByte + ((ackManagerStash - 192) << 8));
return; return;
@ -649,19 +660,8 @@ void DCC::ackManagerLoop(bool blocking) {
} }
break; break;
case POWERON: case POWERON:
if (DCCWaveform::progTrack.getPowerMode() == POWERMODE::OFF) {
DCCWaveform::progTrack.setPowerMode(POWERMODE::ON);
DCCWaveform::progTrack.sentResetsSincePacket = 0;
DCCWaveform::progTrack.autoPowerOff=true;
return;
}
if (checkResets(blocking, 20)) return;
break; break;
case POWEROFF: case POWEROFF:
if (DCCWaveform::progTrack.autoPowerOff) {
DCCWaveform::progTrack.setPowerMode(POWERMODE::OFF);
DCCWaveform::progTrack.autoPowerOff=false;
}
break; break;
case SKIPTARGET: case SKIPTARGET:
break; break;

View File

@ -65,6 +65,12 @@ class DCCWaveform {
void setAckPending(bool debug); //prog track only void setAckPending(bool debug); //prog track only
byte getAck(bool debug); //prog track only 0=NACK, 1=ACK 2=keep waiting byte getAck(bool debug); //prog track only 0=NACK, 1=ACK 2=keep waiting
static bool progTrackSyncMain; // true when prog track is a siding switched to main static bool progTrackSyncMain; // true when prog track is a siding switched to main
inline void doAutoPowerOff() {
if (autoPowerOff) {
setPowerMode(POWERMODE::OFF);
autoPowerOff=false;
}
};
private: private:
static VirtualTimer * interruptTimer; static VirtualTimer * interruptTimer;