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

EXRAIL MOMENTUM

This commit is contained in:
Asbelos 2024-07-19 08:33:50 +01:00
parent 8a623aa1cb
commit ab72a75d8f
6 changed files with 20 additions and 7 deletions

16
DCC.cpp
View File

@ -914,13 +914,17 @@ int DCC::lookupSpeedTable(int locoId, bool autoCreate) {
}
bool DCC::setMomentum(int locoId,int16_t millis_per_notch) {
if (locoId<0 || millis_per_notch<0) return false;
if (locoId==0) defaultMomentum=millis_per_notch;
else {
auto reg=lookupSpeedTable(locoId);
if (reg<0) return false;
speedTable[reg].millis_per_notch=millis_per_notch;
if (locoId==0 && millis_per_notch>=0) {
defaultMomentum=millis_per_notch;
return true;
}
// millis=-1 is ok and means this loco should use the default.
// We dont copy the default here because it can be changed
// while running and have immediate effect on all locos using -1.
if (locoId<=0 || millis_per_notch<-1) return false;
auto reg=lookupSpeedTable(locoId);
if (reg<0) return false; // table full
speedTable[reg].millis_per_notch=millis_per_notch;
return true;
}

View File

@ -68,7 +68,8 @@ Once a new OPCODE is decided upon, update this list.
K, Reserved for future use - Potentially Railcom
l, Loco speedbyte/function map broadcast
L, Reserved for LCC interface (implemented in EXRAIL)
m, message to throttles broadcast
m, message to throttles (broadcast output)
m, set momentum
M, Write DCC packet
n, Reserved for SensorCam
N, Reserved for Sensorcam

View File

@ -566,6 +566,10 @@ void RMFT2::loop2() {
forward=DCC::getThrottleDirection(loco)^invert;
driveLoco(operand);
break;
case OPCODE_MOMENTUM:
DCC::setMomentum(loco,operand);
break;
case OPCODE_FORGET:
if (loco!=0) {

View File

@ -35,6 +35,7 @@
//
enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT,
OPCODE_FWD,OPCODE_REV,OPCODE_SPEED,OPCODE_INVERT_DIRECTION,
OPCODE_MOMENTUM,
OPCODE_RESERVE,OPCODE_FREE,
OPCODE_AT,OPCODE_AFTER,
OPCODE_AFTEROVERLOAD,OPCODE_AUTOSTART,

View File

@ -98,6 +98,7 @@
#undef LCC
#undef LCCX
#undef LCN
#undef MOMENTUM
#undef MOVETT
#undef ACON
#undef ACOF
@ -265,6 +266,7 @@
#define LCC(eventid)
#define LCCX(senderid,eventid)
#define LCD(row,msg)
#define MOMENTUM(mspertick)
#define SCREEN(display,row,msg)
#define LCN(msg)
#define MESSAGE(msg)

View File

@ -551,6 +551,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
#define STEALTH_GLOBAL(code...)
#define LCN(msg) PRINT(msg)
#define MESSAGE(msg) PRINT(msg)
#define MOMENTUM(mspertick) OPCODE_MOMENTUM,V(mspertick),
#define MOVETT(id,steps,activity) OPCODE_SERVO,V(id),OPCODE_PAD,V(steps),OPCODE_PAD,V(EXTurntable::activity),OPCODE_PAD,V(0),
#define ONACTIVATE(addr,subaddr) OPCODE_ONACTIVATE,V(addr<<2|subaddr),
#define ONACTIVATEL(linear) OPCODE_ONACTIVATE,V(linear+3),