From 3f383801515b5768cf4033af1c891a970b81603a Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 25 Nov 2021 12:45:11 -0500 Subject: [PATCH] cleanup dwell and output functions. better time tracking wiht pings --- src/mode/fdm/export.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/mode/fdm/export.js b/src/mode/fdm/export.js index 618bb466..53f7ac60 100644 --- a/src/mode/fdm/export.js +++ b/src/mode/fdm/export.js @@ -115,7 +115,6 @@ tool: 0 }, pidx, path, out, speedMMM, emitMM, emitPerMM, lastp, laste, dist, - append, lines = 0, bytes = 0, bcos = Math.cos(Math.PI/4), @@ -123,11 +122,13 @@ inloops = 0, arcQ = [], minz = { x: Infinity, y: Infinity, z: Infinity }, + // lenghts of each filament (by nozzle) consumed + segments = [], + // palette & ping data isPalette = device.filamentSource === 'palette3', paletteInfo = extras.palette || {}, palettePingStart = paletteInfo.ping / 2, palettePingSpace = paletteInfo.ping || 0, - segments = [], // track purges for palette3 pings purgePos, purgeOn = 0, @@ -186,12 +187,15 @@ } let loops = isBelt && rloops.length ? rloops : undefined; - append = function(line) { + function append(line) { if (line) { lines++; bytes += line.length; output.append(line); } + // batch gcode output to free memory in worker + // consider alternate transfer schemes like indexeddb + // since this transfers the burden to the main thread if (!line || output.length > 1000) { online(output.join("\n")); output = []; @@ -298,8 +302,17 @@ } function dwell(ms) { - append(`G4 P${ms}`); - time += timeDwell; + time += ms; + // break up dwell times over 4s because of + // limitations in some firmwares + while (ms > 0) { + let wait = Math.min(4000, ms); + append(`G4 P${wait}`); + ms -= wait; + if (ms) { + append('G1'); + } + } } function retract(zhop) { @@ -535,10 +548,8 @@ if (purgeOn === 0 && out.point.purgeOn && emitted - purgeOff >= palettePingSpace) { retract(); pushPos(out.point.purgeOn); - append(`G4 P4000`); append('G1'); - append(`G4 P4000`); append('G1'); - append(`G4 P4000`); append('G1'); - append(`G4 P1000`); + // shorter pause accounts for retract/move + dwell(12750); popPos(); unretract(); purgeOn = emitted; @@ -548,8 +559,8 @@ if (purgeOn && pingRemain <= 0) { retract(); pushPos(purgePos); - append(`G4 P4000`); append('G1'); - append(`G4 P3000`); + // shorter pause accounts for retract/move + dwell(6750); popPos(); unretract(); if (!print.purges) {