1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-25 05:31:24 +01:00

Update add position

This commit is contained in:
peteGSX 2023-09-06 07:59:43 +10:00
parent 152f9850bb
commit 6adff43f4b
6 changed files with 25 additions and 25 deletions

View File

@ -1094,7 +1094,7 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
if (tto) return false; if (tto) return false;
if (!DCCTurntable::create(p[0])) return false; if (!DCCTurntable::create(p[0])) return false;
Turntable *tto = Turntable::get(p[0]); Turntable *tto = Turntable::get(p[0]);
tto->addPosition(0); tto->addPosition(0, 0);
} else { // Otherwise move a DCC turntable } else { // Otherwise move a DCC turntable
if (tto && !tto->isEXTT()) { if (tto && !tto->isEXTT()) {
if (!tto->setPosition(p[0], p[1])) return false; 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; return true;
case 3: // <I id ADD value> | <I id position activity> case 3: // <I id position activity> rotate to position for EX-Turntable
{ {
Turntable *tto = Turntable::get(p[0]); Turntable *tto = Turntable::get(p[0]);
if (!tto) return false; if (!tto) return false;
if (p[1] == HASH_KEYWORD_ADD) { // Add position value to turntable if (!tto->isEXTT()) return false;
tto->addPosition(p[2]); if (!tto->setPosition(p[0], p[1], p[2])) return false;
StringFormatter::send(stream, F("<i>\n"));
} else { // <I id position activity> rotate to position for EX-Turntable
if (!tto->isEXTT()) return false;
if (!tto->setPosition(p[0], p[1], p[2])) return false;
}
} }
return true; return true;
case 4: // <I id EXTT vpin home> create an EXTT turntable case 4: // <I id EXTT vpin home> | <I id ADD position value> create an EXTT turntable or add position
{ {
Turntable *tto = Turntable::get(p[0]);
if (p[1] == HASH_KEYWORD_EXTT) { 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; if (!EXTTTurntable::create(p[0], (VPIN)p[2])) return false;
Turntable *tto = Turntable::get(p[0]); 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("<i>\n"));
} else { } else {
return false; return false;
} }

View File

@ -247,7 +247,7 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
VPIN id=operand; VPIN id=operand;
setTurntableHiddenState(DCCTurntable::create(id)); setTurntableHiddenState(DCCTurntable::create(id));
Turntable *tto=Turntable::get(id); Turntable *tto=Turntable::get(id);
tto->addPosition(0); tto->addPosition(0,0);
break; break;
} }
@ -257,15 +257,16 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
int home=getOperand(progCounter,2); int home=getOperand(progCounter,2);
setTurntableHiddenState(EXTTTurntable::create(id,pin)); setTurntableHiddenState(EXTTTurntable::create(id,pin));
Turntable *tto=Turntable::get(id); Turntable *tto=Turntable::get(id);
tto->addPosition(home); tto->addPosition(0,home);
break; break;
} }
case OPCODE_TTADDPOSITION: { case OPCODE_TTADDPOSITION: {
VPIN id=operand; VPIN id=operand;
int value=getOperand(progCounter,1); int position=getOperand(progCounter,1);
int value=getOperand(progCounter,2);
Turntable *tto=Turntable::get(id); Turntable *tto=Turntable::get(id);
tto->addPosition(value); tto->addPosition(position,value);
break; break;
} }
#endif #endif

View File

@ -273,7 +273,7 @@
#define START(route) #define START(route)
#define STOP #define STOP
#define THROW(id) #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 TURNOUT(id,addr,subaddr,description...)
#define TURNOUTL(id,addr,description...) #define TURNOUTL(id,addr,description...)
#define UNJOIN #define UNJOIN

View File

@ -406,7 +406,7 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = {
#define STOP OPCODE_SPEED,V(0), #define STOP OPCODE_SPEED,V(0),
#define THROW(id) OPCODE_THROW,V(id), #define THROW(id) OPCODE_THROW,V(id),
#ifndef IO_NO_HAL #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 #endif
#define TURNOUT(id,addr,subaddr,description...) OPCODE_TURNOUT,V(id),OPCODE_PAD,V(addr),OPCODE_PAD,V(subaddr), #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) #define TURNOUTL(id,addr,description...) TURNOUT(id,(addr-1)/4+1,(addr-1)%4, description)

View File

@ -58,8 +58,8 @@ void Turntable::add(Turntable *tto) {
} }
// Add a position // Add a position
void Turntable::addPosition(uint16_t value) { void Turntable::addPosition(uint8_t idx, uint16_t value) {
_turntablePositions.insert(value); _turntablePositions.insert(idx, value);
} }
// Get value for position // Get value for position

View File

@ -53,10 +53,10 @@ struct TurntablePosition {
class TurntablePositionList { class TurntablePositionList {
public: public:
TurntablePositionList() : head(nullptr), currentIndex(0) {} TurntablePositionList() : head(nullptr) {}
void insert(uint16_t value) { void insert(uint8_t idx, uint16_t value) {
TurntablePosition* newPosition = new TurntablePosition(currentIndex++, value); TurntablePosition* newPosition = new TurntablePosition(idx, value);
if(!head) { if(!head) {
head = newPosition; head = newPosition;
} else { } else {
@ -71,7 +71,6 @@ public:
private: private:
TurntablePosition* head; TurntablePosition* head;
uint8_t currentIndex;
}; };
@ -159,7 +158,7 @@ public:
inline uint16_t getId() { return _turntableData.id; } inline uint16_t getId() { return _turntableData.id; }
inline Turntable *next() { return _nextTurntable; } inline Turntable *next() { return _nextTurntable; }
void printState(Print *stream); void printState(Print *stream);
void addPosition(uint16_t value); void addPosition(uint8_t idx, uint16_t value);
uint16_t getPositionValue(uint8_t position); uint16_t getPositionValue(uint8_t position);
uint8_t getPositionCount(); uint8_t getPositionCount();
bool isMoving() { return _isMoving; } bool isMoving() { return _isMoving; }