Skip to content

Commit

Permalink
Handle DOOR state on connect in FluidNC
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler committed Nov 26, 2024
1 parent f5a09a4 commit a201720
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import com.willwinder.universalgcodesender.model.Position;
import com.willwinder.universalgcodesender.model.UnitUtils;
import com.willwinder.universalgcodesender.services.MessageService;
import static com.willwinder.universalgcodesender.utils.ControllerUtils.sendAndWaitForCompletion;
import static com.willwinder.universalgcodesender.utils.ControllerUtils.sendAndWaitForCompletionWithRetry;
import com.willwinder.universalgcodesender.utils.SemanticVersion;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -26,6 +24,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.willwinder.universalgcodesender.utils.ControllerUtils.sendAndWaitForCompletion;
import static com.willwinder.universalgcodesender.utils.ControllerUtils.sendAndWaitForCompletionWithRetry;

public class FluidNCUtils {
public static final double GRBL_COMPABILITY_VERSION = 1.1d;
public static final SemanticVersion MINIMUM_VERSION = new SemanticVersion(3, 3, 0);
Expand Down Expand Up @@ -175,6 +176,11 @@ public static boolean isControllerResponsive(IController controller, MessageServ
throw new IllegalStateException("Could not query the device status");
}

// The controller is in a locked DOOR state and needs to be reset
if (statusCommand.getControllerStatus().getState() == ControllerState.DOOR) {
return false;
}

// The controller is not up and running properly
if (statusCommand.getControllerStatus().getState() == ControllerState.HOLD || statusCommand.getControllerStatus().getState() == ControllerState.ALARM) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ This file is part of Universal Gcode Sender (UGS).
*/
package com.willwinder.universalgcodesender.firmware.fluidnc.commands;

import com.willwinder.universalgcodesender.types.GcodeCommand;

/**
* A command for detecting if echo mode is activated on the controller
*
* @author Joacim Breiler
*/
public class DetectEchoCommand extends GcodeCommand {
public class DetectEchoCommand extends SystemCommand {
public DetectEchoCommand() {
super("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void isControllerResponsiveWhenControllerRespondsAsIdle() throws Exceptio
}

@Test
public void isControllerResponsiveWhenControllerHold() throws Exception {
public void isControllerResponsiveWhenControllerInStateHold() throws Exception {
IController controller = mock(IController.class);
when(controller.isCommOpen()).thenReturn(true);
MessageService messageService = mock(MessageService.class);
Expand All @@ -161,6 +161,20 @@ public void isControllerResponsiveWhenControllerHold() throws Exception {
assertTrue(FluidNCUtils.isControllerResponsive(controller, messageService));
}

@Test
public void isControllerResponsiveWhenControllerInStateDoor() throws Exception {
IController controller = mock(IController.class);
when(controller.isCommOpen()).thenReturn(true);
MessageService messageService = mock(MessageService.class);
// Respond with status hold
doAnswer(answer -> {
GcodeCommand command = answer.getArgument(0, GcodeCommand.class);
command.appendResponse("<Door:0>");
return null;
}).when(controller).sendCommandImmediately(any(GetStatusCommand.class));
assertFalse(FluidNCUtils.isControllerResponsive(controller, messageService));
}

@Test
public void isControllerResponsiveWhenControllerInAlarm() throws Exception {
IController controller = mock(IController.class);
Expand Down

0 comments on commit a201720

Please sign in to comment.