From 20b12bcb7c66c37b0ea6073ce3919324b535a9b7 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Tue, 12 Apr 2022 18:47:06 +0100 Subject: [PATCH] JA JR and --- DCC.cpp | 5 ++++- DCC.h | 5 ++--- DCCEXParser.cpp | 19 ++++++++++++++++--- EXRAIL2MacroReset.h | 4 ++-- EXRAILMacros.h | 10 +++++----- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index 6674fb9..1c53456 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -647,7 +647,7 @@ byte DCC::cv2(int cv) { return lowByte(cv); } -int DCC::lookupSpeedTable(int locoId) { +int DCC::lookupSpeedTable(int locoId, bool autoCreate) { // determine speed reg for this loco int firstEmpty = MAX_LOCOS; int reg; @@ -655,6 +655,9 @@ int DCC::lookupSpeedTable(int locoId) { if (speedTable[reg].loco == locoId) break; 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) { DIAG(F("Too many locos")); diff --git a/DCC.h b/DCC.h index fbeb603..5d9064c 100644 --- a/DCC.h +++ b/DCC.h @@ -128,7 +128,6 @@ public: static void forgetLoco(int cab); // removes any speed reminders for this loco static void forgetAllLocos(); // removes all speed reminders static void displayCabList(Print *stream); - static FSH *getMotorShieldName(); static inline void setGlobalSpeedsteps(byte s) { globalSpeedsteps = s; @@ -148,7 +147,8 @@ public: unsigned long functions; }; static LOCO speedTable[MAX_LOCOS]; - + static int lookupSpeedTable(int locoId, bool autoCreate=true); + private: static byte joinRelay; static byte loopStatus; @@ -162,7 +162,6 @@ private: static byte cv1(byte opcode, int cv); static byte cv2(int cv); - static int lookupSpeedTable(int locoId); static void issueReminders(); static void callback(int value); diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 4f866c6..11a91d2 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -217,10 +217,23 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) return; // filterCallback asked us to ignore case 't': // THROTTLE { + if (params==1) { // display state + + int16_t slot=DCC::lookupSpeedTable(p[0],false); + if (slot>=0) { + DCC::LOCO * sp=&DCC::speedTable[slot]; + StringFormatter::send(stream,F("\n"), + sp->loco,slot,sp->speedCode,sp->functions); + } + else // send dummy state speed 0 fwd no functions. + StringFormatter::send(stream,F("\n"),p[0]); + return; + } + int16_t cab; int16_t tspeed; int16_t direction; - + if (params == 4) { // cab = p[1]; @@ -523,8 +536,8 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) StringFormatter::send(stream, F(" #ifdef EXRAIL_ACTIVE - sendFlashList(stream,RMFT2::automationIdList); sendFlashList(stream,RMFT2::routeIdList); + sendFlashList(stream,RMFT2::automationIdList); #endif } else { // @@ -589,7 +602,7 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) } 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); if (value==0) return; StringFormatter::send(stream,F(" %d"),value); diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index e28452a..edbfd6d 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -131,7 +131,7 @@ #define ATGTE(sensor_id,value) #define ATLT(sensor_id,value) #define ATTIMEOUT(sensor_id,timeout_ms) -#define AUTOMATION(id, description) +#define AUTOMATION(id,description) #define AUTOSTART #define BROADCAST(msg) #define CALL(route) @@ -192,7 +192,7 @@ #define RESUME #define RETURN #define REV(speed) -#define ROUTE(id, description) +#define ROUTE(id,description) #define ROSTER(cab,name,funcmap...) #define SENDLOCO(cab,route) #define SEQUENCE(id) diff --git a/EXRAILMacros.h b/EXRAILMacros.h index c11bd35..075a69c 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -86,7 +86,7 @@ const FSH * RMFT2::getRouteDescription(int16_t id) { #include "myAutomation.h" default: break; } - return NULL; + return F(""); } // Pass 4... Create Text sending functions @@ -161,20 +161,20 @@ const int16_t FLASH RMFT2::rosterIdList[]={ const FSH * RMFT2::getRosterName(int16_t id) { switch(id) { #include "myAutomation.h" - default: return NULL; + default: break; } - return NULL; + return F(""); } // Pass to get roster functions #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) { switch(id) { #include "myAutomation.h" default: break; } - return NULL; + return F(""); } // Pass 8 Signal definitions