mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
Simplify Withrottle function changes
This commit is contained in:
parent
e5c66a2755
commit
1b07d0a5c6
38
DCC.cpp
38
DCC.cpp
|
@ -192,39 +192,15 @@ void DCC::setFn( int cab, int16_t functionNumber, bool on) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change function according to how button was pressed,
|
// Flip function state
|
||||||
// typically in WiThrottle.
|
void DCC::changeFn( int cab, int16_t functionNumber) {
|
||||||
// Returns new state or -1 if nothing was changed.
|
if (cab<=0 || functionNumber>28) return;
|
||||||
int DCC::changeFn( int cab, int16_t functionNumber, bool pressed) {
|
|
||||||
int funcstate = -1;
|
|
||||||
if (cab<=0 || functionNumber>28) return funcstate;
|
|
||||||
int reg = lookupSpeedTable(cab);
|
int reg = lookupSpeedTable(cab);
|
||||||
if (reg<0) return funcstate;
|
if (reg<0) return;
|
||||||
uint32_t oldFunctionMap=speedTable[reg].functions;
|
|
||||||
|
|
||||||
// Take care of functions:
|
|
||||||
// Imitate how many command stations do it: Button press is
|
|
||||||
// toggle but for F2 where it is momentary
|
|
||||||
unsigned long funcmask = (1UL<<functionNumber);
|
unsigned long funcmask = (1UL<<functionNumber);
|
||||||
if (functionNumber == 2) {
|
speedTable[reg].functions ^= funcmask;
|
||||||
// turn on F2 on press and off again at release of button
|
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
|
||||||
if (pressed) {
|
CommandDistributor::broadcastLoco(reg);
|
||||||
speedTable[reg].functions |= funcmask;
|
|
||||||
funcstate = 1;
|
|
||||||
} else {
|
|
||||||
speedTable[reg].functions &= ~funcmask;
|
|
||||||
funcstate = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// toggle function on press, ignore release
|
|
||||||
if (pressed) {
|
|
||||||
speedTable[reg].functions ^= funcmask;
|
|
||||||
}
|
|
||||||
funcstate = (speedTable[reg].functions & funcmask)? 1 : 0;
|
|
||||||
}
|
|
||||||
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
|
|
||||||
if (oldFunctionMap!=speedTable[reg].functions) CommandDistributor::broadcastLoco(reg);
|
|
||||||
return funcstate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DCC::getFn( int cab, int16_t functionNumber) {
|
int DCC::getFn( int cab, int16_t functionNumber) {
|
||||||
|
|
2
DCC.h
2
DCC.h
|
@ -99,7 +99,7 @@ public:
|
||||||
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);
|
||||||
static void setFn(int cab, int16_t functionNumber, bool on);
|
static void setFn(int cab, int16_t functionNumber, bool on);
|
||||||
static int changeFn(int cab, int16_t functionNumber, bool pressed);
|
static void changeFn(int cab, int16_t functionNumber);
|
||||||
static int getFn(int cab, int16_t functionNumber);
|
static int getFn(int cab, int16_t functionNumber);
|
||||||
static uint32_t getFunctionMap(int cab);
|
static uint32_t getFunctionMap(int cab);
|
||||||
static void updateGroupflags(byte &flags, int16_t functionNumber);
|
static void updateGroupflags(byte &flags, int16_t functionNumber);
|
||||||
|
|
|
@ -316,12 +316,14 @@ void WiThrottle::locoAction(RingStream * stream, byte* aval, char throttleChar,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'F': //F onOff function
|
case 'F': // Function key pressed/released
|
||||||
{
|
{
|
||||||
bool pressed=aval[1]=='1';
|
bool pressed=aval[1]=='1';
|
||||||
int fKey = getInt(aval+2);
|
int fKey = getInt(aval+2);
|
||||||
|
if (fKey!=2 && !pressed) break; // ignore releases except key 2
|
||||||
LOOPLOCOS(throttleChar, cab) {
|
LOOPLOCOS(throttleChar, cab) {
|
||||||
DCC::changeFn(myLocos[loco].cab, fKey, pressed);
|
if (fKey==2) DCC::setFn(myLocos[loco].cab,fKey, pressed);
|
||||||
|
else DCC::changeFn(myLocos[loco].cab, fKey);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,8 @@ class WiThrottle {
|
||||||
~WiThrottle();
|
~WiThrottle();
|
||||||
|
|
||||||
static const int MAX_MY_LOCO=10; // maximum number of locos assigned to a single client
|
static const int MAX_MY_LOCO=10; // maximum number of locos assigned to a single client
|
||||||
static const int HEARTBEAT_SECONDS=4; // heartbeat at 4secs to provide messaging transport
|
static const int HEARTBEAT_SECONDS=10; // heartbeat at 4secs to provide messaging transport
|
||||||
static const int ESTOP_SECONDS=8; // eStop if no incoming messages for more than 8secs
|
static const int ESTOP_SECONDS=20; // eStop if no incoming messages for more than 8secs
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user