mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
Two functions changeFn and setFn dependent on if called from WiThrottle or DCCEXparser
This commit is contained in:
parent
926968bbd7
commit
93446f19ed
53
DCC.cpp
53
DCC.cpp
|
@ -95,32 +95,67 @@ bool DCC::getThrottleDirection(int cab) {
|
||||||
return (speedTable[reg].speedCode & 0x80) !=0;
|
return (speedTable[reg].speedCode & 0x80) !=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCC::setFn( int cab, byte functionNumber, bool pressed) {
|
void DCC::setFn( int cab, byte functionNumber, bool on) {
|
||||||
if (cab<=0 || functionNumber>28) return;
|
if (cab<=0 || functionNumber>28) return;
|
||||||
int reg = lookupSpeedTable(cab);
|
int reg = lookupSpeedTable(cab);
|
||||||
if (reg<0) return;
|
if (reg<0) return;
|
||||||
|
|
||||||
|
// Take care of functions:
|
||||||
|
// Set state of function
|
||||||
|
unsigned long funcmask = (1L<<functionNumber);
|
||||||
|
if (on) {
|
||||||
|
speedTable[reg].functions |= funcmask;
|
||||||
|
} else {
|
||||||
|
speedTable[reg].functions &= ~funcmask;
|
||||||
|
}
|
||||||
|
//DIAG(F("\nFUNCTIONS of %d IS %d\n"),cab,speedTable[reg].functions);
|
||||||
|
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change function according to how button was pressed,
|
||||||
|
// typically in WiThrottle.
|
||||||
|
// Returns new state or -1 if nothing was changed.
|
||||||
|
int DCC::changeFn( int cab, byte functionNumber, bool pressed) {
|
||||||
|
int funcstate = -1;
|
||||||
|
if (cab<=0 || functionNumber>28) return funcstate;
|
||||||
|
int reg = lookupSpeedTable(cab);
|
||||||
|
if (reg<0) return funcstate;
|
||||||
|
|
||||||
// Take care of functions:
|
// Take care of functions:
|
||||||
// Imitate how many command stations do it: Button press is
|
// Imitate how many command stations do it: Button press is
|
||||||
// toggle but for F2 where it is momentary
|
// toggle but for F2 where it is momentary
|
||||||
|
unsigned long funcmask = (1L<<functionNumber);
|
||||||
if (functionNumber == 2) {
|
if (functionNumber == 2) {
|
||||||
// turn on F2 on press and off again at release of button
|
// turn on F2 on press and off again at release of button
|
||||||
if (pressed) speedTable[reg].functions |= (1L<<functionNumber);
|
if (pressed) {
|
||||||
else speedTable[reg].functions &= ~(1L<<functionNumber);
|
speedTable[reg].functions |= funcmask;
|
||||||
|
funcstate = 1;
|
||||||
|
} else {
|
||||||
|
speedTable[reg].functions &= ~funcmask;
|
||||||
|
funcstate = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// toggle function on release, ignore release
|
// toggle function on release, ignore release
|
||||||
if (pressed)
|
if (pressed) {
|
||||||
speedTable[reg].functions ^= (1UL<<functionNumber);
|
speedTable[reg].functions ^= funcmask;
|
||||||
}
|
}
|
||||||
// Set the group flag to say we have touched the particular group.
|
funcstate = speedTable[reg].functions & funcmask;
|
||||||
// A group will be reminded only if it has been touched.
|
}
|
||||||
|
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
|
||||||
|
return funcstate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the group flag to say we have touched the particular group.
|
||||||
|
// A group will be reminded only if it has been touched.
|
||||||
|
void DCC::updateGroupflags(byte & flags, int functionNumber) {
|
||||||
byte groupMask;
|
byte groupMask;
|
||||||
if (functionNumber<=4) groupMask=FN_GROUP_1;
|
if (functionNumber<=4) groupMask=FN_GROUP_1;
|
||||||
else if (functionNumber<=8) groupMask=FN_GROUP_2;
|
else if (functionNumber<=8) groupMask=FN_GROUP_2;
|
||||||
else if (functionNumber<=12) groupMask=FN_GROUP_3;
|
else if (functionNumber<=12) groupMask=FN_GROUP_3;
|
||||||
else if (functionNumber<=20) groupMask=FN_GROUP_4;
|
else if (functionNumber<=20) groupMask=FN_GROUP_4;
|
||||||
else groupMask=FN_GROUP_5;
|
else groupMask=FN_GROUP_5;
|
||||||
speedTable[reg].groupFlags |= groupMask;
|
flags |= groupMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCC::setAccessory(int address, byte number, bool activate) {
|
void DCC::setAccessory(int address, byte number, bool activate) {
|
||||||
|
@ -342,7 +377,7 @@ void DCC::issueReminders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DCC::issueReminder(int reg) {
|
bool DCC::issueReminder(int reg) {
|
||||||
long functions=speedTable[reg].functions;
|
unsigned long functions=speedTable[reg].functions;
|
||||||
int loco=speedTable[reg].loco;
|
int loco=speedTable[reg].loco;
|
||||||
byte flags=speedTable[reg].groupFlags;
|
byte flags=speedTable[reg].groupFlags;
|
||||||
|
|
||||||
|
|
4
DCC.h
4
DCC.h
|
@ -60,6 +60,8 @@ class DCC {
|
||||||
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, byte functionNumber, bool on);
|
static void setFn( int cab, byte functionNumber, bool on);
|
||||||
|
static int changeFn( int cab, byte functionNumber, bool pressed);
|
||||||
|
static void updateGroupflags(byte & flags, int functionNumber);
|
||||||
static void setAccessory(int aAdd, byte aNum, bool activate) ;
|
static void setAccessory(int aAdd, byte aNum, bool activate) ;
|
||||||
static bool writeTextPacket( byte *b, int nBytes);
|
static bool writeTextPacket( byte *b, int nBytes);
|
||||||
static void setDebug(bool on);
|
static void setDebug(bool on);
|
||||||
|
@ -82,7 +84,7 @@ private:
|
||||||
int loco;
|
int loco;
|
||||||
byte speedCode;
|
byte speedCode;
|
||||||
byte groupFlags;
|
byte groupFlags;
|
||||||
long functions;
|
unsigned long functions;
|
||||||
};
|
};
|
||||||
static byte loopStatus;
|
static byte loopStatus;
|
||||||
static void setThrottle2( uint16_t cab, uint8_t speedCode);
|
static void setThrottle2( uint16_t cab, uint8_t speedCode);
|
||||||
|
|
|
@ -238,10 +238,14 @@ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int c
|
||||||
break;
|
break;
|
||||||
case 'F': //F onOff function
|
case 'F': //F onOff function
|
||||||
{
|
{
|
||||||
|
bool funcstate;
|
||||||
bool pressed=aval[1]=='1';
|
bool pressed=aval[1]=='1';
|
||||||
int fKey = getInt(aval+2);
|
int fKey = getInt(aval+2);
|
||||||
LOOPLOCOS(throttleChar, cab) {
|
LOOPLOCOS(throttleChar, cab) {
|
||||||
DCC::setFn(myLocos[loco].cab, fKey, pressed);
|
funcstate = DCC::changeFn(myLocos[loco].cab, fKey, pressed);
|
||||||
|
if(funcstate==0 || funcstate==1)
|
||||||
|
StringFormatter::send(stream,F("M%cA%c%d<;>F%d%d\n"), throttleChar, LorS(myLocos[loco].cab),
|
||||||
|
myLocos[loco].cab, funcstate, fKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user