mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
Withrottle in use change
This commit is contained in:
parent
7815fdcad8
commit
a217031f24
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);
|
||||||
|
|
|
@ -59,6 +59,20 @@ WiThrottle* WiThrottle::getThrottle( int wifiClient) {
|
||||||
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;
|
||||||
|
|
|
@ -41,6 +41,8 @@ class WiThrottle {
|
||||||
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