mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-25 00:56:13 +01:00
Compare commits
No commits in common. "3bfdd16288af0424c7d162f6f13787a79030dc25" and "2202cb0c5eddbc4ca3c1a3df1c95604278f64353" have entirely different histories.
3bfdd16288
...
2202cb0c5e
|
@ -85,7 +85,6 @@ const int16_t HASH_KEYWORD_A='A';
|
|||
const int16_t HASH_KEYWORD_C='C';
|
||||
const int16_t HASH_KEYWORD_G='G';
|
||||
const int16_t HASH_KEYWORD_I='I';
|
||||
const int16_t HASH_KEYWORD_O='O';
|
||||
const int16_t HASH_KEYWORD_R='R';
|
||||
const int16_t HASH_KEYWORD_T='T';
|
||||
const int16_t HASH_KEYWORD_X='X';
|
||||
|
@ -692,29 +691,6 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
|||
}
|
||||
StringFormatter::send(stream, F(">\n"));
|
||||
return;
|
||||
case HASH_KEYWORD_O: // <JO returns turntable list
|
||||
StringFormatter::send(stream, F("<jO"));
|
||||
if (params==1) { // <JO>
|
||||
for ( Turntable * tto=Turntable::first(); tto; tto=tto->next()) {
|
||||
if (tto->isHidden()) continue;
|
||||
StringFormatter::send(stream, F(" %d"),tto->getId());
|
||||
}
|
||||
} else { // <JO id>
|
||||
Turntable *tto=Turntable::get(id);
|
||||
if (!tto || tto->isHidden()) {
|
||||
StringFormatter::send(stream, F(" %d X"), id);
|
||||
} else {
|
||||
uint8_t pos = tto->getPosition();
|
||||
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(">\n"));
|
||||
return;
|
||||
default: break;
|
||||
} // switch(p[1])
|
||||
break; // case J
|
||||
|
@ -1063,27 +1039,19 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
|
|||
return false;
|
||||
|
||||
case 2: // <I id position> - rotate to position for DCC turntables
|
||||
{
|
||||
Turntable *tto = Turntable::get(p[0]);
|
||||
if (tto) {
|
||||
if (tto->getPosition() == p[1]) return true;
|
||||
uint16_t value = tto->getPositionValue(p[1]);
|
||||
if (value) {
|
||||
DIAG(F("Rotate DCC turntable %d to position %d"), p[0], p[1]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case 3: // <I id position activity> rotate to position for EX-Turntable
|
||||
{
|
||||
Turntable *tto = Turntable::get(p[0]);
|
||||
if (tto) {
|
||||
if (!tto->setPosition(p[0], p[1], p[2])) return false;
|
||||
uint16_t value = tto->getPositionValue(p[1]);
|
||||
if (value) {
|
||||
DIAG(F("Position %d value is %d"), p[1], value);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -1093,13 +1061,14 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
|
|||
default: // If we're here, it must be creating a turntable object
|
||||
{
|
||||
if (params > 5 && params < 41 && p[1] == HASH_KEYWORD_EXTT) {
|
||||
DIAG(F("Create EXTT turntable %d on vpin %d and address %d with %d positions"), p[0], p[2], p[3], params - 4);
|
||||
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]);
|
||||
}
|
||||
tto->addPosition(p[3]); // Allow setting a value for the home angle for throttles to draw it
|
||||
tto->addPosition(0); // Need to add position 0 as 0 so positions start at 1
|
||||
} 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 {
|
||||
|
|
|
@ -84,6 +84,19 @@ uint16_t Turntable::getPositionValue(size_t position) {
|
|||
/*
|
||||
* Public static functions
|
||||
*/
|
||||
bool Turntable::isPosition(uint16_t id, uint8_t position) {
|
||||
Turntable *tto = get(id);
|
||||
if (tto) {
|
||||
if (tto->getPosition() == position) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Turntable::setPositionStateOnly(uint16_t id, uint8_t position) {
|
||||
Turntable *tto = get(id);
|
||||
if (!tto) return false;
|
||||
|
@ -104,7 +117,6 @@ bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) {
|
|||
|
||||
if (ok) {
|
||||
tto->setPositionStateOnly(id, position);
|
||||
tto->_turntableData.position = position;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
@ -151,12 +163,10 @@ 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
|
||||
// Get step value from positions
|
||||
// int value = _exttTurntableData.positions[position];
|
||||
// Set position via device driver
|
||||
EXTurntable::writeAnalogue(_exttTurntableData.vpin, value, activity);
|
||||
// EXTurntable::_writeAnalogue(vpin, value, activity, 0);
|
||||
#else
|
||||
(void)position;
|
||||
#endif
|
||||
|
|
|
@ -159,6 +159,7 @@ public:
|
|||
* Public static functions
|
||||
*/
|
||||
inline static bool exists(uint16_t id) { return get(id) != 0; }
|
||||
static bool isPosition(uint16_t id, uint8_t position);
|
||||
static bool setPosition(uint16_t id, uint8_t position, uint8_t activity=0);
|
||||
static bool setPositionStateOnly(uint16_t id, uint8_t position);
|
||||
inline static Turntable *first() { return _firstTurntable; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user