use of com.willwinder.universalgcodesender.listeners.ControllerStatus.AccessoryStates in project Universal-G-Code-Sender by winder.
the class GrblUtils method getStatusFromStatusString.
/**
* Parses a GRBL status string in the legacy format or v1.x format:
* legacy: <status,WPos:1,2,3,MPos:1,2,3>
* 1.x: <status|WPos:1,2,3|Bf:0,0|WCO:0,0,0>
* @param lastStatus required for the 1.x version which requires WCO coords
* and override status from previous status updates.
* @param status the raw status string
* @param version capabilities flags
* @param reportingUnits units
* @return
*/
protected static ControllerStatus getStatusFromStatusString(ControllerStatus lastStatus, final String status, final Capabilities version, Units reportingUnits) {
// Legacy status.
if (!version.hasCapability(GrblCapabilitiesConstants.V1_FORMAT)) {
return new ControllerStatus(getStateFromStatusString(status, version), getMachinePositionFromStatusString(status, version, reportingUnits), getWorkPositionFromStatusString(status, version, reportingUnits));
} else {
String state = "";
Position MPos = null;
Position WPos = null;
Position WCO = null;
OverridePercents overrides = null;
EnabledPins pins = null;
AccessoryStates accessoryStates = null;
Double feedSpeed = null;
Double spindleSpeed = null;
boolean isOverrideReport = false;
// Parse out the status messages.
for (String part : status.substring(0, status.length() - 1).split("\\|")) {
if (part.startsWith("<")) {
int idx = part.indexOf(':');
if (idx == -1)
state = part.substring(1);
else
state = part.substring(1, idx);
} else if (part.startsWith("MPos:")) {
MPos = GrblUtils.getPositionFromStatusString(status, machinePattern, reportingUnits);
} else if (part.startsWith("WPos:")) {
WPos = GrblUtils.getPositionFromStatusString(status, workPattern, reportingUnits);
} else if (part.startsWith("WCO:")) {
WCO = GrblUtils.getPositionFromStatusString(status, wcoPattern, reportingUnits);
} else if (part.startsWith("Ov:")) {
isOverrideReport = true;
String[] overrideParts = part.substring(3).trim().split(",");
if (overrideParts.length == 3) {
overrides = new OverridePercents(Integer.parseInt(overrideParts[0]), Integer.parseInt(overrideParts[1]), Integer.parseInt(overrideParts[2]));
}
} else if (part.startsWith("F:")) {
feedSpeed = Double.parseDouble(part.substring(2));
} else if (part.startsWith("FS:")) {
String[] parts = part.substring(3).split(",");
feedSpeed = Double.parseDouble(parts[0]);
spindleSpeed = Double.parseDouble(parts[1]);
} else if (part.startsWith("Pn:")) {
String value = part.substring(part.indexOf(':') + 1);
pins = new EnabledPins(value);
} else if (part.startsWith("A:")) {
String value = part.substring(part.indexOf(':') + 1);
accessoryStates = new AccessoryStates(value);
}
}
// Grab WCO from state information if necessary.
if (WCO == null) {
// Grab the work coordinate offset.
if (lastStatus != null && lastStatus.getWorkCoordinateOffset() != null) {
WCO = lastStatus.getWorkCoordinateOffset();
} else {
WCO = new Position(0, 0, 0, reportingUnits);
}
}
// Calculate missing coordinate with WCO
if (WPos == null) {
WPos = new Position(MPos.x - WCO.x, MPos.y - WCO.y, MPos.z - WCO.z, reportingUnits);
}
if (MPos == null) {
MPos = new Position(WPos.x + WCO.x, WPos.y + WCO.y, WPos.z + WCO.z, reportingUnits);
}
if (!isOverrideReport && lastStatus != null) {
overrides = lastStatus.getOverrides();
pins = lastStatus.getEnabledPins();
accessoryStates = lastStatus.getAccessoryStates();
} else if (isOverrideReport) {
// set all pins to a disabled state.
if (pins == null) {
pins = new EnabledPins("");
}
// Likewise for accessory states.
if (accessoryStates == null) {
accessoryStates = new AccessoryStates("");
}
}
return new ControllerStatus(state, MPos, WPos, feedSpeed, spindleSpeed, overrides, WCO, pins, accessoryStates);
}
}
use of com.willwinder.universalgcodesender.listeners.ControllerStatus.AccessoryStates in project Universal-G-Code-Sender by winder.
the class OverridesPanel method statusStringListener.
@Override
public void statusStringListener(ControllerStatus status) {
if (status.getOverrides() != null) {
this.feedSpeed.setText(status.getOverrides().feed + "%");
this.spindleSpeed.setText(status.getOverrides().spindle + "%");
this.rapidSpeed.setText(status.getOverrides().rapid + "%");
}
if (status.getAccessoryStates() != null) {
Color defaultBackground = UIManager.getColor("Panel.background");
AccessoryStates states = status.getAccessoryStates();
toggleSpindle.setBackground((states.SpindleCW || states.SpindleCCW) ? Color.GREEN : Color.RED);
toggleFloodCoolant.setBackground(states.Flood ? Color.GREEN : Color.RED);
toggleMistCoolant.setBackground(states.Mist ? Color.GREEN : Color.RED);
toggleSpindle.setOpaque(true);
toggleFloodCoolant.setOpaque(true);
toggleMistCoolant.setOpaque(true);
}
}
Aggregations