Skip to content

Commit

Permalink
Resolve an issue that the UI buttons do not reflect the state of the …
Browse files Browse the repository at this point in the history
…mist coolant and flood coolant properly (#142)
  • Loading branch information
cheton committed Mar 5, 2017
1 parent fd0de0c commit fce3e08
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 38 deletions.
36 changes: 30 additions & 6 deletions src/app/controllers/Grbl/Grbl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*eslint no-bitwise: ["error", { "allow": ["&", "<<"] }] */
/* eslint no-bitwise: ["error", { "allow": ["&", "<<"] }] */
/* eslint no-continue: 0 */
import _ from 'lodash';
import events from 'events';
import {
Expand Down Expand Up @@ -337,33 +338,53 @@ class GrblLineParserResultParserState {
})
.value();

words.forEach((word) => {
for (let i = 0; i < words.length; ++i) {
const word = words[i];

// Gx, Mx
if (word.indexOf('G') === 0 || word.indexOf('M') === 0) {
let r = _.find(GRBL_MODAL_GROUPS, (group) => {
const r = _.find(GRBL_MODAL_GROUPS, (group) => {
return _.includes(group.modes, word);
});

if (r) {
if (!r) {
continue;
}

if (r.group === 'coolant') {
if (word === 'M7') {
_.set(payload, 'modal.coolant.mist', true);
} else if (word === 'M8') {
_.set(payload, 'modal.coolant.flood', true);
} else { // M9
_.set(payload, 'modal.coolant.mist', false);
_.set(payload, 'modal.coolant.flood', false);
}
} else {
_.set(payload, 'modal.' + r.group, word);
}

continue;
}

// T: tool number
if (word.indexOf('T') === 0) {
_.set(payload, 'tool', word.substring(1));
continue;
}

// F: feed rate
if (word.indexOf('F') === 0) {
_.set(payload, 'feedrate', word.substring(1));
continue;
}

// S: spindle speed
if (word.indexOf('S') === 0) {
_.set(payload, 'spindle', word.substring(1));
continue;
}
});
}

return {
type: GrblLineParserResultParserState,
Expand Down Expand Up @@ -592,7 +613,10 @@ class Grbl extends events.EventEmitter {
feedrate: 'G94', // G93: Inverse Time Mode, G94: Units Per Minutes
program: 'M0', // M0, M1, M2, M30
spindle: 'M5', // M3, M4, M5
coolant: 'M9' // M7, M8, M9
coolant: { // M7, M8, M9
mist: false, // M7
flood: false // M8
}
},
tool: '',
feedrate: '',
Expand Down
36 changes: 30 additions & 6 deletions src/app/controllers/Smoothie/Smoothie.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*eslint no-bitwise: ["error", { "allow": ["&", "<<"] }] */
/* eslint no-bitwise: ["error", { "allow": ["&", "<<"] }] */
/* eslint no-continue: 0 */
import _ from 'lodash';
import events from 'events';
import {
Expand Down Expand Up @@ -247,33 +248,53 @@ class SmoothieLineParserResultParserState {
})
.value();

words.forEach((word) => {
for (let i = 0; i < words.length; ++i) {
const word = words[i];

// Gx, Mx
if (word.indexOf('G') === 0 || word.indexOf('M') === 0) {
let r = _.find(SMOOTHIE_MODAL_GROUPS, (group) => {
const r = _.find(SMOOTHIE_MODAL_GROUPS, (group) => {
return _.includes(group.modes, word);
});

if (r) {
if (!r) {
continue;
}

if (r.group === 'coolant') {
if (word === 'M7') {
_.set(payload, 'modal.coolant.mist', true);
} else if (word === 'M8') {
_.set(payload, 'modal.coolant.flood', true);
} else { // M9
_.set(payload, 'modal.coolant.mist', false);
_.set(payload, 'modal.coolant.flood', false);
}
} else {
_.set(payload, 'modal.' + r.group, word);
}

continue;
}

// T: tool number
if (word.indexOf('T') === 0) {
_.set(payload, 'tool', word.substring(1));
continue;
}

// F: feed rate
if (word.indexOf('F') === 0) {
_.set(payload, 'feedrate', word.substring(1));
continue;
}

// S: spindle speed
if (word.indexOf('S') === 0) {
_.set(payload, 'spindle', word.substring(1));
continue;
}
});
}

return {
type: SmoothieLineParserResultParserState,
Expand Down Expand Up @@ -419,7 +440,10 @@ class Smoothie extends events.EventEmitter {
feedrate: 'G94', // G93: Inverse Time Mode, G94: Units Per Minutes
program: 'M0', // M0, M1, M2, M30
spindle: 'M5', // M3, M4, M5
coolant: 'M9' // M7, M8, M9
coolant: { // M7, M8, M9
mist: false, // M7
flood: false // M8
}
},
tool: '',
feedrate: '',
Expand Down
20 changes: 19 additions & 1 deletion src/web/lib/gcode-text.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import isPlainObject from 'lodash/isPlainObject';
import i18n from './i18n';

export default (word) => {
export default (word, group, object) => {
const wordText = {
// Motion
'G0': i18n._('Rapid Move (G0)', { ns: 'gcode' }),
Expand Down Expand Up @@ -64,5 +65,22 @@ export default (word) => {
'M9': i18n._('Coolant Off (M9)', { ns: 'gcode' })
};

if (group === 'coolant') {
if (!isPlainObject(object.coolant)) {
return '';
}
if (object.coolant.mist) {
object.coolant.mist = wordText.M7;
}
if (object.coolant.flood) {
object.coolant.flood = wordText.M8;
}
if (!object.coolant.mist && !object.coolant.flood) {
object.coolant = wordText.M9;
}

return object.coolant;
}

return (wordText[word] || word);
};
10 changes: 9 additions & 1 deletion src/web/widgets/Grbl/Grbl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Grbl extends Component {
const tool = _.get(parserState, 'tool', none);
const ov = _.get(controllerState, 'status.ov', []);
const buf = _.get(controllerState, 'status.buf', {});
const modal = _.mapValues(parserState.modal || {}, (word, group) => mapGCodeToText(word));
const modal = _.mapValues(parserState.modal || {}, mapGCodeToText);

this.plannerBufferMax = Math.max(this.plannerBufferMax, buf.planner) || this.plannerBufferMax;
this.receiveBufferMax = Math.max(this.receiveBufferMax, buf.rx) || this.receiveBufferMax;
Expand Down Expand Up @@ -275,9 +275,17 @@ class Grbl extends Component {
{i18n._('Coolant')}
</div>
<div className="col col-xs-8">
{!_.isPlainObject(modal.coolant) &&
<div className={styles.well} title={modal.coolant}>
{modal.coolant || none}
</div>
}
{_.isPlainObject(modal.coolant) &&
<div className={styles.well}>
<div title={modal.coolant.mist}>{modal.coolant.mist}</div>
<div title={modal.coolant.flood}>{modal.coolant.flood}</div>
</div>
}
</div>
</div>
</Panel.Body>
Expand Down
10 changes: 9 additions & 1 deletion src/web/widgets/Smoothie/Smoothie.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Smoothie extends Component {
const feedrate = _.get(parserState, 'feedrate', none);
const spindle = _.get(parserState, 'spindle', none);
const tool = _.get(parserState, 'tool', none);
const modal = _.mapValues(parserState.modal || {}, (word, group) => mapGCodeToText(word));
const modal = _.mapValues(parserState.modal || {}, mapGCodeToText);

return (
<div>
Expand Down Expand Up @@ -204,9 +204,17 @@ class Smoothie extends Component {
{i18n._('Coolant')}
</div>
<div className="col col-xs-8">
{!_.isPlainObject(modal.coolant) &&
<div className={styles.well} title={modal.coolant}>
{modal.coolant || none}
</div>
}
{_.isPlainObject(modal.coolant) &&
<div className={styles.well}>
<div title={modal.coolant.mist}>{modal.coolant.mist}</div>
<div title={modal.coolant.flood}>{modal.coolant.flood}</div>
</div>
}
</div>
</div>
</Panel.Body>
Expand Down
24 changes: 18 additions & 6 deletions src/web/widgets/Spindle/Spindle.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classNames from 'classnames';
import get from 'lodash/get';
import React, { Component, PropTypes } from 'react';
import shallowCompare from 'react-addons-shallow-compare';
import controller from '../../lib/controller';
Expand All @@ -17,6 +18,9 @@ class Spindle extends Component {
render() {
const { state, actions } = this.props;
const { canClick, spindleSpeed } = state;
const spindle = get(state, 'controller.modal.spindle');
const mistCoolant = get(state, 'controller.modal.coolant.mist');
const floodCoolant = get(state, 'controller.modal.coolant.flood');

return (
<div>
Expand All @@ -29,6 +33,7 @@ class Spindle extends Component {
<button
type="button"
className="btn btn-default"
style={{ padding: '5px 0' }}
onClick={() => {
if (spindleSpeed > 0) {
controller.command('gcode', 'M3 S' + spindleSpeed);
Expand All @@ -43,7 +48,7 @@ class Spindle extends Component {
className={classNames(
'fa',
'fa-rotate-right',
{ 'fa-spin': state.spindleState === 'M3' }
{ 'fa-spin': spindle === 'M3' }
)}
/>
<span className="space space-sm" />
Expand All @@ -54,6 +59,7 @@ class Spindle extends Component {
<button
type="button"
className="btn btn-default"
style={{ padding: '5px 0' }}
onClick={() => {
if (spindleSpeed > 0) {
controller.command('gcode', 'M4 S' + spindleSpeed);
Expand All @@ -68,7 +74,7 @@ class Spindle extends Component {
className={classNames(
'fa',
'fa-rotate-left',
{ 'fa-spin-reverse': state.spindleState === 'M4' }
{ 'fa-spin-reverse': spindle === 'M4' }
)}
/>
<span className="space space-sm" />
Expand All @@ -79,6 +85,7 @@ class Spindle extends Component {
<button
type="button"
className="btn btn-default"
style={{ padding: '5px 0' }}
onClick={() => controller.command('gcode', 'M5')}
title={i18n._('Spindle Off (M5)', { ns: 'gcode' })}
disabled={!canClick}
Expand All @@ -97,6 +104,7 @@ class Spindle extends Component {
<button
type="button"
className="btn btn-default"
style={{ padding: '5px 0' }}
onClick={() => {
controller.command('gcode', 'M7');
}}
Expand All @@ -105,8 +113,9 @@ class Spindle extends Component {
>
<i
className={classNames(
styles['icon-fan'],
{ 'fa-spin': state.coolantState === 'M7' }
styles.icon,
styles.iconFan,
{ 'fa-spin': mistCoolant }
)}
/>
<span className="space space-sm" />
Expand All @@ -117,6 +126,7 @@ class Spindle extends Component {
<button
type="button"
className="btn btn-default"
style={{ padding: '5px 0' }}
onClick={() => {
controller.command('gcode', 'M8');
}}
Expand All @@ -125,8 +135,9 @@ class Spindle extends Component {
>
<i
className={classNames(
styles['icon-fan'],
{ 'fa-spin': state.coolantState === 'M8' }
styles.icon,
styles.iconFan,
{ 'fa-spin': floodCoolant }
)}
/>
<span className="space space-sm" />
Expand All @@ -137,6 +148,7 @@ class Spindle extends Component {
<button
type="button"
className="btn btn-default"
style={{ padding: '5px 0' }}
onClick={() => {
controller.command('gcode', 'M9');
}}
Expand Down
7 changes: 7 additions & 0 deletions src/web/widgets/Spindle/images/coolant.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/web/widgets/Spindle/images/fan.png
Binary file not shown.
7 changes: 7 additions & 0 deletions src/web/widgets/Spindle/images/fan.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fce3e08

Please sign in to comment.