2015-10-15 10:56:01 +02:00
|
|
|
import {Doodle3DManager} from 'src/index.js';
|
2015-07-15 15:06:18 +02:00
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
const doodle3DManager = new Doodle3DManager();
|
|
|
|
const TABLE = document.getElementById('table');
|
2015-07-27 16:32:11 +02:00
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
doodle3DManager.addEventListener('boxappeared', ({box}) => {
|
|
|
|
let row = document.createElement('tr');
|
|
|
|
row.id = box.boxData.wifiboxid;
|
2015-10-12 12:33:33 +02:00
|
|
|
row.style.color = 'black';
|
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
let id = document.createElement('td');
|
|
|
|
let state = document.createElement('td');
|
|
|
|
let localIP = document.createElement('td');
|
|
|
|
let bed = document.createElement('td');
|
|
|
|
let bedTarget = document.createElement('td');
|
|
|
|
let bufferedLines = document.createElement('td');
|
|
|
|
let currentLine = document.createElement('td');
|
|
|
|
let hasControl = document.createElement('td');
|
|
|
|
let hotend = document.createElement('td');
|
|
|
|
let hotendTarget = document.createElement('td');
|
|
|
|
let totalLines = document.createElement('td');
|
2015-10-12 12:33:33 +02:00
|
|
|
|
|
|
|
row.appendChild(id);
|
|
|
|
row.appendChild(localIP);
|
|
|
|
row.appendChild(state);
|
|
|
|
row.appendChild(currentLine);
|
|
|
|
row.appendChild(bufferedLines);
|
|
|
|
row.appendChild(totalLines);
|
|
|
|
row.appendChild(hotend);
|
|
|
|
row.appendChild(hotendTarget);
|
|
|
|
row.appendChild(bed);
|
|
|
|
row.appendChild(bedTarget);
|
|
|
|
row.appendChild(hasControl);
|
|
|
|
|
|
|
|
id.innerHTML = box.boxData.wifiboxid;
|
|
|
|
localIP.innerHTML = box.boxData.localip;
|
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
TABLE.appendChild(row);
|
2015-10-12 12:33:33 +02:00
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
function update ({state: data}) {
|
2015-10-12 12:33:33 +02:00
|
|
|
state.innerHTML = data.state;
|
|
|
|
|
|
|
|
if (data.state !== 'disconnected' && data.state !== 'connecting' && data.state !== 'unknown') {
|
|
|
|
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 {
|
|
|
|
bed.innerHTML = '';
|
|
|
|
bedTarget.innerHTML = '';
|
|
|
|
bufferedLines.innerHTML = '';
|
|
|
|
currentLine.innerHTML = '';
|
|
|
|
hasControl.innerHTML = '';
|
|
|
|
hotend.innerHTML = '';
|
|
|
|
hotendTarget.innerHTML = '';
|
|
|
|
totalLines.innerHTML = '';
|
|
|
|
}
|
2015-10-13 11:03:18 +02:00
|
|
|
}
|
2015-10-12 12:33:33 +02:00
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
if (box.alive) {
|
|
|
|
box.addEventListener('update', update);
|
2015-10-12 12:33:33 +02:00
|
|
|
}
|
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
box.addEventListener('connect', (event) => {
|
|
|
|
row.style.color = 'black';
|
2015-10-15 10:56:01 +02:00
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
box.addEventListener('update', update);
|
|
|
|
});
|
2015-10-12 12:33:33 +02:00
|
|
|
|
|
|
|
box.addEventListener('disconnect', (event) => {
|
2015-10-13 11:03:18 +02:00
|
|
|
row.style.color = 'gray';
|
2015-10-15 10:56:01 +02:00
|
|
|
|
2015-10-12 12:33:33 +02:00
|
|
|
box.removeEventListener('update', update);
|
|
|
|
});
|
2015-07-16 13:55:13 +02:00
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
box.setAutoUpdate(true, 1000);
|
|
|
|
});
|
2015-07-16 13:55:13 +02:00
|
|
|
|
2015-10-13 11:03:18 +02:00
|
|
|
doodle3DManager.addEventListener('boxdisappeared', ({box}) => {
|
|
|
|
let row = document.getElementById(box.boxData.wifiboxid);
|
|
|
|
TABLE.removeChild(row);
|
2015-07-23 19:12:50 +02:00
|
|
|
});
|
|
|
|
|
2015-10-12 12:33:33 +02:00
|
|
|
doodle3DManager.setAutoUpdate(true, 1000);
|