diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 2014762..de1618c 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -1094,7 +1094,7 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[]) if (tto) return false; if (!DCCTurntable::create(p[0])) return false; Turntable *tto = Turntable::get(p[0]); - tto->addPosition(0); + tto->addPosition(0, 0); } else { // Otherwise move a DCC turntable if (tto && !tto->isEXTT()) { if (!tto->setPosition(p[0], p[1])) return false; @@ -1105,27 +1105,27 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[]) } return true; - case 3: // | + case 3: // rotate to position for EX-Turntable { Turntable *tto = Turntable::get(p[0]); if (!tto) return false; - if (p[1] == HASH_KEYWORD_ADD) { // Add position value to turntable - tto->addPosition(p[2]); - StringFormatter::send(stream, F("\n")); - } else { // rotate to position for EX-Turntable - if (!tto->isEXTT()) return false; - if (!tto->setPosition(p[0], p[1], p[2])) return false; - } + if (!tto->isEXTT()) return false; + if (!tto->setPosition(p[0], p[1], p[2])) return false; } return true; - case 4: // create an EXTT turntable + case 4: // | create an EXTT turntable or add position { + Turntable *tto = Turntable::get(p[0]); if (p[1] == HASH_KEYWORD_EXTT) { - if (Turntable::get(p[0])) return false; + if (tto) return false; if (!EXTTTurntable::create(p[0], (VPIN)p[2])) return false; Turntable *tto = Turntable::get(p[0]); - tto->addPosition(p[3]); + tto->addPosition(0, p[3]); + } else if (p[1] == HASH_KEYWORD_ADD) { + if (!tto) return false; + tto->addPosition(p[2], p[3]); + StringFormatter::send(stream, F("\n")); } else { return false; } diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index 77a9f88..d88a6f4 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -247,7 +247,7 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) { VPIN id=operand; setTurntableHiddenState(DCCTurntable::create(id)); Turntable *tto=Turntable::get(id); - tto->addPosition(0); + tto->addPosition(0,0); break; } @@ -257,15 +257,16 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) { int home=getOperand(progCounter,2); setTurntableHiddenState(EXTTTurntable::create(id,pin)); Turntable *tto=Turntable::get(id); - tto->addPosition(home); + tto->addPosition(0,home); break; } case OPCODE_TTADDPOSITION: { VPIN id=operand; - int value=getOperand(progCounter,1); + int position=getOperand(progCounter,1); + int value=getOperand(progCounter,2); Turntable *tto=Turntable::get(id); - tto->addPosition(value); + tto->addPosition(position,value); break; } #endif diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index 7c690b7..21d4f18 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -273,7 +273,7 @@ #define START(route) #define STOP #define THROW(id) -#define TT_ADDPOSITION(turntable_id,value,description) +#define TT_ADDPOSITION(turntable_id,position,value,description) #define TURNOUT(id,addr,subaddr,description...) #define TURNOUTL(id,addr,description...) #define UNJOIN diff --git a/EXRAILMacros.h b/EXRAILMacros.h index f5d905e..68f3bf0 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -406,7 +406,7 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = { #define STOP OPCODE_SPEED,V(0), #define THROW(id) OPCODE_THROW,V(id), #ifndef IO_NO_HAL -#define TT_ADDPOSITION(id,value,description...) OPCODE_TTADDPOSITION,V(id),OPCODE_PAD,V(value), +#define TT_ADDPOSITION(id,position,value,description...) OPCODE_TTADDPOSITION,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(value), #endif #define TURNOUT(id,addr,subaddr,description...) OPCODE_TURNOUT,V(id),OPCODE_PAD,V(addr),OPCODE_PAD,V(subaddr), #define TURNOUTL(id,addr,description...) TURNOUT(id,(addr-1)/4+1,(addr-1)%4, description) diff --git a/Turntables.cpp b/Turntables.cpp index 120ac2f..abbac81 100644 --- a/Turntables.cpp +++ b/Turntables.cpp @@ -58,8 +58,8 @@ void Turntable::add(Turntable *tto) { } // Add a position -void Turntable::addPosition(uint16_t value) { - _turntablePositions.insert(value); +void Turntable::addPosition(uint8_t idx, uint16_t value) { + _turntablePositions.insert(idx, value); } // Get value for position diff --git a/Turntables.h b/Turntables.h index de0151c..15333c9 100644 --- a/Turntables.h +++ b/Turntables.h @@ -53,10 +53,10 @@ struct TurntablePosition { class TurntablePositionList { public: - TurntablePositionList() : head(nullptr), currentIndex(0) {} + TurntablePositionList() : head(nullptr) {} - void insert(uint16_t value) { - TurntablePosition* newPosition = new TurntablePosition(currentIndex++, value); + void insert(uint8_t idx, uint16_t value) { + TurntablePosition* newPosition = new TurntablePosition(idx, value); if(!head) { head = newPosition; } else { @@ -71,7 +71,6 @@ public: private: TurntablePosition* head; - uint8_t currentIndex; }; @@ -159,7 +158,7 @@ public: inline uint16_t getId() { return _turntableData.id; } inline Turntable *next() { return _nextTurntable; } void printState(Print *stream); - void addPosition(uint16_t value); + void addPosition(uint8_t idx, uint16_t value); uint16_t getPositionValue(uint8_t position); uint8_t getPositionCount(); bool isMoving() { return _isMoving; }