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

Working but limited

This commit is contained in:
peteGSX 2023-08-29 13:38:52 +10:00
parent 3bfdd16288
commit b0d8510127
3 changed files with 38 additions and 13 deletions

View File

@ -695,7 +695,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
case HASH_KEYWORD_O: // <JO returns turntable list case HASH_KEYWORD_O: // <JO returns turntable list
StringFormatter::send(stream, F("<jO")); StringFormatter::send(stream, F("<jO"));
if (params==1) { // <JO> if (params==1) { // <JO>
for ( Turntable * tto=Turntable::first(); tto; tto=tto->next()) { for (Turntable * tto=Turntable::first(); tto; tto=tto->next()) {
if (tto->isHidden()) continue; if (tto->isHidden()) continue;
StringFormatter::send(stream, F(" %d"),tto->getId()); 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); StringFormatter::send(stream, F(" %d X"), id);
} else { } else {
uint8_t pos = tto->getPosition(); uint8_t pos = tto->getPosition();
uint8_t type = tto->getType();
uint8_t posCount = tto->getPositionCount();
const FSH *todesc = NULL; const FSH *todesc = NULL;
#ifdef EXRAIL_ACTIVE #ifdef EXRAIL_ACTIVE
// todesc = RMFT2::getTurntableDescription(id); // todesc = RMFT2::getTurntableDescription(id);
#endif #endif
if (todesc == NULL) todesc = F(""); 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")); StringFormatter::send(stream, F(">\n"));
@ -1047,7 +1053,6 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
// ========================== // ==========================
// Turntable // Turntable
// <I> - list all // <I> - list all
// <I id> - delete
// <I id steps> - operate (DCC) // <I id steps> - operate (DCC)
// <I id steps activity> - operate (EXTT) // <I id steps activity> - operate (EXTT)
// <I id EXTT i2caddress vpin position1 position2 ...> - create EXTT // <I id EXTT i2caddress vpin position1 position2 ...> - 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 (Turntable::get(p[0])) return false;
if (!EXTTTurntable::create(p[0], (VPIN)p[2], (uint8_t)p[3])) return false; if (!EXTTTurntable::create(p[0], (VPIN)p[2], (uint8_t)p[3])) return false;
Turntable *tto = Turntable::get(p[0]); Turntable *tto = Turntable::get(p[0]);
for (uint8_t i = params - 4; i > 0; i--) { for (uint8_t i = params - 5; i > 0; i--) {
tto->addPosition(p[i + 3]); 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) { } 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); DIAG(F("Create DCC turntable %d at base address %d with %d positions"), p[0], p[2], params - 2);
} else { } else {

View File

@ -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 * 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); bool ok = tto->setPositionInternal(position, activity);
if (ok) { if (ok) {
tto->setPositionStateOnly(id, position); // Broadcast a position change only if non zero has been set, or home/calibration sent
tto->_turntableData.position = position; if (position > 0 || (position == 0 && (activity == 2 || activity == 3))) {
tto->setPositionStateOnly(id, position);
tto->_turntableData.position = position;
}
} }
return ok; return ok;
} }
@ -134,7 +148,7 @@ EXTTTurntable::EXTTTurntable(uint16_t id, VPIN vpin, uint8_t i2caddress) :
} }
} }
tto = (Turntable *)new EXTTTurntable(id, vpin, 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; return tto;
#else #else
(void)id; (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 // EX-Turntable specific code for moving to the specified position
bool EXTTTurntable::setPositionInternal(uint8_t position, uint8_t activity) { bool EXTTTurntable::setPositionInternal(uint8_t position, uint8_t activity) {
#ifndef IO_NO_HAL #ifndef IO_NO_HAL
DIAG(F("Set EXTT %d to position %d with activity %d"), _exttTurntableData.vpin, position, activity); int16_t value;
if (position == 0) return false; // Position 0 is just so throttles know where home is if (position == 0) {
int16_t value = getPositionValue(position); // Get position value from position list value = 0; // Position 0 is just to send activities
if (!value) return false; // Return false if it's not a valid position } 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 // Set position via device driver
EXTurntable::writeAnalogue(_exttTurntableData.vpin, value, activity); EXTurntable::writeAnalogue(_exttTurntableData.vpin, value, activity);
#else #else

View File

@ -140,11 +140,13 @@ public:
inline bool isHidden() { return _turntableData.hidden; } inline bool isHidden() { return _turntableData.hidden; }
inline void setHidden(bool h) {_turntableData.hidden=h; } inline void setHidden(bool h) {_turntableData.hidden=h; }
inline bool isType(uint8_t type) { return _turntableData.turntableType == type; } 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 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(uint16_t value);
uint16_t getPositionValue(size_t position); uint16_t getPositionValue(size_t position);
uint8_t getPositionCount();
/* /*
* Virtual functions * Virtual functions