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

JA JR and <t cab>

This commit is contained in:
Asbelos 2022-04-12 18:47:06 +01:00
parent e13175635c
commit 20b12bcb7c
5 changed files with 29 additions and 14 deletions

View File

@ -647,7 +647,7 @@ byte DCC::cv2(int cv) {
return lowByte(cv); return lowByte(cv);
} }
int DCC::lookupSpeedTable(int locoId) { int DCC::lookupSpeedTable(int locoId, bool autoCreate) {
// determine speed reg for this loco // determine speed reg for this loco
int firstEmpty = MAX_LOCOS; int firstEmpty = MAX_LOCOS;
int reg; int reg;
@ -655,6 +655,9 @@ int DCC::lookupSpeedTable(int locoId) {
if (speedTable[reg].loco == locoId) break; if (speedTable[reg].loco == locoId) break;
if (speedTable[reg].loco == 0 && firstEmpty == MAX_LOCOS) firstEmpty = reg; if (speedTable[reg].loco == 0 && firstEmpty == MAX_LOCOS) firstEmpty = reg;
} }
// return -1 if not found and not auto creating
if (reg== MAX_LOCOS && !autoCreate) return -1;
if (reg == MAX_LOCOS) reg = firstEmpty; if (reg == MAX_LOCOS) reg = firstEmpty;
if (reg >= MAX_LOCOS) { if (reg >= MAX_LOCOS) {
DIAG(F("Too many locos")); DIAG(F("Too many locos"));

5
DCC.h
View File

@ -128,7 +128,6 @@ public:
static void forgetLoco(int cab); // removes any speed reminders for this loco static void forgetLoco(int cab); // removes any speed reminders for this loco
static void forgetAllLocos(); // removes all speed reminders static void forgetAllLocos(); // removes all speed reminders
static void displayCabList(Print *stream); static void displayCabList(Print *stream);
static FSH *getMotorShieldName(); static FSH *getMotorShieldName();
static inline void setGlobalSpeedsteps(byte s) { static inline void setGlobalSpeedsteps(byte s) {
globalSpeedsteps = s; globalSpeedsteps = s;
@ -148,7 +147,8 @@ public:
unsigned long functions; unsigned long functions;
}; };
static LOCO speedTable[MAX_LOCOS]; static LOCO speedTable[MAX_LOCOS];
static int lookupSpeedTable(int locoId, bool autoCreate=true);
private: private:
static byte joinRelay; static byte joinRelay;
static byte loopStatus; static byte loopStatus;
@ -162,7 +162,6 @@ private:
static byte cv1(byte opcode, int cv); static byte cv1(byte opcode, int cv);
static byte cv2(int cv); static byte cv2(int cv);
static int lookupSpeedTable(int locoId);
static void issueReminders(); static void issueReminders();
static void callback(int value); static void callback(int value);

View File

@ -217,10 +217,23 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
return; // filterCallback asked us to ignore return; // filterCallback asked us to ignore
case 't': // THROTTLE <t [REGISTER] CAB SPEED DIRECTION> case 't': // THROTTLE <t [REGISTER] CAB SPEED DIRECTION>
{ {
if (params==1) { // <t cab> display state
int16_t slot=DCC::lookupSpeedTable(p[0],false);
if (slot>=0) {
DCC::LOCO * sp=&DCC::speedTable[slot];
StringFormatter::send(stream,F("<l %d %d %d %l>\n"),
sp->loco,slot,sp->speedCode,sp->functions);
}
else // send dummy state speed 0 fwd no functions.
StringFormatter::send(stream,F("<l %d -1 128 0>\n"),p[0]);
return;
}
int16_t cab; int16_t cab;
int16_t tspeed; int16_t tspeed;
int16_t direction; int16_t direction;
if (params == 4) if (params == 4)
{ // <t REGISTER CAB SPEED DIRECTION> { // <t REGISTER CAB SPEED DIRECTION>
cab = p[1]; cab = p[1];
@ -523,8 +536,8 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
StringFormatter::send(stream, F("<jA")); StringFormatter::send(stream, F("<jA"));
if (params==1) {// <JA> if (params==1) {// <JA>
#ifdef EXRAIL_ACTIVE #ifdef EXRAIL_ACTIVE
sendFlashList(stream,RMFT2::automationIdList);
sendFlashList(stream,RMFT2::routeIdList); sendFlashList(stream,RMFT2::routeIdList);
sendFlashList(stream,RMFT2::automationIdList);
#endif #endif
} }
else { // <JA id> else { // <JA id>
@ -589,7 +602,7 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
} }
void DCCEXParser::sendFlashList(Print * stream,const int16_t flashList[]) { void DCCEXParser::sendFlashList(Print * stream,const int16_t flashList[]) {
for (int16_t i=0;;i+=2) { for (int16_t i=0;;i++) {
int16_t value=GETFLASHW(flashList+i); int16_t value=GETFLASHW(flashList+i);
if (value==0) return; if (value==0) return;
StringFormatter::send(stream,F(" %d"),value); StringFormatter::send(stream,F(" %d"),value);

View File

@ -131,7 +131,7 @@
#define ATGTE(sensor_id,value) #define ATGTE(sensor_id,value)
#define ATLT(sensor_id,value) #define ATLT(sensor_id,value)
#define ATTIMEOUT(sensor_id,timeout_ms) #define ATTIMEOUT(sensor_id,timeout_ms)
#define AUTOMATION(id, description) #define AUTOMATION(id,description)
#define AUTOSTART #define AUTOSTART
#define BROADCAST(msg) #define BROADCAST(msg)
#define CALL(route) #define CALL(route)
@ -192,7 +192,7 @@
#define RESUME #define RESUME
#define RETURN #define RETURN
#define REV(speed) #define REV(speed)
#define ROUTE(id, description) #define ROUTE(id,description)
#define ROSTER(cab,name,funcmap...) #define ROSTER(cab,name,funcmap...)
#define SENDLOCO(cab,route) #define SENDLOCO(cab,route)
#define SEQUENCE(id) #define SEQUENCE(id)

View File

@ -86,7 +86,7 @@ const FSH * RMFT2::getRouteDescription(int16_t id) {
#include "myAutomation.h" #include "myAutomation.h"
default: break; default: break;
} }
return NULL; return F("");
} }
// Pass 4... Create Text sending functions // Pass 4... Create Text sending functions
@ -161,20 +161,20 @@ const int16_t FLASH RMFT2::rosterIdList[]={
const FSH * RMFT2::getRosterName(int16_t id) { const FSH * RMFT2::getRosterName(int16_t id) {
switch(id) { switch(id) {
#include "myAutomation.h" #include "myAutomation.h"
default: return NULL; default: break;
} }
return NULL; return F("");
} }
// Pass to get roster functions // Pass to get roster functions
#undef ROSTER #undef ROSTER
#define ROSTER(cabid,name,funcmap...) O_DESC(cabid,funcmap) #define ROSTER(cabid,name,funcmap...) case cabid: return F("" funcmap);
const FSH * RMFT2::getRosterFunctions(int16_t id) { const FSH * RMFT2::getRosterFunctions(int16_t id) {
switch(id) { switch(id) {
#include "myAutomation.h" #include "myAutomation.h"
default: break; default: break;
} }
return NULL; return F("");
} }
// Pass 8 Signal definitions // Pass 8 Signal definitions