diff --git a/src/interface/index.js b/src/interface/index.js index 47f8bff..7f8f9b2 100644 --- a/src/interface/index.js +++ b/src/interface/index.js @@ -209,6 +209,13 @@ class Interface extends React.Component { const { name } = this.props; if (isSlicing) return; + if (!settings) { + this.setState({ error: 'please select a printer first' }); + } + if (target === 'WIFI' && !settings.ip) { + this.setState({ error: 'please connect to a WiFi enabled printer' }); + return; + } if (!mesh) { this.setState({ error: 'there is no file to slice' }); return; @@ -311,7 +318,7 @@ class Interface extends React.Component { render() { const { classes, onCancel } = this.props; - const { isSlicing, progress, showFullScreen, error, objectDimensions, openUrlDialog } = this.state; + const { isSlicing, progress, showFullScreen, error, objectDimensions, openUrlDialog, settings } = this.state; const style = { ...(showFullScreen ? {} : { maxWidth: 'inherit', width: '100%', height: '100%' }) }; @@ -349,7 +356,7 @@ class Interface extends React.Component { onRequestClose={this.closePopover} >
diff --git a/src/interface/utils.js b/src/interface/utils.js index 3dd601e..915e0ea 100644 --- a/src/interface/utils.js +++ b/src/interface/utils.js @@ -106,9 +106,10 @@ export function fetchProgress(url, data = {}, onProgress) { if (xhr.upload && onProgress) xhr.upload.onprogress = onProgress; if (xhr.responseType) xhr.responseType = 'blob'; - request.headers.forEach((value, name) => { - xhr.setRequestHeader(name, value) - }); + // Malyan printer doesn't like headers... + // request.headers.forEach((value, name) => { + // xhr.setRequestHeader(name, value) + // }); xhr.send(data.body); }); @@ -118,8 +119,6 @@ const GCODE_SERVER_URL = 'https://gcodeserver.doodle3d.com'; const CONNECT_URL = 'http://connect.doodle3d.com/'; export async function slice(target, name, mesh, settings, updateProgress) { - if (!settings) throw { message: 'please select a printer first', code: 0 }; - let steps; let currentStep = 0; switch (target) { @@ -127,6 +126,7 @@ export async function slice(target, name, mesh, settings, updateProgress) { steps = 1; break; case 'WIFI': + case 'DOODLE3D-WIFI-BOX': steps = 2; break; default: @@ -151,12 +151,29 @@ export async function slice(target, name, mesh, settings, updateProgress) { switch (target) { case 'DOWNLOAD': { - const blob = new File([gcode], `${name}.gcode`, { type: 'text/plain;charset=utf-8' }); + const blob = new File([gcode], `${name}.gcode`, { type: 'text/plain' }); fileSaver.saveAs(blob); break; } case 'WIFI': { + const body = new FormData(); + const file = new File([gcode], 'doodle.gcode', { type: 'plain/text' }); + body.append('file', file); + + await fetchProgress(`http://${settings.ip}/upload`, { method: 'POST', body }, (progess) => { + updateProgress({ + action: 'Uploading', + percentage: currentStep / steps + progess.loaded / progess.total / steps + }); + }); + currentStep ++; + await fetchProgress(`http://${settings.ip}/set?code=M566 ${name}.gcode`, { method: 'GET' }); + await fetchProgress(`http://${settings.ip}/set?code=M565`, { method: 'GET' }); + break; + } + + case 'DOODLE3D-WIFI-BOX': { // upload G-code file to AWS S3 const { data: { reservation, id } } = await fetch(`${GCODE_SERVER_URL}/upload`, { method: 'POST' }) .then(response => response.json());