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 || {},
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);
}
}

View file

@ -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(
"<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) {
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');
});
}

View file

@ -1,7 +1,7 @@
var exports = {
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.",
VERSION:"1.0.89"
VERSION:"1.0.90"
};
if (!module) var module = {};
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>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><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>
</table>
</div>

View file

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