Merge branch 'develop'

This commit is contained in:
casperlamboo 2017-02-15 18:01:08 +01:00
commit 7aecffb876
7 changed files with 26 additions and 32 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
jspm_packages/*
example/test.gcode
node_modules/*
build.js

View File

@ -12,7 +12,7 @@ doodle3DManager.addEventListener('boxappeared', ({ box }) => {
box.addEventListener('disconnect', () => {
console.log('disonnect to box', box);
})
});
box.addEventListener('update', ({ state }) => {
console.log(state);

View File

@ -50,5 +50,8 @@
}
}
}
},
"dependencies": {
"jspm": "^0.17.0-beta.25"
}
}

View File

@ -14,9 +14,7 @@ export default class Network {
return rest.get(`${ this.api }network/status`);
}
assosiate(ssid, phrase, recreate = false) {
const data = { ssid, recreate, phrase };
return rest.post(`${ this.api }network/associate`, data);
return rest.post(`${ this.api }network/associate`, { ssid, phrase, recreate });
}
disassociate() {
//not tested
@ -27,9 +25,7 @@ export default class Network {
return rest.post(`${ this.api }network/openap`, {});
}
remove(ssid) {
return rest.post(`${ this.api }network/remove`, {
'ssid': ssid
});
return rest.post(`${ this.api }network/remove`, { ssid });
}
signin() {
return rest.get(`${ this.api }network/signin`);

View File

@ -20,13 +20,22 @@ export default class Printer {
return rest.post(`${ this.api }printer/heatup`, {});
}
print(gcode = '', first = false, start = false, last) {
const data = { gcode, first, start, last };
return rest.post(`${ this.api }printer/print`, data);
return rest.post(`${ this.api }printer/print`, { gcode, first, start, last });
}
stop(gcode = '') {
const data = { gcode };
return rest.post(`${ this.api }printer/stop`, { gcode });
}
async _sendBatch(gcode, start, index) {
try {
const response = await this.print(gcode, start, start);
return rest.post(`${ this.api }printer/stop`, data);
console.log(`batch sent: ${ index }`);
} catch(error) {
console.log(`failed sending batch: ${ index }`);
await sleep(1000);
await this._sendBatch(gcode, index);
}
}
}

View File

@ -33,7 +33,7 @@ export default class Doodle3DBox extends EventDispatcher {
}
setAutoUpdate(autoUpdate = true, updateInterval = 1000) {
this.updateInterval = updateInterval;
if (this.autoUpdate === autoUpdate) return;
if (this.autoUpdate === autoUpdate) return this;
this.autoUpdate = autoUpdate;
if (autoUpdate) this._update();
@ -69,7 +69,7 @@ export default class Doodle3DBox extends EventDispatcher {
// const progress = await this.printer.progress();
await this._sendBatch(batch, start);
await this.printer._sendBatch(batch, start, index);
start = false;
lastIndex = index + 1; //skip next \n
@ -92,18 +92,4 @@ export default class Doodle3DBox extends EventDispatcher {
await sleep(this.updateInterval);
}
}
async _sendBatch(gcode, start) {
try {
const response = await this.printer.print(gcode, start, start);
// maybe do something with failing response
console.log(`batch sent: ${ index }`);
} catch(error) {
console.log(`failed sending batch: ${ index }`);
await sleep(1000);
await this._sendBatch(gcode, index);
}
}
}

View File

@ -18,13 +18,13 @@ export default class Doodle3DManager extends EventDispatcher {
wifiboxid: 'Node JS Server',
localip: '127.0.0.1:3000'
}*/];
this.checkNonServerBoxes = false;
this.checkNonServerBoxes = true;
this.autoUpdate = false;
}
setAutoUpdate(autoUpdate = true, updateInterval = 1000) {
this.updateInterval = updateInterval;
if (this.autoUpdate === autoUpdate) return;
if (this.autoUpdate === autoUpdate) return this;
this.autoUpdate = autoUpdate;
if (autoUpdate) this._update();
@ -39,12 +39,11 @@ export default class Doodle3DManager extends EventDispatcher {
}
}
async _checkNew() {
let boxes;
let boxes = [];
try {
boxes = await rest.get(`${ this.api }list.php`);
} catch(error) {
console.warn('fail connecting to Doodle3D server');
return;
}
if (this.checkNonServerBoxes) boxes = boxes.concat(this.nonServerBoxes);