diff --git a/js/kiri-print.js b/js/kiri-print.js index 83c26979..8165b77c 100644 --- a/js/kiri-print.js +++ b/js/kiri-print.js @@ -421,7 +421,6 @@ var gs_kiri_print = exports; var options = options || {}, process = this.settings.process, shortDist = process.outputShortDistance, - shortDist2 = process.outputShortDistance * 2, shortFact = process.outputShortFactor, shellMult = options.extrude || process.outputShellMult, printSpeed = options.rate || process.outputFeedrate, @@ -448,12 +447,12 @@ var gs_kiri_print = exports; if (options.shorten && dist > options.shorten && count === points.length) { point = last.offsetPointFrom(point, options.shorten); } - if (isShort) { - addOutput(output, point, shellMult, shortSpeed); - } else if (shortDist && dist < shortDist) { + if (shortDist && dist < shortDist) { var shortRate = shortSpeed + (printSpeed - shortSpeed) * (dist / shortDist); addOutput(output, point, shellMult, shortRate); - } else { + } else if (isShort) { + addOutput(output, point, shellMult, shortSpeed); + } else { addOutput(output, point, shellMult, printSpeed); } } diff --git a/js/kiri.js b/js/kiri.js index a11134b4..413ac80a 100644 --- a/js/kiri.js +++ b/js/kiri.js @@ -973,7 +973,8 @@ self.kiri.license = exports.LICENSE; octo_apik, grid_host, grid_apik, - grid_target; + grid_target, + grid_targets = {}; // run gcode post processor function (when supplied and valid) if (codeproc && self[codeproc]) { @@ -1035,7 +1036,8 @@ self.kiri.license = exports.LICENSE; }); } - function gridprint() { + function gridprint_probe(ev) { + if (ev && ev.code !== 'Enter') return; if (!(grid_host && grid_apik)) return; var xhtr = new XMLHttpRequest(), @@ -1043,6 +1045,52 @@ self.kiri.license = exports.LICENSE; apik = grid_apik.value, target = grid_target.value; + xhtr.onreadystatechange = function() { + if (xhtr.readyState === 4) { + if (xhtr.status >= 200 && xhtr.status < 300) { + var res = JSON.parse(xhtr.responseText); + var sel = false; + var html = []; + grid_targets = {}; + for (var key in res) { + if (!SDB['grid-target']) { + SDB['grid-target'] = key; + sel = true; + } else { + sel = SDB['grid-target'] === key; + } + grid_targets[html.length] = key; + html.push( + "" + ); + } + grid_target.innerHTML = html.join('\n'); + } else { + alert("invalid grid-host: " + xhtr.responseText); + } + } + }; + + xhtr.open("GET", host + "/api/targets"); + xhtr.send(); + } + + function gridprint() { + if (!(grid_host && grid_apik)) return; + + var xhtr = new XMLHttpRequest(), + host = grid_host.value, + apik = grid_apik.value, + target = SDB['grid-target'] || ''; + + if (target === '') { + alert('invalid or missing target'); + return; + } if (host.indexOf("http") !== 0) { alert("host missing protocol (http:// or https://)"); return; @@ -1058,7 +1106,6 @@ self.kiri.license = exports.LICENSE; SDB['grid-host'] = host.trim(); SDB['grid-apik'] = apik.trim(); - SDB['grid-target'] = target.trim(); xhtr.onreadystatechange = function() { if (xhtr.readyState === 4) { @@ -1137,6 +1184,8 @@ self.kiri.license = exports.LICENSE; $('print-filename').value = filename; $('print-filesize').value = currentPrint.bytes; $('print-filament').value = Math.round(currentPrint.distance); + $('grid-host').onkeyup = gridprint_probe; + $('grid-apik').onkeyup = gridprint_probe; calcTime(); calcWeight(); octo_host = $('octo-host'); @@ -1152,9 +1201,13 @@ self.kiri.license = exports.LICENSE; grid_host = $('grid-host'); grid_apik = $('grid-apik'); grid_target = $('grid-target'); + grid_target.onchange = function(ev) { + console.log(grid_targets[grid_target.selectedIndex]); + SDB['grid-target'] = grid_targets[grid_target.selectedIndex]; + }; grid_host.value = SDB['grid-host'] || ''; grid_apik.value = SDB['grid-apik'] || ''; - grid_target.value = SDB['grid-target'] || ''; + gridprint_probe(); showModal('print'); }); } diff --git a/js/license.js b/js/license.js index f81a188f..ca0f0b96 100644 --- a/js/license.js +++ b/js/license.js @@ -1,7 +1,7 @@ var exports = { COPYRIGHT:"Copyright (C) 2014-2017 Stewart Allen - All Rights Reserved", LICENSE:"Unauthorized copying, modification and re-distribution are strictly prohibited without prior written consent.", - VERSION:"1.0.89" + VERSION:"1.0.90" }; if (!module) var module = {}; module.exports = exports; diff --git a/web/kiri/output-gcode.html b/web/kiri/output-gcode.html index 4e909f87..94b258c0 100644 --- a/web/kiri/output-gcode.html +++ b/web/kiri/output-gcode.html @@ -41,7 +41,10 @@ host:port api key - target + target + + + setup grid:print for your network diff --git a/web/kiri/style.css b/web/kiri/style.css index 830c6150..ae1417bf 100644 --- a/web/kiri/style.css +++ b/web/kiri/style.css @@ -188,12 +188,6 @@ input[type=range]::-moz-focus-outer { color: #fff; background-color: #888; } -#opapik { - display: none; -} -#gpapik { - display: none; -} /** sender dialog */