Skip to content

Commit

Permalink
Support for TinyG and g2core override control (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed May 14, 2017
1 parent e9423a9 commit 017b9d8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 11 deletions.
62 changes: 54 additions & 8 deletions src/app/controllers/TinyG/TinyG.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class TinyGParser {
TinyGParserResultQueueReports,
TinyGParserResultStatusReports,
TinyGParserResultSystemSettings,
TinyGParserResultOverrides,
TinyGParserResultReceiveReports
];

Expand Down Expand Up @@ -136,6 +137,35 @@ class TinyGParserResultSystemSettings {
}
}

class TinyGParserResultOverrides {
static parse(data) {
const mfo = _.get(data, 'r.mfo');
const mto = _.get(data, 'r.mto');
const sso = _.get(data, 'r.sso');

if (!mfo && !mto && !sso) {
return null;
}

const payload = {};

if (mfo) {
payload.mfo = mfo;
}
if (mto) {
payload.mto = mto;
}
if (sso) {
payload.sso = sso;
}

return {
type: TinyGParserResultOverrides,
payload: payload
};
}
}

class TinyGParserResultReceiveReports {
static parse(data) {
const r = _.get(data, 'r.r') || _.get(data, 'r');
Expand Down Expand Up @@ -184,13 +214,17 @@ class TinyG extends events.EventEmitter {
settings = {
// Identification Parameters
// https://github.com/synthetos/g2/wiki/Configuring-0.99-System-Groups#identification-parameters
fv: 0, // Firmware Version
fb: 0, // Firmware Build
fbs: '', // Firmware Build String
fbc: '', // Firmware Build Config
hp: 0, // Hardware Platform: 1=Xmega, 2=Due, 3=v9(ARM)
hv: 0, // Hardware Version
id: '' // board ID
fb: 0, // firmware build
fbs: '', // firmware build string
fbc: '', // firmware build config
fv: 0, // firmware version
hp: 0, // hardware platform: 1=Xmega, 2=Due, 3=v9(ARM)
hv: 0, // hardware version
id: '', // board ID

mfo: 1, // manual feedrate override
mto: 1, // manual traverse override
sso: 1 // spindle speed override
};
footer = {
revision: 0,
Expand Down Expand Up @@ -369,8 +403,20 @@ class TinyG extends events.EventEmitter {
...this.settings,
...payload.sys
};

this.emit('sys', payload.sys);
} else if (type === TinyGParserResultOverrides) {
const {
mfo = this.settings.mfo,
mto = this.settings.mto,
sso = this.settings.sso
} = payload;
this.settings = { // enforce change
...this.settings,
mfo,
mto,
sso
};
this.emit('ov', { mfo, mto, sso });
} else if (type === TinyGParserResultReceiveReports) {
const settings = {};
for (let key in payload.r) {
Expand Down
40 changes: 37 additions & 3 deletions src/app/controllers/TinyG/TinyGController.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,13 +935,47 @@ class TinyGController {
this.write(socket, '\x18'); // ^x
},
'feedOverride': () => {
// Not supported
const [value] = args;
let mfo = this.controller.settings.mfo;

if (value === 0) {
mfo = 1;
} else if ((mfo * 100 + value) > 200) {
mfo = 2;
} else if ((mfo * 100 + value) < 5) {
mfo = 0.05;
} else {
mfo = (mfo * 100 + value) / 100;
}

this.command(socket, 'gcode', `{mfo:${mfo}}`);
},
'spindleOverride': () => {
// Not supported
const [value] = args;
let sso = this.controller.settings.sso;

if (value === 0) {
sso = 1;
} else if ((sso * 100 + value) > 200) {
sso = 2;
} else if ((sso * 100 + value) < 5) {
sso = 0.05;
} else {
sso = (sso * 100 + value) / 100;
}

this.command(socket, 'gcode', `{sso:${sso}}`);
},
'rapidOverride': () => {
// Not supported
const [value] = args;

if (value === 0 || value === 100) {
this.command(socket, 'gcode', '{mto:1}');
} else if (value === 50) {
this.command(socket, 'gcode', '{mto:0.5}');
} else if (value === 25) {
this.command(socket, 'gcode', '{mto:0.25}');
}
},
'lasertest:on': () => {
const [power = 0, duration = 0] = args;
Expand Down

0 comments on commit 017b9d8

Please sign in to comment.