0
0
mirror of https://github.com/Doodle3D/Doodle3D-API synced 2024-12-24 22:33:48 +01:00
Doodle3D-API/example/app.js

97 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-07-15 17:11:14 +02:00
import Doodle3DAPI from 'doodle3d-API';
import rest from 'rest-API';
2015-07-15 15:06:18 +02:00
var api = "http://connect.doodle3d.com/api/";
2015-07-16 13:55:13 +02:00
var known = [];
2015-07-15 15:06:18 +02:00
function addBox (boxData) {
2015-07-16 13:55:13 +02:00
if (know.indexOf(boxData.localip) === -1) {
known.push(boxData.localip);
2015-07-15 15:06:18 +02:00
2015-07-16 13:55:13 +02:00
var row = document.createElement('tr');
row.style.color = "gray";
2015-07-15 15:06:18 +02:00
2015-07-16 13:55:13 +02:00
var id = document.createElement('td');
var localIP = document.createElement('td');
var bed = document.createElement('td');
var bedTarget = document.createElement('td');
var bufferedLines = document.createElement('td');
var currentLine = document.createElement('td');
var hasControl = document.createElement('td');
var hotend = document.createElement('td');
var hotendTarget = document.createElement('td');
var state = document.createElement('td');
var totalLines = document.createElement('td');
2015-07-15 15:06:18 +02:00
2015-07-16 13:55:13 +02:00
row.appendChild(id);
row.appendChild(localIP);
row.appendChild(bed);
row.appendChild(bedTarget);
row.appendChild(bufferedLines);
row.appendChild(currentLine);
row.appendChild(hasControl);
row.appendChild(hotend);
row.appendChild(hotendTarget);
row.appendChild(state);
row.appendChild(totalLines);
2015-07-15 15:06:18 +02:00
2015-07-16 13:55:13 +02:00
id.innerHTML = boxData.wifiboxid;
localIP.innerHTML = boxData.localip;
2015-07-15 15:06:18 +02:00
2015-07-16 13:55:13 +02:00
document.getElementById("table").appendChild(row);
var doodle3DAPI = new Doodle3DAPI(boxData.localip);
doodle3DAPI.onconnect = function () {
row.style.color = "black";
};
doodle3DAPI.ondisconnect = function () {
row.style.color = "gray";
};
doodle3DAPI.onupdate = function (data) {
2015-07-15 15:06:18 +02:00
state.innerHTML = data.state;
2015-07-16 13:55:13 +02:00
if (data.state === "idle") {
bed.innerHTML = data.bed;
bedTarget.innerHTML = data.bed_target;
bufferedLines.innerHTML = data.buffered_lines;
currentLine.innerHTML = data.current_line;
hasControl.innerHTML = data.has_control;
hotend.innerHTML = data.hotend;
hotendTarget.innerHTML = data.hotend_target;
state.innerHTML = data.state;
totalLines.innerHTML = data.total_lines;
}
else {
}
};
doodle3DAPI.startUpdateLoop();
}
}
function searchBoxes () {
rest.get(api + "list.php", function (error, boxes) {
if (error) {
return;
console.warn(error);
2015-07-15 15:06:18 +02:00
}
2015-07-16 13:55:13 +02:00
for (var i = 0; i < boxes.length; i ++) {
var box = boxes[i];
addBox(box);
2015-07-15 15:06:18 +02:00
}
2015-07-16 13:55:13 +02:00
});
2015-07-15 15:06:18 +02:00
}
2015-07-16 13:55:13 +02:00
setInterval(searchBoxes, 5000);
searchBoxes();
2015-07-15 15:06:18 +02:00
2015-07-16 13:55:13 +02:00
addBox({
localip: window.location.host + ":3000",
wifiboxid: "Node Server"
2015-07-15 15:06:18 +02:00
});
addBox({
localip: "192.168.5.1",
wifiboxid: "Wired Printer"
});