mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-09-07 12:46:21 +02:00
implement print to malyan
This commit is contained in:
parent
e384c74f8e
commit
67981872aa
@ -209,6 +209,13 @@ class Interface extends React.Component {
|
|||||||
const { name } = this.props;
|
const { name } = this.props;
|
||||||
|
|
||||||
if (isSlicing) return;
|
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) {
|
if (!mesh) {
|
||||||
this.setState({ error: 'there is no file to slice' });
|
this.setState({ error: 'there is no file to slice' });
|
||||||
return;
|
return;
|
||||||
@ -311,7 +318,7 @@ class Interface extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { classes, onCancel } = this.props;
|
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%' }) };
|
const style = { ...(showFullScreen ? {} : { maxWidth: 'inherit', width: '100%', height: '100%' }) };
|
||||||
|
|
||||||
@ -349,7 +356,7 @@ class Interface extends React.Component {
|
|||||||
onRequestClose={this.closePopover}
|
onRequestClose={this.closePopover}
|
||||||
>
|
>
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuItem primaryText="Send over WiFi" onTouchTap={() => this.slice('WIFI')} />
|
<MenuItem disabled={!Boolean(settings && settings.ip)} primaryText="Send over WiFi" onTouchTap={() => this.slice('WIFI')} />
|
||||||
<MenuItem primaryText="Download GCode" onTouchTap={() => this.slice('DOWNLOAD')} />
|
<MenuItem primaryText="Download GCode" onTouchTap={() => this.slice('DOWNLOAD')} />
|
||||||
</Menu>
|
</Menu>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
@ -106,9 +106,10 @@ export function fetchProgress(url, data = {}, onProgress) {
|
|||||||
if (xhr.upload && onProgress) xhr.upload.onprogress = onProgress;
|
if (xhr.upload && onProgress) xhr.upload.onprogress = onProgress;
|
||||||
if (xhr.responseType) xhr.responseType = 'blob';
|
if (xhr.responseType) xhr.responseType = 'blob';
|
||||||
|
|
||||||
request.headers.forEach((value, name) => {
|
// Malyan printer doesn't like headers...
|
||||||
xhr.setRequestHeader(name, value)
|
// request.headers.forEach((value, name) => {
|
||||||
});
|
// xhr.setRequestHeader(name, value)
|
||||||
|
// });
|
||||||
|
|
||||||
xhr.send(data.body);
|
xhr.send(data.body);
|
||||||
});
|
});
|
||||||
@ -118,8 +119,6 @@ const GCODE_SERVER_URL = 'https://gcodeserver.doodle3d.com';
|
|||||||
const CONNECT_URL = 'http://connect.doodle3d.com/';
|
const CONNECT_URL = 'http://connect.doodle3d.com/';
|
||||||
|
|
||||||
export async function slice(target, name, mesh, settings, updateProgress) {
|
export async function slice(target, name, mesh, settings, updateProgress) {
|
||||||
if (!settings) throw { message: 'please select a printer first', code: 0 };
|
|
||||||
|
|
||||||
let steps;
|
let steps;
|
||||||
let currentStep = 0;
|
let currentStep = 0;
|
||||||
switch (target) {
|
switch (target) {
|
||||||
@ -127,6 +126,7 @@ export async function slice(target, name, mesh, settings, updateProgress) {
|
|||||||
steps = 1;
|
steps = 1;
|
||||||
break;
|
break;
|
||||||
case 'WIFI':
|
case 'WIFI':
|
||||||
|
case 'DOODLE3D-WIFI-BOX':
|
||||||
steps = 2;
|
steps = 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -151,12 +151,29 @@ export async function slice(target, name, mesh, settings, updateProgress) {
|
|||||||
|
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case 'DOWNLOAD': {
|
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);
|
fileSaver.saveAs(blob);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'WIFI': {
|
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
|
// upload G-code file to AWS S3
|
||||||
const { data: { reservation, id } } = await fetch(`${GCODE_SERVER_URL}/upload`, { method: 'POST' })
|
const { data: { reservation, id } } = await fetch(`${GCODE_SERVER_URL}/upload`, { method: 'POST' })
|
||||||
.then(response => response.json());
|
.then(response => response.json());
|
||||||
|
Loading…
Reference in New Issue
Block a user