allow api.function.export to take optional callback function to receive gcode

This commit is contained in:
Stewart Allen 2020-07-03 20:41:43 -04:00
commit 0a9256eb36
2 changed files with 12 additions and 8 deletions

View file

@ -19,18 +19,18 @@
let printSeq = parseInt(SDB['kiri-print-seq'] || SDB['print-seq'] || "0") + 1; let printSeq = parseInt(SDB['kiri-print-seq'] || SDB['print-seq'] || "0") + 1;
function exportPrint() { function exportPrint(options) {
let currentPrint = API.print.get(); let currentPrint = API.print.get();
if (currentPrint) { if (currentPrint) {
API.event.emit('export', API.mode.get()); API.event.emit('export', API.mode.get());
switch (API.mode.get()) { switch (API.mode.get()) {
case 'LASER': return exportPrintLaser(currentPrint); case 'LASER': return exportPrintLaser(currentPrint);
case 'FDM': return exportPrintGCODE(currentPrint); case 'FDM': return exportPrintGCODE(currentPrint, options);
case 'CAM': return exportPrintGCODE(currentPrint); case 'CAM': return exportPrintGCODE(currentPrint, options);
case 'SLA': return exportPrintSLA(currentPrint); case 'SLA': return exportPrintSLA(currentPrint);
} }
} else { } else {
API.function.print(exportPrint); API.function.print(function() { exportPrint(options) });
} }
} }
@ -73,13 +73,17 @@
} }
} }
function exportPrintGCODE(currentPrint) { function exportPrintGCODE(currentPrint, options) {
if (currentPrint) { if (currentPrint) {
currentPrint.exportGCode(true, function(gcode) { currentPrint.exportGCode(true, function(gcode) {
exportGCode(gcode,currentPrint); if (typeof(options) === 'function') {
options(gcode);
} else {
exportGCode(gcode, currentPrint);
}
}); });
} else { } else {
API.function.print(exportPrint); API.function.print(function() { exportPrint(options) });
} }
} }

View file

@ -205,7 +205,7 @@
function: { function: {
slice: prepareSlices, slice: prepareSlices,
print: preparePrint, print: preparePrint,
export: function() { KIRI.export() }, export: function() { KIRI.export(...arguments) },
cancel: cancelWorker, cancel: cancelWorker,
clear: clearWidgetCache clear: clearWidgetCache
}, },