diff --git a/package.json b/package.json index 81754ecef..54fc7736d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gSender", - "version": "1.4.7", + "version": "1.4.8", "description": "Electron sender for GRBL based CNC machines", "author": { "name": "Sienci Labs ", diff --git a/src/app/containers/Preferences/Preferences.jsx b/src/app/containers/Preferences/Preferences.jsx index 0e7a0af4c..d31f7c4ff 100644 --- a/src/app/containers/Preferences/Preferences.jsx +++ b/src/app/containers/Preferences/Preferences.jsx @@ -178,6 +178,7 @@ class PreferencesPage extends PureComponent { }, showWarning: store.get('widgets.visualizer.showWarning'), showLineWarnings: store.get('widgets.visualizer.showLineWarnings'), + spindleDelay: store.get('widgets.spindle.delay'), shouldWarnZero: store.get('workspace.shouldWarnZero', false), ipRange: store.get('widgets.connection.ip', [192, 168, 5, 1]), toolChange: { @@ -528,13 +529,9 @@ class PreferencesPage extends PureComponent { pubsub.publish('spindle:updated', newSpindleValue); }, - handleDelayToggle: (hasDelay) => { - const { spindle } = this.state; + handleDelayChange: (delay) => { this.setState({ - spindle: { - ...spindle, - delay: hasDelay - } + spindleDelay: delay }); } }, @@ -863,7 +860,8 @@ class PreferencesPage extends PureComponent { safeRetractHeight, customDecimalPlaces, spindle, - toolChange + toolChange, + spindleDelay } = this.state; store.set('workspace.reverseWidgets', reverseWidgets); @@ -883,7 +881,7 @@ class PreferencesPage extends PureComponent { store.replace('workspace[probeProfile]', probe); store.set('widgets.spindle.spindleMax', spindle.spindleMax); store.set('widgets.spindle.spindleMin', spindle.spindleMin); - store.set('widgets.spindle.delay', spindle.delay); + store.set('widgets.spindle.delay', spindleDelay); this.probeConfig.set('retractionDistance', probeSettings.retractionDistance); this.probeConfig.set('probeFeedrate', probeSettings.normalFeedrate); this.probeConfig.set('probeFastFeedrate', probeSettings.fastFeedrate); diff --git a/src/app/containers/Preferences/SpindleLaser/index.js b/src/app/containers/Preferences/SpindleLaser/index.js index fae2c57c6..0502a411d 100644 --- a/src/app/containers/Preferences/SpindleLaser/index.js +++ b/src/app/containers/Preferences/SpindleLaser/index.js @@ -6,6 +6,7 @@ import controller from 'app/lib/controller'; import SettingWrapper from '../components/SettingWrapper'; import Fieldset from '../components/Fieldset'; +import Input from '../components/Input'; import GeneralArea from '../components/GeneralArea'; import TooltipCustom from '../../../components/TooltipCustom/ToolTip'; import Laser from './Laser'; @@ -14,8 +15,14 @@ import { collectUserUsageData } from '../../../lib/heatmap'; import { USAGE_TOOL_NAME } from '../../../constants'; const SpindleLaser = ({ active, state, actions }) => { + const { spindle } = state; + const spindleActions = actions.spindle; + const [delay, setDelay] = useState(spindle.delay); const [machineProfile, setMachineProfile] = useState(store.get('workspace.machineProfile', {})); - const [delay, setDelay] = useState(store.get('widgets.spindle.delay', false)); + + useEffect(() => { + setDelay(spindle.delay); + }, [spindle]); useEffect(() => { const timeout = setTimeout(() => { @@ -55,13 +62,7 @@ const SpindleLaser = ({ active, state, actions }) => { setMachineProfile(updatedObj); }; - const handleSpindleDelayToggle = () => { - const spindleActions = actions.spindle; - spindleActions.handleDelayToggle(!delay); - setDelay(!delay); - }; - - const { spindle, laserOnOutline } = machineProfile; + const { spindle: isSpindle, laserOnOutline } = machineProfile; return ( @@ -71,7 +72,7 @@ const SpindleLaser = ({ active, state, actions }) => { @@ -79,20 +80,22 @@ const SpindleLaser = ({ active, state, actions }) => { - - + spindleActions.handleDelayChange(e.target.value)} /> +

Please reload your file after changing delay.

