1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +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);
}
void DCC::setProgTrackSyncMain(bool on) {
DCCWaveform::progTrackSyncMain=on;
}
const ackOp PROGMEM WRITE_BIT0_PROG[] = {
BASELINE,

1
DCC.h
View File

@ -63,6 +63,7 @@ class DCC {
static void setAccessory(int aAdd, byte aNum, bool activate) ;
static bool writeTextPacket( byte *b, int nBytes);
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
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;
bool DCCWaveform::progTrackSyncMain=false;
void DCCWaveform::begin() {
Hardware::init();
@ -102,6 +102,8 @@ void DCCWaveform::checkPowerOverload() {
if (millis() - lastSampleTaken < sampleDelay) return;
lastSampleTaken = millis();
int tripValue= rawCurrentTripValue;
if (!isMainTrack && (ackPending || progTrackSyncMain)) tripValue=ACK_CURRENT_TRIP;
switch (powerMode) {
case POWERMODE::OFF:
@ -110,11 +112,11 @@ void DCCWaveform::checkPowerOverload() {
case POWERMODE::ON:
// Check current
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 {
setPowerMode(POWERMODE::OVERLOAD);
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);
sampleDelay = POWER_SAMPLE_OVERLOAD_WAIT;
}
@ -140,19 +142,19 @@ bool DCCWaveform::interrupt1() {
// otherwise can cause hangs in main loop waiting for the pendingBuffer.
switch (state) {
case 0: // start of bit transmission
Hardware::setSignal(isMainTrack, HIGH);
setSignal(HIGH);
state = 1;
return true; // must call interrupt2 to set currentBit
case 1: // 58us after case 0
if (currentBit) {
Hardware::setSignal(isMainTrack, LOW);
setSignal(LOW);
state = 0;
}
else state = 2;
break;
case 2: // 116us after case 0
Hardware::setSignal(isMainTrack, LOW);
setSignal(LOW);
state = 3;
break;
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() {
// 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 setAckPending(bool debug); //prog track only
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:
@ -69,6 +70,7 @@ class DCCWaveform {
bool interrupt1();
void interrupt2();
void checkAck();
void setSignal(bool high);
bool isMainTrack;