Skip to content

Commit

Permalink
Resolve an issue that firmware build 101.xx cannot recognize spindle …
Browse files Browse the repository at this point in the history
…enable ({spe:n}) and spindle direction ({spd:n}) commands (#338) (#351)
  • Loading branch information
cheton committed Jul 5, 2018
1 parent 7423d97 commit 424743c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 23 deletions.
28 changes: 20 additions & 8 deletions src/app/controllers/TinyG/TinyG.js
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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');
Expand All @@ -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');
Expand Down
57 changes: 42 additions & 15 deletions src/app/controllers/TinyG/TinyGController.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 424743c

Please sign in to comment.