add support for start and end code

This commit is contained in:
casperlamboo 2018-01-15 13:44:59 +01:00
parent 43af4e05ab
commit 10fb3714c7
3 changed files with 31 additions and 11 deletions

View File

@ -122,6 +122,15 @@ export default class {
return this; return this;
} }
addGCode(gcode, { temperature, bedTemperature, heatedbed }) {
gcode = gcode
.replace(/{temperature}/gi, temperature)
.replace(/{bedTemperature}/gi, bedTemperature)
.replace(/{if heatedBed}/gi, heatedbed ? '' : ';');
this._addGCode(gcode);
}
getGCode() { getGCode() {
return { return {
gcode: this._gcode, gcode: this._gcode,

View File

@ -76,16 +76,20 @@ export default function(settings, geometry, openObjectIndexes, constructLinePrev
function gcodeToString(gcode) { function gcodeToString(gcode) {
const currentValues = {}; const currentValues = {};
return gcode.reduce((string, command) => { return gcode.reduce((string, command) => {
let first = true; if (typeof command === 'string') {
for (const action in command) { string += command;
const value = command[action]; } else {
const currentValue = currentValues[action]; let first = true;
if (first) { for (const action in command) {
string += `${action}${value}`; const value = command[action];
first = false; const currentValue = currentValues[action];
} else if (currentValue !== value) { if (first) {
string += ` ${action}${value}`; string += `${action}${value}`;
currentValues[action] = value; first = false;
} else if (currentValue !== value) {
string += ` ${action}${value}`;
currentValues[action] = value;
}
} }
} }
string += '\n'; string += '\n';
@ -101,7 +105,10 @@ function createGcodeGeometry(gcode) {
let lastPoint = [0, 0, 0]; let lastPoint = [0, 0, 0];
for (let i = 0; i < gcode.length; i ++) { for (let i = 0; i < gcode.length; i ++) {
const { G, F, X, Y, Z } = gcode[i]; const command = gcode[i];
if (typeof command === 'string') continue;
const { G, F, X, Y, Z } = command;
if (X || Y || Z) { if (X || Y || Z) {
if (G === 1) { if (G === 1) {

View File

@ -22,6 +22,8 @@ export default function slicesToGCode(slices, settings) {
const gcode = new GCode(nozzleToFilamentRatio); const gcode = new GCode(nozzleToFilamentRatio);
if (settings.startCode) gcode.addGCode(settings.startCode, settings);
const defaultProfile = { const defaultProfile = {
travelProfile: travel, travelProfile: travel,
retractionProfile: retraction retractionProfile: retraction
@ -77,6 +79,8 @@ export default function slicesToGCode(slices, settings) {
} }
} }
if (settings.endCode) gcode.addGCode(settings.endCode, settings);
return gcode.getGCode(); return gcode.getGCode();
} }