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

Introduce POWERON and POWEROFF opcodes

This commit is contained in:
Harald Barth 2020-09-08 09:47:40 +02:00
parent 665a540a73
commit 5c775531f6
3 changed files with 19 additions and 1 deletions

15
DCC.cpp
View File

@ -643,6 +643,21 @@ void DCC::ackManagerLoop(bool blocking) {
opcode=pgm_read_byte_near(ackManagerProg); opcode=pgm_read_byte_near(ackManagerProg);
} }
break; break;
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;
case POWEROFF:
if (DCCWaveform::progTrack.autoPowerOff) {
DCCWaveform::progTrack.setPowerMode(POWERMODE::OFF);
DCCWaveform::progTrack.autoPowerOff=false;
}
break;
case SKIPTARGET: case SKIPTARGET:
break; break;
default: default:

4
DCC.h
View File

@ -44,6 +44,8 @@ SETCV, // sets cv number to next prog byte
STASHLOCOID, // keeps current byte value for later STASHLOCOID, // keeps current byte value for later
COMBINELOCOID, // combines current value with stashed value and returns it COMBINELOCOID, // combines current value with stashed value and returns it
ITSKIP, // skip to SKIPTARGET if ack true ITSKIP, // skip to SKIPTARGET if ack true
POWERON, // check if power on prog track is on and remember state
POWEROFF, // turn power off again if it was off before POWERON
SKIPTARGET=0xFF // jump to target SKIPTARGET=0xFF // jump to target
}; };
@ -120,7 +122,7 @@ private:
static ACK_CALLBACK ackManagerCallback; static ACK_CALLBACK ackManagerCallback;
static void ackManagerSetup(int cv, byte bitNumOrbyteValue, ackOp const program[], ACK_CALLBACK callback, bool blocking); static void ackManagerSetup(int cv, byte bitNumOrbyteValue, ackOp const program[], ACK_CALLBACK callback, bool blocking);
static void ackManagerLoop(bool blocking); static void ackManagerLoop(bool blocking);
static bool checkResets(bool blocking); static bool checkResets(bool blocking, uint8_t numResets);
static const int PROG_REPEATS=8; // repeats of programming commands (some decoders need at least 8 to be reliable) static const int PROG_REPEATS=8; // repeats of programming commands (some decoders need at least 8 to be reliable)

View File

@ -60,6 +60,7 @@ class DCCWaveform {
void schedulePacket(const byte buffer[], byte byteCount, byte repeats); void schedulePacket(const byte buffer[], byte byteCount, byte repeats);
volatile bool packetPending; volatile bool packetPending;
volatile byte sentResetsSincePacket; volatile byte sentResetsSincePacket;
volatile bool autoPowerOff=false;
void setAckBaseline(bool debug); //prog track only void setAckBaseline(bool debug); //prog track only
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