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

Refactor Strategy Selection and Improve Tool Page Description Display #587

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 0 additions & 11 deletions src/app/containers/Preferences/Preferences.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class PreferencesPage extends PureComponent {
shouldWarnZero: store.get('workspace.shouldWarnZero', false),
ipRange: store.get('widgets.connection.ip', [192, 168, 5, 1]),
toolChange: {
passthrough: store.get('workspace.toolChange.passthrough', false),
skipDialog: store.get('workspace.toolChange.skipDialog', false)
},
rotary: {
Expand Down Expand Up @@ -750,15 +749,6 @@ class PreferencesPage extends PureComponent {
}
},
toolChange: {
handlePassthroughToggle: () => {
const { toolChange } = this.state;
this.setState({
toolChange: {
...toolChange,
passthrough: !toolChange.passthrough
}
});
},
handleSkipDialog: () => {
const { toolChange } = this.state;
this.setState({
Expand Down Expand Up @@ -897,7 +887,6 @@ class PreferencesPage extends PureComponent {
this.probeConfig.set('probeFastFeedrate', probeSettings.fastFeedrate);
this.probeConfig.set('connectivityTest', probeSettings.connectivityTest);
this.probeConfig.set('zProbeDistance', probeSettings.zProbeDistance);
store.set('workspace.toolChange.passthrough', toolChange.passthrough);
store.set('workspace.toolChange.skipDialog', toolChange.skipDialog);

controller.command('settings:updated', this.state);
Expand Down
49 changes: 22 additions & 27 deletions src/app/containers/Preferences/ToolChange/ToolChange.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export const TOOLCHANGE_OPTIONS = {
key: 'CODE',
label: 'Code',
description: 'Run code before and after the toolchange.'
},
PASSTHROUGH: {
key: 'PASSTHROUGH',
label: 'Passthrough',
description: 'Send the toolchange line as is. This assumes that your firmware can properly handle both M6 and T commands.'
}
};

Expand All @@ -67,7 +72,7 @@ const ToolChange = ({ state, actions, mpos, $13 }) => {
// State
const [toolChangeOption, setToolChangeOption] = useState(store.get('workspace.toolChangeOption'));
const [toolChangePosition, setToolChangePosition] = useState($13 ? convertToolChangePosition() : store.get('workspace.toolChangePosition'));
const [optionDescription, setOptionDescription] = useState('');
const [optionDescription, setOptionDescription] = useState(TOOLCHANGE_OPTIONS[toolChangeOption.toUpperCase()]?.description);
const [preHook, setPreHook] = useState(store.get('workspace.toolChangeHooks.preHook'));
const [postHook, setPostHook] = useState(store.get('workspace.toolChangeHooks.postHook'));
//const [combineBlocks, setCombineBlocks] = useState(false);
Expand Down Expand Up @@ -152,30 +157,7 @@ const ToolChange = ({ state, actions, mpos, $13 }) => {
return (
<div style={{ width: '70%' }}>
<Fieldset legend="Tool Change" className={styles.paddingBottom}>
{
toolChangeOption !== 'Code' && (
<TooltipCustom content="Send the toolchange line as is. This assumes that your firmware can properly handle both M6 and T commands." location="default">
<ToggleSwitch
label="Passthrough"
checked={state.toolChange.passthrough}
onChange={actions.toolChange.handlePassthroughToggle}
style={{ marginBottom: '1rem' }}
/>
</TooltipCustom>
)
}
{
toolChangeOption === 'Code' && (
<TooltipCustom content="Combine the blocks and avoid dialogs on tool changes - useful for ATC configurations" location="default">
<ToggleSwitch
label="Skip Dialog"
checked={state.toolChange.skipDialog}
onChange={actions.toolChange.handleSkipDialog}
style={{ marginBottom: '1rem' }}
/>
</TooltipCustom>
)
}

<small>Strategy to handle M6 tool change commands</small>
<div className={styles.addMargin}>
<Select
Expand All @@ -194,6 +176,19 @@ const ToolChange = ({ state, actions, mpos, $13 }) => {
<p className={styles.description}>{optionDescription}</p>
</div>
{
toolChangeOption === 'Code' && (
<TooltipCustom content="Combine the blocks and avoid dialogs on tool changes - useful for ATC configurations" location="default">
<ToggleSwitch
label="Skip Dialog"
checked={state.toolChange.skipDialog}
onChange={actions.toolChange.handleSkipDialog}
style={{ marginBottom: '1rem' }}
/>
</TooltipCustom>
)
}
{

toolChangeOption === 'Fixed Tool Sensor' && (
<div>
<Input
Expand Down Expand Up @@ -225,7 +220,7 @@ const ToolChange = ({ state, actions, mpos, $13 }) => {
toolChangeOption === 'Code' && (
<div>
<div className={styles.spreadRow}>
<MacroVariableDropdown textarea={preHookRef} label="Before change code"/>
<MacroVariableDropdown textarea={preHookRef} label="Before change code" />
</div>
<textarea
rows="6"
Expand All @@ -237,7 +232,7 @@ const ToolChange = ({ state, actions, mpos, $13 }) => {
ref={preHookRef}
/>
<div className={styles.spreadRow} style={{ marginTop: '10px' }}>
<MacroVariableDropdown textarea={postHookRef} label="After change code"/>
<MacroVariableDropdown textarea={postHookRef} label="After change code" />
</div>
<textarea
rows="6"
Expand Down
1 change: 0 additions & 1 deletion src/app/store/defaultState.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const defaultState = {
longestTimeRun: 0,
jobTimes: [],
toolChange: {
passthrough: false,
skipDialog: false,
},
toolChangeOption: 'Ignore',
Expand Down
30 changes: 12 additions & 18 deletions src/server/controllers/Grbl/GrblController.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,14 @@ class GrblController {
}

// // M6 Tool Change
//const passthroughM6 = store.get('preferences.toolChange.passthrough', false);
const passthroughM6 = _.get(this.toolChangeContext, 'passthrough', false);
if (_.includes(words, 'M6')) {
log.debug('M6 Tool Change');
this.feeder.hold({
data: 'M6',
comment: commentString
}); // Hold reason

if (!passthroughM6) {
const { toolChangeOption } = this.toolChangeContext;
if (toolChangeOption !== 'Passthrough') {
log.debug('M6 Tool Change');
this.feeder.hold({
data: 'M6',
comment: commentString
}); // Hold reason
line = line.replace('M6', '(M6)');
}
}
Expand Down Expand Up @@ -473,7 +471,8 @@ class GrblController {
}

/* Emit event to UI for toolchange handler */
if (_.includes(words, 'M6')) {
const { toolChangeOption } = this.toolChangeContext;
if (_.includes(words, 'M6') && toolChangeOption !== 'Passthrough') {
log.debug(`M6 Tool Change: line=${sent + 1}, sent=${sent}, received=${received}`);

// No toolchange in check mode
Expand All @@ -482,8 +481,6 @@ class GrblController {
return line.replace('M6', '(M6)');
}

const { toolChangeOption } = this.toolChangeContext;

let tool = line.match(toolCommand);

// Handle specific cases for macro and pause, ignore is default and comments line out with no other action
Expand Down Expand Up @@ -514,11 +511,8 @@ class GrblController {
}
}

//const passthroughM6 = store.get('preferences.toolChange.passthrough', false);
const passthroughM6 = _.get(this.toolChangeContext, 'passthrough', false);
if (!passthroughM6) {
line = line.replace('M6', '(M6)');
}
line = line.replace('M6', '(M6)');

//line = line.replace(`${tool?.[0]}`, `(${tool?.[0]})`);
}

Expand Down Expand Up @@ -1759,7 +1753,7 @@ class GrblController {
// @param {number} value The amount of percentage increase or decrease.
'spindleOverride': () => {
const [value] = args;
const [,, spindleOV] = this.state.status.ov;
const [, , spindleOV] = this.state.status.ov;

let diff = value - spindleOV;
//Limits for keyboard/gamepad shortcuts
Expand Down
24 changes: 14 additions & 10 deletions src/server/controllers/Grblhal/GrblHalController.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,20 @@ class GrblHalController {
this.updateSpindleModal(spindleCommand);
}

// // M6 Tool Change
// M6 Tool Change
if (_.includes(words, 'M6')) {
log.debug('M6 Tool Change');
this.feeder.hold({ data: 'M6', comment: commentString }); // Hold reason
line = line.replace('M6', '(M6)');
const { toolChangeOption } = this.toolChangeContext;
if (toolChangeOption !== 'Passthrough') {
log.debug('M6 Tool Change');
this.feeder.hold({
data: 'M6',
comment: commentString
}); // Hold reason
line = line.replace('M6', '(M6)');
}
}


if (this.isInRotaryMode) {
const containsACommand = A_AXIS_COMMANDS.test(line);
const containsYCommand = Y_AXIS_COMMANDS.test(line);
Expand Down Expand Up @@ -463,9 +470,9 @@ class GrblHalController {
}

/* Emit event to UI for toolchange handler */
if (_.includes(words, 'M6')) {
const { toolChangeOption } = this.toolChangeContext;
if (_.includes(words, 'M6') && toolChangeOption !== 'Passthrough') {
log.debug(`M6 Tool Change: line=${sent + 1}, sent=${sent}, received=${received}`);
const { toolChangeOption } = this.toolChangeContext;

const currentState = _.get(this.state, 'status.activeState', '');
if (currentState === 'Check') {
Expand Down Expand Up @@ -504,10 +511,7 @@ class GrblHalController {
}
}

const passthroughM6 = _.get(this.toolChangeContext, 'passthrough', false);
if (!passthroughM6 || toolChangeOption === 'Code') {
line = line.replace('M6', '(M6)');
}
line = line.replace('M6', '(M6)');
//line = line.replace(`${tool?.[0]}`, `(${tool?.[0]})`);
}

Expand Down