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