1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

Function toggle but F2

This commit is contained in:
Harald Barth 2020-08-01 00:35:22 +02:00
parent b0a7933b7b
commit 926968bbd7
2 changed files with 27 additions and 15 deletions

21
DCC.cpp
View File

@ -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,15 +95,25 @@ 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
if (functionNumber == 2) {
// turn on F2 on press and off again at release of button
if (pressed) speedTable[reg].functions |= (1L<<functionNumber);
else speedTable[reg].functions &= ~(1L<<functionNumber); else speedTable[reg].functions &= ~(1L<<functionNumber);
} else {
// toggle function on release, ignore release
if (pressed)
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; 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;

View File

@ -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;