Skip to content

Commit 5596176

Browse files
committed
Preliminary support for Marlin 3D printer firmware
1 parent 58b181d commit 5596176

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/Controller.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
METRIC_UNITS,
99
// Controller
1010
GRBL,
11+
MARLIN,
1112
SMOOTHIE,
1213
TINYG
1314
} from './constants';
@@ -350,7 +351,7 @@ class Controller {
350351
// Gets the machine state.
351352
// @return {string|number} Returns the machine state.
352353
getMachineState() {
353-
if ([GRBL, SMOOTHIE, TINYG].indexOf(this.type) < 0) {
354+
if ([GRBL, MARLIN, SMOOTHIE, TINYG].indexOf(this.type) < 0) {
354355
return '';
355356
}
356357

@@ -362,6 +363,8 @@ class Controller {
362363

363364
if (this.type === GRBL) {
364365
machineState = this.state.machineState;
366+
} else if (this.type === MARLIN) {
367+
machineState = this.state.machineState;
365368
} else if (this.type === SMOOTHIE) {
366369
machineState = this.state.machineState;
367370
} else if (this.type === TINYG) {
@@ -397,6 +400,23 @@ class Controller {
397400
});
398401
}
399402

403+
// Marlin
404+
if (this.type === MARLIN) {
405+
const { pos, modal = {} } = this.state;
406+
const units = {
407+
'G20': IMPERIAL_UNITS,
408+
'G21': METRIC_UNITS
409+
}[modal.units];
410+
411+
// Machine position are reported in current units
412+
return mapValues({
413+
...defaultMachinePosition,
414+
...pos
415+
}, (val) => {
416+
return (units === IMPERIAL_UNITS) ? in2mm(val) : val;
417+
});
418+
}
419+
400420
// Smoothieware
401421
if (this.type === SMOOTHIE) {
402422
const { mpos, modal = {} } = this.state;
@@ -455,6 +475,23 @@ class Controller {
455475
});
456476
}
457477

478+
// Marlin
479+
if (this.type === MARLIN) {
480+
const { pos, modal = {} } = this.state;
481+
const units = {
482+
'G20': IMPERIAL_UNITS,
483+
'G21': METRIC_UNITS
484+
}[modal.units];
485+
486+
// Work position are reported in current units
487+
return mapValues({
488+
...defaultWorkPosition,
489+
...pos
490+
}, (val) => {
491+
return (units === IMPERIAL_UNITS) ? in2mm(val) : val;
492+
});
493+
}
494+
458495
// Smoothieware
459496
if (this.type === SMOOTHIE) {
460497
const { wpos, modal = {} } = this.state;
@@ -514,6 +551,13 @@ class Controller {
514551
};
515552
}
516553

554+
if (this.type === MARLIN) {
555+
return {
556+
...defaultModalState,
557+
...this.state.modal
558+
};
559+
}
560+
517561
if (this.type === SMOOTHIE) {
518562
return {
519563
...defaultModalState,

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const METRIC_UNITS = 'mm';
44

55
// Controller
66
export const GRBL = 'Grbl';
7+
export const MARLIN = 'Marlin';
78
export const SMOOTHIE = 'Smoothie';
89
export const TINYG = 'TinyG';
910

0 commit comments

Comments
 (0)