1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-25 00:56:13 +01:00

Compare commits

..

2 Commits

Author SHA1 Message Date
peteGSX
3bfdd16288 Start on JO 2023-08-28 13:11:37 +10:00
peteGSX
df4a501e8a Writing to driver 2023-08-28 08:36:09 +10:00
3 changed files with 46 additions and 26 deletions

View File

@ -85,6 +85,7 @@ 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';
@ -691,6 +692,29 @@ 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
@ -1039,19 +1063,27 @@ 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) {
uint16_t value = tto->getPositionValue(p[1]);
if (value) {
DIAG(F("Position %d value is %d"), p[1], value);
} else {
return false;
}
if (!tto->setPosition(p[0], p[1], p[2])) return false;
} else {
return false;
}
@ -1061,14 +1093,13 @@ 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(0); // Need to add position 0 as 0 so positions start at 1
tto->addPosition(p[3]); // 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 {

View File

@ -84,19 +84,6 @@ 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;
@ -117,6 +104,7 @@ bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) {
if (ok) {
tto->setPositionStateOnly(id, position);
tto->_turntableData.position = position;
}
return ok;
}
@ -163,10 +151,12 @@ 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
// Get step value from positions
// int value = _exttTurntableData.positions[position];
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
// Set position via device driver
// EXTurntable::_writeAnalogue(vpin, value, activity, 0);
EXTurntable::writeAnalogue(_exttTurntableData.vpin, value, activity);
#else
(void)position;
#endif

View File

@ -159,7 +159,6 @@ 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; }