Search in sources :

Example 1 with ControlState

use of com.willwinder.universalgcodesender.model.UGSEvent.ControlState in project Universal-G-Code-Sender by winder.

the class GrblController method handleStatusString.

// No longer a listener event
private void handleStatusString(final String string) {
    if (this.capabilities == null) {
        return;
    }
    ControlState before = getControlState();
    String beforeState = controllerStatus == null ? "" : controllerStatus.getState();
    controllerStatus = GrblUtils.getStatusFromStatusString(controllerStatus, string, capabilities, getFirmwareSettings().getReportingUnits());
    // Make UGS more responsive to the state being reported by GRBL.
    if (before != getControlState()) {
        this.dispatchStateChange(getControlState());
    }
    // GRBL 1.1 jog complete transition
    if (StringUtils.equals(beforeState, "Jog") && controllerStatus.getState().equals("Idle")) {
        this.comm.cancelSend();
    }
    // Set and restore the step mode when transitioning from CHECK mode to IDLE.
    if (before == COMM_CHECK && getControlState() != COMM_CHECK) {
        setSingleStepMode(temporaryCheckSingleStepMode);
    } else if (before != COMM_CHECK && getControlState() == COMM_CHECK) {
        temporaryCheckSingleStepMode = getSingleStepMode();
        setSingleStepMode(true);
    }
    // pausing.
    if (isCanceling) {
        if (attemptsRemaining > 0 && lastLocation != null) {
            attemptsRemaining--;
            // If the machine goes into idle, we no longer need to cancel.
            if (this.controllerStatus.getState().equals("Idle") || this.controllerStatus.getState().equalsIgnoreCase("Check")) {
                isCanceling = false;
                // Make sure the GUI gets updated
                this.dispatchStateChange(getControlState());
            } else // Otherwise check if the machine is Hold/Queue and stopped.
            if ((this.controllerStatus.getState().equals("Hold") || this.controllerStatus.getState().equals("Queue")) && lastLocation.equals(this.controllerStatus.getMachineCoord())) {
                try {
                    this.issueSoftReset();
                } catch (Exception e) {
                    this.errorMessageForConsole(e.getMessage() + "\n");
                }
                isCanceling = false;
            }
            if (isCanceling && attemptsRemaining == 0) {
                this.errorMessageForConsole(Localization.getString("grbl.exception.cancelReset") + "\n");
            }
        }
        lastLocation = new Position(this.controllerStatus.getMachineCoord());
    }
    // Save max Z location
    if (this.controllerStatus != null && this.getUnitsCode() != null && this.controllerStatus.getMachineCoord() != null) {
        Units u = this.getUnitsCode().equalsIgnoreCase("G21") ? Units.MM : Units.INCH;
        double zLocationMM = this.controllerStatus.getMachineCoord().z;
        if (u == Units.INCH)
            zLocationMM *= 26.4;
        if (zLocationMM > this.maxZLocationMM) {
            maxZLocationMM = zLocationMM;
        }
    }
    dispatchStatusString(controllerStatus);
}
Also used : ControlState(com.willwinder.universalgcodesender.model.UGSEvent.ControlState) Position(com.willwinder.universalgcodesender.model.Position) Units(com.willwinder.universalgcodesender.model.UnitUtils.Units)

Example 2 with ControlState

use of com.willwinder.universalgcodesender.model.UGSEvent.ControlState in project Universal-G-Code-Sender by winder.

the class GUIBackendTest method getControlStateShouldBeOkWhenConnected.

@Test
public void getControlStateShouldBeOkWhenConnected() throws Exception {
    instance.connect(FIRMWARE, PORT, BAUD_RATE);
    when(controller.getControlState()).thenReturn(ControlState.COMM_IDLE);
    ControlState result = instance.getControlState();
    assertEquals(ControlState.COMM_IDLE, result);
}
Also used : ControlState(com.willwinder.universalgcodesender.model.UGSEvent.ControlState) Test(org.junit.Test)

Example 3 with ControlState

use of com.willwinder.universalgcodesender.model.UGSEvent.ControlState in project Universal-G-Code-Sender by winder.

the class GUIBackendTest method getControlStateShouldReturnStateDisconnectedWhenNotConnected.

@Test
public void getControlStateShouldReturnStateDisconnectedWhenNotConnected() {
    ControlState result = instance.getControlState();
    assertEquals(ControlState.COMM_DISCONNECTED, result);
}
Also used : ControlState(com.willwinder.universalgcodesender.model.UGSEvent.ControlState) Test(org.junit.Test)

Aggregations

ControlState (com.willwinder.universalgcodesender.model.UGSEvent.ControlState)3 Test (org.junit.Test)2 Position (com.willwinder.universalgcodesender.model.Position)1 Units (com.willwinder.universalgcodesender.model.UnitUtils.Units)1