Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
a440be05bThis file is pinned to the selected release. Download the original to open it in your design tool.
// More specific Full report sent on startup
//import _ from 'lodash';
import _ from "lodash";
class GrblHalLineParserResultCompleteStatus {
static parse(line) {
const r = line.match(
/^<(Idle|Run|Hold|Jog|Alarm|Door|Check|Home|Sleep|Tool)(:\d*)?\|(.*\|FW:grblHAL)(.*)?>$/,
);
if (!r) {
return null;
}
console.log(r);
const state = r[1];
let subState = r[2] || "";
subState = subState.replace(":", "");
const payload = {};
const result = {};
// Separate parameters and store them in results, further split by comma for sub values
{
r[3].split("|").forEach((param) => {
const nv = param.match(/^([a-zA-Z]+):?(.*)$/);
if (nv) {
result[nv[1]] = nv[2].split(",");
}
});
}
{
// Active state (Idle, Jog, etc) and substate (mostly alarm/door)
payload.activeState = state;
payload.subState = subState || "";
}
// Machine Position (v0.9, v1.1)
if (_.has(result, "MPos")) {
const axes = ["x", "y", "z", "a", "b", "c"];
const mPos = _.get(result, "MPos", ["0.000", "0.000", "0.000"]); // Defaults to [x, y, z]
payload.mpos = {};
for (let i = 0; i < mPos.length; ++i) {
payload.mpos[axes[i]] = mPos[i];
}
}
// Work Position (v0.9, v1.1)
if (_.has(result, "WPos")) {
const axes = ["x", "y", "z", "a", "b", "c"];
const wPos = _.get(result, "WPos", ["0.000", "0.000", "0.000"]); // Defaults to [x, y, z]
payload.wpos = {};
for (let i = 0; i < wPos.length; ++i) {
payload.wpos[axes[i]] = wPos[i];
}
}
// Work Coordinate Offset (v1.1)
if (_.has(result, "WCO")) {
const axes = ["x", "y", "z", "a", "b", "c"];
const wco = _.get(result, "WCO", ["0.000", "0.000", "0.000"]); // Defaults to [x, y, z]
payload.wco = {};
for (let i = 0; i < wco.length; ++i) {
payload.wco[axes[i]] = wco[i];
}
}
// Input Pin State (v1.1)
// * Pn:XYZPDHRS indicates which input pins Grbl has detected as 'triggered'.
// * Each letter of XYZPDHRS denotes a particular 'triggered' input pin.
// - X Y Z XYZ limit pins, respectively
// - P the probe pin.
// - D H R S the door, hold, soft-reset, and cycle-start pins, respectively.
// - Example: Pn:PZ indicates the probe and z-limit pins are 'triggered'.
// - Note: A may be added in later versions for an A-axis limit pin.
if (_.has(result, "Pn")) {
const pins = _.get(result, "Pn[0]", "");
payload.pinState = {};
pins.split("").forEach((pin) => {
payload.pinState[pin] = true;
});
}
// Probe protection status
// P:0 -> default probe selected, no protection
// P:0,P -> default probe selected, protection enabled
if (_.has(result, "P")) {
console.log('startup probe:', result.P);
payload.probe = {
type: Number(result.P[0]),
protected: result.P[1] === "P",
};
}
// Current Tool
if (_.has(result, "T")) {
// Handle updating current tool
payload.currentTool = Number(result.T[0]);
}
// Has Homed
if (_.has(result, "H")) {
payload.hasHomed = Boolean(Number(result.H[0]));
// handle hasHomed
}
// SD Card
if (_.has(result, "SD")) {
payload.sdCard = Boolean(Number(result.SD[0]));
} else {
payload.sdCard = false;
}
return {
type: GrblHalLineParserResultCompleteStatus,
payload,
};
}
}
export default GrblHalLineParserResultCompleteStatus;