mirror of
https://github.com/usatiuk/EggbotWireless.git
synced 2025-10-26 16:57:48 +01:00
gcode parser thing
This commit is contained in:
25
App/package-lock.json
generated
25
App/package-lock.json
generated
@@ -5819,6 +5819,11 @@
|
|||||||
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==",
|
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"konva": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/konva/-/konva-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-TR1YUga/x8NShLS8vryzEXVDC8kQThOZRxX8x99/ABnfVRH4MN9LtBqn8YJxQWByMcwqjAzlNQWA3XuxCCVW0Q=="
|
||||||
|
},
|
||||||
"lcid": {
|
"lcid": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz",
|
||||||
@@ -8146,6 +8151,26 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.8.6.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.8.6.tgz",
|
||||||
"integrity": "sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA=="
|
"integrity": "sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA=="
|
||||||
},
|
},
|
||||||
|
"react-konva": {
|
||||||
|
"version": "16.8.7-3",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-konva/-/react-konva-16.8.7-3.tgz",
|
||||||
|
"integrity": "sha512-ybtT21EjinPFnN9/EqjWvbLNOd5uDwjkUWkITkP9OTaItZKfbCZw5aVpjpxTrRC69v4rzXXG+cdHAsbE6zt/6A==",
|
||||||
|
"requires": {
|
||||||
|
"react-reconciler": "^0.20.4",
|
||||||
|
"scheduler": "^0.13.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"react-reconciler": {
|
||||||
|
"version": "0.20.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-reconciler/-/react-reconciler-0.20.4.tgz",
|
||||||
|
"integrity": "sha512-kxERc4H32zV2lXMg/iMiwQHOtyqf15qojvkcZ5Ja2CPkjVohHw9k70pdDBwrnQhLVetUJBSYyqU3yqrlVTOajA==",
|
||||||
|
"requires": {
|
||||||
|
"loose-envify": "^1.1.0",
|
||||||
|
"object-assign": "^4.1.1",
|
||||||
|
"prop-types": "^15.6.2",
|
||||||
|
"scheduler": "^0.13.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-test-renderer": {
|
"react-test-renderer": {
|
||||||
"version": "16.8.6",
|
"version": "16.8.6",
|
||||||
"resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.8.6.tgz",
|
"resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.8.6.tgz",
|
||||||
|
|||||||
@@ -34,9 +34,11 @@
|
|||||||
"typescript": "^3.5.3"
|
"typescript": "^3.5.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"konva": "^4.0.0",
|
||||||
"normalize.css": "^8.0.1",
|
"normalize.css": "^8.0.1",
|
||||||
"react": "^16.8.6",
|
"react": "^16.8.6",
|
||||||
"react-dom": "^16.8.6"
|
"react-dom": "^16.8.6",
|
||||||
|
"react-konva": "^16.8.7-3"
|
||||||
},
|
},
|
||||||
"postcss": {
|
"postcss": {
|
||||||
"plugins": {
|
"plugins": {
|
||||||
|
|||||||
56
App/src/GcodeParser.tsx
Normal file
56
App/src/GcodeParser.tsx
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
export enum CommandType {
|
||||||
|
unk = "unk",
|
||||||
|
G01 = "G01",
|
||||||
|
G00 = "G00",
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GenericCommand {
|
||||||
|
type: CommandType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface G01Command extends GenericCommand {
|
||||||
|
type: CommandType.G01;
|
||||||
|
X?: number;
|
||||||
|
Y?: number;
|
||||||
|
Z?: number;
|
||||||
|
F?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface G00Command extends GenericCommand {
|
||||||
|
type: CommandType.G00;
|
||||||
|
X?: number;
|
||||||
|
Y?: number;
|
||||||
|
Z?: number;
|
||||||
|
F?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UnkCommand extends GenericCommand {
|
||||||
|
type: CommandType.unk;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Command = G01Command | G00Command | UnkCommand;
|
||||||
|
|
||||||
|
function getCommandType(type: string): CommandType {
|
||||||
|
if (type.toUpperCase() === "G01") {
|
||||||
|
return CommandType.G01;
|
||||||
|
}
|
||||||
|
if (type.toUpperCase() === "G00") {
|
||||||
|
return CommandType.G00;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CommandType.unk;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseCommand(cmd: string): Command {
|
||||||
|
const words = cmd.toUpperCase().split(" ");
|
||||||
|
let command: Command = { type: getCommandType(words.shift()) };
|
||||||
|
|
||||||
|
const args = words.map(word => {
|
||||||
|
const arg = word.slice(0, 1);
|
||||||
|
const val = word.slice(1);
|
||||||
|
(command as any)[arg] = parseFloat(val);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(command);
|
||||||
|
return command;
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { IEggbotStatus, getStatus, putCommand } from "~api/eggbot";
|
import { IEggbotStatus, getStatus, putCommand } from "~api/eggbot";
|
||||||
|
import GcodeVisualiser from "~GcodeVisualiser";
|
||||||
|
import { parseCommand } from "~GcodeParser";
|
||||||
|
|
||||||
interface IGcodeSenderComponentState {
|
interface IGcodeSenderComponentState {
|
||||||
eggbotStatus: IEggbotStatus | null;
|
eggbotStatus: IEggbotStatus | null;
|
||||||
@@ -25,8 +27,8 @@ export class GcodeSenderComponent extends React.PureComponent<
|
|||||||
{},
|
{},
|
||||||
IGcodeSenderComponentState
|
IGcodeSenderComponentState
|
||||||
> {
|
> {
|
||||||
constructor() {
|
constructor(props: {}) {
|
||||||
super(null);
|
super(props);
|
||||||
this.state = defaultState;
|
this.state = defaultState;
|
||||||
|
|
||||||
this.handleInputChange = this.handleInputChange.bind(this);
|
this.handleInputChange = this.handleInputChange.bind(this);
|
||||||
@@ -57,13 +59,13 @@ export class GcodeSenderComponent extends React.PureComponent<
|
|||||||
|
|
||||||
public async update() {
|
public async update() {
|
||||||
const status = await getStatus();
|
const status = await getStatus();
|
||||||
console.log(status);
|
|
||||||
const gcodeLinesQueue = [...this.state.gcodeLinesQueue];
|
const gcodeLinesQueue = [...this.state.gcodeLinesQueue];
|
||||||
const gcodeLinesSent = [...this.state.gcodeLinesSent];
|
const gcodeLinesSent = [...this.state.gcodeLinesSent];
|
||||||
const { executing } = this.state;
|
const { executing } = this.state;
|
||||||
if (executing && status.commandQueue < 5) {
|
if (executing && status.commandQueue < 5) {
|
||||||
if (gcodeLinesQueue && gcodeLinesQueue.length > 0) {
|
if (gcodeLinesQueue && gcodeLinesQueue.length > 0) {
|
||||||
const command = gcodeLinesQueue.shift();
|
const command = gcodeLinesQueue.shift();
|
||||||
|
console.log(parseCommand(command));
|
||||||
putCommand(command.substr(0, 50));
|
putCommand(command.substr(0, 50));
|
||||||
gcodeLinesSent.push(command);
|
gcodeLinesSent.push(command);
|
||||||
}
|
}
|
||||||
@@ -73,20 +75,21 @@ export class GcodeSenderComponent extends React.PureComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const queuedCommands = this.state.gcodeLinesQueue.map(el => (
|
const { gcodeLinesQueue, gcodeLinesSent } = this.state;
|
||||||
<div>{el}</div>
|
|
||||||
));
|
|
||||||
|
|
||||||
const executedCommands = this.state.gcodeLinesSent.map(el => (
|
const queuedCommandsList = gcodeLinesQueue.map(el => <div>{el}</div>);
|
||||||
<div>{el}</div>
|
|
||||||
));
|
const executedCommandsList = gcodeLinesSent.map(el => <div>{el}</div>);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<div>
|
<div>
|
||||||
{this.state.executing ? (
|
{this.state.executing ? (
|
||||||
<div>
|
<div>
|
||||||
<div style={{ color: "green" }}>{executedCommands}</div>
|
<div style={{ color: "green" }}>
|
||||||
<div>{queuedCommands}</div>
|
{executedCommandsList}
|
||||||
|
</div>
|
||||||
|
<div>{queuedCommandsList}</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div>
|
<div>
|
||||||
@@ -99,6 +102,11 @@ export class GcodeSenderComponent extends React.PureComponent<
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<GcodeVisualiser
|
||||||
|
gcodeLinesQueue={gcodeLinesQueue}
|
||||||
|
gcodeLinesSent={gcodeLinesSent}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
App/src/GcodeVisualiser.tsx
Normal file
32
App/src/GcodeVisualiser.tsx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { Layer, Rect, Stage, Group } from "react-konva";
|
||||||
|
|
||||||
|
interface IGcodeVisualiserProps {
|
||||||
|
gcodeLinesSent: string[];
|
||||||
|
gcodeLinesQueue: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GcodeVisualiser extends React.PureComponent<
|
||||||
|
IGcodeVisualiserProps,
|
||||||
|
{}
|
||||||
|
> {
|
||||||
|
constructor(props: IGcodeVisualiserProps) {
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Stage width={700} height={700}>
|
||||||
|
<Layer>
|
||||||
|
<Rect
|
||||||
|
x={10}
|
||||||
|
y={10}
|
||||||
|
width={50}
|
||||||
|
height={50}
|
||||||
|
fill={"black"}
|
||||||
|
shadowBlur={10}
|
||||||
|
/>
|
||||||
|
</Layer>
|
||||||
|
</Stage>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user