From d6132fd65211f50c763653f3a682d728be1864f3 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 17 Jan 2021 23:49:00 -0500 Subject: [PATCH] add M808 looping regions and a UI for setting them --- src/kiri/conf.js | 1 + src/kiri/init.js | 1 + src/mode/fdm/export.js | 38 +++++++++++++++++++++++++++++++++++++- web/kiri/lang/en.js | 2 ++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/kiri/conf.js b/src/kiri/conf.js index d257dc9b..7ce8531d 100644 --- a/src/kiri/conf.js +++ b/src/kiri/conf.js @@ -332,6 +332,7 @@ outputWipeDistance: 0, outputLayerRetract: false, outputOriginCenter: true, + outputLoopLayers: "", outputInvertX: false, outputInvertY: false, detectThinWalls: false, diff --git a/src/kiri/init.js b/src/kiri/init.js index 6c64ba0b..c54f5c78 100644 --- a/src/kiri/init.js +++ b/src/kiri/init.js @@ -1754,6 +1754,7 @@ antiBacklash: UC.newInput(LANG.ad_abkl_s, {title:LANG.ad_abkl_l, bound:UC.bound(0,3), convert:UC.toInt, modes:FDM}), fdmSep: UC.newBlank({class:"pop-sep", modes:FDM}), gcodePauseLayers: UC.newInput(LANG.ag_paws_s, {title:LANG.ag_paws_l, modes:FDM, comma:true}), + outputLoopLayers: UC.newInput(LANG.ag_loop_s, {title:LANG.ag_loop_l, modes:FDM, comma:true, show:isBelt}), outputLayerRetract: UC.newBoolean(LANG.ad_lret_s, onBooleanClick, {title:LANG.ad_lret_l, modes:FDM}), // SLA diff --git a/src/mode/fdm/export.js b/src/mode/fdm/export.js index 0e8c02f0..ea986b73 100644 --- a/src/mode/fdm/export.js +++ b/src/mode/fdm/export.js @@ -41,6 +41,7 @@ emitted = 0, retracted = 0, pos = {x:0, y:0, z:0, f:0}, + lout = null, last = null, zpos = 0, zhop = process.zHopDistance || 0, @@ -77,13 +78,28 @@ lines = 0, bytes = 0, bcos = Math.cos(Math.PI/4), - icos = 1 / bcos; + icos = 1 / bcos, + loops = process.outputLoopLayers, + inLoop; + + if (isBelt && loops) { + loops = loops.split(',').map(range => { + return range.split('-').map(v => parseInt(v)); + }).filter(a => a.length > 1).map(a => { + return { start:a[0], end:a[1], iter:a[2] >= 0 ? a[2] : 1} + }); + } + if (!isBelt || (loops && loops.length < 1)) { + loops = undefined; + } (process.gcodePauseLayers || "").split(",").forEach(function(lv) { let v = parseInt(lv); if (v >= 0) pause.push(v); }); + // console.log(loops) + append = function(line) { if (line) { lines++; @@ -203,6 +219,7 @@ epos.x = originCenter ? -pos.x : device.bedWidth - pos.x; epos.z = pos.z * icos; epos.y = -pos.y + epos.z * bcos; + lout = epos; } if (emit.x) o.append(" X").append(epos.x.toFixed(decimals)); if (emit.y) o.append(" Y").append(epos.y.toFixed(decimals)); @@ -251,6 +268,7 @@ subst.z = zpos = path.z; subst.Z = subst.z; + subst.e = subst.E = outputLength; subst.layer = layer; subst.height = path.height.toFixed(3); @@ -262,6 +280,24 @@ appendAllSub(pauseCmd) } + if (loops) { + if (inLoop) { + if (layer === inLoop.end) { + append(`M808`); + inLoop = undefined; + } + } else { + for (let loop of loops) { + if (layer === loop.start) { + append(`M808 L${loop.iter}`); + append(`G92 Z${lout.z.round(decimals)} E${outputLength.round(decimals)}`); + inLoop = loop; + break; + } + } + } + } + if (gcodeLayer && gcodeLayer.length) { appendAllSub(gcodeLayer); } else { diff --git a/web/kiri/lang/en.js b/web/kiri/lang/en.js index c324ac0a..eb39f2e6 100644 --- a/web/kiri/lang/en.js +++ b/web/kiri/lang/en.js @@ -496,6 +496,8 @@ kiri.lang['en-us'] = { ag_nozl_l: "select output nozzle or head", ag_paws_s: "pause layers", ag_paws_l: "comma-separated list of layers\nto inject pause commands before", + ag_loop_s: "loop layers", + ag_loop_l: "layer ranges to repeat in the format\nfirst-last-count,first-last-count,...\nomitted count = 1", // SLA MENU sa_menu: "slicing",