mirror of
https://github.com/Doodle3D/Doodle3D-API
synced 2024-12-22 22:03:48 +01:00
Merge branch 'develop'
This commit is contained in:
commit
e236858f27
12
.gitignore
vendored
12
.gitignore
vendored
@ -1,8 +1,4 @@
|
|||||||
|
node_modules
|
||||||
jspm_packages/*
|
dist
|
||||||
example/test.gcode
|
lib
|
||||||
node_modules/*
|
module
|
||||||
|
|
||||||
build.js
|
|
||||||
|
|
||||||
build.js.map
|
|
||||||
|
2
.npmignore
Normal file
2
.npmignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
jspm_packages
|
@ -1,28 +0,0 @@
|
|||||||
import { Doodle3DManager } from 'src/index.js';
|
|
||||||
|
|
||||||
const doodle3DManager = new Doodle3DManager();
|
|
||||||
doodle3DManager.setAutoUpdate(true, 1000);
|
|
||||||
|
|
||||||
doodle3DManager.addEventListener('boxappeared', ({ box }) => {
|
|
||||||
box.setAutoUpdate(true, 1000);
|
|
||||||
|
|
||||||
box.addEventListener('connect', () => {
|
|
||||||
console.log('connect to box', box);
|
|
||||||
});
|
|
||||||
|
|
||||||
box.addEventListener('disconnect', () => {
|
|
||||||
console.log('disonnect to box', box);
|
|
||||||
});
|
|
||||||
|
|
||||||
box.addEventListener('update', ({ state }) => {
|
|
||||||
console.log(state);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
doodle3DManager.addEventListener('boxdisappeared', ({ box }) => {
|
|
||||||
box.setAutoUpdate(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
doodle3DManager.addEventListener('boxeschanged', ({ boxes }) => {
|
|
||||||
|
|
||||||
});
|
|
@ -1,14 +0,0 @@
|
|||||||
<!DOCTYPE>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Doodle3D Box</title>
|
|
||||||
|
|
||||||
<script type="text/javascript" src="../jspm_packages/system.js"></script>
|
|
||||||
<script type="text/javascript" src="../jspm.config.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script type="text/javascript">
|
|
||||||
System.import('./app.js');
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
72
index.js
Normal file
72
index.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render } from 'react-dom';
|
||||||
|
import { Doodle3DManager } from './src/index.js';
|
||||||
|
|
||||||
|
class Box extends React.Component {
|
||||||
|
state = {
|
||||||
|
status: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
const { box } = this.props;
|
||||||
|
box.setAutoUpdate(true, 1000);
|
||||||
|
|
||||||
|
box.addEventListener('update', ({ state }) => {
|
||||||
|
this.setState({ status: state });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnMount() {
|
||||||
|
const { box } = this.props;
|
||||||
|
box.setAutoUpdate(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p><b>name: {this.props.box.boxData.wifiboxid}</b></p>
|
||||||
|
<ul>
|
||||||
|
{Object.entries(this.state.status).map(([key, value]) => <li key={key}>{key}: {value}</li>)}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class OverView extends React.Component {
|
||||||
|
state = {
|
||||||
|
boxes: []
|
||||||
|
};
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
const doodle3DManager = new Doodle3DManager();
|
||||||
|
doodle3DManager.checkNonServerBoxes = false;
|
||||||
|
doodle3DManager.setAutoUpdate(true, 1000);
|
||||||
|
|
||||||
|
doodle3DManager.addEventListener('boxappeared', ({ box }) => {
|
||||||
|
this.setState({ boxes: [...this.state.boxes, <Box box={box} />] })
|
||||||
|
});
|
||||||
|
|
||||||
|
doodle3DManager.addEventListener('boxdisappeared', ({ box }) => {
|
||||||
|
this.setState({ boxes: this.state.boxes.filter(box => box.props.box.boxData.id !== box.boxData.id) })
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({ doodle3DManager })
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnMount() {
|
||||||
|
const { doodle3DManager } = this.state;
|
||||||
|
if (doodle3DManager) doodle3DManager.setAutoUpdate(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { boxes } = this.state;
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{boxes.map((box, i) => <span key={i}>{box}</span>)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
render(<OverView />, document.getElementById('app'));
|
@ -1,51 +0,0 @@
|
|||||||
SystemJS.config({
|
|
||||||
paths: {
|
|
||||||
"github:": "jspm_packages/github/",
|
|
||||||
"npm:": "jspm_packages/npm/",
|
|
||||||
"Doodle3D-API/": "src/"
|
|
||||||
},
|
|
||||||
browserConfig: {
|
|
||||||
"baseURL": "/"
|
|
||||||
},
|
|
||||||
devConfig: {
|
|
||||||
"map": {
|
|
||||||
"babel-runtime": "npm:babel-runtime@5.8.38",
|
|
||||||
"core-js": "npm:core-js@1.2.7",
|
|
||||||
"traceur": "github:jmcriffey/bower-traceur@0.0.90",
|
|
||||||
"traceur-runtime": "github:jmcriffey/bower-traceur-runtime@0.0.90",
|
|
||||||
"process": "github:jspm/nodelibs-process@0.2.0-alpha",
|
|
||||||
"fs": "github:jspm/nodelibs-fs@0.2.0-alpha",
|
|
||||||
"plugin-babel": "npm:systemjs-plugin-babel@0.0.12",
|
|
||||||
"path": "github:jspm/nodelibs-path@0.2.0-alpha"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
transpiler: "plugin-babel",
|
|
||||||
babelOptions: {
|
|
||||||
"optional": [
|
|
||||||
"runtime"
|
|
||||||
],
|
|
||||||
"stage": 0
|
|
||||||
},
|
|
||||||
map: {
|
|
||||||
"babel": "npm:babel-core@5.7.4"
|
|
||||||
},
|
|
||||||
packages: {
|
|
||||||
"Doodle3D-API": {
|
|
||||||
"main": "index.js"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
SystemJS.config({
|
|
||||||
packageConfigPaths: [
|
|
||||||
"npm:@*/*.json",
|
|
||||||
"npm:*.json",
|
|
||||||
"github:*/*.json"
|
|
||||||
],
|
|
||||||
map: {
|
|
||||||
"EventDispatcher": "github:mrdoob/eventdispatcher.js@1.0.0",
|
|
||||||
"github/fetch": "github:github/fetch@0.9.0",
|
|
||||||
"jquery": "github:components/jquery@2.2.4"
|
|
||||||
},
|
|
||||||
packages: {}
|
|
||||||
});
|
|
7170
package-lock.json
generated
Normal file
7170
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
97
package.json
97
package.json
@ -1,57 +1,58 @@
|
|||||||
{
|
{
|
||||||
"jspm": {
|
"name": "@doodle3d/doodle3d-api",
|
||||||
"name": "Doodle3D-API",
|
"version": "1.0.0",
|
||||||
"main": "index.js",
|
"description": "Doodle3D API for communication with the Doodle3D WiFi-Box",
|
||||||
"directories": {
|
"main": "lib/index.js",
|
||||||
"lib": "src"
|
"module": "module/index.js",
|
||||||
|
"esnext": "src/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "webpack-dev-server -w",
|
||||||
|
"prepare": "npm run build",
|
||||||
|
"build": "npm run build:main && npm run build:module",
|
||||||
|
"build:main": "BABEL_ENV=main babel src -s -d lib",
|
||||||
|
"build:module": "BABEL_ENV=module babel src -s -d module"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"EventDispatcher": "github:mrdoob/eventdispatcher.js@^1.0.0",
|
"eventdispatcher.js": "0.0.2",
|
||||||
"github/fetch": "github:github/fetch@^0.9.0",
|
"whatwg-fetch": "^2.0.3"
|
||||||
"jquery": "github:components/jquery@^2.1.4"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-runtime": "npm:babel-runtime@^5.1.13",
|
"react": "^16.0.0",
|
||||||
"core-js": "npm:core-js@^1.2.0",
|
"react-dom": "^16.0.0",
|
||||||
"fs": "github:jspm/nodelibs-fs@^0.2.0-alpha",
|
"babel-plugin-inline-import": "^2.0.6",
|
||||||
"path": "github:jspm/nodelibs-path@^0.2.0-alpha",
|
"babel-preset-stage-0": "^6.24.1",
|
||||||
"plugin-babel": "npm:systemjs-plugin-babel@^0.0.12",
|
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
||||||
"process": "github:jspm/nodelibs-process@^0.2.0-alpha",
|
"babel-plugin-transform-class-properties": "^6.24.1",
|
||||||
"traceur": "github:jmcriffey/bower-traceur@0.0.90",
|
"babel-plugin-transform-es2015-classes": "^6.24.1",
|
||||||
"traceur-runtime": "github:jmcriffey/bower-traceur-runtime@0.0.90"
|
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||||
|
"babel-preset-env": "^1.6.1",
|
||||||
|
"babel-preset-react": "^6.24.1",
|
||||||
|
"babel-cli": "6.24.1",
|
||||||
|
"babel-core": "6.24.1",
|
||||||
|
"babel-loader": "7.0.0",
|
||||||
|
"babel-plugin-add-module-exports": "0.2.1",
|
||||||
|
"babel-preset-es2015": "6.24.1",
|
||||||
|
"babel-polyfill": "^6.23.0",
|
||||||
|
"file-saver": "^1.3.3",
|
||||||
|
"html-webpack-template": "^6.0.2",
|
||||||
|
"imports-loader": "^0.7.1",
|
||||||
|
"material-ui": "^0.19.4",
|
||||||
|
"react-tap-event-plugin": "^3.0.2",
|
||||||
|
"url-loader": "^0.5.9",
|
||||||
|
"babel-plugin-transform-runtime": "^6.23.0",
|
||||||
|
"html-webpack-plugin": "^2.29.0",
|
||||||
|
"webpack": "^3.3.0",
|
||||||
|
"webpack-dev-server": "^2.5.1",
|
||||||
|
"worker-loader": "^0.8.1"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"repository": {
|
||||||
"github:components/jquery@2.2.4": {
|
"type": "git",
|
||||||
"main": "jquery"
|
"url": "git+https://github.com/casperlamboo/Doodle3D-API.git"
|
||||||
},
|
},
|
||||||
"github:jmcriffey/bower-traceur-runtime@0.0.90": {
|
"author": "",
|
||||||
"format": "global",
|
"license": "ISC",
|
||||||
"meta": {
|
"bugs": {
|
||||||
"traceur-runtime.js": {
|
"url": "https://github.com/casperlamboo/Doodle3D-API/issues"
|
||||||
"exports": "$traceurRuntime",
|
|
||||||
"format": "global"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"github:jmcriffey/bower-traceur@0.0.90": {
|
"homepage": "https://github.com/casperlamboo/Doodle3D-API#readme"
|
||||||
"format": "global",
|
|
||||||
"meta": {
|
|
||||||
"traceur.js": {
|
|
||||||
"exports": "traceur",
|
|
||||||
"format": "global"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"npm:babel-runtime@5.8.38": {
|
|
||||||
"main": false,
|
|
||||||
"dependencies": {},
|
|
||||||
"optionalDependencies": {
|
|
||||||
"core-js": "^1.2.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"jspm": "^0.17.0-beta.25"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
import * as rest from '../rest.js';
|
import { parseFetch } from '../utils.js';
|
||||||
|
|
||||||
export default class Config {
|
export default class Config {
|
||||||
constructor(api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
get(...keys) {
|
get(...keys) {
|
||||||
return rest.get(`${ this.api }config/?${ keys.join('=&') }=`);
|
return fetch(`${this.api}config/?${keys.join('=&')}=`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
getAll() {
|
getAll() {
|
||||||
return rest.get(`${ this.api }config/all`);
|
return fetch(`${this.api}config/all`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
set(data) {
|
set(data) {
|
||||||
return rest.post(`${ this.api }config`, data);
|
return fetch(`${this.api}config`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
import * as rest from '../rest.js';
|
import { parseFetch } from '../utils.js';
|
||||||
|
|
||||||
export default class Info {
|
export default class Info {
|
||||||
constructor(api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
get() {
|
get() {
|
||||||
return rest.get(`${ this.api }info`);
|
return fetch(`${this.api}info`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
status() {
|
status() {
|
||||||
return rest.get(`${ this.api }info/status`);
|
return fetch(`${this.api}info/status`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
downloadLogFiles() {
|
downloadLogFiles() {
|
||||||
window.location = `${ this.api }info/logfiles`;
|
window.location = `${this.api}info/logfiles`;
|
||||||
}
|
}
|
||||||
acces() {
|
acces() {
|
||||||
return rest.get(`${ this.api }info/access`);
|
return fetch(`${this.api}info/access`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,54 @@
|
|||||||
import * as rest from '../rest.js';
|
import { parseFetch } from '../utils.js';
|
||||||
|
|
||||||
export default class Network {
|
export default class Network {
|
||||||
constructor(api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
scan() {
|
scan() {
|
||||||
return rest.get(`${ this.api }network/scan`);
|
return fecth(`${this.api}network/scan`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
known() {
|
known() {
|
||||||
return rest.get(`${ this.api }network/known`);
|
return fecth(`${this.api}network/known`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
status() {
|
status() {
|
||||||
return rest.get(`${ this.api }network/status`);
|
return fecth(`${this.api}network/status`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
assosiate(ssid, phrase, recreate = false) {
|
assosiate(ssid, phrase, recreate = false) {
|
||||||
return rest.post(`${ this.api }network/associate`, { ssid, phrase, recreate });
|
return fetch(`${this.api}network/associate`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ ssid, phrase, recreate })
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
disassociate() {
|
disassociate() {
|
||||||
//not tested
|
//not tested
|
||||||
return rest.post(`${ this.api }network/disassociate`, {});
|
return fetch(`${this.api}network/disassociate`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({})
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
openAccesPoint() {
|
openAccesPoint() {
|
||||||
//not tested
|
//not tested
|
||||||
return rest.post(`${ this.api }network/openap`, {});
|
return fetch(`${this.api}network/openap`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({})
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
remove(ssid) {
|
remove(ssid) {
|
||||||
return rest.post(`${ this.api }network/remove`, { ssid });
|
return fetch(`${this.api}network/remove`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ ssid })
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
signin() {
|
signin() {
|
||||||
return rest.get(`${ this.api }network/signin`);
|
return fecth(`${this.api}network/signin`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
async alive() {
|
async alive() {
|
||||||
try {
|
try {
|
||||||
await rest.get(`${ this.api }network/alive`);
|
await fetch(`${this.api}network/alive`, { method: 'GET' }).then(parseFetch);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,40 +1,49 @@
|
|||||||
import * as rest from '../rest.js';
|
import { parseFetch, sleep } from '../utils.js';
|
||||||
|
|
||||||
export default class Printer {
|
export default class Printer {
|
||||||
constructor(api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
temperature() {
|
temperature() {
|
||||||
return rest.get(`${ this.api }printer/temperature`);
|
return fetch(`${this.api}printer/temperature`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
progress() {
|
progress() {
|
||||||
return rest.get(`${ this.api }printer/progress`);
|
return fetch(`${this.api}printer/progress`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
state() {
|
state() {
|
||||||
return rest.get(`${ this.api }printer/state`);
|
return fetch(`${this.api}printer/state`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
listAll() {
|
listAll() {
|
||||||
return rest.get(`${ this.api }printer/listall`);
|
return fetch(`${this.api}printer/listall`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
heatup() {
|
heatup() {
|
||||||
return rest.post(`${ this.api }printer/heatup`, {});
|
return fetch(`${this.api}printer/heatup`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({})
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
print(gcode = '', first = false, start = false, last) {
|
print(gcode = '', first = false, start = false, last) {
|
||||||
return rest.post(`${ this.api }printer/print`, { gcode, first, start, last });
|
return fetch(`${this.api}printer/print`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ gcode, first, start, last })
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
stop(gcode = '') {
|
stop(gcode = '') {
|
||||||
return rest.post(`${ this.api }printer/stop`, { gcode });
|
return fetch(`${this.api}printer/stop`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ gcode, first, start, last })
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
async _sendBatch(gcode, start, index) {
|
async _sendBatch(gcode, start, index) {
|
||||||
try {
|
try {
|
||||||
const response = await this.print(gcode, start, start);
|
const response = await this.print(gcode, start, start);
|
||||||
|
console.log(`batch sent: ${index}`);
|
||||||
console.log(`batch sent: ${ index }`);
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.log(`failed sending batch: ${ index }`);
|
console.log(`failed sending batch: ${index}`);
|
||||||
|
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
|
|
||||||
await this._sendBatch(gcode, index);
|
await this._sendBatch(gcode, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,27 @@
|
|||||||
import * as rest from '../rest.js';
|
import { parseFetch } from '../utils.js';
|
||||||
|
|
||||||
export default class Sketch {
|
export default class Sketch {
|
||||||
constructor(api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
getSketch(id) {
|
getSketch(id) {
|
||||||
return rest.get(`${ this.api }sketch/?id=${ id }`);
|
return fetch(`${this.api}sketch/?id=${id}`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
set(data = '') {
|
set(data = '') {
|
||||||
return rest.post(`${ this.api }sketch`, { data });
|
return fetch(`${this.api}sketch`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ data })
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
status() {
|
status() {
|
||||||
return rest.get(`${ this.api }sketch/status`);
|
return fetch(`${this.api}sketch/status`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
clear() {
|
clear() {
|
||||||
return rest.post(`${ this.api }sketch/clear`);
|
return fetch(`${this.api}sketch/clear`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({})
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import * as rest from '../rest.js';
|
import { parseFetch } from '../utils.js';
|
||||||
|
|
||||||
export default class System {
|
export default class System {
|
||||||
constructor(api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
versions() {
|
versions() {
|
||||||
return rest.get(`${ this.api }system/fwversions`);
|
return fetch(`${this.api}system/fwversions`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,34 @@
|
|||||||
import * as rest from '../rest.js';
|
import { parseFetch } from '../utils.js';
|
||||||
|
|
||||||
export default class Update {
|
export default class Update {
|
||||||
constructor(api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
status() {
|
status() {
|
||||||
return rest.get(`${ this.api }update/status`);
|
return fetch(`${this.api}update/status`, { method: 'GET' }).then(parseFetch);
|
||||||
}
|
}
|
||||||
download() {
|
download() {
|
||||||
//not tested
|
//not tested
|
||||||
return rest.post(`${ this.api }update/download`, {});
|
return fetch(`${this.api}update/download`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({})
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
install() {
|
install() {
|
||||||
//not tested
|
//not tested
|
||||||
return rest.post(`${ this.api }update/install`, {});
|
return fetch(`${this.api}update/install`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({})
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
clear() {
|
clear() {
|
||||||
//not tested
|
//not tested
|
||||||
return rest.post(`${ this.api }update/clear`, {});
|
return fetch(`${this.api}update/clear`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({})
|
||||||
|
}).then(parseFetch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import EventDispatcher from 'EventDispatcher';
|
import EventDispatcher from 'eventdispatcher.js';
|
||||||
import { sleep } from './utils.js';
|
import { sleep } from './utils.js';
|
||||||
import ConfigAPI from './api/config.js';
|
import ConfigAPI from './api/config.js';
|
||||||
import InfoAPI from './api/info.js';
|
import InfoAPI from './api/info.js';
|
||||||
@ -14,7 +14,7 @@ export default class Doodle3DBox extends EventDispatcher {
|
|||||||
|
|
||||||
this.boxData = boxData;
|
this.boxData = boxData;
|
||||||
|
|
||||||
this.api = `http://${ boxData.localip }/d3dapi/`;
|
this.api = `http://${boxData.localip}/d3dapi/`;
|
||||||
|
|
||||||
this.alive = false;
|
this.alive = false;
|
||||||
this.autoUpdate = false;
|
this.autoUpdate = false;
|
||||||
@ -54,7 +54,7 @@ export default class Doodle3DBox extends EventDispatcher {
|
|||||||
async sendGCode(gcode) {
|
async sendGCode(gcode) {
|
||||||
const printerState = await this.printer.state();
|
const printerState = await this.printer.state();
|
||||||
if (printerState.state !== 'idle') {
|
if (printerState.state !== 'idle') {
|
||||||
throw `Cannot print, print state is ${ printerState.state }`;
|
throw `Cannot print, print state is ${printerState.state}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gcode.endsWith('\n')) {
|
if (!gcode.endsWith('\n')) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import * as rest from './rest.js';
|
|
||||||
import Doodle3DBox from './doodle3dbox.js';
|
import Doodle3DBox from './doodle3dbox.js';
|
||||||
import EventDispatcher from 'EventDispatcher';
|
import EventDispatcher from 'eventdispatcher.js';
|
||||||
import { sleep } from './utils.js';
|
import { sleep, parseFetch } from './utils.js';
|
||||||
|
|
||||||
export default class Doodle3DManager extends EventDispatcher {
|
export default class Doodle3DManager extends EventDispatcher {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -41,7 +40,7 @@ export default class Doodle3DManager extends EventDispatcher {
|
|||||||
async _checkNew() {
|
async _checkNew() {
|
||||||
let boxes = [];
|
let boxes = [];
|
||||||
try {
|
try {
|
||||||
boxes = await rest.get(`${ this.api }list.php`);
|
boxes = await fetch(`${this.api}list.php`, { method: 'GET' }).then(parseFetch);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.warn('fail connecting to Doodle3D server');
|
console.warn('fail connecting to Doodle3D server');
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'whatwg-fetch';
|
||||||
|
|
||||||
import Doodle3DManager from './doodle3dmanager.js';
|
import Doodle3DManager from './doodle3dmanager.js';
|
||||||
import Doodle3DBox from './doodle3dbox.js';
|
import Doodle3DBox from './doodle3dbox.js';
|
||||||
|
|
||||||
|
84
src/rest.js
84
src/rest.js
@ -1,84 +0,0 @@
|
|||||||
import $ from 'jquery';
|
|
||||||
|
|
||||||
const GET_TIMEOUT = 5000;
|
|
||||||
const POST_TIMEOUT = 10000;
|
|
||||||
|
|
||||||
export function get(url) {
|
|
||||||
return send(url, 'GET');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function post(url, data) {
|
|
||||||
return send(url, 'POST', data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function send(url, type, data) {
|
|
||||||
const timeout = (type === 'GET') ? GET_TIMEOUT : POST_TIMEOUT;
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
$.ajax({
|
|
||||||
url, type, data, timeout, dataType: 'json',
|
|
||||||
success: (response) => {
|
|
||||||
if (response.status === 'success') {
|
|
||||||
resolve(response.data);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
reject(response.msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).fail(reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
import 'github/fetch';
|
|
||||||
|
|
||||||
export function get (url) {
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
|
|
||||||
fetch(url).then((response) => {
|
|
||||||
|
|
||||||
return response.json();
|
|
||||||
|
|
||||||
}).then((json) => {
|
|
||||||
|
|
||||||
if (json.status === 'success') {
|
|
||||||
resolve(json.data);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
reject(json.msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}).catch(reject);
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function post (url, data) {
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
|
|
||||||
fetch(url, {
|
|
||||||
method: 'post',
|
|
||||||
enctype: 'x-www-form-urlencoded',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data)
|
|
||||||
}).then((response) => {
|
|
||||||
|
|
||||||
return response.json();
|
|
||||||
|
|
||||||
}).then((json) => {
|
|
||||||
|
|
||||||
if (json.status === 'success') {
|
|
||||||
resolve(json.data);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
reject(json.msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}).catch(reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
@ -3,3 +3,10 @@ export function sleep(time) {
|
|||||||
setTimeout(resolve, time);
|
setTimeout(resolve, time);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parseFetch(response) {
|
||||||
|
return response.json().then(({ status, data, msg }) => {
|
||||||
|
if (!status === 'success') throw new Error(msg);
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
159423
test.gcode
Normal file
159423
test.gcode
Normal file
File diff suppressed because it is too large
Load Diff
54
webpack.config.js
Normal file
54
webpack.config.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
const path = require('path');
|
||||||
|
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||||
|
const HTMLWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
|
||||||
|
const babelLoader = {
|
||||||
|
loader: 'babel-loader',
|
||||||
|
options: {
|
||||||
|
presets: [
|
||||||
|
require('babel-preset-env'),
|
||||||
|
require('babel-preset-react')
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
require('babel-plugin-transform-object-rest-spread'),
|
||||||
|
require('babel-plugin-transform-class-properties'),
|
||||||
|
require('babel-plugin-transform-runtime')
|
||||||
|
],
|
||||||
|
babelrc: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: './index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'bundle.js',
|
||||||
|
path: path.resolve(__dirname, 'dist')
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: babelLoader
|
||||||
|
}, { // make THREE global available to three.js examples
|
||||||
|
test: /three\/examples\/.+\.js/,
|
||||||
|
use: 'imports-loader?THREE=three'
|
||||||
|
}, {
|
||||||
|
test: /\.worker\.js$/,
|
||||||
|
use: ['worker-loader', babelLoader]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new HTMLWebpackPlugin({
|
||||||
|
title: 'Doodle3D API - Simple example',
|
||||||
|
template: require('html-webpack-template'),
|
||||||
|
inject: false,
|
||||||
|
appMountId: 'app'
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
devtool: "source-map",
|
||||||
|
devServer: {
|
||||||
|
contentBase: 'dist'
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user