checkpoint palette3 and purge tower work

This commit is contained in:
Stewart Allen 2021-11-12 23:21:11 -05:00
commit 7306ef5c0c
7 changed files with 96 additions and 26 deletions

View file

@ -145,6 +145,10 @@ KIRI.work = {
send("snap", data, function(reply) { }); send("snap", data, function(reply) { });
}, },
png: function(data, ondone) {
send("png", data, ondone);
},
// widget sync // widget sync
sync: function(widgets) { sync: function(widgets) {
if (!widgets) { if (!widgets) {

View file

@ -106,10 +106,6 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
$('print-filename').value + ".gcode"); $('print-filename').value + ".gcode");
} }
function download_palette() {
console.log('todo');
}
API.ajax("/kiri/output-laser.html", function(html) { API.ajax("/kiri/output-laser.html", function(html) {
let segments = 0; let segments = 0;
data.forEach(layer => { segments += layer.length }); data.forEach(layer => { segments += layer.length });
@ -465,14 +461,16 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
if (info.segments) { if (info.segments) {
// todo: reduce segments to eliminate 0 lenghts and transitions before 150mm // todo: reduce segments to eliminate 0 lenghts and transitions before 150mm
let { settings, segments } = info; let { settings, segments } = info;
let { bounds } = settings; let { device, bounds } = settings;
let { min, max } = bounds; let { min, max } = bounds;
let driveInfo = {}; let driveInfo = {};
let volume = {}; let volume = {};
let length = {}; let length = {};
// add 600mm of filament to the last segment for bowden drives
segments.peek().emitted += 650;
for (let seg of segments) { for (let seg of segments) {
let seginfo = driveInfo[seg.tool] = driveInfo[seg.tool] || { length: 0, volume: 0 }; let seginfo = driveInfo[seg.tool] = driveInfo[seg.tool] || { length: 0, volume: 0 };
seginfo.length += seg.emitted; seginfo.length += seg.emitted + 5;
seginfo.volume += seg.emitted * Math.PI; seginfo.volume += seg.emitted * Math.PI;
volume[seg.tool+1] = seginfo.volume; volume[seg.tool+1] = seginfo.volume;
length[seg.tool+1] = seginfo.length; length[seg.tool+1] = seginfo.length;
@ -482,7 +480,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
version: "3.2", version: "3.2",
printerProfile: { printerProfile: {
id: settings.extras.palette.printer, id: settings.extras.palette.printer,
name: "my printer" name: device.deviceName || "My Printer"
}, },
preheatTemperature: { nozzle: [0], bed: 0 }, preheatTemperature: { nozzle: [0], bed: 0 },
paletteNozzle: 0, paletteNozzle: 0,
@ -536,16 +534,20 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
pings: [], pings: [],
algorithms algorithms
}; };
console.log({meta, palette}); let png;
KIRI.work.png({}, data => {
png = data.png;
});
downloadPalette.onclick = function() { downloadPalette.onclick = function() {
KIRI.client.zip([ KIRI.client.zip([
{name:"meta.json", data:JSON.stringify(meta,undefined,4)}, {name:"meta.json", data:JSON.stringify(meta,undefined,4)},
{name:"palette.json", data:JSON.stringify(palette,undefined,4)} {name:"palette.json", data:JSON.stringify(palette,undefined,4)},
{name:"thumbnail.png", data:png.buffer}
], progress => { ], progress => {
API.show.progress(progress.percent/100, "generating palette files"); API.show.progress(progress.percent/100, "generating palette files");
}, output => { }, output => {
API.show.progress(0); API.show.progress(0);
API.util.download(output, `${name}.mafx`); API.util.download(output, `${$('print-filename').value}.mafx`);
}) })
}; };
} }

View file

@ -132,7 +132,7 @@
if (!conf.palette) { if (!conf.palette) {
conf.palette = { printer: "uuid" }; conf.palette = { printer: "uuid" };
} }
let uuid = prompt('Printer UID from Canvas', conf.palette.printer); let uuid = prompt('Unique Printer Identifier (can me made up)', conf.palette.printer);
if (uuid) { if (uuid) {
conf.palette.printer = uuid; conf.palette.printer = uuid;
} }

View file

@ -1094,7 +1094,6 @@
if (MODE === MODES.SLA && !callback) { if (MODE === MODES.SLA && !callback) {
callback = preparePreview; callback = preparePreview;
} }
// force layout in belt mode when widget exceeds bed length // force layout in belt mode when widget exceeds bed length
if (WIDGETS.length && settings.device.bedBelt) { if (WIDGETS.length && settings.device.bedBelt) {
let doLayout = false; let doLayout = false;

View file

@ -218,6 +218,20 @@ KIRI.worker = {
send.done(); send.done();
}, },
png: function(data, send) {
if (current.snap) {
let sws = current.snap.url;
let b64 = atob(sws.substring(sws.indexOf(',') + 1));
let bin = Uint8Array.from(b64, c => c.charCodeAt(0));
let img = new png.PNG();
img.parse(bin, (err, data) => {
send.done({png: bin}, [ bin ]);
});
} else {
send.done({error: "missing snapshot"});
}
},
clear: function(data, send) { clear: function(data, send) {
current.snap = null; current.snap = null;
current.print = null; current.print = null;

View file

@ -268,11 +268,16 @@
} }
}); });
} }
if (extrudeAbs && line.indexOf('E') > 0) { if (line.indexOf('E') > 0) {
line.split(";")[0].split(' ').forEach(function (tok) { line.split(";")[0].split(' ').forEach(function (tok) {
// use max E position from gcode-preamble // use max E position from gcode-preamble
if (tok[0] == 'E') { if (tok[0] == 'E') {
outputLength = Math.max(outputLength, parseFloat(tok.substring(1)) || 0); if (extrudeAbs) {
outputLength = Math.max(outputLength, parseFloat(tok.substring(1)) || 0);
emitted = outputLength;
} else {
emitted += parseFloat(tok.substring(1) || 0);
}
} }
}); });
} }

