diff --git a/.gitignore b/.gitignore index b56c68b..53b0e4b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ -jspm_packages/* \ No newline at end of file +jspm_packages/* +example/test.gcode + +build.js + +build.js.map diff --git a/README.md b/README.md index a73c584..1bf105f 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,24 @@ Doodle3D API for communication with the Doodle3D WiFi-Box ```javascript -import Doodle3DAPI from 'doodle3dapi'; +import { Doodle3DManager } from 'Doodle3D/Doodle3D-API'; -var localIP = "192.168.5.1"; -var doodle3DAPI = new Doodle3DAPI(localIP); -doodle3DAPI.onconnect = function () { +const doodle3DManager = new Doodle3DManager(); -}; -doodle3DAPI.ondisconnect = function () { +doodle3DManager.addEventListener('boxappeared', ({box}) => { + box.addEventListener('connect', (event) => { + }); -}; -doodle3DAPI.onupdate = function (data) { + box.addEventListener('disconnect', (event) => { + }); + + box.addEventListener('update', (event) => { + const status = event.state; + }); + + box.setAutoUpdate(true, 1000); +}); + +doodle3DManager.setAutoUpdate(true, 1000); -}; -doodle3DAPI.startUpdateLoop(); ``` diff --git a/config.js b/config.js deleted file mode 100644 index e32f34d..0000000 --- a/config.js +++ /dev/null @@ -1,37 +0,0 @@ -System.config({ - "baseURL": "/", - "defaultJSExtensions": true, - "transpiler": "babel", - "babelOptions": { - "optional": [ - "runtime" - ] - }, - "paths": { - "github:*": "jspm_packages/github/*", - "npm:*": "jspm_packages/npm/*" - } -}); - -System.config({ - "map": { - "babel": "npm:babel-core@5.7.4", - "babel-runtime": "npm:babel-runtime@5.7.0", - "core-js": "npm:core-js@0.9.18", - "github/fetch": "github:github/fetch@0.9.0", - "traceur": "github:jmcriffey/bower-traceur@0.0.90", - "traceur-runtime": "github:jmcriffey/bower-traceur-runtime@0.0.90", - "github:jspm/nodelibs-process@0.1.1": { - "process": "npm:process@0.10.1" - }, - "npm:babel-runtime@5.7.0": { - "process": "github:jspm/nodelibs-process@0.1.1" - }, - "npm:core-js@0.9.18": { - "fs": "github:jspm/nodelibs-fs@0.1.2", - "process": "github:jspm/nodelibs-process@0.1.1", - "systemjs-json": "github:systemjs/plugin-json@0.1.0" - } - } -}); - diff --git a/example/app.js b/example/app.js index eb130bf..c90aeec 100644 --- a/example/app.js +++ b/example/app.js @@ -1,106 +1,28 @@ -import Doodle3DAPI from 'src/index.js'; -import * as rest from 'src/restapi.js'; +import { Doodle3DManager } from 'src/index.js'; -var api = 'http://connect.doodle3d.com/api/'; +const doodle3DManager = new Doodle3DManager(); +doodle3DManager.setAutoUpdate(true, 1000); -var addBox = (function () { - var known = []; +doodle3DManager.addEventListener('boxappeared', ({ box }) => { + box.setAutoUpdate(true, 1000); - return function (boxData) { - if (known.indexOf(boxData.localip) === -1) { - known.push(boxData.localip); + box.addEventListener('connect', () => { + console.log('connect to box', box); + }); - var row = document.createElement('tr'); - row.style.color = 'gray'; + box.addEventListener('disconnect', () => { + console.log('disonnect to box', box); + }) - 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'); - - 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); - - id.innerHTML = boxData.wifiboxid; - localIP.innerHTML = boxData.localip; - - document.getElementById('table').appendChild(row); - - var doodle3DAPI = new Doodle3DAPI(boxData.localip); - doodle3DAPI.onconnect = function () { - row.style.color = 'black'; - }; - doodle3DAPI.ondisconnect = function () { - row.style.color = 'gray'; - }; - doodle3DAPI.onupdate = function (data) { - state.innerHTML = data.state; - if (data.state !== 'disconnected' && data.state !== 'connecting' && data.state !== 'unknown') { - bed.innerHTML = data.bed; - bedTarget.innerHTML = data.bed_target; - bufferedLines.innerHTML = data.buffered_lines; - currentLine.innerHTML = data.current_line; - hasControl.innerHTML = data.has_control; - hotend.innerHTML = data.hotend; - hotendTarget.innerHTML = data.hotend_target; - state.innerHTML = data.state; - totalLines.innerHTML = data.total_lines; - } - else { - bed.innerHTML = ''; - bedTarget.innerHTML = ''; - bufferedLines.innerHTML = ''; - currentLine.innerHTML = ''; - hasControl.innerHTML = ''; - hotend.innerHTML = ''; - hotendTarget.innerHTML = ''; - state.innerHTML = ''; - totalLines.innerHTML = ''; - } - }; - doodle3DAPI.startUpdateLoop(); - } - } -})(); - -function searchBoxes () { - rest.get(api + 'list.php').then((boxes) => { - for (var i = 0; i < boxes.length; i ++) { - var box = boxes[i]; - - addBox(box); - } - }); -} -setInterval(searchBoxes, 5000); -searchBoxes(); - -/* -addBox({ - localip: '127.0.0.1:3000', - wifiboxid: 'Node Server' + box.addEventListener('update', ({ state }) => { + console.log(state); + }); }); - -addBox({ - localip: '192.168.5.1', - wifiboxid: 'Wired Printer' +doodle3DManager.addEventListener('boxdisappeared', ({ box }) => { + box.setAutoUpdate(false); }); -*/ \ No newline at end of file +doodle3DManager.addEventListener('boxeschanged', ({ boxes }) => { + +}); diff --git a/example/index.html b/example/index.html index bedade4..f40af86 100644 --- a/example/index.html +++ b/example/index.html @@ -1,45 +1,14 @@
+ID | -Local IP | -State | -Current Line | -Buffered Lines | -Total Lines | -Hotend | -Hotend Target | -Bed | -Bed Target | -Has Control | -
---|