mirror of
https://github.com/Doodle3D/Doodle3D-API
synced 2025-01-05 11:03:49 +01:00
Updated autoupdate loop
This commit is contained in:
parent
528ddb7bc8
commit
5584a1f71e
@ -1,4 +1,4 @@
|
|||||||
import Doodle3DManager from 'src/doodle3dmanager.js';
|
import {Doodle3DManager} from 'src/index.js';
|
||||||
|
|
||||||
const doodle3DManager = new Doodle3DManager();
|
const doodle3DManager = new Doodle3DManager();
|
||||||
const TABLE = document.getElementById('table');
|
const TABLE = document.getElementById('table');
|
||||||
|
@ -14,8 +14,6 @@ export default class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set (data) {
|
set (data) {
|
||||||
var scope = this;
|
|
||||||
|
|
||||||
return rest.post(`${this.api}config`, data);
|
return rest.post(`${this.api}config`, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import EventDispatcher from 'casperlamboo/EventDispatcher';
|
import EventDispatcher from 'casperlamboo/EventDispatcher';
|
||||||
import * as rest from './restapi.js';
|
|
||||||
import ConfigAPI from './configapi.js';
|
import ConfigAPI from './configapi.js';
|
||||||
import InfoAPI from './infoapi.js';
|
import InfoAPI from './infoapi.js';
|
||||||
import NetworkAPI from './networkapi.js';
|
import NetworkAPI from './networkapi.js';
|
||||||
@ -22,7 +21,6 @@ export default class extends EventDispatcher {
|
|||||||
this.state = {};
|
this.state = {};
|
||||||
|
|
||||||
this.maxBatchSize = 10*1024;
|
this.maxBatchSize = 10*1024;
|
||||||
this.maxBufferSize = 1024*1024;
|
|
||||||
this.fullBufferTimeout = 10000;
|
this.fullBufferTimeout = 10000;
|
||||||
|
|
||||||
this.config = new ConfigAPI(this.api);
|
this.config = new ConfigAPI(this.api);
|
||||||
@ -92,28 +90,17 @@ export default class extends EventDispatcher {
|
|||||||
let lastIndex = 0;
|
let lastIndex = 0;
|
||||||
let start = true;
|
let start = true;
|
||||||
while (lastIndex !== gcode.length) {
|
while (lastIndex !== gcode.length) {
|
||||||
let index = gcode.lastIndexOf('\n', lastIndex + this.maxBatchSize);
|
let lastIndex = lastIndex + this.maxBatchSize;
|
||||||
|
let index = gcode.lastIndexOf('\n', lastIndex);
|
||||||
let batch = gcode.substring(lastIndex, index);
|
let batch = gcode.substring(lastIndex, index);
|
||||||
|
|
||||||
let progress = await this.printer.progress();
|
let progress = await this.printer.progress();
|
||||||
|
|
||||||
if (progress['buffered_lines'] + batch.length < this.maxBufferSize) {
|
|
||||||
try {
|
|
||||||
await this._sendBatch(batch, start);
|
await this._sendBatch(batch, start);
|
||||||
|
|
||||||
start = false;
|
start = false;
|
||||||
lastIndex = index + 1; //skip next \n
|
lastIndex = index + 1; //skip next \n
|
||||||
}
|
}
|
||||||
catch (error) {
|
|
||||||
console.log('error while sending gcode', error);
|
|
||||||
|
|
||||||
await sleep(this.fullBufferTimeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
await sleep(this.fullBufferTimeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.autoUpdate = autoUpdateState;
|
this.autoUpdate = autoUpdateState;
|
||||||
|
|
||||||
@ -139,12 +126,11 @@ export default class extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendBatch (gcode, index) {
|
_sendBatch (gcode, start) {
|
||||||
return new Promise (async (resolve, reject) => {
|
return new Promise (async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
let first = index === 0;
|
let response = await this.printer.print(gcode, start, start);
|
||||||
let start = first;
|
// maybe do something with failing response
|
||||||
let printRequest = await this.printer.print(gcode, first, start);
|
|
||||||
|
|
||||||
console.log(`batch sent: ${index}`, printRequest);
|
console.log(`batch sent: ${index}`, printRequest);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import Doodle3DAPI from './doodle3dapi.js';
|
|||||||
import EventDispatcher from 'casperlamboo/EventDispatcher';
|
import EventDispatcher from 'casperlamboo/EventDispatcher';
|
||||||
import {sleep} from './utils.js';
|
import {sleep} from './utils.js';
|
||||||
|
|
||||||
export default class extends EventDispatcher {
|
export default class Doodle3DManager extends EventDispatcher {
|
||||||
constructor () {
|
constructor () {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -50,24 +50,35 @@ export default class extends EventDispatcher {
|
|||||||
|
|
||||||
_checkAlive () {
|
_checkAlive () {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
for (let box of this.boxes) {
|
|
||||||
let alive = await box.checkAlive();
|
|
||||||
|
|
||||||
|
await Promise.all(this.boxes.map((box) => {
|
||||||
|
let promise = box.checkAlive();
|
||||||
|
promise.then((alive) => {
|
||||||
if (!alive) {
|
if (!alive) {
|
||||||
this._removeBox(box);
|
this._removeBox(box);
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
}));
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_checkNew () {
|
_checkNew () {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
|
let boxes;
|
||||||
try {
|
try {
|
||||||
let boxes = await rest.get(`${this.api}list.php`);
|
boxes = await rest.get(`${this.api}list.php`);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.warn('fail connecting to Doodle3D server', error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.checkNonServerBoxes) {
|
if (this.checkNonServerBoxes) {
|
||||||
boxes = boxes.concat(this.nonServerBoxes);
|
boxes = [...boxes, ...this.nonServerBoxes];
|
||||||
}
|
}
|
||||||
|
|
||||||
let knownIPs = this.boxes.map((box) => box.boxData.localip);
|
let knownIPs = this.boxes.map((box) => box.boxData.localip);
|
||||||
@ -85,10 +96,6 @@ export default class extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.warn('fail connecting to Doodle3D server');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user