1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

Prog-Track-As-Siding

This commit is contained in:
Asbelos 2020-07-12 00:11:30 +01:00
parent 2fbbbfc8bd
commit a245b9d119
4 changed files with 26 additions and 9 deletions

View File

@ -157,7 +157,9 @@ void DCC::writeCVBitMain(int cab, int cv, byte bNum, bool bValue) {
DCCWaveform::mainTrack.schedulePacket(b, nB, 4); DCCWaveform::mainTrack.schedulePacket(b, nB, 4);
} }
void DCC::setProgTrackSyncMain(bool on) {
DCCWaveform::progTrackSyncMain=on;
}
const ackOp PROGMEM WRITE_BIT0_PROG[] = { const ackOp PROGMEM WRITE_BIT0_PROG[] = {
BASELINE, BASELINE,

1
DCC.h
View File

@ -63,6 +63,7 @@ class DCC {
static void setAccessory(int aAdd, byte aNum, bool activate) ; static void setAccessory(int aAdd, byte aNum, bool activate) ;
static bool writeTextPacket( byte *b, int nBytes); static bool writeTextPacket( byte *b, int nBytes);
static void setDebug(bool on); static void setDebug(bool on);
static void setProgTrackSyncMain(bool on); // when true, prog track becomes driveable
// ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1 // ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1
static void readCV(int cv, ACK_CALLBACK callback); static void readCV(int cv, ACK_CALLBACK callback);

View File

@ -26,7 +26,7 @@ DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false, (int)(PROG_MAX_MI
const int ACK_MIN_PULSE_RAW=65 / PROG_SENSE_FACTOR; const int ACK_MIN_PULSE_RAW=65 / PROG_SENSE_FACTOR;
bool DCCWaveform::progTrackSyncMain=false;
void DCCWaveform::begin() { void DCCWaveform::begin() {
Hardware::init(); Hardware::init();
@ -102,6 +102,8 @@ void DCCWaveform::checkPowerOverload() {
if (millis() - lastSampleTaken < sampleDelay) return; if (millis() - lastSampleTaken < sampleDelay) return;
lastSampleTaken = millis(); lastSampleTaken = millis();
int tripValue= rawCurrentTripValue;
if (!isMainTrack && (ackPending || progTrackSyncMain)) tripValue=ACK_CURRENT_TRIP;
switch (powerMode) { switch (powerMode) {
case POWERMODE::OFF: case POWERMODE::OFF:
@ -110,11 +112,11 @@ void DCCWaveform::checkPowerOverload() {
case POWERMODE::ON: case POWERMODE::ON:
// Check current // Check current
lastCurrent = Hardware::getCurrentRaw(isMainTrack); lastCurrent = Hardware::getCurrentRaw(isMainTrack);
if (lastCurrent <= (ackPending?ACK_CURRENT_TRIP:rawCurrentTripValue)) sampleDelay = POWER_SAMPLE_ON_WAIT; if (lastCurrent <= tripValue) sampleDelay = POWER_SAMPLE_ON_WAIT;
else { else {
setPowerMode(POWERMODE::OVERLOAD); setPowerMode(POWERMODE::OVERLOAD);
unsigned int mA=Hardware::getCurrentMilliamps(isMainTrack,lastCurrent); unsigned int mA=Hardware::getCurrentMilliamps(isMainTrack,lastCurrent);
unsigned int maxmA=Hardware::getCurrentMilliamps(isMainTrack,ackPending?ACK_CURRENT_TRIP:rawCurrentTripValue); unsigned int maxmA=Hardware::getCurrentMilliamps(isMainTrack,tripValue);
DIAG(F("\n*** %S TRACK POWER OVERLOAD current=%d max=%d ***\n"), isMainTrack ? F("MAIN") : F("PROG"), mA, maxmA); DIAG(F("\n*** %S TRACK POWER OVERLOAD current=%d max=%d ***\n"), isMainTrack ? F("MAIN") : F("PROG"), mA, maxmA);
sampleDelay = POWER_SAMPLE_OVERLOAD_WAIT; sampleDelay = POWER_SAMPLE_OVERLOAD_WAIT;
} }
@ -140,19 +142,19 @@ bool DCCWaveform::interrupt1() {
// otherwise can cause hangs in main loop waiting for the pendingBuffer. // otherwise can cause hangs in main loop waiting for the pendingBuffer.
switch (state) { switch (state) {
case 0: // start of bit transmission case 0: // start of bit transmission
Hardware::setSignal(isMainTrack, HIGH); setSignal(HIGH);
state = 1; state = 1;
return true; // must call interrupt2 to set currentBit return true; // must call interrupt2 to set currentBit
case 1: // 58us after case 0 case 1: // 58us after case 0
if (currentBit) { if (currentBit) {
Hardware::setSignal(isMainTrack, LOW); setSignal(LOW);
state = 0; state = 0;
} }
else state = 2; else state = 2;
break; break;
case 2: // 116us after case 0 case 2: // 116us after case 0
Hardware::setSignal(isMainTrack, LOW); setSignal(LOW);
state = 3; state = 3;
break; break;
case 3: // finished sending zero bit case 3: // finished sending zero bit
@ -168,6 +170,16 @@ bool DCCWaveform::interrupt1() {
} }
void DCCWaveform::setSignal(bool high) {
if (progTrackSyncMain) {
if (!isMainTrack) return; // ignore PROG track waveform while in sync
// set both tracks to same signal
Hardware::setSignal(true, high);
Hardware::setSignal(false, high);
return;
}
Hardware::setSignal(isMainTrack,high);
}
void DCCWaveform::interrupt2() { void DCCWaveform::interrupt2() {
// set currentBit to be the next bit to be sent. // set currentBit to be the next bit to be sent.

View File

@ -62,6 +62,7 @@ class DCCWaveform {
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
static bool progTrackSyncMain; // true when prog track is a siding switched to main
private: private:
@ -69,6 +70,7 @@ class DCCWaveform {
bool interrupt1(); bool interrupt1();
void interrupt2(); void interrupt2();
void checkAck(); void checkAck();
void setSignal(bool high);
bool isMainTrack; bool isMainTrack;