mirror of
https://github.com/Doodle3D/Doodle3D-API
synced 2024-11-05 04:33:24 +01:00
fixed bug in example
This commit is contained in:
parent
76a7b02dc7
commit
528ddb7bc8
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
||||
|
||||
jspm_packages/*
|
||||
example/test.gcode
|
||||
|
||||
build.js
|
||||
|
||||
build.js.map
|
||||
|
19
config.js
19
config.js
@ -1,21 +1,19 @@
|
||||
System.config({
|
||||
"baseURL": "/",
|
||||
"defaultJSExtensions": true,
|
||||
"transpiler": "babel",
|
||||
"babelOptions": {
|
||||
baseURL: "/",
|
||||
defaultJSExtensions: true,
|
||||
transpiler: "babel",
|
||||
babelOptions: {
|
||||
"optional": [
|
||||
"runtime"
|
||||
],
|
||||
],
|
||||
"stage": 0
|
||||
},
|
||||
"paths": {
|
||||
paths: {
|
||||
"github:*": "jspm_packages/github/*",
|
||||
"npm:*": "jspm_packages/npm/*"
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
System.config({
|
||||
"map": {
|
||||
map: {
|
||||
"babel": "npm:babel-core@5.7.4",
|
||||
"babel-runtime": "npm:babel-runtime@5.7.0",
|
||||
"casperlamboo/EventDispatcher": "github:casperlamboo/EventDispatcher@master",
|
||||
@ -37,4 +35,3 @@ System.config({
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,26 +1,24 @@
|
||||
import Doodle3DManager from 'src/doodle3dmanager.js';
|
||||
|
||||
let list = document.getElementById('list');
|
||||
const doodle3DManager = new Doodle3DManager();
|
||||
const TABLE = document.getElementById('table');
|
||||
|
||||
let doodle3DManager = new Doodle3DManager();
|
||||
|
||||
doodle3DManager.addEventListener('boxappeared', async (event) => {
|
||||
let box = event.box;
|
||||
|
||||
var row = document.createElement('tr');
|
||||
doodle3DManager.addEventListener('boxappeared', ({box}) => {
|
||||
let row = document.createElement('tr');
|
||||
row.id = box.boxData.wifiboxid;
|
||||
row.style.color = 'black';
|
||||
|
||||
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');
|
||||
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');
|
||||
|
||||
row.appendChild(id);
|
||||
row.appendChild(localIP);
|
||||
@ -37,10 +35,9 @@ doodle3DManager.addEventListener('boxappeared', async (event) => {
|
||||
id.innerHTML = box.boxData.wifiboxid;
|
||||
localIP.innerHTML = box.boxData.localip;
|
||||
|
||||
document.getElementById('table').appendChild(row);
|
||||
TABLE.appendChild(row);
|
||||
|
||||
function update (event) {
|
||||
let data = event.state;
|
||||
function update ({state: data}) {
|
||||
state.innerHTML = data.state;
|
||||
|
||||
if (data.state !== 'disconnected' && data.state !== 'connecting' && data.state !== 'unknown') {
|
||||
@ -64,30 +61,30 @@ doodle3DManager.addEventListener('boxappeared', async (event) => {
|
||||
hotendTarget.innerHTML = '';
|
||||
totalLines.innerHTML = '';
|
||||
}
|
||||
};
|
||||
|
||||
box.setAutoUpdate(true, 1000);
|
||||
|
||||
function update (event) {
|
||||
console.log(event);
|
||||
}
|
||||
|
||||
box.addEventListener('update', update);
|
||||
if (box.alive) {
|
||||
box.addEventListener('update', update);
|
||||
}
|
||||
|
||||
box.addEventListener('connect', (event) => {
|
||||
row.style.color = 'black';
|
||||
|
||||
box.addEventListener('update', update);
|
||||
});
|
||||
|
||||
box.addEventListener('disconnect', (event) => {
|
||||
row.style.color = 'gray';
|
||||
|
||||
box.removeEventListener('update', update);
|
||||
});
|
||||
|
||||
box.setAutoUpdate(true, 1000);
|
||||
});
|
||||
|
||||
doodle3DManager.addEventListener('boxdisappeared', (event) => {
|
||||
let box = event.box;
|
||||
|
||||
for (let node of list.children) {
|
||||
if (node.innerHTML === box.boxData.wifiboxid) {
|
||||
list.removeChild(node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
doodle3DManager.addEventListener('boxdisappeared', ({box}) => {
|
||||
let row = document.getElementById(box.boxData.wifiboxid);
|
||||
TABLE.removeChild(row);
|
||||
});
|
||||
|
||||
doodle3DManager.setAutoUpdate(true, 1000);
|
||||
|
@ -80,6 +80,9 @@ export default class extends EventDispatcher {
|
||||
return;
|
||||
}
|
||||
|
||||
let autoUpdateState = this.autoUpdate;
|
||||
this.autoUpdate = false;
|
||||
|
||||
if (!gcode.endsWith('\n')) {
|
||||
gcode += '\n';
|
||||
}
|
||||
@ -95,17 +98,25 @@ export default class extends EventDispatcher {
|
||||
let progress = await this.printer.progress();
|
||||
|
||||
if (progress['buffered_lines'] + batch.length < this.maxBufferSize) {
|
||||
lastIndex = index + 1; //skip next \n
|
||||
try {
|
||||
await this._sendBatch(batch, start);
|
||||
|
||||
await this._sendBatch(batch, start);
|
||||
start = false;
|
||||
lastIndex = index + 1; //skip next \n
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error while sending gcode', error);
|
||||
|
||||
start = false;
|
||||
await sleep(this.fullBufferTimeout);
|
||||
}
|
||||
}
|
||||
else {
|
||||
await sleep(this.fullBufferTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
this.autoUpdate = autoUpdateState;
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
@ -131,8 +142,8 @@ export default class extends EventDispatcher {
|
||||
_sendBatch (gcode, index) {
|
||||
return new Promise (async (resolve, reject) => {
|
||||
try {
|
||||
let start = index === 0;
|
||||
let first = start;
|
||||
let first = index === 0;
|
||||
let start = first;
|
||||
let printRequest = await this.printer.print(gcode, first, start);
|
||||
|
||||
console.log(`batch sent: ${index}`, printRequest);
|
||||
|
@ -1,7 +1,5 @@
|
||||
export function sleep (time) {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, time);
|
||||
setTimeout(resolve, time);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user