mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-23 12:51:24 +01:00
ESP32: implement JOIN
This commit is contained in:
parent
d3dbeaa666
commit
e36e867ec2
22
DCCACK.cpp
22
DCCACK.cpp
@ -67,23 +67,25 @@ CALLBACK_STATE DCCACK::callbackState=READY;
|
||||
ACK_CALLBACK DCCACK::ackManagerCallback;
|
||||
|
||||
void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_CALLBACK callback) {
|
||||
ackManagerRejoin=TrackManager::isJoined();
|
||||
if (ackManagerRejoin) {
|
||||
// Change from JOIN must zero resets packet.
|
||||
TrackManager::setJoin(false);
|
||||
DCCWaveform::progTrack.clearResets();
|
||||
}
|
||||
|
||||
progDriver=TrackManager::getProgDriver();
|
||||
if (progDriver==NULL) {
|
||||
callback(-3); // we dont have a prog track!
|
||||
return;
|
||||
}
|
||||
TrackManager::setJoin(ackManagerRejoin);
|
||||
callback(-3); // we dont have a prog track!
|
||||
return;
|
||||
}
|
||||
if (!progDriver->canMeasureCurrent()) {
|
||||
TrackManager::setJoin(ackManagerRejoin);
|
||||
callback(-2); // our prog track cant measure current
|
||||
return;
|
||||
}
|
||||
|
||||
ackManagerRejoin=TrackManager::isJoined();
|
||||
if (ackManagerRejoin ) {
|
||||
// Change from JOIN must zero resets packet.
|
||||
TrackManager::setJoin(false);
|
||||
DCCWaveform::progTrack.clearResets();
|
||||
}
|
||||
|
||||
autoPowerOff=false;
|
||||
if (progDriver->getPower() == POWERMODE::OFF) {
|
||||
autoPowerOff=true; // power off afterwards
|
||||
|
@ -213,10 +213,10 @@ void DCCWaveform::begin() {
|
||||
for(const auto& md: TrackManager::getMainDrivers()) {
|
||||
pinpair p = md->getSignalPin();
|
||||
if(rmtMainChannel) {
|
||||
// DIAG(F("added pins %d %d to MAIN channel"), p.pin, p.invpin);
|
||||
//DIAG(F("added pins %d %d to MAIN channel"), p.pin, p.invpin);
|
||||
rmtMainChannel->addPin(p); // add pin to existing main channel
|
||||
} else {
|
||||
// DIAG(F("new MAIN channel with pins %d %d"), p.pin, p.invpin);
|
||||
//DIAG(F("new MAIN channel with pins %d %d"), p.pin, p.invpin);
|
||||
rmtMainChannel = new RMTChannel(p, true); /* create new main channel */
|
||||
}
|
||||
}
|
||||
@ -224,10 +224,10 @@ void DCCWaveform::begin() {
|
||||
if (md) {
|
||||
pinpair p = md->getSignalPin();
|
||||
if (rmtProgChannel) {
|
||||
// DIAG(F("added pins %d %d to PROG channel"), p.pin, p.invpin);
|
||||
//DIAG(F("added pins %d %d to PROG channel"), p.pin, p.invpin);
|
||||
rmtProgChannel->addPin(p); // add pin to existing prog channel
|
||||
} else {
|
||||
// DIAG(F("new PROGchannel with pins %d %d"), p.pin, p.invpin);
|
||||
//DIAG(F("new PROGchannel with pins %d %d"), p.pin, p.invpin);
|
||||
rmtProgChannel = new RMTChannel(p, false);
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
#define GITHUB_SHA "PORTX-HAL-20220817"
|
||||
#define GITHUB_SHA "PORTX-HAL-20220817-1"
|
||||
|
@ -50,6 +50,9 @@ byte TrackManager::lastTrack=0;
|
||||
bool TrackManager::progTrackSyncMain=false;
|
||||
bool TrackManager::progTrackBoosted=false;
|
||||
int16_t TrackManager::joinRelay=UNUSED_PIN;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
byte TrackManager::tempProgTrack=MAX_TRACKS+1;
|
||||
#endif
|
||||
|
||||
|
||||
// The setup call is done this way so that the tracks can be in a list
|
||||
@ -141,11 +144,11 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
// remove pin from MUX matrix and turn it off
|
||||
pinpair p = track[trackToSet]->getSignalPin();
|
||||
// DIAG(F("Track=%c remove pin %d"),trackToSet+'A', p.pin);
|
||||
//DIAG(F("Track=%c remove pin %d"),trackToSet+'A', p.pin);
|
||||
gpio_reset_pin((gpio_num_t)p.pin);
|
||||
pinMode(p.pin, OUTPUT); // gpio_reset_pin may reset to input
|
||||
if (p.invpin != UNUSED_PIN) {
|
||||
DIAG(F("Track=%c remove ^pin %d"),trackToSet+'A', p.invpin);
|
||||
//DIAG(F("Track=%c remove ^pin %d"),trackToSet+'A', p.invpin);
|
||||
gpio_reset_pin((gpio_num_t)p.invpin);
|
||||
pinMode(p.invpin, OUTPUT); // gpio_reset_pin may reset to input
|
||||
}
|
||||
@ -384,6 +387,22 @@ void TrackManager::setJoinRelayPin(byte joinRelayPin) {
|
||||
}
|
||||
|
||||
void TrackManager::setJoin(bool joined) {
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if (joined) {
|
||||
FOR_EACH_TRACK(t) {
|
||||
if (trackMode[t]==TRACK_MODE_PROG) {
|
||||
tempProgTrack = t;
|
||||
setTrackMode(t, TRACK_MODE_MAIN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (tempProgTrack != MAX_TRACKS+1) {
|
||||
setTrackMode(tempProgTrack, TRACK_MODE_PROG);
|
||||
tempProgTrack = MAX_TRACKS+1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
progTrackSyncMain=joined;
|
||||
if (joinRelay!=UNUSED_PIN) digitalWrite(joinRelay,joined?HIGH:LOW);
|
||||
}
|
||||
|
@ -90,6 +90,9 @@ class TrackManager {
|
||||
static MotorDriver* track[MAX_TRACKS];
|
||||
static TRACK_MODE trackMode[MAX_TRACKS];
|
||||
static int16_t trackDCAddr[MAX_TRACKS]; // dc address if TRACK_MODE_DC or TRACK_MODE_DCX
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
static byte tempProgTrack; // holds the prog track number during join
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user