diff --git a/src/app/sagas/controllerSagas.js b/src/app/sagas/controllerSagas.js index ae8f56657..ec6f7a340 100644 --- a/src/app/sagas/controllerSagas.js +++ b/src/app/sagas/controllerSagas.js @@ -345,6 +345,7 @@ export function* initialize() { const machineProfile = store.get('workspace.machineProfile'); const showLineWarnings = store.get('widgets.visualizer.showLineWarnings'); + const delay = store.get('widgets.spindle.delay'); // Reset homing run flag to prevent rapid position without running homing reduxStore.dispatch({ type: controllerActions.RESET_HOMING, @@ -357,6 +358,10 @@ export function* initialize() { if (showLineWarnings) { controller.command('settings:updated', { showLineWarnings }); } + + if (delay !== undefined) { + controller.command('settings:updated', { spindleDelay: delay }); + } const hooks = store.get('workspace.toolChangeHooks', {}); const toolChangeOption = store.get('workspace.toolChangeOption', 'Ignore'); const toolChangeContext = { diff --git a/src/app/store/defaultState.js b/src/app/store/defaultState.js index c07a609f9..8e8d7cab9 100644 --- a/src/app/store/defaultState.js +++ b/src/app/store/defaultState.js @@ -290,7 +290,7 @@ const defaultState = { speed: 1000, spindleMax: 30000, spindleMin: 10000, - delay: false, + delay: 0, laser: { power: 100, duration: 1, diff --git a/src/app/store/index.js b/src/app/store/index.js index 385e45c1e..200231468 100644 --- a/src/app/store/index.js +++ b/src/app/store/index.js @@ -6,7 +6,7 @@ import get from 'lodash/get'; import set from 'lodash/set'; // import merge from 'lodash/merge'; import uniq from 'lodash/uniq'; -import { isEmpty, isNumber, isString } from 'lodash'; +import { isEmpty } from 'lodash'; import semver from 'semver'; import settings from '../config/settings'; import ImmutableStore from '../lib/immutable-store'; @@ -160,31 +160,20 @@ const normalizeState = (state) => { }; const merge = (base, saved) => { - const numberRegex = /^-?\d+.?\d*$/; - const baseIsObject = base instanceof Object; const baseIsArray = Array.isArray(base); const savedIsObject = saved instanceof Object; const savedIsArray = Array.isArray(saved); - const fromStringToNumber = isNumber(base) && isString(saved) && numberRegex.test(saved); - const fromNumberToString = isNumber(saved) && isString(base) && numberRegex.test(base); - + // if they are both not objects, use saved. migration will be made later if needed if ( (!(baseIsObject) || baseIsArray) && (!(savedIsObject) || savedIsArray) ) { - // if they are the same type, use saved - // when numbers are rounded, they become strings - // so if it changes between those two types, and the string is a number, keep saved - if ((typeof base === typeof saved) || fromStringToNumber || fromNumberToString) { - return saved; - } - // if they are not, default structure changed, so use base - return base; + return saved; + // if one is an object and the other isn't, then default structure changed, so use base } else if ((!(baseIsObject) || baseIsArray) || (!(savedIsObject) || savedIsArray)) { - // if one is an object and the other isn't, then default structure changed, so use base return base; } @@ -255,6 +244,15 @@ const migrateStore = () => { return; } + if (semver.lt(cnc.version, '1.4.8')) { + const delay = store.get('widgets.spindle.delay'); + if (delay) { + store.set('widgets.spindle.delay', 1); + } else { + store.set('widgets.spindle.delay', 0); + } + } + if (semver.lt(cnc.version, '1.4.4')) { store.replace('widgets.connection.controller.type', 'Grbl'); } diff --git a/src/package.json b/src/package.json index 92a63d0aa..dbb4a29ea 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "gSender", - "version": "1.4.7", + "version": "1.4.8", "productName": "gSender", "description": "CNC Milling Controller", "author": { diff --git a/src/server/controllers/Grbl/GrblController.js b/src/server/controllers/Grbl/GrblController.js index 071ced5e5..3a1cc0699 100644 --- a/src/server/controllers/Grbl/GrblController.js +++ b/src/server/controllers/Grbl/GrblController.js @@ -1453,13 +1453,13 @@ class GrblController { // add delay to spindle startup if enabled const preferences = store.get('preferences', {}); - const delay = _.get(preferences, 'spindle.delay', false); + const delay = _.get(preferences, 'spindleDelay', 0); // test if there is a G4 command already const delayRegex = new RegExp('(G4 ?P?[0-9]+)'); // only add one if there isn't - if (delay && !delayRegex.test(gcode)) { - gcode = gcode.replace(/\b(?:S\d* ?M[34]|M[34] ?S\d*)\b/g, '$& G4 P1'); + if (Number(delay) && !delayRegex.test(gcode)) { + gcode = gcode.replace(/\b(?:S\d* ?M[34]|M[34] ?S\d*)\b/g, `$& G4 P${delay}`); } const gcodeWithoutComments = gcode.replace(bracketCommentLine, ''); diff --git a/src/server/controllers/Grblhal/GrblHalController.js b/src/server/controllers/Grblhal/GrblHalController.js index dcfbafd50..76bd4b794 100644 --- a/src/server/controllers/Grblhal/GrblHalController.js +++ b/src/server/controllers/Grblhal/GrblHalController.js @@ -1496,10 +1496,10 @@ class GrblHalController { // add delay to spindle startup if enabled const preferences = store.get('preferences', {}); - const delay = _.get(preferences, 'spindle.delay', false); + const delay = _.get(preferences, 'spindleDelay', 0); - if (delay) { - gcode = gcode.replace(/\b(?:S\d* ?M[34]|M[34] ?S\d*)\b(?! ?G4 ?P?\b)/g, '$& G4 P1'); + if (Number(delay)) { + gcode = gcode.replace(/\b(?:S\d* ?M[34]|M[34] ?S\d*)\b(?! ?G4 ?P?\b)/g, `$& G4 P${delay}`); } const ok = this.sender.load(name, gcode + '\n', context);