Skip to content

Commit b86734e

Browse files
Handle turntable 180 degree reverse
My PR DCC-EX/EX-Turntable#111 gives a much IMO need for a 180 degree reverse on the turntable. This will ensure we get correct messaging and commands.
1 parent e7e9973 commit b86734e

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

IODevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ class EXTurntable : public IODevice {
425425
LED_Off = 7, // Turn LED off
426426
Acc_On = 8, // Turn accessory pin on
427427
Acc_Off = 9, // Turn accessory pin off
428+
Reverse = 18, // Reverse turntable 180 degrees
428429
};
429430

430431
private:

IO_EXTurntable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void EXTurntable::_loop(unsigned long currentMicros) {
7272
I2CManager.read(_I2CAddress, readBuffer, 1);
7373
_stepperStatus = readBuffer[0];
7474
if (_stepperStatus != _previousStatus && _stepperStatus == 0) { // Broadcast when a rotation finishes
75-
if ( _currentActivity < 4) {
75+
if ( _currentActivity < ActivityNumber::LED_On || _currentActivity == ActivityNumber::Reverse) {
7676
_broadcastStatus(_firstVpin, _stepperStatus, _currentActivity);
7777
}
7878
_previousStatus = _stepperStatus;
@@ -96,7 +96,7 @@ int EXTurntable::_read(VPIN vpin) {
9696
void EXTurntable::_broadcastStatus (VPIN vpin, uint8_t status, uint8_t activity) {
9797
Turntable *tto = Turntable::getByVpin(vpin);
9898
if (tto) {
99-
if (activity < 4) {
99+
if (activity < ActivityNumber::LED_On || activity == ActivityNumber::Reverse) {
100100
tto->setMoving(status);
101101
CommandDistributor::broadcastTurntable(tto->getId(), tto->getPosition(), status);
102102
}
@@ -129,9 +129,9 @@ void EXTurntable::_writeAnalogue(VPIN vpin, int value, uint8_t activity, uint16_
129129
DIAG(F("I2CManager write I2C Address:%d stepsMSB:%d stepsLSB:%d activity:%d"),
130130
_I2CAddress.toString(), stepsMSB, stepsLSB, activity);
131131
#else
132-
(void)duration;
132+
(void)duration;
133133
#endif
134-
if (activity < 4) _stepperStatus = 1; // Tell the device driver Turntable-EX is busy
134+
if (activity < ActivityNumber::LED_On || activity == ActivityNumber::Reverse) _stepperStatus = 1; // Tell the device driver Turntable-EX is busy
135135
_previousStatus = _stepperStatus;
136136
_currentActivity = activity;
137137
_broadcastStatus(vpin, _stepperStatus, activity); // Broadcast when the rotation starts

Turntables.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) {
142142
Turntable *tto = Turntable::get(id);
143143
if (!tto) return false;
144144
if (tto->isMoving()) return false;
145+
146+
if(activity == EXTurntable::ActivityNumber::Reverse){
147+
// A 180-degree turn keeps the same logical track position.
148+
position = tto->getPosition();
149+
}
145150
bool ok = tto->setPositionInternal(position, activity);
146151

147152
if (ok) {
@@ -152,7 +157,7 @@ bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) {
152157
// Trigger EXRAIL rotateEvent for both types here if changed
153158
#if defined(EXRAIL_ACTIVE)
154159
bool rotated = false;
155-
if (position != tto->_previousPosition) rotated = true;
160+
if (position != tto->_previousPosition || activity == EXTurntable::ActivityNumber::Reverse) rotated = true;
156161
RMFT2::rotateEvent(id, rotated);
157162
#endif
158163
}
@@ -204,12 +209,19 @@ using DevState = IODevice::DeviceStateEnum;
204209
bool EXTTTurntable::setPositionInternal(uint8_t position, uint8_t activity) {
205210
#ifndef IO_NO_HAL
206211
int16_t value;
207-
if (position == 0) {
208-
value = 0; // Position 0 is just to send activities
209-
} else {
210-
if (activity > 1) return false; // If sending a position update, only phase changes valid (0|1)
212+
if(activity == EXTurntable::ActivityNumber::Reverse) {
213+
// Keep logical position unchanged while issuing the 180 action.
214+
position = _turntableData.position;
211215
value = getPositionValue(position); // Get position value from position list
216+
}else {
217+
if (position == 0) {
218+
value = 0; // Position 0 is just to send activities
219+
} else {
220+
if (activity > EXTurntable::ActivityNumber::Turn_PInvert) return false; // If sending a position update, only phase changes valid (0|1)
221+
value = getPositionValue(position); // Get position value from position list
222+
}
212223
}
224+
213225
if (position > 0 && !value) return false; // Return false if it's not a valid position
214226
// Set position via device driver
215227
_previousPosition = _turntableData.position;

0 commit comments

Comments
 (0)