From 424743cd38a29dcf47f625ce6fe912c48ff32f2b Mon Sep 17 00:00:00 2001 From: Cheton Wu Date: Fri, 6 Jul 2018 01:13:26 +0800 Subject: [PATCH] Resolve an issue that firmware build 101.xx cannot recognize spindle enable ({spe:n}) and spindle direction ({spd:n}) commands (#338) (#351) --- src/app/controllers/TinyG/TinyG.js | 28 +++++++--- src/app/controllers/TinyG/TinyGController.js | 57 ++++++++++++++------ 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/src/app/controllers/TinyG/TinyG.js b/src/app/controllers/TinyG/TinyG.js index 2d53957d7..0c612fb4b 100644 --- a/src/app/controllers/TinyG/TinyG.js +++ b/src/app/controllers/TinyG/TinyG.js @@ -254,9 +254,10 @@ class TinyG extends events.EventEmitter { y: '0.000', z: '0.000' }, - spe: 0, // Spindle enable - spd: 0, // Spindle direction - sps: 0, // Spindle speed + spe: 0, // [edge-082.10] Spindle enable + spd: 0, // [edge-082.10] Spindle direction + spc: 0, // [edge-101.03] Spindle control + sps: 0, // [edge-082.10] Spindle speed modal: { motion: '', // G0, G1, G2, G3, G38.2, G38.3, G38.4, G38.5, G80 wcs: '', // G54, G55, G56, G57, G58, G59 @@ -419,7 +420,7 @@ class TinyG extends events.EventEmitter { }[val] || ''; _.set(target, 'modal.path', gcode); }, - // Spindle enable + // [edge-082.10] Spindle enable (removed in edge-101.03) 'spe': (target, val) => { _.set(target, 'spe', val); @@ -431,7 +432,7 @@ class TinyG extends events.EventEmitter { _.set(target, 'modal.spindle', (spd === 0) ? 'M3' : 'M4'); } }, - // Spindle direction + // [edge-082.10] Spindle direction (removed in edge-101.03) 'spd': (target, val) => { _.set(target, 'spd', val); @@ -443,11 +444,22 @@ class TinyG extends events.EventEmitter { _.set(target, 'modal.spindle', (spd === 0) ? 'M3' : 'M4'); } }, - // Spindle speed + // [edge-101.03] Spindle control + // 0 = OFF, 1 = CW, 2 = CCW + 'spc': (target, val) => { + if (val === 0) { // OFF + _.set(target, 'modal.spindle', 'M5'); + } else if (val === 1) { // CW + _.set(target, 'modal.spindle', 'M3'); + } else if (val === 2) { // CCW + _.set(target, 'modal.spindle', 'M4'); + } + }, + // [edge-082.10] Spindle speed 'sps': (target, val) => { _.set(target, 'sps', val); }, - // Mist coolant + // [edge-082.10] Mist coolant 'com': (target, val) => { if (val === 0) { // Coolant Off _.set(target, 'modal.coolant', 'M9'); @@ -464,7 +476,7 @@ class TinyG extends events.EventEmitter { // Mist _.set(target, 'modal.coolant', 'M7'); }, - // Flood coolant + // [edge-082.10] Flood coolant 'cof': (target, val) => { if (val === 0) { // Coolant Off _.set(target, 'modal.coolant', 'M9'); diff --git a/src/app/controllers/TinyG/TinyGController.js b/src/app/controllers/TinyG/TinyGController.js index 167608ec6..5ba848a19 100644 --- a/src/app/controllers/TinyG/TinyGController.js +++ b/src/app/controllers/TinyG/TinyGController.js @@ -113,11 +113,12 @@ class TinyGController { mpoa: true, mpob: true, mpoc: true, - spe: true, // Spindle enable (edge-082.10) - spd: true, // Spindle direction (edge-082.10) - sps: true, // Spindle speed (edge-082.10) - cof: true, // Flood coolant (edge-082.10) - com: true // Mist coolant (edge-082.10) + spe: true, // [edge-082.10] Spindle enable (removed in edge-101.03) + spd: true, // [edge-082.10] Spindle direction (removed in edge-101.03) + spc: true, // [edge-101.03] Spindle control + sps: true, // [edge-082.10] Spindle speed + com: true, // [edge-082.10] Mist coolant + cof: true // [edge-082.10] Flood coolant }; timer = { query: null, @@ -384,13 +385,26 @@ class TinyGController { // https://github.com/synthetos/g2/wiki/g2core-Communications this.controller.on('r', (r) => { + // + // Ignore unrecognized commands + // if (r && r.spe === null) { - // Disable unrecognized commands - this.sr.spe = false; // Spindle enable - this.sr.spd = false; // Spindle direction - this.sr.sps = false; // Spindle speed - this.sr.cof = false; // Flood coolant - this.sr.com = false; // Mist coolant + this.sr.spe = false; // No spindle enable + } + if (r && r.spd === null) { + this.sr.spd = false; // No spindle direction + } + if (r && r.spc === null) { + this.sr.spc = false; // No spindle control + } + if (r && r.sps === null) { + this.sr.sps = false; // No spindle speed + } + if (r && r.com === null) { + this.sr.com = false; // No mist coolant + } + if (r && r.cof === null) { + this.sr.cof = false; // No flood coolant } const { hold, sent, received } = this.sender.state; @@ -673,11 +687,24 @@ class TinyGController { // in milliseconds (50ms minimum interval) send('{si:100}'); - // Check whether the spindle enable command is supported - send('{spe:n}'); + await delay(100); - // Wait for 500ms to examine supported status report fields - await delay(500); + // Check whether the spindle and coolant commands are supported + send('{spe:n}'); + await delay(100); + send('{spd:n}'); + await delay(100); + send('{spc:n}'); + await delay(100); + send('{sps:n}'); + await delay(100); + send('{com:n}'); + await delay(100); + send('{cof:n}'); + await delay(100); + + // Wait for a certain amount of time before setting status report fields + await delay(100); // Settings Status Report Fields // https://github.com/synthetos/TinyG/wiki/TinyG-Status-Reports#setting-status-report-fields