mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
ESP32: implement JOIN
This commit is contained in:
parent
d3dbeaa666
commit
e36e867ec2
22
DCCACK.cpp
22
DCCACK.cpp
|
@ -67,16 +67,6 @@ CALLBACK_STATE DCCACK::callbackState=READY;
|
||||||
ACK_CALLBACK DCCACK::ackManagerCallback;
|
ACK_CALLBACK DCCACK::ackManagerCallback;
|
||||||
|
|
||||||
void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_CALLBACK callback) {
|
void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_CALLBACK callback) {
|
||||||
progDriver=TrackManager::getProgDriver();
|
|
||||||
if (progDriver==NULL) {
|
|
||||||
callback(-3); // we dont have a prog track!
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!progDriver->canMeasureCurrent()) {
|
|
||||||
callback(-2); // our prog track cant measure current
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ackManagerRejoin=TrackManager::isJoined();
|
ackManagerRejoin=TrackManager::isJoined();
|
||||||
if (ackManagerRejoin) {
|
if (ackManagerRejoin) {
|
||||||
// Change from JOIN must zero resets packet.
|
// Change from JOIN must zero resets packet.
|
||||||
|
@ -84,6 +74,18 @@ void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_C
|
||||||
DCCWaveform::progTrack.clearResets();
|
DCCWaveform::progTrack.clearResets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progDriver=TrackManager::getProgDriver();
|
||||||
|
if (progDriver==NULL) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
autoPowerOff=false;
|
autoPowerOff=false;
|
||||||
if (progDriver->getPower() == POWERMODE::OFF) {
|
if (progDriver->getPower() == POWERMODE::OFF) {
|
||||||
autoPowerOff=true; // power off afterwards
|
autoPowerOff=true; // power off afterwards
|
||||||
|
|
|
@ -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::progTrackSyncMain=false;
|
||||||
bool TrackManager::progTrackBoosted=false;
|
bool TrackManager::progTrackBoosted=false;
|
||||||
int16_t TrackManager::joinRelay=UNUSED_PIN;
|
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
|
// The setup call is done this way so that the tracks can be in a list
|
||||||
|
@ -145,7 +148,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||||
gpio_reset_pin((gpio_num_t)p.pin);
|
gpio_reset_pin((gpio_num_t)p.pin);
|
||||||
pinMode(p.pin, OUTPUT); // gpio_reset_pin may reset to input
|
pinMode(p.pin, OUTPUT); // gpio_reset_pin may reset to input
|
||||||
if (p.invpin != UNUSED_PIN) {
|
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);
|
gpio_reset_pin((gpio_num_t)p.invpin);
|
||||||
pinMode(p.invpin, OUTPUT); // gpio_reset_pin may reset to input
|
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) {
|
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;
|
progTrackSyncMain=joined;
|
||||||
if (joinRelay!=UNUSED_PIN) digitalWrite(joinRelay,joined?HIGH:LOW);
|
if (joinRelay!=UNUSED_PIN) digitalWrite(joinRelay,joined?HIGH:LOW);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,9 @@ class TrackManager {
|
||||||
static MotorDriver* track[MAX_TRACKS];
|
static MotorDriver* track[MAX_TRACKS];
|
||||||
static TRACK_MODE trackMode[MAX_TRACKS];
|
static TRACK_MODE trackMode[MAX_TRACKS];
|
||||||
static int16_t trackDCAddr[MAX_TRACKS]; // dc address if TRACK_MODE_DC or TRACK_MODE_DCX
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user