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

Revisiting logic

This commit is contained in:
peteGSX 2023-09-04 18:46:28 +10:00
parent dd890e65bf
commit 86f4567556
2 changed files with 7 additions and 5 deletions

View File

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

View File

@ -140,8 +140,8 @@ bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) {
if (ok) { if (ok) {
// Broadcast a position change only if non zero has been set, or home/calibration sent // Broadcast a position change only if non zero has been set, or home/calibration sent
tto->_previousPosition = tto->getPosition();
if (position > 0 || (position == 0 && (activity == 2 || activity == 3))) { if (position > 0 || (position == 0 && (activity == 2 || activity == 3))) {
tto->_previousPosition = tto->getPosition();
tto->_turntableData.position = position; tto->_turntableData.position = position;
if (tto->isEXTT()) { if (tto->isEXTT()) {
tto->setPositionStateOnly(id, position, 1); tto->setPositionStateOnly(id, position, 1);
@ -179,6 +179,7 @@ using DevState = IODevice::DeviceStateEnum;
} }
if (!IODevice::exists(vpin)) return nullptr; if (!IODevice::exists(vpin)) return nullptr;
if (IODevice::getStatus(vpin) == DevState::DEVSTATE_FAILED) return nullptr; if (IODevice::getStatus(vpin) == DevState::DEVSTATE_FAILED) return nullptr;
if (Turntable::getByVpin(vpin)) return nullptr;
tto = (Turntable *)new EXTTTurntable(id, vpin); tto = (Turntable *)new EXTTTurntable(id, vpin);
DIAG(F("Turntable 0x%x size %d size %d"), tto, sizeof(Turntable), sizeof(struct TurntableData)); DIAG(F("Turntable 0x%x size %d size %d"), tto, sizeof(Turntable), sizeof(struct TurntableData));
return tto; return tto;