mirror of
https://github.com/Doodle3D/Doodle3D-API
synced 2025-01-05 11:03:49 +01:00
fixes for last commit
This commit is contained in:
parent
c831a7cc02
commit
76a7b02dc7
@ -17,14 +17,6 @@ export default class extends EventDispatcher {
|
|||||||
|
|
||||||
this.api = `http://${boxData.localip}/d3dapi/`;
|
this.api = `http://${boxData.localip}/d3dapi/`;
|
||||||
|
|
||||||
this.config = new ConfigAPI(this.api);
|
|
||||||
this.info = new InfoAPI(this.api);
|
|
||||||
this.network = new NetworkAPI(this.api);
|
|
||||||
this.printer = new PrinterAPI(this.api);
|
|
||||||
this.sketch = new SketchAPI(this.api);
|
|
||||||
this.system = new SystemAPI(this.api);
|
|
||||||
this.update = new UpdateAPI(this.api);
|
|
||||||
|
|
||||||
this.alive = false;
|
this.alive = false;
|
||||||
this.autoUpdate = false;
|
this.autoUpdate = false;
|
||||||
this.state = {};
|
this.state = {};
|
||||||
@ -32,6 +24,14 @@ export default class extends EventDispatcher {
|
|||||||
this.maxBatchSize = 10*1024;
|
this.maxBatchSize = 10*1024;
|
||||||
this.maxBufferSize = 1024*1024;
|
this.maxBufferSize = 1024*1024;
|
||||||
this.fullBufferTimeout = 10000;
|
this.fullBufferTimeout = 10000;
|
||||||
|
|
||||||
|
this.config = new ConfigAPI(this.api);
|
||||||
|
this.info = new InfoAPI(this.api);
|
||||||
|
this.network = new NetworkAPI(this.api);
|
||||||
|
this.printer = new PrinterAPI(this.api);
|
||||||
|
this.sketch = new SketchAPI(this.api);
|
||||||
|
this.system = new SystemAPI(this.api);
|
||||||
|
this.update = new UpdateAPI(this.api);
|
||||||
}
|
}
|
||||||
|
|
||||||
setAutoUpdate (autoUpdate = true, updateInterval = 1000) {
|
setAutoUpdate (autoUpdate = true, updateInterval = 1000) {
|
||||||
@ -111,29 +111,20 @@ export default class extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _update () {
|
async _update () {
|
||||||
let alive = await this.checkAlive();
|
while (this.autoUpdate) {
|
||||||
if (alive) {
|
try {
|
||||||
while (this.autoUpdate) {
|
this.state = await this.info.status();
|
||||||
try {
|
|
||||||
this.state = await this.info.status();
|
|
||||||
|
|
||||||
this.dispatchEvent({
|
this.dispatchEvent({
|
||||||
type: 'update',
|
type: 'update',
|
||||||
state: this.state
|
state: this.state
|
||||||
});
|
});
|
||||||
|
}
|
||||||
await sleep(this.updateInterval);
|
catch (error) {
|
||||||
}
|
await this.checkAlive();
|
||||||
catch (error) {
|
|
||||||
this._update();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
await sleep(this.updateInterval);
|
|
||||||
|
|
||||||
this._update();
|
await sleep(this.updateInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ export default class {
|
|||||||
return rest.post(`${this.api}network/associate`, data);
|
return rest.post(`${this.api}network/associate`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
disassosiate () {
|
disassociate () {
|
||||||
//not tested
|
//not tested
|
||||||
|
|
||||||
return rest.post(`${this.api}network/disassociate`, {});
|
return rest.post(`${this.api}network/disassociate`, {});
|
||||||
|
@ -37,9 +37,10 @@ export default class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop (gcode = '') {
|
stop (gcode = '') {
|
||||||
this._currentBatch = 0;
|
let data = {
|
||||||
this._printBatches = [];
|
gcode
|
||||||
|
};
|
||||||
|
|
||||||
return rest.post(`${this.api}printer/stop`, {gcode});
|
return rest.post(`${this.api}printer/stop`, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
|
|
||||||
|
const GET_TIMEOUT = 5000;
|
||||||
|
const POST_TIMEOUT = 10000;
|
||||||
|
|
||||||
export function get (url) {
|
export function get (url) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
timeout: 5000,
|
timeout: GET_TIMEOUT,
|
||||||
success: (response) => {
|
success: (response) => {
|
||||||
if (response.status === 'success') {
|
if (response.status === 'success') {
|
||||||
resolve(response.data, response.msg);
|
resolve(response.data, response.msg);
|
||||||
@ -25,7 +28,7 @@ export function post (url, data) {
|
|||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: data,
|
data: data,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
timeout: 10000,
|
timeout: POST_TIMEOUT,
|
||||||
success: (response) => {
|
success: (response) => {
|
||||||
if (response.status === 'success') {
|
if (response.status === 'success') {
|
||||||
resolve(response.data);
|
resolve(response.data);
|
||||||
|
Loading…
Reference in New Issue
Block a user