Skip to content

Commit

Permalink
Resets the controller when initializing in check state (#2697)
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler authored Feb 15, 2025
1 parent d560008 commit 260ac54
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,11 @@ public static boolean isControllerResponsive(GrblController controller) throws E
throw new IllegalStateException("Could not query the device status");
}

// Some commands are not available in check mode
if (statusCommand.getControllerStatus().getState() == ControllerState.CHECK) {
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 @@ -175,6 +175,11 @@ public static boolean isControllerResponsive(IController controller, MessageServ
throw new IllegalStateException("Could not query the device status");
}

// Some commands are not available in check mode
if (statusCommand.getControllerStatus().getState() == ControllerState.CHECK) {
return false;
}

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

import com.willwinder.universalgcodesender.firmware.grbl.GrblCapabilitiesConstants;
import com.willwinder.universalgcodesender.firmware.grbl.GrblBuildOptions;
import com.willwinder.universalgcodesender.firmware.grbl.GrblCapabilitiesConstants;
import com.willwinder.universalgcodesender.listeners.ControllerState;
import com.willwinder.universalgcodesender.listeners.ControllerStatus;
import static com.willwinder.universalgcodesender.model.Axis.X;
import static com.willwinder.universalgcodesender.model.Axis.Y;
import static com.willwinder.universalgcodesender.model.Axis.Z;
import com.willwinder.universalgcodesender.model.Position;
import com.willwinder.universalgcodesender.model.UnitUtils;
import org.junit.Test;

import static com.willwinder.universalgcodesender.model.Axis.*;
import static com.willwinder.universalgcodesender.model.UnitUtils.Units.INCH;
import static com.willwinder.universalgcodesender.model.UnitUtils.Units.MM;
import com.willwinder.universalgcodesender.services.MessageService;
import com.willwinder.universalgcodesender.types.GcodeCommand;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* @author wwinder
Expand Down Expand Up @@ -725,4 +736,39 @@ public void isGrblStatusStringV1_shouldReturnTrueOnStatusMessage() {
assertFalse(GrblUtils.isGrblStatusStringV1("banana"));
assertFalse(GrblUtils.isGrblStatusStringV1("<Idle,MPos:5.529,0.560,7.000,WPos:1.529,-5.440,-0.000>"));
}


@Test
public void isControllerResponsiveWhenControllerInStateCheck() throws Exception {
GrblController controller = mock(GrblController.class);
when(controller.isCommOpen()).thenReturn(true);
MessageService messageService = mock(MessageService.class);
when(controller.getMessageService()).thenReturn(messageService);

// Respond with status hold
doAnswer(answer -> {
GcodeCommand command = answer.getArgument(0, GcodeCommand.class);
command.appendResponse("<Check>");
return null;
}).when(controller).sendCommandImmediately(any(GcodeCommand.class));

assertFalse(GrblUtils.isControllerResponsive(controller));
}

@Test
public void isControllerResponsiveWhenControllerInStateIdle() throws Exception {
GrblController controller = mock(GrblController.class);
when(controller.isCommOpen()).thenReturn(true);
MessageService messageService = mock(MessageService.class);
when(controller.getMessageService()).thenReturn(messageService);

// Respond with status hold
doAnswer(answer -> {
GcodeCommand command = answer.getArgument(0, GcodeCommand.class);
command.appendResponse("<Idle>");
return null;
}).when(controller).sendCommandImmediately(any(GcodeCommand.class));

assertTrue(GrblUtils.isControllerResponsive(controller));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ public void isControllerResponsiveWhenControllerInStateHold() throws Exception {
assertTrue(FluidNCUtils.isControllerResponsive(controller, messageService));
}

@Test
public void isControllerResponsiveWhenControllerInStateCheck() 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("<Check>");
return null;
}).when(controller).sendCommandImmediately(any(GetStatusCommand.class));

assertFalse(FluidNCUtils.isControllerResponsive(controller, messageService));
}

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

0 comments on commit 260ac54

Please sign in to comment.