update print target and add stub for auto-detect print server

This commit is contained in:
Stewart Allen 2018-03-14 10:08:11 -04:00
commit cb43d70cb8
3 changed files with 18 additions and 15 deletions

View file

@ -43,7 +43,7 @@ if (self.window) {
if (worker) worker.terminate(); if (worker) worker.terminate();
for (var key in slicing) { for (var key in slicing) {
slicing[key]({error: "cancelled"}); slicing[key]({error: "cancelled slicing"});
} }
slicing = {}; slicing = {};
running = {}; running = {};

View file

@ -541,6 +541,7 @@ self.kiri.license = exports.LICENSE;
clearWorker : KIRI.work.clear, clearWorker : KIRI.work.clear,
getSettings : getSettings, getSettings : getSettings,
putSettings : putSettings, putSettings : putSettings,
ghostDetect : function() { return false },
hideImport : function() { UI.import.style.display = 'none' }, hideImport : function() { UI.import.style.display = 'none' },
mouse : { mouse : {
moved : function() { return mouseMoved }, moved : function() { return mouseMoved },
@ -1009,7 +1010,7 @@ self.kiri.license = exports.LICENSE;
{type:"application/octet-stream"}); {type:"application/octet-stream"});
} }
function octoprint() { function sendto_octoprint() {
if (!(octo_host && octo_apik)) return; if (!(octo_host && octo_apik)) return;
var form = new FormData(), var form = new FormData(),
@ -1050,15 +1051,15 @@ self.kiri.license = exports.LICENSE;
ajax.send(form); ajax.send(form);
} }
function gridprint_tracker(host,key) { function gridhost_tracker(host,key) {
ajax(host+"/api/check?key="+key, function(data) { ajax(host+"/api/check?key="+key, function(data) {
data = js2o(data); data = js2o(data);
DBUG.log(data); DBUG.log(data);
if (!data.done && !data.error) setTimeout(function() { gridprint_tracker(host,key) }, 1000); if (!data.done && !data.error) setTimeout(function() { gridhost_tracker(host,key) }, 1000);
}); });
} }
function gridprint_probe(ev) { function gridhost_probe(ev) {
if (ev && ev.code !== 'Enter') return; if (ev && ev.code !== 'Enter') return;
if (!(grid_host && grid_apik)) return; if (!(grid_host && grid_apik)) return;
@ -1069,6 +1070,8 @@ self.kiri.license = exports.LICENSE;
if (!apik) $('gpapik').style.display = 'none'; if (!apik) $('gpapik').style.display = 'none';
if (!host && KIRI.api.ghostDetect(gridhost_probe)) return;
xhtr.onreadystatechange = function() { xhtr.onreadystatechange = function() {
if (xhtr.readyState === 4) { if (xhtr.readyState === 4) {
if (xhtr.status >= 200 && xhtr.status < 300) { if (xhtr.status >= 200 && xhtr.status < 300) {
@ -1109,7 +1112,7 @@ self.kiri.license = exports.LICENSE;
xhtr.send(); xhtr.send();
} }
function gridprint() { function sendto_gridhost() {
if (!(grid_host && grid_apik)) return; if (!(grid_host && grid_apik)) return;
var xhtr = new XMLHttpRequest(), var xhtr = new XMLHttpRequest(),
@ -1143,7 +1146,7 @@ self.kiri.license = exports.LICENSE;
STATS.add('gp-'+status); STATS.add('gp-'+status);
if (status >= 200 && status < 300) { if (status >= 200 && status < 300) {
var json = js2o(xhtr.responseText); var json = js2o(xhtr.responseText);
gridprint_tracker(host,json.key); gridhost_tracker(host,json.key);
ajax(host+"/api/wait?key="+json.key, function(data) { ajax(host+"/api/wait?key="+json.key, function(data) {
data = js2o(data); data = js2o(data);
DBUG.log(data); DBUG.log(data);
@ -1205,8 +1208,8 @@ self.kiri.license = exports.LICENSE;
UI.print.innerHTML = html; UI.print.innerHTML = html;
$('print-close').onclick = hideModal; $('print-close').onclick = hideModal;
$('print-download').onclick = download; $('print-download').onclick = download;
$('print-octoprint').onclick = octoprint; $('print-octoprint').onclick = sendto_octoprint;
$('print-gridprint').onclick = gridprint; $('print-gridhost').onclick = sendto_gridhost;
$('print-serial').onclick = showSerial; $('print-serial').onclick = showSerial;
$('print-serial').style.display = MODE === MODES.CAM ? '' : 'none'; $('print-serial').style.display = MODE === MODES.CAM ? '' : 'none';
$('print-filament-row').style.display = MODE === MODES.FDM ? '' : 'none'; $('print-filament-row').style.display = MODE === MODES.FDM ? '' : 'none';
@ -1214,8 +1217,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-host').onkeyup = gridhost_probe;
$('grid-apik').onkeyup = gridprint_probe; $('grid-apik').onkeyup = gridhost_probe;
calcTime(); calcTime();
calcWeight(); calcWeight();
octo_host = $('octo-host'); octo_host = $('octo-host');
@ -1224,7 +1227,7 @@ self.kiri.license = exports.LICENSE;
$('ophost').style.display = 'none'; $('ophost').style.display = 'none';
$('opapik').style.display = 'none'; $('opapik').style.display = 'none';
$('ophint').style.display = 'none'; $('ophint').style.display = 'none';
$('send-to-gridprint').style.display = 'none'; $('send-to-gridhost').style.display = 'none';
} }
octo_host.value = SDB['octo-host'] || ''; octo_host.value = SDB['octo-host'] || '';
octo_apik.value = SDB['octo-apik'] || ''; octo_apik.value = SDB['octo-apik'] || '';
@ -1236,7 +1239,7 @@ self.kiri.license = exports.LICENSE;
}; };
grid_host.value = SDB['grid-host'] || ''; grid_host.value = SDB['grid-host'] || '';
grid_apik.value = SDB['grid-apik'] || ''; grid_apik.value = SDB['grid-apik'] || '';
gridprint_probe(); gridhost_probe();
showModal('print'); showModal('print');
}); });
} }

View file

@ -36,9 +36,9 @@
</table> </table>
</div> </div>
<div class="print-sel" id="send-to-gridprint"> <div class="print-sel" id="send-to-gridhost">
<table> <table>
<tr><th colspan="2"><button id="print-gridprint">send to grid:host</button></th></tr> <tr><th colspan="2"><button id="print-gridhost">send to grid:host</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> <tr><th>target</th><td>