cleanup dwell and output functions. better time tracking wiht pings

This commit is contained in:
Stewart Allen 2021-11-25 12:45:11 -05:00
commit 3f38380151

View file

@ -115,7 +115,6 @@
tool: 0 tool: 0
}, },
pidx, path, out, speedMMM, emitMM, emitPerMM, lastp, laste, dist, pidx, path, out, speedMMM, emitMM, emitPerMM, lastp, laste, dist,
append,
lines = 0, lines = 0,
bytes = 0, bytes = 0,
bcos = Math.cos(Math.PI/4), bcos = Math.cos(Math.PI/4),
@ -123,11 +122,13 @@
inloops = 0, inloops = 0,
arcQ = [], arcQ = [],
minz = { x: Infinity, y: Infinity, z: Infinity }, minz = { x: Infinity, y: Infinity, z: Infinity },
// lenghts of each filament (by nozzle) consumed
segments = [],
// palette & ping data
isPalette = device.filamentSource === 'palette3', isPalette = device.filamentSource === 'palette3',
paletteInfo = extras.palette || {}, paletteInfo = extras.palette || {},
palettePingStart = paletteInfo.ping / 2, palettePingStart = paletteInfo.ping / 2,
palettePingSpace = paletteInfo.ping || 0, palettePingSpace = paletteInfo.ping || 0,
segments = [],
// track purges for palette3 pings // track purges for palette3 pings
purgePos, purgePos,
purgeOn = 0, purgeOn = 0,
@ -186,12 +187,15 @@
} }
let loops = isBelt && rloops.length ? rloops : undefined; let loops = isBelt && rloops.length ? rloops : undefined;
append = function(line) { function append(line) {
if (line) { if (line) {
lines++; lines++;
bytes += line.length; bytes += line.length;
output.append(line); 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) { if (!line || output.length > 1000) {
online(output.join("\n")); online(output.join("\n"));
output = []; output = [];
@ -298,8 +302,17 @@
} }
function dwell(ms) { function dwell(ms) {
append(`G4 P${ms}`); time += ms;
time += timeDwell; // 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) { function retract(zhop) {
@ -535,10 +548,8 @@
if (purgeOn === 0 && out.point.purgeOn && emitted - purgeOff >= palettePingSpace) { if (purgeOn === 0 && out.point.purgeOn && emitted - purgeOff >= palettePingSpace) {
retract(); retract();
pushPos(out.point.purgeOn); pushPos(out.point.purgeOn);
append(`G4 P4000`); append('G1'); // shorter pause accounts for retract/move
append(`G4 P4000`); append('G1'); dwell(12750);
append(`G4 P4000`); append('G1');
append(`G4 P1000`);
popPos(); popPos();
unretract(); unretract();
purgeOn = emitted; purgeOn = emitted;
@ -548,8 +559,8 @@
if (purgeOn && pingRemain <= 0) { if (purgeOn && pingRemain <= 0) {
retract(); retract();
pushPos(purgePos); pushPos(purgePos);
append(`G4 P4000`); append('G1'); // shorter pause accounts for retract/move
append(`G4 P3000`); dwell(6750);
popPos(); popPos();
unretract(); unretract();
if (!print.purges) { if (!print.purges) {