Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Grbl compatibility #28

Merged
merged 18 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# The .env file is used to load environmental variables that are not necessary in a production environment (like FLASK_ENV=development)
# Check the wiki for the available environmental variables

# feeder logger level: 5 -> acks received from the device (and above), level 6 -> lines sent to the device (and above), other standard logging levels of python
FEEDER_LEVEL=5
# feeder logger level:
# * 4 -> log low level commands (used to manage the board status)
# * 5 -> acks received from the device (and above) about the drawing process
# * 6 -> lines sent to the device (and above)
# * other standard logging levels of python
FEEDER_LEVEL=30

# flask logger level: uses standard python loggin levels (10-debug, 20-info, 30-warning, 40-error, 50-critical). Can set to warning to hide standard http requests
FLASK_LEVEL=30
Expand Down
6 changes: 5 additions & 1 deletion .flaskenv
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# for additional custom variables check the ".env.template" file
FLASK_APP=server

# feeder logger level: 5 -> acks received from the device (and above), level 6 -> lines sent to the device (and above), other standard logging levels of python
# feeder logger level:
# * 4 -> log low level commands (used to manage the board status)
# * 5 -> acks received from the device (and above) about the drawing process
# * 6 -> lines sent to the device (and above)
# * other standard logging levels of python
FEEDER_LEVEL=30

# flask logger level: uses standard python loggin levels (10-debug, 20-info, 30-warning, 40-error, 50-critical). Can set to warning to hide standard http requests
Expand Down
25 changes: 25 additions & 0 deletions dev_tools/update_frontend_version_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import subprocess

def get_commit_shash():
result = subprocess.check_output(['git', 'log', '--pretty=format:"%h"', "-n", "1"])
return result.decode(encoding="UTF-8").replace('"', '')



# This script save the current git hash in a .env file for react.
# The script load the last commit hash as version (used by the frontend to check if it is necessary to clear the local storage)
# Additional variables can be added directly in the list of lines below
# run it like: (env)$> python dev_tools/update_frontend_version_hash.py


file_path = "./frontend/.env"

lines = [
"/* THIS FILE IS GENERATED WITH THE FOLLOWING UTIL: */\n",
"/* dev_tools/update_frontend_version.py*/\n",
"/* Have a look there if you need to put additional variables */\n\n",
"REACT_APP_VERSION = {}".format(get_commit_shash())] # start the server


with open(file_path, "w") as f:
f.writelines(lines)
5 changes: 5 additions & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* THIS FILE IS GENERATED WITH THE FOLLOWING UTIL: */
/* dev_tools/update_frontend_version.py*/
/* Have a look there if you need to put additional variables */

REACT_APP_VERSION = e23dde3
4 changes: 2 additions & 2 deletions frontend/src/components/DrawingDataDownloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { connect } from 'react-redux';
import { getRefreshDrawings } from '../structure/tabs/drawings/selector';
import { setDrawings, setRefreshDrawing } from '../structure/tabs/drawings/Drawings.slice';

import { drawings_request } from '../sockets/SAE';
import { drawings_refresh_response} from '../sockets/SAC';
import { drawings_request } from '../sockets/sEmits';
import { drawings_refresh_response} from '../sockets/sCallbacks';

