@@ -570,18 +570,27 @@ void SS2K::goHome(bool bothDirections) {
570570 vTaskDelay (50 / portTICK_PERIOD_MS);
571571 driver.ihold ((uint8_t )(1 ));
572572 vTaskDelay (50 / portTICK_PERIOD_MS);
573- this ->updateStepperSpeed (1500 );
574- bool stalled = false ;
575573 int threshold = 0 ;
576- vTaskDelay ( 1000 / portTICK_PERIOD_MS) ;
574+ bool stalled = false ;
577575 if (bothDirections) {
576+ // Back off limit in case we are alread here.
577+ stepper->move (-userConfig->getShiftStep ());
578+ while (stepper->isRunning ()) {
579+ vTaskDelay (50 / portTICK_PERIOD_MS);
580+ }
581+ this ->updateStepperSpeed (1500 );
582+ vTaskDelay (500 / portTICK_PERIOD_MS);
578583 stepper->runForward ();
579584 vTaskDelay (250 / portTICK_PERIOD_MS); // wait until stable
580585 threshold = driver.SG_RESULT (); // take reading
581586 Serial.printf (" %d " , driver.SG_RESULT ());
582587 vTaskDelay (250 / portTICK_PERIOD_MS);
583588 while (!stalled) {
584- // stalled = (threshold < 200); // Were we already at the stop?
589+ if (abs (rtConfig->getShifterPosition () - ss2k->lastShifterPosition )) { // let the user abort with the shift button.
590+ userConfig->setHMin (INT32_MIN);
591+ userConfig->setHMax (INT32_MIN);
592+ return ;
593+ }
585594 stalled = (driver.SG_RESULT () < threshold - 100 );
586595 }
587596 stalled = false ;
@@ -591,13 +600,25 @@ void SS2K::goHome(bool bothDirections) {
591600 rtConfig->setMaxStep (stepper->getCurrentPosition () - 200 );
592601 SS2K_LOG (MAIN_LOG_TAG, " Max Position found: %d." , rtConfig->getMaxStep ());
593602 stepper->enableOutputs ();
603+ } else { // Back off limit in case we are alread here.
604+ stepper->move (userConfig->getShiftStep ());
605+ while (stepper->isRunning ()) {
606+ vTaskDelay (50 / portTICK_PERIOD_MS);
607+ }
608+ this ->updateStepperSpeed (1500 );
609+ vTaskDelay (500 / portTICK_PERIOD_MS);
594610 }
595611 stepper->runBackward ();
596612 vTaskDelay (250 / portTICK_PERIOD_MS);
597613 threshold = driver.SG_RESULT ();
598614 Serial.printf (" %d " , driver.SG_RESULT ());
599615 vTaskDelay (250 / portTICK_PERIOD_MS);
600616 while (!stalled) {
617+ if (abs (rtConfig->getShifterPosition () - ss2k->lastShifterPosition )) { // let the user abort with the shift button.
618+ userConfig->setHMin (INT32_MIN);
619+ userConfig->setHMax (INT32_MIN);
620+ return ;
621+ }
601622 stalled = (driver.SG_RESULT () < threshold - 75 );
602623 }
603624 stepper->forceStop ();
0 commit comments