diff --git a/.gitignore b/.gitignore index 53b0e4b..25dcdde 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ jspm_packages/* example/test.gcode +node_modules/* build.js diff --git a/example/app.js b/example/app.js index c90aeec..4ee2141 100644 --- a/example/app.js +++ b/example/app.js @@ -12,7 +12,7 @@ doodle3DManager.addEventListener('boxappeared', ({ box }) => { box.addEventListener('disconnect', () => { console.log('disonnect to box', box); - }) + }); box.addEventListener('update', ({ state }) => { console.log(state); diff --git a/package.json b/package.json index 51e08e8..40487f4 100644 --- a/package.json +++ b/package.json @@ -50,5 +50,8 @@ } } } + }, + "dependencies": { + "jspm": "^0.17.0-beta.25" } } diff --git a/src/api/network.js b/src/api/network.js index 0348bc2..af15500 100644 --- a/src/api/network.js +++ b/src/api/network.js @@ -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`); diff --git a/src/api/printer.js b/src/api/printer.js index 1d1a53d..47bf979 100644 --- a/src/api/printer.js +++ b/src/api/printer.js @@ -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); + } } } diff --git a/src/doodle3dbox.js b/src/doodle3dbox.js index dfb7da6..fd3c6fe 100644 --- a/src/doodle3dbox.js +++ b/src/doodle3dbox.js @@ -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); - } - } } diff --git a/src/doodle3dmanager.js b/src/doodle3dmanager.js index 46d0615..3b8ddac 100644 --- a/src/doodle3dmanager.js +++ b/src/doodle3dmanager.js @@ -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);