use of com.willwinder.universalgcodesender.listeners.ControllerState in project Universal-G-Code-Sender by winder.
the class SourceMultiviewElement method UGSEvent.
@Override
public void UGSEvent(UGSEvent ugsEvent) {
// Disable the editor if not idle or disconnected
if (ugsEvent instanceof ControllerStateEvent) {
ControllerState state = backend.getControllerState();
getEditorPane().setEditable(state == ControllerState.IDLE || state == ControllerState.DISCONNECTED);
}
}
use of com.willwinder.universalgcodesender.listeners.ControllerState in project Universal-G-Code-Sender by winder.
the class AnalogJogAction method UGSEvent.
@Override
public void UGSEvent(UGSEvent evt) {
if (evt instanceof ControllerStateEvent) {
ControllerState state = ((ControllerStateEvent) evt).getState();
setEnabled(state == ControllerState.IDLE || state == ControllerState.JOG);
}
}
use of com.willwinder.universalgcodesender.listeners.ControllerState in project Universal-G-Code-Sender by winder.
the class TinyGUtils method updateControllerStatus.
/**
* Parses the TinyG status result response and creates a new current controller status
*
* @param lastControllerStatus the last controller status to update
* @param response the response string from the controller
* @return a new updated controller status
*/
public static ControllerStatus updateControllerStatus(final ControllerStatus lastControllerStatus, final JsonObject response) {
if (isStatusResponse(response)) {
JsonObject statusResultObject = response.getAsJsonObject(FIELD_STATUS_REPORT);
Position workCoord = lastControllerStatus.getWorkCoord();
UnitUtils.Units feedSpeedUnits = lastControllerStatus.getFeedSpeedUnits();
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_UNIT)) {
UnitUtils.Units units = statusResultObject.get(FIELD_STATUS_REPORT_UNIT).getAsInt() == 1 ? UnitUtils.Units.MM : UnitUtils.Units.INCH;
workCoord = new Position(workCoord.getX(), workCoord.getY(), workCoord.getZ(), units);
feedSpeedUnits = units;
}
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_POSX)) {
workCoord.setX(statusResultObject.get(FIELD_STATUS_REPORT_POSX).getAsDouble());
}
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_POSY)) {
workCoord.setY(statusResultObject.get(FIELD_STATUS_REPORT_POSY).getAsDouble());
}
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_POSZ)) {
workCoord.setZ(statusResultObject.get(FIELD_STATUS_REPORT_POSZ).getAsDouble());
}
// The machine coordinates are always in MM, make sure the position is using that unit before updating the values
Position machineCoord = lastControllerStatus.getMachineCoord().getPositionIn(UnitUtils.Units.MM);
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_MPOX)) {
machineCoord.setX(statusResultObject.get(FIELD_STATUS_REPORT_MPOX).getAsDouble());
}
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_MPOY)) {
machineCoord.setY(statusResultObject.get(FIELD_STATUS_REPORT_MPOY).getAsDouble());
}
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_MPOZ)) {
machineCoord.setZ(statusResultObject.get(FIELD_STATUS_REPORT_MPOZ).getAsDouble());
}
int overrideFeed = 100;
int overrideRapid = 100;
int overrideSpindle = 100;
if (lastControllerStatus.getOverrides() != null) {
overrideFeed = lastControllerStatus.getOverrides().feed;
overrideRapid = lastControllerStatus.getOverrides().rapid;
overrideSpindle = lastControllerStatus.getOverrides().spindle;
}
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_MFO)) {
double speed = statusResultObject.get(FIELD_STATUS_REPORT_MFO).getAsDouble();
overrideFeed = (int) Math.round(speed * 100.0);
}
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_SSO)) {
double speed = statusResultObject.get(FIELD_STATUS_REPORT_SSO).getAsDouble();
overrideSpindle = (int) Math.round(speed * 100.0);
}
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_MTO)) {
double speed = statusResultObject.get(FIELD_STATUS_REPORT_MTO).getAsDouble();
overrideRapid = (int) Math.round(speed * 100.0);
}
Double feedSpeed = lastControllerStatus.getFeedSpeed();
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_VELOCITY)) {
feedSpeed = statusResultObject.get(FIELD_STATUS_REPORT_VELOCITY).getAsDouble();
}
ControllerState state = lastControllerStatus.getState();
if (hasNumericField(statusResultObject, FIELD_STATUS_REPORT_STATUS)) {
state = getState(statusResultObject.get(FIELD_STATUS_REPORT_STATUS).getAsInt());
}
Double spindleSpeed = lastControllerStatus.getSpindleSpeed();
Position workCoordinateOffset = lastControllerStatus.getWorkCoordinateOffset();
ControllerStatus.EnabledPins enabledPins = lastControllerStatus.getEnabledPins();
ControllerStatus.AccessoryStates accessoryStates = lastControllerStatus.getAccessoryStates();
ControllerStatus.OverridePercents overrides = new ControllerStatus.OverridePercents(overrideFeed, overrideRapid, overrideSpindle);
return new ControllerStatus(state, machineCoord, workCoord, feedSpeed, feedSpeedUnits, spindleSpeed, overrides, workCoordinateOffset, enabledPins, accessoryStates);
}
return lastControllerStatus;
}
use of com.willwinder.universalgcodesender.listeners.ControllerState 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;
}
CommunicatorState before = getControlState();
ControllerState beforeState = controllerStatus == null ? ControllerState.DISCONNECTED : 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 (beforeState == ControllerState.JOG && controllerStatus.getState() == ControllerState.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 (controllerStatus.getState() == ControllerState.IDLE || controllerStatus.getState() == ControllerState.CHECK) {
isCanceling = false;
// Make sure the GUI gets updated
this.dispatchStateChange(getControlState());
} else // Otherwise check if the machine is Hold/Queue and stopped.
if ((controllerStatus.getState() == ControllerState.HOLD || controllerStatus.getState() == ControllerState.DOOR) && lastLocation.equals(this.controllerStatus.getMachineCoord())) {
try {
this.issueSoftReset();
} catch (Exception e) {
this.dispatchConsoleMessage(MessageType.ERROR, e.getMessage() + "\n");
}
isCanceling = false;
}
if (isCanceling && attemptsRemaining == 0) {
this.dispatchConsoleMessage(MessageType.ERROR, Localization.getString("grbl.exception.cancelReset") + "\n");
}
}
lastLocation = new Position(this.controllerStatus.getMachineCoord());
}
dispatchStatusString(controllerStatus);
}
use of com.willwinder.universalgcodesender.listeners.ControllerState in project Universal-G-Code-Sender by winder.
the class ProbeService method UGSEvent.
@Override
public void UGSEvent(UGSEvent evt) {
if (this.currentOperation == ProbeOperation.NONE)
return;
if (evt instanceof ControllerStateEvent) {
ControllerStateEvent controllerStateEvent = (ControllerStateEvent) evt;
ControllerState state = controllerStateEvent.getState();
if (state == ControllerState.DISCONNECTED) {
resetProbe();
} else if (state == ControllerState.IDLE) {
// Finalize
if (this.currentOperation.getNumProbes() <= this.probePositions.size()) {
try {
continuation.execute();
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception finalizing " + this.currentOperation + " probe operation.", e);
} finally {
params.endPosition = this.backend.getMachinePosition();
this.resetProbe();
}
}
}
} else if (evt instanceof ProbeEvent) {
this.probePositions.add(((ProbeEvent) evt).getProbePosition());
try {
continuation.execute();
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception during " + this.currentOperation + " probe operation.", e);
resetProbe();
}
}
}
Aggregations