Skip to content

Commit

Permalink
Add support for host commands (e.g. action:pause) and use suspend/res…
Browse files Browse the repository at this point in the history
…ume instead of !/~ (#515)

* use proper suspend and resume commands, smoothie does not support !/~ properly

* adding support for action host commands send from smoothie to host machine

Co-authored-by: Cheton Wu <cheton@gmail.com>
  • Loading branch information
fishpepper and cheton committed Oct 24, 2021
1 parent 46cc507 commit 2292765
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/server/controllers/Smoothie/SmoothieController.js
Expand Up @@ -455,6 +455,20 @@ class SmoothieController {
this.emit('serialport:read', res.raw);
});

// handle action:xxx host commands
this.runner.on('action', (res) => {
log.error(`incoming action: action:${res.message} !`);
if (res.message === 'pause') {
this.workflow.pause({ data: 'action:pause' });
} else if (res.message === 'resume') {
this.workflow.resume({ data: 'action:resume' });
} else if (res.message === 'cancel') {
this.workflow.stop();
} else {
log.error(`Unknown action command: action:${res.message} ignored`);
}
});

this.runner.on('parserstate', (res) => {
this.actionMask.queryParserState.state = false;
this.actionMask.queryParserState.reply = true;
Expand Down Expand Up @@ -1004,7 +1018,7 @@ class SmoothieController {

const activeState = _.get(this.state, 'status.activeState', '');
if (activeState === SMOOTHIE_ACTIVE_STATE_HOLD) {
this.write('~'); // resume
this.writeln('resume'); // resume
}
},
'pause': () => {
Expand All @@ -1016,7 +1030,7 @@ class SmoothieController {

this.workflow.pause();

this.write('!');
this.writeln('suspend');
},
'resume': () => {
log.warn(`Warning: The "${cmd}" command is deprecated and will be removed in a future release.`);
Expand All @@ -1025,7 +1039,7 @@ class SmoothieController {
'gcode:resume': () => {
this.event.trigger('gcode:resume');

this.write('~');
this.writeln('resume');

this.workflow.resume();
},
Expand All @@ -1037,7 +1051,7 @@ class SmoothieController {
if (this.workflow.state === WORKFLOW_STATE_RUNNING) {
return;
}
this.write('~');
this.writeln('resume');
this.feeder.unhold();
this.feeder.next();
},
Expand All @@ -1047,12 +1061,12 @@ class SmoothieController {
'feedhold': () => {
this.event.trigger('feedhold');

this.write('!');
this.writeln('suspend');
},
'cyclestart': () => {
this.event.trigger('cyclestart');

this.write('~');
this.writeln('resume');
},
'statusreport': () => {
this.write('?');
Expand Down
4 changes: 4 additions & 0 deletions src/server/controllers/Smoothie/SmoothieLineParser.js
Expand Up @@ -3,6 +3,7 @@ import SmoothieLineParserResultStatus from './SmoothieLineParserResultStatus';
import SmoothieLineParserResultOk from './SmoothieLineParserResultOk';
import SmoothieLineParserResultError from './SmoothieLineParserResultError';
import SmoothieLineParserResultAlarm from './SmoothieLineParserResultAlarm';
import SmoothieLineParserResultAction from './SmoothieLineParserResultAction';
import SmoothieLineParserResultParserState from './SmoothieLineParserResultParserState';
import SmoothieLineParserResultParameters from './SmoothieLineParserResultParameters';
import SmoothieLineParserResultVersion from './SmoothieLineParserResultVersion';
Expand All @@ -22,6 +23,9 @@ class SmoothieLineParser {
// ALARM:
SmoothieLineParserResultAlarm,

// action:x
SmoothieLineParserResultAction,

// [G38.2 G54 G17 G21 G91 G94 M0 M5 M9 T0 F20. S0.]
SmoothieLineParserResultParserState,

Expand Down
22 changes: 22 additions & 0 deletions src/server/controllers/Smoothie/SmoothieLineParserResultAction.js
@@ -0,0 +1,22 @@
class SmoothieLineParserResultAction {
static parse(line) {
// handle action commands from the host
// see https://reprap.org/wiki/G-code#Replies_from_the_RepRap_machine_to_the_host_computer
// '// action:{pause,resume,cancel}\r\n'
const r = line.match(/^\/\/ action:(.+)$/);
if (!r) {
return null;
}

const payload = {
message: r[1]
};

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

export default SmoothieLineParserResultAction;
5 changes: 5 additions & 0 deletions src/server/controllers/Smoothie/SmoothieRunner.js
Expand Up @@ -5,6 +5,7 @@ import SmoothieLineParserResultStatus from './SmoothieLineParserResultStatus';
import SmoothieLineParserResultOk from './SmoothieLineParserResultOk';
import SmoothieLineParserResultError from './SmoothieLineParserResultError';
import SmoothieLineParserResultAlarm from './SmoothieLineParserResultAlarm';
import SmoothieLineParserResultAction from './SmoothieLineParserResultAction';
import SmoothieLineParserResultParserState from './SmoothieLineParserResultParserState';
import SmoothieLineParserResultParameters from './SmoothieLineParserResultParameters';
import SmoothieLineParserResultVersion from './SmoothieLineParserResultVersion';
Expand Down Expand Up @@ -103,6 +104,10 @@ class SmoothieRunner extends events.EventEmitter {
this.emit('alarm', payload);
return;
}
if (type === SmoothieLineParserResultAction) {
this.emit('action', payload);
return;
}
if (type === SmoothieLineParserResultParserState) {
const { modal, tool, feedrate, spindle } = payload;
const nextState = {
Expand Down

0 comments on commit 2292765

Please sign in to comment.