0
0
mirror of https://github.com/Doodle3D/Doodle3D-API synced 2024-11-16 16:37:55 +01:00
Doodle3D-API/example/app.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

import Doodle3DManager from 'src/doodle3dmanager.js';
2015-07-15 15:06:18 +02:00
var doodle3DManager = new Doodle3DManager();
2015-07-15 15:06:18 +02:00
doodle3DManager.addEventListener('boxappeared', (event) => {
var box = event.box;
2015-07-15 15:06:18 +02:00
var row = document.createElement('tr');
row.style.color = 'gray';
2015-07-15 15:06:18 +02:00
var id = document.createElement('td');
var state = 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 totalLines = document.createElement('td');
2015-07-15 15:06:18 +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);
2015-07-15 15:06:18 +02:00
id.innerHTML = box.boxData.wifiboxid;
localIP.innerHTML = box.boxData.localip;
2015-07-15 15:06:18 +02:00
document.getElementById('table').appendChild(row);
2015-07-15 15:06:18 +02:00
box.addEventListener('connect', (event) => {
row.style.color = 'black';
});
2015-07-16 13:55:13 +02:00
box.addEventListener('disconnect', (event) => {
row.style.color = 'gray';
});
2015-07-16 13:55:13 +02:00
box.addEventListener('update', (event) => {
var status = event.state;
2015-07-16 13:55:13 +02:00
state.innerHTML = status.state;
if (status.state !== 'disconnected' && status.state !== 'connecting' && status.state !== 'unknown') {
bed.innerHTML = status.bed;
bedTarget.innerHTML = status.bed_target;
bufferedLines.innerHTML = status.buffered_lines;
currentLine.innerHTML = status.current_line;
hasControl.innerHTML = status.has_control;
hotend.innerHTML = status.hotend;
hotendTarget.innerHTML = status.hotend_target;
state.innerHTML = status.state;
totalLines.innerHTML = status.total_lines;
}
else {
bed.innerHTML = '';
bedTarget.innerHTML = '';
bufferedLines.innerHTML = '';
currentLine.innerHTML = '';
hasControl.innerHTML = '';
hotend.innerHTML = '';
hotendTarget.innerHTML = '';
state.innerHTML = '';
totalLines.innerHTML = '';
2015-07-15 15:06:18 +02:00
}
2015-07-16 13:55:13 +02:00
});
box.setAutoUpdate(true);
});
doodle3DManager.setAutoUpdate(true);