diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index f8dd9d4..9047cad 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -695,7 +695,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) case HASH_KEYWORD_O: // - for ( Turntable * tto=Turntable::first(); tto; tto=tto->next()) { + for (Turntable * tto=Turntable::first(); tto; tto=tto->next()) { if (tto->isHidden()) continue; StringFormatter::send(stream, F(" %d"),tto->getId()); } @@ -705,12 +705,18 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) StringFormatter::send(stream, F(" %d X"), id); } else { uint8_t pos = tto->getPosition(); + uint8_t type = tto->getType(); + uint8_t posCount = tto->getPositionCount(); const FSH *todesc = NULL; #ifdef EXRAIL_ACTIVE // todesc = RMFT2::getTurntableDescription(id); #endif if (todesc == NULL) todesc = F(""); - StringFormatter::send(stream, F(" %d %d"), id, pos); + StringFormatter::send(stream, F(" %d %d %d %d"), id, type, pos, posCount); + for (uint8_t p = 0; p < posCount; p++) { + int16_t value = tto->getPositionValue(p); + StringFormatter::send(stream, F(" %d"), value); + } } } StringFormatter::send(stream, F(">\n")); @@ -1047,7 +1053,6 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[]) // ========================== // Turntable // - list all -// - delete // - operate (DCC) // - operate (EXTT) // - create EXTT @@ -1096,10 +1101,10 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[]) if (Turntable::get(p[0])) return false; if (!EXTTTurntable::create(p[0], (VPIN)p[2], (uint8_t)p[3])) return false; Turntable *tto = Turntable::get(p[0]); - for (uint8_t i = params - 4; i > 0; i--) { - tto->addPosition(p[i + 3]); + for (uint8_t i = params - 5; i > 0; i--) { + tto->addPosition(p[i + 4]); } - tto->addPosition(p[3]); // Allow setting a value for the home angle for throttles to draw it + tto->addPosition(p[4]); // Allow setting a value for the home angle for throttles to draw it } else if (params > 3 && params < 39 && p[1] == HASH_KEYWORD_DCC) { DIAG(F("Create DCC turntable %d at base address %d with %d positions"), p[0], p[2], params - 2); } else { diff --git a/Turntables.cpp b/Turntables.cpp index 5332aa5..bcc0a94 100644 --- a/Turntables.cpp +++ b/Turntables.cpp @@ -81,6 +81,17 @@ uint16_t Turntable::getPositionValue(size_t position) { } } +// Get the count of positions associated with the turntable +uint8_t Turntable::getPositionCount() { + TurntablePosition* currentPosition = _turntablePositions.getHead(); + uint8_t count = 0; + while (currentPosition) { + count++; + currentPosition = currentPosition->next; + } + return count; +} + /* * Public static functions */ @@ -103,8 +114,11 @@ bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) { bool ok = tto->setPositionInternal(position, activity); if (ok) { - tto->setPositionStateOnly(id, position); - tto->_turntableData.position = position; + // Broadcast a position change only if non zero has been set, or home/calibration sent + if (position > 0 || (position == 0 && (activity == 2 || activity == 3))) { + tto->setPositionStateOnly(id, position); + tto->_turntableData.position = position; + } } return ok; } @@ -134,7 +148,7 @@ EXTTTurntable::EXTTTurntable(uint16_t id, VPIN vpin, uint8_t i2caddress) : } } tto = (Turntable *)new EXTTTurntable(id, vpin, i2caddress); - DIAG(F("Turntable 0x%x"), tto); + DIAG(F("Turntable 0x%x size %d size %d"), tto, sizeof(Turntable), sizeof(struct TurntableData)); return tto; #else (void)id; @@ -151,10 +165,14 @@ EXTTTurntable::EXTTTurntable(uint16_t id, VPIN vpin, uint8_t i2caddress) : // EX-Turntable specific code for moving to the specified position bool EXTTTurntable::setPositionInternal(uint8_t position, uint8_t activity) { #ifndef IO_NO_HAL - DIAG(F("Set EXTT %d to position %d with activity %d"), _exttTurntableData.vpin, position, activity); - if (position == 0) return false; // Position 0 is just so throttles know where home is - int16_t value = getPositionValue(position); // Get position value from position list - if (!value) return false; // Return false if it's not a valid position + int16_t value; + if (position == 0) { + value = 0; // Position 0 is just to send activities + } else { + if (activity > 1) return false; // If sending a position update, only phase changes valid (0|1) + value = getPositionValue(position); // Get position value from position list + } + if (position > 0 && !value) return false; // Return false if it's not a valid position // Set position via device driver EXTurntable::writeAnalogue(_exttTurntableData.vpin, value, activity); #else diff --git a/Turntables.h b/Turntables.h index f3a3321..1016140 100644 --- a/Turntables.h +++ b/Turntables.h @@ -140,11 +140,13 @@ public: inline bool isHidden() { return _turntableData.hidden; } inline void setHidden(bool h) {_turntableData.hidden=h; } inline bool isType(uint8_t type) { return _turntableData.turntableType == type; } + inline uint8_t getType() { return _turntableData.turntableType; } inline uint16_t getId() { return _turntableData.id; } inline Turntable *next() { return _nextTurntable; } void printState(Print *stream); void addPosition(uint16_t value); uint16_t getPositionValue(size_t position); + uint8_t getPositionCount(); /* * Virtual functions