Skip to content

Commit

Permalink
Writing to driver
Browse files Browse the repository at this point in the history
  • Loading branch information
peteGSX committed Aug 27, 2023
1 parent 2202cb0 commit df4a501
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
19 changes: 13 additions & 6 deletions DCCEXParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,16 +1039,13 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
return false;

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]);
if (tto) {
if (tto->getPosition() == p[1]) return true;
uint16_t value = tto->getPositionValue(p[1]);
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 {
return false;
}
Expand All @@ -1057,11 +1054,21 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
}
}
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
{
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]);
Expand Down
22 changes: 6 additions & 16 deletions Turntables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
// 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
// EXTurntable::_writeAnalogue(vpin, value, activity, 0);
EXTurntable::writeAnalogue(_exttTurntableData.vpin, value, activity);
#else
(void)position;
#endif
Expand Down
1 change: 0 additions & 1 deletion Turntables.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class Turntable {
* 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; }
Expand Down

0 comments on commit df4a501

Please sign in to comment.