View file

@ -243,17 +243,23 @@
} }
// determine size/location of purge blocks // determine size/location of purge blocks
let blokw = isPalette ? 20 : 10, blokh = isPalette ? 20 : 10;
let stepw = blokw + nozzle / 2;
let blokpos, walkpos, blok; let blokpos, walkpos, blok;
if (bounds.min.x < bounds.min.y) { if (bounds.min.x < bounds.min.y) {
let dx = ((bounds.max.x - bounds.min.x) - (extcount * 10)) / 2 + 5; let mx = (bounds.max.x + bounds.min.x) / 2;
blokpos = { x:bounds.min.x + dx, y: bounds.max.y + 5}; let px = mx - (extcount * blokw) / 2 + (blokw / 2);
walkpos = { x:10, y:0 }; let dx = ((bounds.max.x - bounds.min.x) - (extcount * blokw)) / 2;
blok = { x:9, y:4 }; blokpos = { x:px, y: bounds.max.y + 2 + blokh / 2};
walkpos = { x:stepw, y:0 };
blok = { x:blokw, y:blokh };
} else { } else {
let dy = ((bounds.max.y - bounds.min.y) - (extcount * 10)) / 2 + 5; let my = (bounds.max.y + bounds.min.y) / 2;
blokpos = { x:bounds.max.x + 5, y: bounds.min.y + dy}; let py = my - (extcount * blokw) / 2 + (blokw / 2);
walkpos = { x:0, y:10 }; blokpos = { x:bounds.max.x + 2 + blokh / 2, y:py};
blok = { x:4, y:9 }; walkpos = { x:0, y:stepw };
blok = { x:blokh, y:blokw };
} }
// replace extruders array with object array containing more info // replace extruders array with object array containing more info
@ -261,30 +267,70 @@
if (!ext) return ext; if (!ext) return ext;
let noz = device.extruders[i].extNozzle, let noz = device.extruders[i].extNozzle,
pos = {x:blokpos.x, y:blokpos.y, z:0}, pos = {x:blokpos.x, y:blokpos.y, z:0},
rect = newPolygon().centerRectangle(pos, blok.x, blok.y),
full = linesToPoly(POLY.fillArea([
newPolygon().centerRectangle(pos, blok.x - noz, blok.y - noz)
], 45, noz)),
sparse = linesToPoly(POLY.fillArea([
newPolygon().centerRectangle(pos, blok.x - noz, blok.y - noz)
], 135, noz * 5)),
rec = { rec = {
extruder: i, extruder: i,
poly: newPolygon().centerSpiral(pos, blok.x, blok.y, noz*2, 3) rect,
full,
sparse
}; };
blokpos.x += walkpos.x; blokpos.x += walkpos.x;
blokpos.y += walkpos.y; blokpos.y += walkpos.y;
return rec; return rec;
}); });
function linesToPoly(points) {
let poly = newPolygon().setOpen();
let ping = 0;
for (let i=0; i<points.length; i += 2) {
let p1 = points[i];
let p2 = points[i+1];
if (ping++ % 2 === 0) {
poly.push(p1);
poly.push(p2);
} else {
poly.push(p2);
poly.push(p1);
}
}
return poly;
}
let lastPurgeTool;
// generate purge block for given nozzle // generate purge block for given nozzle
function purge(nozzle, track, layer, start, z, using) { function purge(nozzle, track, layer, start, z, using) {
if (!purgeTower || extcount < 2 || isBelt) { if (!purgeTower || extcount < 2 || isBelt) {
return start; return start;
} }
let rec = track[nozzle]; let rec = track[nozzle];
let thin = using >= 0 || lastPurgeTool === nozzle;
let tool = using >= 0 ? using : nozzle;
let first = layer.slice.index === 0;
let rate = first ? process.firstLayerRate : process.outputFeedrate;
lastPurgeTool = tool;
if (rec) { if (rec) {
track[nozzle] = null; track[nozzle] = null;
if (layer.last()) { if (layer.last()) {
layer.last().retract = true; layer.last().retract = true;
} }
start = print.polyPrintPath(rec.poly.clone().setZ(z), start, layer, { start = print.polyPrintPath(rec.rect.clone().setZ(z), start, layer, {
tool: using !== undefined ? using : nozzle, tool,
rate,
simple: true,
open: false,
});
start = print.polyPrintPath((thin && !first ? rec.sparse : rec.full).clone().setZ(z), start, layer, {
tool,
rate,
simple: true,
open: true, open: true,
simple: true
}); });
layer.last().retract = true; layer.last().retract = true;
return start; return start;