Skip to content

Commit

Permalink
feat: encode Gcode parameter values where possible
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas committed Dec 10, 2024
1 parent 893b758 commit b153b64
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 49 deletions.
3 changes: 2 additions & 1 deletion src/components/layout/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ import BrowserMixin from '@/mixins/browser'
import { SocketActions } from '@/api/socketActions'
import type { OutputPin } from '@/store/printer/types'
import type { Device } from '@/store/power/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({
components: {
Expand Down Expand Up @@ -390,7 +391,7 @@ export default class AppBar extends Mixins(StateMixin, ServicesMixin, FilesMixin
case 'klipper': {
const value = (device.value !== 0) ? 0 : device.scale
this.sendGcode(`SET_PIN PIN=${device.name} VALUE=${value}`, `${this.$waits.onSetOutputPin}${device.name}`)
this.sendGcode(`SET_PIN PIN=${encodeGcodeParamValue(device.name)} VALUE=${value}`, `${this.$waits.onSetOutputPin}${device.name}`)
break
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/components/widgets/beacon/BeaconCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ import SaveModelDialog from './SaveModelDialog.vue'
import StateMixin from '@/mixins/state'
import ToolheadMixin from '@/mixins/toolhead'
import type { BeaconModel, BeaconState } from '@/store/printer/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({
components: {
Expand Down Expand Up @@ -173,12 +174,12 @@ export default class BeaconCard extends Mixins(StateMixin, ToolheadMixin) {
)
if (result) {
this.sendGcode(`BEACON_MODEL_SELECT NAME="${name}"`)
this.sendGcode(`BEACON_MODEL_SELECT NAME=${encodeGcodeParamValue(name)}`)
}
}
removeModel (name: string) {
this.sendGcode(`BEACON_MODEL_REMOVE NAME="${name}"`)
this.sendGcode(`BEACON_MODEL_REMOVE NAME=${encodeGcodeParamValue(name)}`)
}
calibrate () {
Expand All @@ -194,10 +195,10 @@ export default class BeaconCard extends Mixins(StateMixin, ToolheadMixin) {
handleModelSave (config: { name: string; removeDefault: boolean }) {
if (config.name !== this.beacon.model) {
this.sendGcode(`BEACON_MODEL_SAVE NAME="${config.name}"`)
this.sendGcode(`BEACON_MODEL_SAVE NAME=${encodeGcodeParamValue(config.name)}`)
}
if (config.removeDefault) {
this.sendGcode(`BEACON_MODEL_REMOVE NAME="${this.beacon.model}"`)
if (config.removeDefault && this.beacon.model) {
this.sendGcode(`BEACON_MODEL_REMOVE NAME=${encodeGcodeParamValue(this.beacon.model)}`)
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/components/widgets/bedmesh/BedMeshControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ import type {
MatrixType,
BedMeshProfileListEntry
} from '@/store/mesh/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({
components: {
Expand Down Expand Up @@ -386,20 +387,20 @@ export default class BedMesh extends Mixins(StateMixin, ToolheadMixin) {
)
if (result) {
this.sendGcode(`BED_MESH_PROFILE LOAD="${name}"`)
this.sendGcode(`BED_MESH_PROFILE LOAD=${encodeGcodeParamValue(name)}`)
}
}
removeProfile (name: string) {
this.sendGcode(`BED_MESH_PROFILE REMOVE="${name}"`)
this.sendGcode(`BED_MESH_PROFILE REMOVE=${encodeGcodeParamValue(name)}`)
}
handleMeshSave (config: { name: string; removeDefault: boolean }) {
if (config.name !== this.currentMesh.profile_name) {
this.sendGcode(`BED_MESH_PROFILE SAVE="${config.name}"`)
this.sendGcode(`BED_MESH_PROFILE SAVE=${encodeGcodeParamValue(config.name)}`)
}
if (config.removeDefault) {
this.sendGcode(`BED_MESH_PROFILE REMOVE="${this.currentMesh.profile_name}"`)
this.sendGcode(`BED_MESH_PROFILE REMOVE=${encodeGcodeParamValue(this.currentMesh.profile_name)}`)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<script lang="ts">
import { Component, Mixins, VModel } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({})
export default class ExcludeObjectDialog extends Mixins(StateMixin) {
Expand Down Expand Up @@ -73,7 +74,7 @@ export default class ExcludeObjectDialog extends Mixins(StateMixin) {
if (result) {
const reqId = name.toUpperCase().replace(/\s/g, '_')
this.sendGcode(`EXCLUDE_OBJECT NAME=${reqId}`)
this.sendGcode(`EXCLUDE_OBJECT NAME=${encodeGcodeParamValue(reqId)}`)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/widgets/gcode-preview/GcodePreviewCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ import type { AppFile } from '@/store/files/types'
import type { MinMax } from '@/store/gcodePreview/types'
import { getFileDataTransferDataFromDataTransfer, hasFileDataTransferTypeInDataTransfer } from '@/util/file-data-transfer'
import consola from 'consola'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({
components: {
Expand Down Expand Up @@ -399,7 +400,7 @@ export default class GcodePreviewCard extends Mixins(StateMixin, FilesMixin, Bro
if (result) {
const reqId = id.toUpperCase().replace(/\s/g, '_')
this.sendGcode(`EXCLUDE_OBJECT NAME=${reqId}`)
this.sendGcode(`EXCLUDE_OBJECT NAME=${encodeGcodeParamValue(reqId)}`)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/macros/MacroBtn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ import { Component, Prop, Mixins } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import type { Macro } from '@/store/macros/types'
import gcodeMacroParams from '@/util/gcode-macro-params'
import { gcodeCommandBuilder, isBasicGcodeCommand, getParamNameForRawGcodeCommand } from '@/util/gcode-command-builder'
import { gcodeCommandBuilder, isBasicGcodeCommand, getParamNameForRawGcodeCommand } from '@/util/gcode-helpers'
type MacroParameter = {
value: string | number
Expand Down
3 changes: 2 additions & 1 deletion src/components/widgets/outputs/OutputFan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator'
import type { Fan } from '@/store/printer/types'
import StateMixin from '@/mixins/state'
import BrowserMixin from '@/mixins/browser'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({})
export default class OutputFan extends Mixins(StateMixin, BrowserMixin) {
Expand All @@ -69,7 +70,7 @@ export default class OutputFan extends Mixins(StateMixin, BrowserMixin) {
}
if (this.fan.type === 'fan_generic') {
target = target / 100
this.sendGcode(`SET_FAN_SPEED FAN=${this.fan.name} SPEED=${target}`, `${this.$waits.onSetFanSpeed}${this.fan.name}`)
this.sendGcode(`SET_FAN_SPEED FAN=${encodeGcodeParamValue(this.fan.name)} SPEED=${target}`, `${this.$waits.onSetFanSpeed}${this.fan.name}`)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/widgets/outputs/OutputLed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator'
import { IroColor } from '@irojs/iro-core'
import StateMixin from '@/mixins/state'
import type { Led } from '@/store/printer/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
type Rgbw = {
r: number,
Expand Down Expand Up @@ -132,7 +133,7 @@ export default class OutputLed extends Mixins(StateMixin) {
.map(channel => ` ${this.channelLookup[channel]}=${Math.round(color[channel] * 1000 / 255) / 1000}`)
.join('')
this.sendGcode(`SET_LED LED=${this.led.name}${colorsString}`)
this.sendGcode(`SET_LED LED=${encodeGcodeParamValue(this.led.name)}${colorsString}`)
}
}
</script>
3 changes: 2 additions & 1 deletion src/components/widgets/outputs/OutputPin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import BrowserMixin from '@/mixins/browser'
import type { OutputPin as IOutputPin } from '@/store/printer/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({})
export default class OutputPin extends Mixins(StateMixin, BrowserMixin) {
Expand Down Expand Up @@ -67,7 +68,7 @@ export default class OutputPin extends Mixins(StateMixin, BrowserMixin) {
target = Math.round(target * this.pin.scale) / 100
}
this.sendGcode(`SET_PIN PIN=${this.pin.name} VALUE=${target}`, `${this.$waits.onSetOutputPin}${this.pin.name}`)
this.sendGcode(`SET_PIN PIN=${encodeGcodeParamValue(this.pin.name)} VALUE=${target}`, `${this.$waits.onSetOutputPin}${this.pin.name}`)
}
}
</script>
3 changes: 2 additions & 1 deletion src/components/widgets/runout-sensors/RunoutSensorsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import { Component, Mixins, Prop } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import type { RunoutSensor } from '@/store/printer/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({})
export default class RunoutSensorsCard extends Mixins(StateMixin) {
Expand All @@ -66,7 +67,7 @@ export default class RunoutSensorsCard extends Mixins(StateMixin) {
}
changeSensor (item: RunoutSensor, value: boolean) {
this.sendGcode(`SET_FILAMENT_SENSOR SENSOR=${item.name} ENABLE=${+value}`)
this.sendGcode(`SET_FILAMENT_SENSOR SENSOR=${encodeGcodeParamValue(item.name)} ENABLE=${+value}`)
}
}
</script>
5 changes: 3 additions & 2 deletions src/components/widgets/status/PauseAtLayerDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<script lang="ts">
import StateMixin from '@/mixins/state'
import type { Macro } from '@/store/macros/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
import { Component, VModel, Mixins } from 'vue-property-decorator'
type PauseNextLayer = {
Expand Down Expand Up @@ -144,15 +145,15 @@ export default class PauseAtLayerDialog extends Mixins(StateMixin) {
if (this.setPauseNextLayerMacro) {
if (this.pauseNextLayer.enable) {
gcodes.push(`SET_PAUSE_NEXT_LAYER ENABLE=1 MACRO="${this.pauseNextLayer.call}"`)
gcodes.push(`SET_PAUSE_NEXT_LAYER ENABLE=1 MACRO=${encodeGcodeParamValue(this.pauseNextLayer.call)}`)
} else {
gcodes.push('SET_PAUSE_NEXT_LAYER ENABLE=0')
}
}
if (this.setPauseAtLayerMacro) {
if (this.pauseAtLayer.enable) {
gcodes.push(`SET_PAUSE_AT_LAYER ENABLE=1 LAYER=${this.pauseAtLayer.layer} MACRO="${this.pauseAtLayer.call}"`)
gcodes.push(`SET_PAUSE_AT_LAYER ENABLE=1 LAYER=${this.pauseAtLayer.layer} MACRO=${encodeGcodeParamValue(this.pauseAtLayer.call)}`)
} else {
gcodes.push('SET_PAUSE_AT_LAYER ENABLE=0')
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/widgets/thermals/TemperatureCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import TemperatureTargets from '@/components/widgets/thermals/TemperatureTargets
import TemperaturePresetsMenu from './TemperaturePresetsMenu.vue'
import type { TemperaturePreset } from '@/store/config/types'
import type { ChartSelectedLegends } from '@/store/charts/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({
components: {
Expand Down Expand Up @@ -214,10 +215,10 @@ export default class TemperatureCard extends Mixins(StateMixin, BrowserMixin) {
for (const key in preset.values) {
const item = preset.values[key]
if (item.type === 'heater' && item.active && item.value > -1) {
this.sendGcode(`SET_HEATER_TEMPERATURE HEATER=${key} TARGET=${item.value}`)
this.sendGcode(`SET_HEATER_TEMPERATURE HEATER=${encodeGcodeParamValue(key)} TARGET=${item.value}`)
}
if (item.type === 'fan' && item.active && item.value > -1) {
this.sendGcode(`SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=${key} TARGET=${item.value}`)
this.sendGcode(`SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=${encodeGcodeParamValue(key)} TARGET=${item.value}`)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/widgets/thermals/TemperatureTargets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ import StateMixin from '@/mixins/state'
import type { Fan, Heater, Sensor } from '@/store/printer/types'
import { takeRightWhile } from 'lodash-es'
import type { ChartData, ChartSelectedLegends } from '@/store/charts/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({
components: {
Expand Down Expand Up @@ -351,11 +352,11 @@ export default class TemperatureTargets extends Mixins(StateMixin) {
}
setHeaterTargetTemp (heater: string, target: number) {
this.sendGcode(`SET_HEATER_TEMPERATURE HEATER=${heater} TARGET=${target}`)
this.sendGcode(`SET_HEATER_TEMPERATURE HEATER=${encodeGcodeParamValue(heater)} TARGET=${target}`)
}
setFanTargetTemp (fan: string, target: number) {
this.sendGcode(`SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=${fan} TARGET=${target}`)
this.sendGcode(`SET_TEMPERATURE_FAN_TARGET TEMPERATURE_FAN=${encodeGcodeParamValue(fan)} TARGET=${target}`)
}
getRateOfChange (item: Heater | Sensor) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/widgets/toolhead/ExtruderSelection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script lang="ts">
import { Component, Mixins } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({})
export default class ExtruderSelection extends Mixins(StateMixin) {
Expand All @@ -29,7 +30,7 @@ export default class ExtruderSelection extends Mixins(StateMixin) {
}
set extruder (extruder: string) {
this.sendGcode(`ACTIVATE_EXTRUDER EXTRUDER=${extruder}`, this.$waits.onExtruderChange)
this.sendGcode(`ACTIVATE_EXTRUDER EXTRUDER=${encodeGcodeParamValue(extruder)}`, this.$waits.onExtruderChange)
}
}
</script>
5 changes: 3 additions & 2 deletions src/components/widgets/toolhead/ExtruderStepperSync.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import { Component, Mixins, Prop } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import type { KnownExtruder, ExtruderStepper } from '@/store/printer/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({})
export default class ExtruderStepperSync extends Mixins(StateMixin) {
Expand All @@ -49,11 +50,11 @@ export default class ExtruderStepperSync extends Mixins(StateMixin) {
}
sendSyncExtruderMotion (value: string | null) {
this.sendGcode(`SYNC_EXTRUDER_MOTION EXTRUDER=${this.extruderStepper.name} MOTION_QUEUE=${value ?? ''}`, `${this.$waits.onSyncExtruder}${this.extruderStepper.name}`)
this.sendGcode(`SYNC_EXTRUDER_MOTION EXTRUDER=${encodeGcodeParamValue(this.extruderStepper.name)} MOTION_QUEUE=${value ?? ''}`, `${this.$waits.onSyncExtruder}${this.extruderStepper.name}`)
}
sendSetStepperEnable (value: boolean) {
this.sendGcode(`SET_STEPPER_ENABLE STEPPER="${this.extruderStepper.key}" ENABLE=${+value}`, `${this.$waits.onStepperEnable}${this.extruderStepper.name}`)
this.sendGcode(`SET_STEPPER_ENABLE STEPPER=${encodeGcodeParamValue(this.extruderStepper.key)} ENABLE=${+value}`, `${this.$waits.onStepperEnable}${this.extruderStepper.name}`)
}
}
</script>
3 changes: 2 additions & 1 deletion src/components/widgets/toolhead/PressureAdvanceAdjust.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import StateMixin from '@/mixins/state'
import ToolheadMixin from '@/mixins/toolhead'
import BrowserMixin from '@/mixins/browser'
import type { ExtruderStepper } from '@/store/printer/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({})
export default class PressureAdvanceAdjust extends Mixins(StateMixin, ToolheadMixin, BrowserMixin) {
Expand All @@ -67,7 +68,7 @@ export default class PressureAdvanceAdjust extends Mixins(StateMixin, ToolheadMi
sendSetPressureAdvance (arg: string, val: number) {
if (this.extruderStepper) {
const { name } = this.extruderStepper
this.sendGcode(`SET_PRESSURE_ADVANCE ${arg}=${val} EXTRUDER=${name}`, `${this.$waits.onSetPressureAdvance}${name}`)
this.sendGcode(`SET_PRESSURE_ADVANCE ${arg}=${val} EXTRUDER=${encodeGcodeParamValue(name)}`, `${this.$waits.onSetPressureAdvance}${name}`)
} else {
this.sendGcode(`SET_PRESSURE_ADVANCE ${arg}=${val}`, this.$waits.onSetPressureAdvance)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import { Component, Mixins, Prop } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import type { Stepper } from '@/store/printer/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
@Component({})
export default class ToolheadControlBarsStepper extends Mixins(StateMixin) {
Expand Down Expand Up @@ -49,7 +50,7 @@ export default class ToolheadControlBarsStepper extends Mixins(StateMixin) {
}
sendForceMoveGcode (distance: number) {
this.sendGcode(`FORCE_MOVE STEPPER="${this.stepper.key}" DISTANCE=${distance} VELOCITY=${this.rate} ACCEL=${this.accel}`)
this.sendGcode(`FORCE_MOVE STEPPER=${encodeGcodeParamValue(this.stepper.key)} DISTANCE=${distance} VELOCITY=${this.rate} ACCEL=${this.accel}`)
}
}
</script>
2 changes: 1 addition & 1 deletion src/util/__tests__/gcode-command-builder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gcodeCommandBuilder } from '../gcode-command-builder'
import { gcodeCommandBuilder } from '../gcode-helpers'

describe('gcodeCommandBuilder', () => {
it.each([
Expand Down
Loading

0 comments on commit b153b64

Please sign in to comment.