mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-25 05:31:24 +01:00
Ready to test
This commit is contained in:
parent
86f4567556
commit
3094c52bf8
@ -94,8 +94,8 @@ int EXTurntable::_read(VPIN vpin) {
|
|||||||
void EXTurntable::_broadcastStatus (VPIN vpin, uint8_t status) {
|
void EXTurntable::_broadcastStatus (VPIN vpin, uint8_t status) {
|
||||||
Turntable *tto = Turntable::getByVpin(vpin);
|
Turntable *tto = Turntable::getByVpin(vpin);
|
||||||
if (tto) {
|
if (tto) {
|
||||||
CommandDistributor::broadcastTurntable(tto->getId(), tto->getPosition(), status);
|
|
||||||
tto->setMoving(status);
|
tto->setMoving(status);
|
||||||
|
CommandDistributor::broadcastTurntable(tto->getId(), tto->getPosition(), status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,40 +115,27 @@ uint8_t Turntable::getPosition(uint16_t id) {
|
|||||||
return tto->getPosition();
|
return tto->getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast position changes
|
|
||||||
bool Turntable::setPositionStateOnly(uint16_t id, uint8_t position, bool moving) {
|
|
||||||
Turntable *tto = get(id);
|
|
||||||
if (!tto) return false;
|
|
||||||
// Only need to broadcast from here if it's a DCC type, device driver broadcasts EXTT
|
|
||||||
if (!tto->isEXTT()) { CommandDistributor::broadcastTurntable(id, position, moving); }
|
|
||||||
#if defined(EXRAIL_ACTIVE)
|
|
||||||
bool rotated = false;
|
|
||||||
if (position != tto->_previousPosition) rotated = true;
|
|
||||||
if (!tto->isEXTT()) { RMFT2::rotateEvent(id, rotated); }
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initiate a turntable move
|
// Initiate a turntable move
|
||||||
bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) {
|
bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) {
|
||||||
#if defined(DIAG_IO)
|
#if defined(DIAG_IO)
|
||||||
DIAG(F("Turntable(%d, %d)"), id, position);
|
DIAG(F("Rotate turntable %d to position %d, activity %d)"), id, position, activity);
|
||||||
#endif
|
#endif
|
||||||
Turntable *tto = Turntable::get(id);
|
Turntable *tto = Turntable::get(id);
|
||||||
if (!tto) return false;
|
if (!tto) return false;
|
||||||
|
if (tto->isMoving()) return false;
|
||||||
bool ok = tto->setPositionInternal(position, activity);
|
bool ok = tto->setPositionInternal(position, activity);
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// Broadcast a position change only if non zero has been set, or home/calibration sent
|
// We only deal with broadcasts for DCC turntables here, EXTT in the device driver
|
||||||
if (position > 0 || (position == 0 && (activity == 2 || activity == 3))) {
|
if (!tto->isEXTT()) {
|
||||||
tto->_previousPosition = tto->getPosition();
|
CommandDistributor::broadcastTurntable(id, position, false);
|
||||||
tto->_turntableData.position = position;
|
|
||||||
if (tto->isEXTT()) {
|
|
||||||
tto->setPositionStateOnly(id, position, 1);
|
|
||||||
} else {
|
|
||||||
tto->setPositionStateOnly(id, position, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Trigger EXRAIL rotateEvent for both types here if changed
|
||||||
|
#if defined(EXRAIL_ACTIVE)
|
||||||
|
bool rotated = false;
|
||||||
|
if (position != tto->_previousPosition) rotated = true;
|
||||||
|
RMFT2::rotateEvent(id, rotated);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@ -206,6 +193,8 @@ using DevState = IODevice::DeviceStateEnum;
|
|||||||
}
|
}
|
||||||
if (position > 0 && !value) return false; // Return false if it's not a valid position
|
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
|
||||||
|
_previousPosition = _turntableData.position;
|
||||||
|
_turntableData.position = position;
|
||||||
EXTurntable::writeAnalogue(_exttTurntableData.vpin, value, activity);
|
EXTurntable::writeAnalogue(_exttTurntableData.vpin, value, activity);
|
||||||
#else
|
#else
|
||||||
(void)position;
|
(void)position;
|
||||||
@ -248,6 +237,8 @@ DCCTurntable::DCCTurntable(uint16_t id) : Turntable(id, TURNTABLE_DCC) {}
|
|||||||
int16_t addr=value>>3;
|
int16_t addr=value>>3;
|
||||||
int16_t subaddr=(value>>1) & 0x03;
|
int16_t subaddr=(value>>1) & 0x03;
|
||||||
bool active=value & 0x01;
|
bool active=value & 0x01;
|
||||||
|
_previousPosition = _turntableData.position;
|
||||||
|
_turntableData.position = position;
|
||||||
DCC::setAccessory(addr, subaddr, active);
|
DCC::setAccessory(addr, subaddr, active);
|
||||||
#else
|
#else
|
||||||
(void)position;
|
(void)position;
|
||||||
|
@ -179,7 +179,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
inline static bool exists(uint16_t id) { return get(id) != 0; }
|
inline static bool exists(uint16_t id) { return get(id) != 0; }
|
||||||
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, bool moving);
|
|
||||||
static uint8_t getPosition(uint16_t id);
|
static uint8_t getPosition(uint16_t id);
|
||||||
inline static Turntable *first() { return _firstTurntable; }
|
inline static Turntable *first() { return _firstTurntable; }
|
||||||
static bool printAll(Print *stream) {
|
static bool printAll(Print *stream) {
|
||||||
|
Loading…
Reference in New Issue
Block a user