change gp target to drop-down

This commit is contained in:
Stewart Allen 2018-01-19 11:10:59 -05:00
commit b230372d7f
5 changed files with 66 additions and 17 deletions

View file

@ -421,7 +421,6 @@ var gs_kiri_print = exports;
var options = options || {}, var options = options || {},
process = this.settings.process, process = this.settings.process,
shortDist = process.outputShortDistance, shortDist = process.outputShortDistance,
shortDist2 = process.outputShortDistance * 2,
shortFact = process.outputShortFactor, shortFact = process.outputShortFactor,
shellMult = options.extrude || process.outputShellMult, shellMult = options.extrude || process.outputShellMult,
printSpeed = options.rate || process.outputFeedrate, printSpeed = options.rate || process.outputFeedrate,
@ -448,12 +447,12 @@ var gs_kiri_print = exports;
if (options.shorten && dist > options.shorten && count === points.length) { if (options.shorten && dist > options.shorten && count === points.length) {
point = last.offsetPointFrom(point, options.shorten); point = last.offsetPointFrom(point, options.shorten);
} }
if (isShort) { if (shortDist && dist < shortDist) {
addOutput(output, point, shellMult, shortSpeed);
} else if (shortDist && dist < shortDist) {
var shortRate = shortSpeed + (printSpeed - shortSpeed) * (dist / shortDist); var shortRate = shortSpeed + (printSpeed - shortSpeed) * (dist / shortDist);
addOutput(output, point, shellMult, shortRate); addOutput(output, point, shellMult, shortRate);
} else { } else if (isShort) {
addOutput(output, point, shellMult, shortSpeed);
} else {
addOutput(output, point, shellMult, printSpeed); addOutput(output, point, shellMult, printSpeed);
} }
} }

View file

@ -973,7 +973,8 @@ self.kiri.license = exports.LICENSE;
octo_apik, octo_apik,
grid_host, grid_host,
grid_apik, grid_apik,
grid_target; grid_target,
grid_targets = {};
// run gcode post processor function (when supplied and valid) // run gcode post processor function (when supplied and valid)
if (codeproc && self[codeproc]) { 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; if (!(grid_host && grid_apik)) return;
var xhtr = new XMLHttpRequest(), var xhtr = new XMLHttpRequest(),
@ -1043,6 +1045,52 @@ self.kiri.license = exports.LICENSE;
apik = grid_apik.value, apik = grid_apik.value,
target = grid_target.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(
"<option id='gpo-'" + key + " value='" +key + "'" +
(sel ? " selected" : "") +
">" +
(res[key].comment || key) +
"</option>"
);
}
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) { if (host.indexOf("http") !== 0) {
alert("host missing protocol (http:// or https://)"); alert("host missing protocol (http:// or https://)");
return; return;
@ -1058,7 +1106,6 @@ self.kiri.license = exports.LICENSE;
SDB['grid-host'] = host.trim(); SDB['grid-host'] = host.trim();
SDB['grid-apik'] = apik.trim(); SDB['grid-apik'] = apik.trim();
SDB['grid-target'] = target.trim();
xhtr.onreadystatechange = function() { xhtr.onreadystatechange = function() {
if (xhtr.readyState === 4) { if (xhtr.readyState === 4) {
@ -1137,6 +1184,8 @@ self.kiri.license = exports.LICENSE;
$('print-filename').value = filename; $('print-filename').value = filename;
$('print-filesize').value = currentPrint.bytes; $('print-filesize').value = currentPrint.bytes;
$('print-filament').value = Math.round(currentPrint.distance); $('print-filament').value = Math.round(currentPrint.distance);
$('grid-host').onkeyup = gridprint_probe;
$('grid-apik').onkeyup = gridprint_probe;
calcTime(); calcTime();
calcWeight(); calcWeight();
octo_host = $('octo-host'); octo_host = $('octo-host');
@ -1152,9 +1201,13 @@ self.kiri.license = exports.LICENSE;
grid_host = $('grid-host'); grid_host = $('grid-host');
grid_apik = $('grid-apik'); grid_apik = $('grid-apik');
grid_target = $('grid-target'); 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_host.value = SDB['grid-host'] || '';
grid_apik.value = SDB['grid-apik'] || ''; grid_apik.value = SDB['grid-apik'] || '';
grid_target.value = SDB['grid-target'] || ''; gridprint_probe();
showModal('print'); showModal('print');
}); });
} }

View file

@ -1,7 +1,7 @@
var exports = { var exports = {
COPYRIGHT:"Copyright (C) 2014-2017 Stewart Allen <stewart@neuron.com> - All Rights Reserved", COPYRIGHT:"Copyright (C) 2014-2017 Stewart Allen <stewart@neuron.com> - All Rights Reserved",
LICENSE:"Unauthorized copying, modification and re-distribution are strictly prohibited without prior written consent.", 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 = {}; if (!module) var module = {};
module.exports = exports; module.exports = exports;

View file

@ -41,7 +41,10 @@
<tr><th colspan="2"><button id="print-gridprint">send to grid:print</button></th></tr> <tr><th colspan="2"><button id="print-gridprint">send to grid:print</button></th></tr>
<tr><th>host:port</th><td><input id="grid-host" size="35" placeholder="http(s)://host:port" /></td></tr> <tr><th>host:port</th><td><input id="grid-host" size="35" placeholder="http(s)://host:port" /></td></tr>
<tr id="gpapik"><th>api key</th><td><input id="grid-apik" size="35" /></td></tr> <tr id="gpapik"><th>api key</th><td><input id="grid-apik" size="35" /></td></tr>
<tr><th>target</th><td><input id="grid-target" size="35" /></td></tr> <tr><th>target</th><td>
<!--<input id="grid-target" size="35" />-->
<select id="grid-target"></select>
</td></tr>
<tr><td colspan="2"><span id="grid-hint">setup <a href="https://github.com/stewartoallen/grid-print" target="_help">grid:print</a> for your network</span></td></tr> <tr><td colspan="2"><span id="grid-hint">setup <a href="https://github.com/stewartoallen/grid-print" target="_help">grid:print</a> for your network</span></td></tr>
</table> </table>
</div> </div>

View file

@ -188,12 +188,6 @@ input[type=range]::-moz-focus-outer {
color: #fff; color: #fff;
background-color: #888; background-color: #888;
} }
#opapik {
display: none;
}
#gpapik {
display: none;
}
/** sender dialog */ /** sender dialog */