Skip to content

Commit 41e6fbd

Browse files
committed
Tidied up a previous change
1 parent 0efe2d5 commit 41e6fbd

2 files changed

Lines changed: 18 additions & 35 deletions

File tree

src/GCodes/GCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ class GCodes
366366
#if SUPPORT_ASYNC_MOVES
367367
void UnlockMovementFrom(const GCodeBuffer& gb, MovementSystemNumber firstMsNumber) noexcept; // Release movement locks greater or equal to than the specified one
368368
#endif
369+
bool WaitForEndstopOrProbingMoveToFinish(GCodeBuffer& gb) noexcept; // Wait for movement to stop after performing a move that may terminate early
369370

370371
void SetInitialAxisAndDrivePositions() noexcept; // Called at initialisation and when new axes are added
371372
void AdjustEndpoint(size_t drive, float ratio) const noexcept; // Adjust an endpoint following a change to steps/mm

src/GCodes/GCodes4.cpp

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
# include <Comms/PanelDueUpdater.h>
2727
#endif
2828

29+
// Wait for movement to stop after performing a move that may terminate early
30+
bool GCodes::WaitForEndstopOrProbingMoveToFinish(GCodeBuffer& gb) noexcept
31+
{
32+
return LockCurrentMovementSystemAndWaitForStandstill(gb)
33+
#if SUPPORT_CAN_EXPANSION
34+
&& CanMotion::RevertStoppedDrivers()
35+
#endif
36+
;
37+
}
38+
2939
// Execute a step of the state machine
3040
// CAUTION: don't allocate any long strings or other large objects directly within this function.
3141
// The reason is that this function calls FinishedBedProbing(), which on a delta calls DoAutoCalibration(), which uses lots of stack.
@@ -50,11 +60,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
5060
switch (state)
5161
{
5262
case GCodeState::waitingForSpecialMoveToComplete:
53-
if ( LockCurrentMovementSystemAndWaitForStandstill(gb) // movement should already be locked, but we need to wait for standstill and fetch the current position
54-
#if SUPPORT_CAN_EXPANSION
55-
&& CanMotion::RevertStoppedDrivers()
56-
#endif
57-
)
63+
if (WaitForEndstopOrProbingMoveToFinish(gb)) // movement should already be locked, but we need to wait for standstill and fetch the current position
5864
{
5965
// Check whether we need to action any endstops
6066
if (ms.axesToHome.IsNonEmpty()) // check whether we made any G1 H1 moves and need to set axis positions
@@ -217,11 +223,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
217223
break;
218224

219225
case GCodeState::probingToolOffset4: // executing M585, probing move has started
220-
if ( LockCurrentMovementSystemAndWaitForStandstill(gb)
221-
#if SUPPORT_CAN_EXPANSION
222-
&& CanMotion::RevertStoppedDrivers()
223-
#endif
224-
)
226+
if (WaitForEndstopOrProbingMoveToFinish(gb))
225227
{
226228
if (m585Settings.useProbe)
227229
{
@@ -290,11 +292,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
290292
break;
291293

292294
case GCodeState::findCenterOfCavity3: // Executing M675, min probing move has started
293-
if ( LockCurrentMovementSystemAndWaitForStandstill(gb)
294-
#if SUPPORT_CAN_EXPANSION
295-
&& CanMotion::RevertStoppedDrivers()
296-
#endif
297-
)
295+
if (WaitForEndstopOrProbingMoveToFinish(gb))
298296
{
299297
const auto zp = platform.GetZProbeOrDefault(currentZProbeNumber);
300298
zp->SetProbing(false);
@@ -332,11 +330,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
332330
break;
333331

334332
case GCodeState::findCenterOfCavity5: // Executing M675, max probing move has started
335-
if ( LockCurrentMovementSystemAndWaitForStandstill(gb)
336-
#if SUPPORT_CAN_EXPANSION
337-
&& CanMotion::RevertStoppedDrivers()
338-
#endif
339-
)
333+
if (WaitForEndstopOrProbingMoveToFinish(gb))
340334
{
341335
reprap.GetHeat().SuspendHeaters(false);
342336
const auto zp = platform.GetZProbeOrDefault(currentZProbeNumber);
@@ -1000,11 +994,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
1000994
break;
1001995

1002996
case GCodeState::gridProbing4: // ready to lift the probe after probing the current grid probe point
1003-
if ( LockCurrentMovementSystemAndWaitForStandstill(gb)
1004-
#if SUPPORT_CAN_EXPANSION
1005-
&& CanMotion::RevertStoppedDrivers()
1006-
#endif
1007-
)
997+
if (WaitForEndstopOrProbingMoveToFinish(gb))
1008998
{
1009999
doingManualBedProbe = false;
10101000
++tapsDone;
@@ -1415,11 +1405,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
14151405

14161406
case GCodeState::probingAtPoint4:
14171407
// Executing G30. The probe wasn't triggered at the start of the move, and the probing move has been commanded.
1418-
if ( LockCurrentMovementSystemAndWaitForStandstill(gb)
1419-
#if SUPPORT_CAN_EXPANSION
1420-
&& CanMotion::RevertStoppedDrivers()
1421-
#endif
1422-
)
1408+
if (WaitForEndstopOrProbingMoveToFinish(gb))
14231409
{
14241410
// Probing move has stopped
14251411
reprap.GetHeat().SuspendHeaters(false);
@@ -1684,11 +1670,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
16841670

16851671
case GCodeState::straightProbe3:
16861672
// Executing G38. The probe wasn't in target state at the start of the move, and the probing move has been commanded.
1687-
if ( LockCurrentMovementSystemAndWaitForStandstill(gb)
1688-
#if SUPPORT_CAN_EXPANSION
1689-
&& CanMotion::RevertStoppedDrivers()
1690-
#endif
1691-
)
1673+
if (WaitForEndstopOrProbingMoveToFinish(gb))
16921674
{
16931675
// Probing move has stopped
16941676
reprap.GetHeat().SuspendHeaters(false);

0 commit comments

Comments
 (0)