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

Writing to driver

This commit is contained in:
peteGSX 2023-08-28 08:36:09 +10:00
parent 2202cb0c5e
commit df4a501e8a
3 changed files with 21 additions and 25 deletions

View File

@ -1039,16 +1039,13 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
return false; return false;
case 2: // <I id position> - rotate to position for DCC turntables case 2: // <I id position> - rotate to position for DCC turntables
DIAG(F("Rotate DCC turntable %d to position %d"), p[0], p[1]);
return true;
case 3: // <I id position activity> rotate to position for EX-Turntable
{ {
Turntable *tto = Turntable::get(p[0]); Turntable *tto = Turntable::get(p[0]);
if (tto) { if (tto) {
if (tto->getPosition() == p[1]) return true;
uint16_t value = tto->getPositionValue(p[1]); uint16_t value = tto->getPositionValue(p[1]);
if (value) { if (value) {
DIAG(F("Position %d value is %d"), p[1], value); DIAG(F("Rotate DCC turntable %d to position %d"), p[0], p[1]);
} else { } else {
return false; return false;
} }
@ -1058,10 +1055,20 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
} }
return true; 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;
} else {
return false;
}
}
return true;
default: // If we're here, it must be creating a turntable object default: // If we're here, it must be creating a turntable object
{ {
if (params > 5 && params < 41 && p[1] == HASH_KEYWORD_EXTT) { 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 (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]);

View File

@ -84,19 +84,6 @@ uint16_t Turntable::getPositionValue(size_t position) {
/* /*
* Public static functions * 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) { bool Turntable::setPositionStateOnly(uint16_t id, uint8_t position) {
Turntable *tto = get(id); Turntable *tto = get(id);
if (!tto) return false; if (!tto) return false;
@ -117,6 +104,7 @@ bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) {
if (ok) { if (ok) {
tto->setPositionStateOnly(id, position); tto->setPositionStateOnly(id, position);
tto->_turntableData.position = position;
} }
return ok; 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 // 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
// Get step value from positions DIAG(F("Set EXTT %d to position %d with activity %d"), _exttTurntableData.vpin, position, activity);
// int value = _exttTurntableData.positions[position]; // Get position value from position list
int16_t value = getPositionValue(position);
if (!value) return false; // Return false if it's not a valid position
// Set position via device driver // Set position via device driver
// EXTurntable::_writeAnalogue(vpin, value, activity, 0); EXTurntable::writeAnalogue(_exttTurntableData.vpin, value, activity);
#else #else
(void)position; (void)position;
#endif #endif

View File

@ -159,7 +159,6 @@ public:
* Public static functions * Public static functions
*/ */
inline static bool exists(uint16_t id) { return get(id) != 0; } 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 setPosition(uint16_t id, uint8_t position, uint8_t activity=0);
static bool setPositionStateOnly(uint16_t id, uint8_t position); static bool setPositionStateOnly(uint16_t id, uint8_t position);
inline static Turntable *first() { return _firstTurntable; } inline static Turntable *first() { return _firstTurntable; }