mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
Function toggle but F2
This commit is contained in:
parent
b0a7933b7b
commit
926968bbd7
37
DCC.cpp
37
DCC.cpp
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* © 2020, Chris Harlow. All rights reserved.
|
* © 2020, Chris Harlow. All rights reserved.
|
||||||
|
* © 2020, Harald Barth
|
||||||
*
|
*
|
||||||
* This file is part of Asbelos DCC API
|
* This file is part of Asbelos DCC API
|
||||||
*
|
*
|
||||||
|
@ -94,22 +95,32 @@ 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 on) {
|
void DCC::setFn( int cab, byte functionNumber, bool pressed) {
|
||||||
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;
|
||||||
// set the function on/off in the functions and set the group flag to
|
|
||||||
// say we have touched the particular group.
|
// Take care of functions:
|
||||||
// A group will be reminded only if it has been touched.
|
// Imitate how many command stations do it: Button press is
|
||||||
if (on) speedTable[reg].functions |= (1L<<functionNumber);
|
// toggle but for F2 where it is momentary
|
||||||
else speedTable[reg].functions &= ~(1L<<functionNumber);
|
if (functionNumber == 2) {
|
||||||
byte groupMask;
|
// turn on F2 on press and off again at release of button
|
||||||
if (functionNumber<=4) groupMask=FN_GROUP_1;
|
if (pressed) speedTable[reg].functions |= (1L<<functionNumber);
|
||||||
else if (functionNumber<=8) groupMask=FN_GROUP_2;
|
else speedTable[reg].functions &= ~(1L<<functionNumber);
|
||||||
else if (functionNumber<=12) groupMask=FN_GROUP_3;
|
} else {
|
||||||
else if (functionNumber<=20) groupMask=FN_GROUP_4;
|
// toggle function on release, ignore release
|
||||||
else groupMask=FN_GROUP_5;
|
if (pressed)
|
||||||
speedTable[reg].groupFlags |= groupMask;
|
speedTable[reg].functions ^= (1UL<<functionNumber);
|
||||||
|
}
|
||||||
|
// Set the group flag to say we have touched the particular group.
|
||||||
|
// A group will be reminded only if it has been touched.
|
||||||
|
byte groupMask;
|
||||||
|
if (functionNumber<=4) groupMask=FN_GROUP_1;
|
||||||
|
else if (functionNumber<=8) groupMask=FN_GROUP_2;
|
||||||
|
else if (functionNumber<=12) groupMask=FN_GROUP_3;
|
||||||
|
else if (functionNumber<=20) groupMask=FN_GROUP_4;
|
||||||
|
else groupMask=FN_GROUP_5;
|
||||||
|
speedTable[reg].groupFlags |= groupMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCC::setAccessory(int address, byte number, bool activate) {
|
void DCC::setAccessory(int address, byte number, bool activate) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* © 2020, Chris Harlow. All rights reserved.
|
* © 2020, Chris Harlow. All rights reserved.
|
||||||
|
* © 2020, Harald Barth
|
||||||
*
|
*
|
||||||
* This file is part of Asbelos DCC API
|
* This file is part of Asbelos DCC API
|
||||||
*
|
*
|
||||||
|
@ -237,10 +238,10 @@ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int c
|
||||||
break;
|
break;
|
||||||
case 'F': //F onOff function
|
case 'F': //F onOff function
|
||||||
{
|
{
|
||||||
bool onOff=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,onOff);
|
DCC::setFn(myLocos[loco].cab, fKey, pressed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user