const mapStateToProps = (state) => {
return { must_refresh: getRefreshDrawings(state) }
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/PlaylistDataDownloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { connect } from 'react-redux';
import { getRefreshPlaylists } from '../structure/tabs/playlists/selector';
import { setPlaylists, setRefreshPlaylists } from '../structure/tabs/playlists/Playlists.slice';

import { playlists_request } from '../sockets/SAE';
import { playlists_refresh_response } from '../sockets/SAC';
import { playlists_request } from '../sockets/sEmits';
import { playlists_refresh_response } from '../sockets/sCallbacks';


const mapStateToProps = (state) => {
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/SortableElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ class SortableElements extends Component{

return <ElementCard key={el.id}
handleUnmount={()=>this.removeElement(el.id)}
showCross={this.state.show_child_cross}
onClick={()=>console.log("click2")}>
showCross={this.state.show_child_cross}>
<ElementType element={el}
onClick={()=>console.log("click")}
onOptionsChange={(el) => this.props.onElementOptionsChange(el)}
hideOptions={this.props.hideOptions}/>
</ElementCard>
Expand Down
File renamed without changes.
11 changes: 10 additions & 1 deletion frontend/src/sockets/SAE.js → frontend/src/sockets/sEmits.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {socket} from './SAC';
import {socket} from './sCallbacks';

// sends a gcode command to the feeder
function send_command(command){
Expand Down Expand Up @@ -82,11 +82,20 @@ function queue_set_order(list){

function queue_stop_drawing(){
socket.emit("queue_stop_drawing");
window.show_toast(<div>The drawing is being stopped. <br/>The device will still run until the buffer is empty.</div>)
}


// ---- MANUAL CONTROL ----

function control_emergency_stop(){
socket.emit("control_emergency_stop")
}


export {
send_command,
control_emergency_stop,
drawing_delete,
drawings_request,
drawing_queue,
Expand Down
18 changes: 15 additions & 3 deletions frontend/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createStore } from 'redux';
import { combineReducers } from '@reduxjs/toolkit';

import settingsReducer from './structure/tabs/settings/Settings.slice';
import manualControlReducer from './structure/tabs/manual/ManualControl.slice';
import queueReducer from './structure/tabs/queue/Queue.slice';
import tabsReducer from './structure/tabs/Tabs.slice';
import drawingsReducer from './structure/tabs/drawings/Drawings.slice';
Expand All @@ -14,13 +13,27 @@ function saveToLocalStorage(state) {
try {
const serialisedState = JSON.stringify(state);
localStorage.setItem("persistantState", serialisedState);
localStorage.setItem("version", process.env.REACT_APP_VERSION)
} catch (e) {
console.warn(e);
}
}

// will create the storage with the values saved in local storage
function loadFromLocalStorage() {
// if is loading a new version from the server, clear the local storage (to avoid compatibility issues between different frontend versions)
try{
const version = localStorage.getItem("version");
if (version !== process.env.REACT_APP_VERSION){
console.warn("New version detected. Clearing local storage");
localStorage.clear();
}
} catch (e) {
console.warn(e);
localStorage.clear();
}

// loads state from local storage if available
try {
const serialisedState = localStorage.getItem("persistantState");
if (serialisedState === null) return undefined;
Expand All @@ -29,11 +42,10 @@ function loadFromLocalStorage() {
console.warn(e);
return undefined;
}
}
}

const store = createStore(combineReducers({
settings: settingsReducer,
manualControl: manualControlReducer,
queue: queueReducer,
tabs: tabsReducer,
drawings: drawingsReducer,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/structure/SWUpdates.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from 'react';
import { connect } from 'react-redux';

import {socket} from "../sockets/SAC";
import {socket} from "../sockets/sCallbacks";
import { shouldCheckUpdate } from './tabs/settings/selector';
import { updateCheckTime } from './tabs/settings/Settings.slice';

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/structure/Toasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Spinner } from 'react-bootstrap';

import Toast from 'react-bootstrap/Toast';

import { connection_status_callback, show_toast } from "../sockets/SAC";
import { connection_status_callback, show_toast } from "../sockets/sCallbacks";
import { cloneDict } from '../utils/dictUtils';

class CustomToast extends Component{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/structure/TopBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import QueuePreview from './tabs/queue/QueuePreview';
import { showBack } from './tabs/selector';
import { setTab, tabBack } from './tabs/Tabs.slice';
import { systemIsLinux } from './tabs/settings/selector';
import { settings_reboot_system, settings_shutdown_system } from '../sockets/SAE';
import { settings_reboot_system, settings_shutdown_system } from '../sockets/sEmits';

const mapStateToProps = (state) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/structure/tabs/drawings/SingleDrawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Container, Form, Modal } from 'react-bootstrap';
import { FileEarmarkX, Play, Plus, PlusSquare, X } from 'react-bootstrap-icons';
import { connect } from 'react-redux';

import { drawing_delete, drawing_queue } from '../../../sockets/SAE';
import { drawing_delete, drawing_queue } from '../../../sockets/sEmits';

import ConfirmButton from '../../../components/ConfirmButton';
import IconButton from '../../../components/IconButton';
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/structure/tabs/drawings/UploadDrawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class UploadDrawingsModal extends Component{
}

render(){
// TODO add thr files upload if necessary... Need somebody to try it out first
return <Modal show={this.props.show} onHide={this.handleClose.bind(this)} size="lg" centered>
<Modal.Header className="center">
<Modal.Title>Upload new drawing</Modal.Title>
Expand All @@ -79,11 +80,11 @@ class UploadDrawingsModal extends Component{
<div className={ "w-100" + (this.state.loading ? " d-none" : "")}>
<Dropzone
onDrop={this.handleFiles.bind(this)}
accept={".gcode"}
accept={".gcode"}
noKeyboard>
{({getRootProps, getInputProps, isDragActive}) => (<div {...getRootProps()} className={"animated-background m-2 p-5 mh-100 d-flex justify-content-center align-items-center" + (isDragActive ? " drag-active" : "")}>
<input {...getInputProps()}/>
<div className="d-block text-center">Drag and drop the .gcode/.nc file here <br/>or click to open the file explorer
<div className="d-block text-center">Drag and drop the .gcode file here <br/>or click to open the file explorer
</div>
</div>)}
</Dropzone>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/structure/tabs/leds/Leds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Container } from 'react-bootstrap';
import { ChromePicker } from 'react-color';

import { Section } from '../../../components/Section';
import { leds_set_color } from '../../../sockets/SAE';
import { leds_set_color } from '../../../sockets/sEmits';


class LedsController extends Component{
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/structure/tabs/manual/CommandLine.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Component } from 'react';
import {Form, Row, Col, Button } from 'react-bootstrap';

import { send_command } from '../../../sockets/SAE';
import { device_command_line_return, device_new_position} from '../../../sockets/SAC';
import { send_command } from '../../../sockets/sEmits';
import { device_command_line_return, device_new_position} from '../../../sockets/sCallbacks';
import CommandViewer from './CommandViewer';

class CommandLine extends Component{
Expand Down Expand Up @@ -93,10 +93,12 @@ class CommandLine extends Component{
</Row>
<Row>
<Col className="center">
<Form.Check
label="Show device acks"
onChange={(event)=>{this.setState({show_acks: event.target.checked})}}
checked={this.state.show_acks}/>
<Form.Check
label="Show device acks"
id="ack_check"
type="switch"
onChange={(event)=>{this.setState({show_acks: event.target.checked})}}
checked={this.state.show_acks}/>
</Col>
</Row>
</Form.Group>
Expand Down
16 changes: 4 additions & 12 deletions frontend/src/structure/tabs/manual/ManualControl.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import React, { Component } from 'react';
import { Container, Row, Col, Button } from 'react-bootstrap';
import { connect } from 'react-redux';

import "./ManualControl.scss";

import { Section } from '../../../components/Section';
import CommandLine from './CommandLine';
import Preview from './Preview';

import { send_command } from '../../../sockets/SAE';
import { getDimensions } from './selector.js';

const mapStateToProps = (state) => {
return {
dimensions: getDimensions(state)
}
}
import { control_emergency_stop, send_command } from '../../../sockets/sEmits';

class ManualControl extends Component{

Expand All @@ -29,12 +21,12 @@ class ManualControl extends Component{
<CommandLine/>
</Col>
<Col md>
<Preview width={this.props.dimensions.width} height={this.props.dimensions.height}/>
<Preview/>
</Col>
</Row>
<Row>
<Col className="center">
<Button className="w-25 mr-3" onClick={()=>{send_command('M112')}} title="Warning: this button will not stop the device during homing">EMERGENCY STOP</Button>
<Button className="w-25 mr-3" onClick={()=>{control_emergency_stop()}} title="Warning: this button will not stop the device during homing">EMERGENCY STOP</Button>
<Button className="2-25" onClick={()=>{send_command('G28')}}>Home</Button>
</Col>
</Row>
Expand All @@ -45,4 +37,4 @@ class ManualControl extends Component{
}
}

export default connect(mapStateToProps)(ManualControl);
export default ManualControl;
2 changes: 1 addition & 1 deletion frontend/src/structure/tabs/manual/ManualControl.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@import '~bootstrap/scss/variables';
@import '~bootstrap/scss/mixins';
.preview-style{
background-color: #eeeeee;
background-color: #000000;
width: 100%;
}

Expand Down
22 changes: 0 additions & 22 deletions frontend/src/structure/tabs/manual/ManualControl.slice.js

This file was deleted.

Loading