mirror of
https://github.com/Doodle3D/Doodle3D-API
synced 2024-11-14 16:27:56 +01:00
comply with linter
This commit is contained in:
parent
fbd5d5bf2d
commit
48693feaab
@ -1,19 +1,16 @@
|
|||||||
import * as rest from '../rest.js';
|
import * as rest from '../rest.js';
|
||||||
|
|
||||||
export default class {
|
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 rest.get(`${ this.api }config/?${ keys.join('=&') }=`);
|
||||||
}
|
}
|
||||||
|
getAll() {
|
||||||
getAll () {
|
|
||||||
return rest.get(`${ this.api }config/all`);
|
return rest.get(`${ this.api }config/all`);
|
||||||
}
|
}
|
||||||
|
set(data) {
|
||||||
set (data) {
|
|
||||||
return rest.post(`${ this.api }config`, data);
|
return rest.post(`${ this.api }config`, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
import * as rest from '../rest.js';
|
import * as rest from '../rest.js';
|
||||||
|
|
||||||
export default class {
|
export default class Info {
|
||||||
constructor (api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
|
get() {
|
||||||
get () {
|
|
||||||
return rest.get(`${ this.api }info`);
|
return rest.get(`${ this.api }info`);
|
||||||
}
|
}
|
||||||
|
status() {
|
||||||
status () {
|
|
||||||
return rest.get(`${ this.api }info/status`);
|
return rest.get(`${ this.api }info/status`);
|
||||||
}
|
}
|
||||||
|
downloadLogFiles() {
|
||||||
downloadLogFiles () {
|
|
||||||
window.location = `${ this.api }info/logfiles`;
|
window.location = `${ this.api }info/logfiles`;
|
||||||
}
|
}
|
||||||
|
acces() {
|
||||||
acces () {
|
|
||||||
return rest.get(`${ this.api }info/access`);
|
return rest.get(`${ this.api }info/access`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,51 +1,40 @@
|
|||||||
import * as rest from '../rest.js';
|
import * as rest from '../rest.js';
|
||||||
|
|
||||||
export default class {
|
export default class Network {
|
||||||
constructor (api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
|
scan() {
|
||||||
scan () {
|
|
||||||
return rest.get(`${ this.api }network/scan`);
|
return rest.get(`${ this.api }network/scan`);
|
||||||
}
|
}
|
||||||
|
known() {
|
||||||
known () {
|
|
||||||
return rest.get(`${ this.api }network/known`);
|
return rest.get(`${ this.api }network/known`);
|
||||||
}
|
}
|
||||||
|
status() {
|
||||||
status () {
|
|
||||||
return rest.get(`${ this.api }network/status`);
|
return rest.get(`${ this.api }network/status`);
|
||||||
}
|
}
|
||||||
|
assosiate(ssid, phrase, recreate = false) {
|
||||||
assosiate (ssid, phrase, recreate = false) {
|
|
||||||
const data = { ssid, recreate, phrase };
|
const data = { ssid, recreate, phrase };
|
||||||
|
|
||||||
return rest.post(`${ this.api }network/associate`, data);
|
return rest.post(`${ this.api }network/associate`, data);
|
||||||
}
|
}
|
||||||
|
disassociate() {
|
||||||
disassociate () {
|
|
||||||
//not tested
|
//not tested
|
||||||
|
|
||||||
return rest.post(`${ this.api }network/disassociate`, {});
|
return rest.post(`${ this.api }network/disassociate`, {});
|
||||||
}
|
}
|
||||||
|
openAccesPoint() {
|
||||||
openAccesPoint () {
|
|
||||||
//not tested
|
//not tested
|
||||||
|
|
||||||
return rest.post(`${ this.api }network/openap`, {});
|
return rest.post(`${ this.api }network/openap`, {});
|
||||||
}
|
}
|
||||||
|
remove(ssid) {
|
||||||
remove (ssid) {
|
|
||||||
return rest.post(`${ this.api }network/remove`, {
|
return rest.post(`${ this.api }network/remove`, {
|
||||||
'ssid': ssid
|
'ssid': ssid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
signin() {
|
||||||
signin () {
|
|
||||||
return rest.get(`${ this.api }network/signin`);
|
return rest.get(`${ this.api }network/signin`);
|
||||||
}
|
}
|
||||||
|
async alive() {
|
||||||
async alive () {
|
|
||||||
try {
|
try {
|
||||||
await rest.get(`${ this.api }network/alive`);
|
await rest.get(`${ this.api }network/alive`);
|
||||||
|
|
||||||
|
@ -1,37 +1,30 @@
|
|||||||
import * as rest from '../rest.js';
|
import * as rest from '../rest.js';
|
||||||
|
|
||||||
export default class {
|
export default class Printer {
|
||||||
constructor (api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
|
temperature() {
|
||||||
temperature () {
|
|
||||||
return rest.get(`${ this.api }printer/temperature`);
|
return rest.get(`${ this.api }printer/temperature`);
|
||||||
}
|
}
|
||||||
|
progress() {
|
||||||
progress () {
|
|
||||||
return rest.get(`${ this.api }printer/progress`);
|
return rest.get(`${ this.api }printer/progress`);
|
||||||
}
|
}
|
||||||
|
state() {
|
||||||
state () {
|
|
||||||
return rest.get(`${ this.api }printer/state`);
|
return rest.get(`${ this.api }printer/state`);
|
||||||
}
|
}
|
||||||
|
listAll() {
|
||||||
listAll () {
|
|
||||||
return rest.get(`${ this.api }printer/listall`);
|
return rest.get(`${ this.api }printer/listall`);
|
||||||
}
|
}
|
||||||
|
heatup() {
|
||||||
heatup () {
|
|
||||||
return rest.post(`${ this.api }printer/heatup`, {});
|
return rest.post(`${ this.api }printer/heatup`, {});
|
||||||
}
|
}
|
||||||
|
print(gcode = '', first = false, start = false, last) {
|
||||||
print (gcode = '', first = false, start = false, last) {
|
|
||||||
const data = { gcode, first, start, last };
|
const data = { gcode, first, start, last };
|
||||||
|
|
||||||
return rest.post(`${ this.api }printer/print`, data);
|
return rest.post(`${ this.api }printer/print`, data);
|
||||||
}
|
}
|
||||||
|
stop(gcode = '') {
|
||||||
stop (gcode = '') {
|
|
||||||
const data = { gcode };
|
const data = { gcode };
|
||||||
|
|
||||||
return rest.post(`${ this.api }printer/stop`, data);
|
return rest.post(`${ this.api }printer/stop`, data);
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
import * as rest from '../rest.js';
|
import * as rest from '../rest.js';
|
||||||
|
|
||||||
export default class {
|
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 rest.get(`${ this.api }sketch/?id=${ id }`);
|
||||||
}
|
}
|
||||||
|
set(data = '') {
|
||||||
set (data = '') {
|
|
||||||
return rest.post(`${ this.api }sketch`, { data });
|
return rest.post(`${ this.api }sketch`, { data });
|
||||||
}
|
}
|
||||||
|
status() {
|
||||||
status () {
|
|
||||||
return rest.get(`${ this.api }sketch/status`);
|
return rest.get(`${ this.api }sketch/status`);
|
||||||
}
|
}
|
||||||
|
clear() {
|
||||||
clear () {
|
|
||||||
return rest.post(`${ this.api }sketch/clear`);
|
return rest.post(`${ this.api }sketch/clear`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import * as rest from '../rest.js';
|
import * as rest from '../rest.js';
|
||||||
|
|
||||||
export default class {
|
export default class System {
|
||||||
constructor (api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
|
versions() {
|
||||||
versions () {
|
|
||||||
return rest.get(`${ this.api }system/fwversions`);
|
return rest.get(`${ this.api }system/fwversions`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,22 @@
|
|||||||
import * as rest from '../rest.js';
|
import * as rest from '../rest.js';
|
||||||
|
|
||||||
export default class {
|
export default class Update {
|
||||||
constructor (api) {
|
constructor(api) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
|
status() {
|
||||||
status () {
|
|
||||||
return rest.get(`${ this.api }update/status`);
|
return rest.get(`${ this.api }update/status`);
|
||||||
}
|
}
|
||||||
|
download() {
|
||||||
download () {
|
|
||||||
//not tested
|
//not tested
|
||||||
|
|
||||||
return rest.post(`${ this.api }update/download`, {});
|
return rest.post(`${ this.api }update/download`, {});
|
||||||
}
|
}
|
||||||
|
install() {
|
||||||
install () {
|
|
||||||
//not tested
|
//not tested
|
||||||
|
|
||||||
return rest.post(`${ this.api }update/install`, {});
|
return rest.post(`${ this.api }update/install`, {});
|
||||||
}
|
}
|
||||||
|
clear() {
|
||||||
clear () {
|
|
||||||
//not tested
|
//not tested
|
||||||
|
|
||||||
return rest.post(`${ this.api }update/clear`, {});
|
return rest.post(`${ this.api }update/clear`, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import SystemAPI from './api/system.js';
|
|||||||
import UpdateAPI from './api/update.js';
|
import UpdateAPI from './api/update.js';
|
||||||
|
|
||||||
export default class Doodle3DBox extends EventDispatcher {
|
export default class Doodle3DBox extends EventDispatcher {
|
||||||
constructor (boxData) {
|
constructor(boxData) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.boxData = boxData;
|
this.boxData = boxData;
|
||||||
@ -31,8 +31,7 @@ export default class Doodle3DBox extends EventDispatcher {
|
|||||||
this.system = new SystemAPI(this.api);
|
this.system = new SystemAPI(this.api);
|
||||||
this.update = new UpdateAPI(this.api);
|
this.update = new UpdateAPI(this.api);
|
||||||
}
|
}
|
||||||
|
setAutoUpdate(autoUpdate = true, updateInterval = 1000) {
|
||||||
setAutoUpdate (autoUpdate = true, updateInterval = 1000) {
|
|
||||||
this.updateInterval = updateInterval;
|
this.updateInterval = updateInterval;
|
||||||
if (this.autoUpdate === autoUpdate) return;
|
if (this.autoUpdate === autoUpdate) return;
|
||||||
|
|
||||||
@ -41,8 +40,7 @@ export default class Doodle3DBox extends EventDispatcher {
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
async checkAlive() {
|
||||||
async checkAlive () {
|
|
||||||
const alive = await this.network.alive();
|
const alive = await this.network.alive();
|
||||||
|
|
||||||
if (alive !== this.alive) {
|
if (alive !== this.alive) {
|
||||||
@ -53,8 +51,7 @@ export default class Doodle3DBox extends EventDispatcher {
|
|||||||
this.alive = alive;
|
this.alive = alive;
|
||||||
return alive;
|
return alive;
|
||||||
}
|
}
|
||||||
|
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 }`;
|
||||||
@ -78,8 +75,7 @@ export default class Doodle3DBox extends EventDispatcher {
|
|||||||
lastIndex = index + 1; //skip next \n
|
lastIndex = index + 1; //skip next \n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async _update() {
|
||||||
async _update () {
|
|
||||||
while (this.autoUpdate) {
|
while (this.autoUpdate) {
|
||||||
if (this.alive) {
|
if (this.alive) {
|
||||||
try {
|
try {
|
||||||
@ -96,8 +92,7 @@ export default class Doodle3DBox extends EventDispatcher {
|
|||||||
await sleep(this.updateInterval);
|
await sleep(this.updateInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async _sendBatch(gcode, start) {
|
||||||
async _sendBatch (gcode, start) {
|
|
||||||
try {
|
try {
|
||||||
const response = await this.printer.print(gcode, start, start);
|
const response = await this.printer.print(gcode, start, start);
|
||||||
// maybe do something with failing response
|
// maybe do something with failing response
|
||||||
|
@ -4,7 +4,7 @@ import EventDispatcher from 'casperlamboo/EventDispatcher';
|
|||||||
import { sleep } from './utils.js';
|
import { sleep } from './utils.js';
|
||||||
|
|
||||||
export default class Doodle3DManager extends EventDispatcher {
|
export default class Doodle3DManager extends EventDispatcher {
|
||||||
constructor () {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.api = 'http://connect.doodle3d.com/api/';
|
this.api = 'http://connect.doodle3d.com/api/';
|
||||||
@ -22,8 +22,7 @@ export default class Doodle3DManager extends EventDispatcher {
|
|||||||
|
|
||||||
this.autoUpdate = false;
|
this.autoUpdate = false;
|
||||||
}
|
}
|
||||||
|
setAutoUpdate(autoUpdate = true, updateInterval = 1000) {
|
||||||
setAutoUpdate (autoUpdate = true, updateInterval = 1000) {
|
|
||||||
this.updateInterval = updateInterval;
|
this.updateInterval = updateInterval;
|
||||||
if (this.autoUpdate === autoUpdate) return;
|
if (this.autoUpdate === autoUpdate) return;
|
||||||
|
|
||||||
@ -32,16 +31,14 @@ export default class Doodle3DManager extends EventDispatcher {
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
async _update() {
|
||||||
async _update () {
|
|
||||||
while (this.autoUpdate) {
|
while (this.autoUpdate) {
|
||||||
await this._checkNew();
|
await this._checkNew();
|
||||||
|
|
||||||
await sleep(this.updateInterval);
|
await sleep(this.updateInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async _checkNew() {
|
||||||
async _checkNew () {
|
|
||||||
let boxes;
|
let boxes;
|
||||||
try {
|
try {
|
||||||
boxes = await rest.get(`${ this.api }list.php`);
|
boxes = await rest.get(`${ this.api }list.php`);
|
||||||
@ -76,14 +73,12 @@ export default class Doodle3DManager extends EventDispatcher {
|
|||||||
this.dispatchEvent({ type: 'boxeschanged', boxes: this.boxes });
|
this.dispatchEvent({ type: 'boxeschanged', boxes: this.boxes });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_addBox(box) {
|
||||||
_addBox (box) {
|
|
||||||
this.boxes.push(box);
|
this.boxes.push(box);
|
||||||
|
|
||||||
this.dispatchEvent({ type: 'boxappeared', box });
|
this.dispatchEvent({ type: 'boxappeared', box });
|
||||||
}
|
}
|
||||||
|
_removeBox(box) {
|
||||||
_removeBox (box) {
|
|
||||||
const index = this.boxes.indexOf(box);
|
const index = this.boxes.indexOf(box);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
this.boxes.splice(index, 1);
|
this.boxes.splice(index, 1);
|
||||||
|
@ -3,11 +3,11 @@ import $ from 'jquery';
|
|||||||
const GET_TIMEOUT = 5000;
|
const GET_TIMEOUT = 5000;
|
||||||
const POST_TIMEOUT = 10000;
|
const POST_TIMEOUT = 10000;
|
||||||
|
|
||||||
export function get (url) {
|
export function get(url) {
|
||||||
return send(url, 'GET');
|
return send(url, 'GET');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function post (url, data) {
|
export function post(url, data) {
|
||||||
return send(url, 'POST', data);
|
return send(url, 'POST', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export function sleep (time) {
|
export function sleep(time) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(resolve, time);
|
setTimeout(resolve, time);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user