From 74664c137e884136042f05eacca805b3b8d49c9c Mon Sep 17 00:00:00 2001 From: Mathew Winters Date: Tue, 21 Apr 2026 20:12:53 +1200 Subject: [PATCH 1/2] Provides a 180 degree reverse function On activity 18, the turntable will do a 180 degree turn. Eg I found that a turntable software didn't actually do a full reverse, which would be quite handy to have. --- IOFunctions.cpp | 5 ++++- TurntableFunctions.cpp | 18 ++++++++++++++++++ TurntableFunctions.h | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/IOFunctions.cpp b/IOFunctions.cpp index 2907a1a..32bb454 100644 --- a/IOFunctions.cpp +++ b/IOFunctions.cpp @@ -398,7 +398,10 @@ void receiveEvent(int received) { Serial.println(F("DEBUG: Turn accessory pin off")); } setAccessory(LOW); - +#if TURNTABLE_EX_MODE == TURNTABLE + } else if (activity == 18 && !stepper.isRunning() && !calibrating) { + reverseTurntable(activity); +#endif #ifdef USE_RT_EX_TURNTABLE } else if ((activity >= 10) && (activity <= 17)) { setExtra(activity); diff --git a/TurntableFunctions.cpp b/TurntableFunctions.cpp index 0414cd8..10e6785 100644 --- a/TurntableFunctions.cpp +++ b/TurntableFunctions.cpp @@ -283,6 +283,24 @@ void moveToPosition(long steps, uint8_t phaseSwitch) { } } +void reverseTurntable(uint8_t phaseSwitch){ + // Calculate new target 180 degrees from lastTarget + long newTarget = lastTarget + halfTurnSteps; + if (newTarget >= fullTurnSteps) { + newTarget -= fullTurnSteps; + } + // Set phase if needed + setPhase(phaseSwitch); + // Move to new target + stepper.enableOutputs(); + stepper.moveTo(newTarget); + lastTarget = newTarget; + lastStep = newTarget; + + Serial.print(F("Reverseing Turntable: Rotating to ")); + Serial.println(newTarget); +} + // Function to set phase. void setPhase(uint8_t phase) { #if RELAY_ACTIVE_STATE == HIGH diff --git a/TurntableFunctions.h b/TurntableFunctions.h index 4d300ed..18d8836 100644 --- a/TurntableFunctions.h +++ b/TurntableFunctions.h @@ -36,6 +36,7 @@ extern bool calibrating; extern uint8_t homed; extern AccelStepper stepper; extern long fullTurnSteps; +extern long halfTurnSteps; extern long phaseSwitchStartSteps; extern long phaseSwitchStopSteps; extern long lastTarget; @@ -56,6 +57,7 @@ void initiateHoming(); void initiateCalibration(); void setLEDActivity(uint8_t activity); void setAccessory(bool state); +void reverseTurntable(uint8_t phaseSwitch); #ifdef USE_RT_EX_TURNTABLE void setExtra(uint8_t activity); From f137a9184781ab89930e540f4cf099e41cf04256 Mon Sep 17 00:00:00 2001 From: Mathew Winters Date: Wed, 22 Apr 2026 18:42:21 +1200 Subject: [PATCH 2/2] Fix rotating 180 from home position. --- TurntableFunctions.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/TurntableFunctions.cpp b/TurntableFunctions.cpp index 10e6785..e2d608d 100644 --- a/TurntableFunctions.cpp +++ b/TurntableFunctions.cpp @@ -183,6 +183,7 @@ void moveHome() { #endif stepper.setCurrentPosition(0); lastStep = 0; + lastTarget = 0; homed = 1; Serial.println(F("Turntable homed successfully")); if (debug) { @@ -284,8 +285,12 @@ void moveToPosition(long steps, uint8_t phaseSwitch) { } void reverseTurntable(uint8_t phaseSwitch){ - // Calculate new target 180 degrees from lastTarget - long newTarget = lastTarget + halfTurnSteps; + // Calculate new target 180 degrees from current logical position. + long baseTarget = lastStep % fullTurnSteps; + if (baseTarget < 0) { + baseTarget += fullTurnSteps; + } + long newTarget = baseTarget + halfTurnSteps; if (newTarget >= fullTurnSteps) { newTarget -= fullTurnSteps; }