mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 13:21:23 +01:00
commit
5f9324994e
9
DCC.cpp
9
DCC.cpp
@ -95,15 +95,6 @@ bool DCC::getThrottleDirection(int cab) {
|
|||||||
return (speedTable[reg].speedCode & 0x80) !=0;
|
return (speedTable[reg].speedCode & 0x80) !=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DCC::isThrottleInUse(int locoId) {
|
|
||||||
// return true if this loco address is already in table, false otherwise
|
|
||||||
int reg;
|
|
||||||
for (reg = 0; reg < MAX_LOCOS; reg++) {
|
|
||||||
if (speedTable[reg].loco == locoId) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set function to value on or off
|
// Set function to value on or off
|
||||||
void DCC::setFn( int cab, byte functionNumber, bool on) {
|
void DCC::setFn( int cab, byte functionNumber, bool on) {
|
||||||
if (cab<=0 || functionNumber>28) return;
|
if (cab<=0 || functionNumber>28) return;
|
||||||
|
1
DCC.h
1
DCC.h
@ -56,7 +56,6 @@ class DCC {
|
|||||||
static void setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection);
|
static void setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection);
|
||||||
static uint8_t getThrottleSpeed(int cab);
|
static uint8_t getThrottleSpeed(int cab);
|
||||||
static bool getThrottleDirection(int cab);
|
static bool getThrottleDirection(int cab);
|
||||||
static bool isThrottleInUse(int cab);
|
|
||||||
static void writeCVByteMain(int cab, int cv, byte bValue);
|
static void writeCVByteMain(int cab, int cv, byte bValue);
|
||||||
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);
|
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);
|
||||||
static void setFunction( int cab, byte fByte, byte eByte);
|
static void setFunction( int cab, byte fByte, byte eByte);
|
||||||
|
@ -183,8 +183,7 @@ void DCCWaveform::setSignal(bool high) {
|
|||||||
if (progTrackSyncMain) {
|
if (progTrackSyncMain) {
|
||||||
if (!isMainTrack) return; // ignore PROG track waveform while in sync
|
if (!isMainTrack) return; // ignore PROG track waveform while in sync
|
||||||
// set both tracks to same signal
|
// set both tracks to same signal
|
||||||
Hardware::setSignal(true, high);
|
Hardware::setSyncSignal(high);
|
||||||
Hardware::setSignal(false, high);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Hardware::setSignal(isMainTrack,high);
|
Hardware::setSignal(isMainTrack,high);
|
||||||
|
16
Hardware.cpp
16
Hardware.cpp
@ -64,6 +64,22 @@ void Hardware::setSignal(bool isMainTrack, bool high) {
|
|||||||
if (pin2 != UNUSED_PIN) WritePin(pin2, high ? LOW : HIGH);
|
if (pin2 != UNUSED_PIN) WritePin(pin2, high ? LOW : HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hardware::setSyncSignal(bool high) {
|
||||||
|
// This sets the same signal down both tracks at the same time.
|
||||||
|
// Speed notes....
|
||||||
|
// Objective is to get the two track signals to change as close as possible
|
||||||
|
// the high ? HIGH:LOW will only be evaluated once
|
||||||
|
// The UNUSED_PIN check will be done at compile time.
|
||||||
|
// If even more speed is required, its possible (not SAMD) to pre-prepare the
|
||||||
|
// DIO pinnumber->pincode translation so the WritePin (digitalWrite2) does not
|
||||||
|
// have to calculate the register and bit numbers every time.
|
||||||
|
|
||||||
|
WritePin(MAIN_SIGNAL_PIN, high ? HIGH : LOW);
|
||||||
|
WritePin(PROG_SIGNAL_PIN, high ? HIGH : LOW);
|
||||||
|
if (MAIN_SIGNAL_PIN_ALT != UNUSED_PIN) WritePin(MAIN_SIGNAL_PIN_ALT, high ? LOW : HIGH);
|
||||||
|
if (PROG_SIGNAL_PIN_ALT != UNUSED_PIN) WritePin(PROG_SIGNAL_PIN_ALT, high ? LOW : HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
int Hardware::getCurrentRaw(bool isMainTrack) {
|
int Hardware::getCurrentRaw(bool isMainTrack) {
|
||||||
// tooo much crap for a interrupt routine. Will see how that goes.
|
// tooo much crap for a interrupt routine. Will see how that goes.
|
||||||
byte faultpin = isMainTrack ? MAIN_FAULT_PIN : PROG_FAULT_PIN;
|
byte faultpin = isMainTrack ? MAIN_FAULT_PIN : PROG_FAULT_PIN;
|
||||||
|
@ -24,6 +24,7 @@ class Hardware {
|
|||||||
static void init();
|
static void init();
|
||||||
static void setPower(bool isMainTrack, bool on);
|
static void setPower(bool isMainTrack, bool on);
|
||||||
static void setSignal(bool isMainTrack, bool high);
|
static void setSignal(bool isMainTrack, bool high);
|
||||||
|
static void setSyncSignal( bool high);
|
||||||
static unsigned int getCurrentMilliamps(bool isMainTrack, int rawValue);
|
static unsigned int getCurrentMilliamps(bool isMainTrack, int rawValue);
|
||||||
static int getCurrentRaw(bool isMainTrack);
|
static int getCurrentRaw(bool isMainTrack);
|
||||||
static void setBrake(bool isMainTrack, bool on);
|
static void setBrake(bool isMainTrack, bool on);
|
||||||
|
@ -55,10 +55,24 @@ bool WiThrottle::annotateLeftRight=false;
|
|||||||
|
|
||||||
WiThrottle* WiThrottle::getThrottle( int wifiClient) {
|
WiThrottle* WiThrottle::getThrottle( int wifiClient) {
|
||||||
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle)
|
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle)
|
||||||
if (wt->clientid==wifiClient) return wt;
|
if (wt->clientid==wifiClient) return wt;
|
||||||
return new WiThrottle( wifiClient);
|
return new WiThrottle( wifiClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WiThrottle::isThrottleInUse(int cab) {
|
||||||
|
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle)
|
||||||
|
if (wt->areYouUsingThrottle(cab)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WiThrottle::areYouUsingThrottle(int cab) {
|
||||||
|
LOOPLOCOS('*', cab) { // see if I have this cab in use
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// One instance of WiThrottle per connected client, so we know what the locos are
|
// One instance of WiThrottle per connected client, so we know what the locos are
|
||||||
|
|
||||||
WiThrottle::WiThrottle( int wificlientid) {
|
WiThrottle::WiThrottle( int wificlientid) {
|
||||||
@ -166,8 +180,7 @@ void WiThrottle::parse(Print & stream, byte * cmdx) {
|
|||||||
case 'Q': //
|
case 'Q': //
|
||||||
LOOPLOCOS('*', -1) { //stop and drop all locos still assigned to this WiThrottle
|
LOOPLOCOS('*', -1) { //stop and drop all locos still assigned to this WiThrottle
|
||||||
if (myLocos[loco].throttle!='\0') {
|
if (myLocos[loco].throttle!='\0') {
|
||||||
DCC::setThrottle(myLocos[loco].cab,0,1);
|
DCC::setThrottle(myLocos[loco].cab,1,1);
|
||||||
DCC::forgetLoco(myLocos[loco].cab); //unregister this loco address
|
|
||||||
StringFormatter::send(stream, F("M%c-%c%d<;>\n"), myLocos[loco].throttle, LorS(myLocos[loco].cab), myLocos[loco].cab);
|
StringFormatter::send(stream, F("M%c-%c%d<;>\n"), myLocos[loco].throttle, LorS(myLocos[loco].cab), myLocos[loco].cab);
|
||||||
myLocos[loco].throttle='\0';
|
myLocos[loco].throttle='\0';
|
||||||
}
|
}
|
||||||
@ -216,7 +229,7 @@ void WiThrottle::multithrottle(Print & stream, byte * cmd){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//return error if address is already in use
|
//return error if address is already in use
|
||||||
if (DCC::isThrottleInUse(locoid)) {
|
if (isThrottleInUse(locoid)) {
|
||||||
StringFormatter::send(stream, F("HMAddress '%d' in use!\n"), locoid);
|
StringFormatter::send(stream, F("HMAddress '%d' in use!\n"), locoid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -239,8 +252,7 @@ void WiThrottle::multithrottle(Print & stream, byte * cmd){
|
|||||||
case '-': // stop and remove loco(s)
|
case '-': // stop and remove loco(s)
|
||||||
LOOPLOCOS(throttleChar, locoid) {
|
LOOPLOCOS(throttleChar, locoid) {
|
||||||
myLocos[loco].throttle='\0';
|
myLocos[loco].throttle='\0';
|
||||||
DCC::setThrottle(myLocos[loco].cab,0, DCC::getThrottleDirection(myLocos[loco].cab));
|
DCC::setThrottle(myLocos[loco].cab,1, DCC::getThrottleDirection(myLocos[loco].cab));
|
||||||
DCC::forgetLoco(myLocos[loco].cab); //unregister this loco address
|
|
||||||
StringFormatter::send(stream, F("M%c-%c%d<;>\n"), throttleChar, LorS(myLocos[loco].cab), myLocos[loco].cab);
|
StringFormatter::send(stream, F("M%c-%c%d<;>\n"), throttleChar, LorS(myLocos[loco].cab), myLocos[loco].cab);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +318,7 @@ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int c
|
|||||||
case 'I': // Idle, set speed to 0
|
case 'I': // Idle, set speed to 0
|
||||||
case 'Q': // Quit, set speed to 0
|
case 'Q': // Quit, set speed to 0
|
||||||
LOOPLOCOS(throttleChar, cab) {
|
LOOPLOCOS(throttleChar, cab) {
|
||||||
DCC::setThrottle(myLocos[loco].cab,0, DCC::getThrottleDirection(myLocos[loco].cab));
|
DCC::setThrottle(myLocos[loco].cab,1, DCC::getThrottleDirection(myLocos[loco].cab));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -326,7 +338,6 @@ void WiThrottle::checkHeartbeat() {
|
|||||||
if (myLocos[loco].throttle!='\0') {
|
if (myLocos[loco].throttle!='\0') {
|
||||||
DIAG(F(" dropping cab %c"),clientid, myLocos[loco].cab);
|
DIAG(F(" dropping cab %c"),clientid, myLocos[loco].cab);
|
||||||
DCC::setThrottle(myLocos[loco].cab, 1, DCC::getThrottleDirection(myLocos[loco].cab)); //eStop
|
DCC::setThrottle(myLocos[loco].cab, 1, DCC::getThrottleDirection(myLocos[loco].cab)); //eStop
|
||||||
DCC::forgetLoco(myLocos[loco].cab); //unregister this loco address
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete this;
|
delete this;
|
||||||
|
@ -40,7 +40,9 @@ class WiThrottle {
|
|||||||
static WiThrottle* firstThrottle;
|
static WiThrottle* firstThrottle;
|
||||||
static int getInt(byte * cmd);
|
static int getInt(byte * cmd);
|
||||||
static int getLocoId(byte * cmd);
|
static int getLocoId(byte * cmd);
|
||||||
static char LorS(int cab);
|
static char LorS(int cab);
|
||||||
|
static bool isThrottleInUse(int cab);
|
||||||
|
bool areYouUsingThrottle(int cab);
|
||||||
WiThrottle* nextThrottle;
|
WiThrottle* nextThrottle;
|
||||||
int clientid;
|
int clientid;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user