Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions TurntableFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,33 @@ void setupStepperDriver() {
// Function to find the home position.
void moveHome() {
setPhase(0);
#if defined(ROTATE_BEFORE_HOME)
static bool _rotateBeforeHomeDone = false;
static bool _clearingHome = false;
// Phase 1: sensor active on entry — rotate until it deactivates.
if (!_rotateBeforeHomeDone && !_clearingHome && !stepper.isRunning() && getHomeState() == HOME_SENSOR_ACTIVE_STATE) {
if (!stepper.isRunning()) {
Serial.println(F("Home sensor active at startup, rotating clear before homing"));
stepper.enableOutputs();
stepper.move(sanitySteps);
}
_clearingHome = true;
return;
}
// Phase 2: still clearing — wait for sensor to deactivate.
if (_clearingHome) {
if (getHomeState() == HOME_SENSOR_ACTIVE_STATE) {
return; // still on sensor, keep rotating
}
// Sensor has cleared — stop current move and let normal homing start fresh.
_clearingHome = false;
_rotateBeforeHomeDone = true;
stepper.stop();
lastTarget = sanitySteps; // reset so normal homing won't see a false failure
Serial.println(F("Sensor cleared, starting homing"));
return; // let stepper decelerate; next call starts normal homing
}
#endif
if (getHomeState() == HOME_SENSOR_ACTIVE_STATE) {
stepper.stop();
#if defined(DISABLE_OUTPUTS_IDLE)
Expand Down
8 changes: 8 additions & 0 deletions config.example.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@
// #define ROTATE_FORWARD_ONLY
// #define ROTATE_REVERSE_ONLY

/////////////////////////////////////////////////////////////////////////////////////
// If the home sensor may be active when the turntable powers on (e.g. the bridge
// rests on the sensor), enable this option to rotate away from the sensor before
// beginning the normal homing sequence. This ensures homing always triggers on a
// clean leading edge of the sensor.
//
// #define ROTATE_BEFORE_HOME

/////////////////////////////////////////////////////////////////////////////////////
// Define the LED blink rates for fast and slow blinking in milliseconds.
//
Expand Down
Loading