implement gcode server support

This commit is contained in:
Simon Voordouw 2017-05-12 16:33:48 +02:00
parent 7aecffb876
commit c838625a86
2 changed files with 26 additions and 0 deletions

View File

@ -25,6 +25,15 @@ export default class Printer {
stop(gcode = '') {
return rest.post(`${ this.api }printer/stop`, { gcode });
}
fetch(gcode = '') {
rest.post(`https://tranquil-meadow-94621.herokuapp.com/upload`, { gcode })
.then(response => {
console.log(`gcode file id: ${ response }`);
rest.post(`${ this.api }printer/fetch`, { id: response.id });
}).catch(err => {
console.log(err);
});
}
async _sendBatch(gcode, start, index) {
try {
const response = await this.print(gcode, start, start);

View File

@ -51,6 +51,23 @@ export default class Doodle3DBox extends EventDispatcher {
this.alive = alive;
return alive;
}
async startLargePrint(gcode) {
try {
const printerState = await this.printer.state();
if (printerState.state !== 'idle') {
throw `Cannot print, print state is ${ printerState.state }`;
}
if (!gcode.endsWith('\n')) {
gcode += '\n';
}
this.printer.fetch(gcode);
} catch (e) {
console.log(e);
}
}
async sendGCode(gcode) {
const printerState = await this.printer.state();
if (printerState.state !== 'idle') {