Skip to content

Commit b153b64

Browse files
committed
feat: encode Gcode parameter values where possible
Signed-off-by: Pedro Lamas <[email protected]>
1 parent 893b758 commit b153b64

File tree

19 files changed

+78
-49
lines changed

19 files changed

+78
-49
lines changed

src/components/layout/AppBar.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ import BrowserMixin from '@/mixins/browser'
184184
import { SocketActions } from '@/api/socketActions'
185185
import type { OutputPin } from '@/store/printer/types'
186186
import type { Device } from '@/store/power/types'
187+
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
187188
188189
@Component({
189190
components: {
@@ -390,7 +391,7 @@ export default class AppBar extends Mixins(StateMixin, ServicesMixin, FilesMixin
390391
391392
case 'klipper': {
392393
const value = (device.value !== 0) ? 0 : device.scale
393-
this.sendGcode(`SET_PIN PIN=${device.name} VALUE=${value}`, `${this.$waits.onSetOutputPin}${device.name}`)
394+
this.sendGcode(`SET_PIN PIN=${encodeGcodeParamValue(device.name)} VALUE=${value}`, `${this.$waits.onSetOutputPin}${device.name}`)
394395
break
395396
}
396397
}

src/components/widgets/beacon/BeaconCard.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ import SaveModelDialog from './SaveModelDialog.vue'
140140
import StateMixin from '@/mixins/state'
141141
import ToolheadMixin from '@/mixins/toolhead'
142142
import type { BeaconModel, BeaconState } from '@/store/printer/types'
143+
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
143144
144145
@Component({
145146
components: {
@@ -173,12 +174,12 @@ export default class BeaconCard extends Mixins(StateMixin, ToolheadMixin) {
173174
)
174175
175176
if (result) {
176-
this.sendGcode(`BEACON_MODEL_SELECT NAME="${name}"`)
177+
this.sendGcode(`BEACON_MODEL_SELECT NAME=${encodeGcodeParamValue(name)}`)
177178
}
178179
}
179180
180181
removeModel (name: string) {
181-
this.sendGcode(`BEACON_MODEL_REMOVE NAME="${name}"`)
182+
this.sendGcode(`BEACON_MODEL_REMOVE NAME=${encodeGcodeParamValue(name)}`)
182183
}
183184
184185
calibrate () {
@@ -194,10 +195,10 @@ export default class BeaconCard extends Mixins(StateMixin, ToolheadMixin) {
194195
195196
handleModelSave (config: { name: string; removeDefault: boolean }) {
196197
if (config.name !== this.beacon.model) {
197-
this.sendGcode(`BEACON_MODEL_SAVE NAME="${config.name}"`)
198+
this.sendGcode(`BEACON_MODEL_SAVE NAME=${encodeGcodeParamValue(config.name)}`)
198199
}
199-
if (config.removeDefault) {
200-
this.sendGcode(`BEACON_MODEL_REMOVE NAME="${this.beacon.model}"`)
200+
if (config.removeDefault && this.beacon.model) {
201+
this.sendGcode(`BEACON_MODEL_REMOVE NAME=${encodeGcodeParamValue(this.beacon.model)}`)
201202
}
202203
}
203204
}

src/components/widgets/bedmesh/BedMeshControls.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ import type {
278278
MatrixType,
279279
BedMeshProfileListEntry
280280
} from '@/store/mesh/types'
281+
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
281282
282283
@Component({
283284
components: {
@@ -386,20 +387,20 @@ export default class BedMesh extends Mixins(StateMixin, ToolheadMixin) {
386387
)
387388
388389
if (result) {
389-
this.sendGcode(`BED_MESH_PROFILE LOAD="${name}"`)
390+
this.sendGcode(`BED_MESH_PROFILE LOAD=${encodeGcodeParamValue(name)}`)
390391
}
391392
}
392393
393394
removeProfile (name: string) {
394-
this.sendGcode(`BED_MESH_PROFILE REMOVE="${name}"`)
395+
this.sendGcode(`BED_MESH_PROFILE REMOVE=${encodeGcodeParamValue(name)}`)
395396
}
396397
397398
handleMeshSave (config: { name: string; removeDefault: boolean }) {
398399
if (config.name !== this.currentMesh.profile_name) {
399-
this.sendGcode(`BED_MESH_PROFILE SAVE="${config.name}"`)
400+
this.sendGcode(`BED_MESH_PROFILE SAVE=${encodeGcodeParamValue(config.name)}`)
400401
}
401402
if (config.removeDefault) {
402-
this.sendGcode(`BED_MESH_PROFILE REMOVE="${this.currentMesh.profile_name}"`)
403+
this.sendGcode(`BED_MESH_PROFILE REMOVE=${encodeGcodeParamValue(this.currentMesh.profile_name)}`)
403404
}
404405
}
405406

src/components/widgets/exclude-objects/ExcludeObjectsDialog.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<script lang="ts">
4646
import { Component, Mixins, VModel } from 'vue-property-decorator'
4747
import StateMixin from '@/mixins/state'
48+
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
4849
4950
@Component({})
5051
export default class ExcludeObjectDialog extends Mixins(StateMixin) {
@@ -73,7 +74,7 @@ export default class ExcludeObjectDialog extends Mixins(StateMixin) {
7374
if (result) {
7475
const reqId = name.toUpperCase().replace(/\s/g, '_')
7576
76-
this.sendGcode(`EXCLUDE_OBJECT NAME=${reqId}`)
77+
this.sendGcode(`EXCLUDE_OBJECT NAME=${encodeGcodeParamValue(reqId)}`)
7778
}
7879
}
7980
}

src/components/widgets/gcode-preview/GcodePreviewCard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ import type { AppFile } from '@/store/files/types'
150150
import type { MinMax } from '@/store/gcodePreview/types'
151151
import { getFileDataTransferDataFromDataTransfer, hasFileDataTransferTypeInDataTransfer } from '@/util/file-data-transfer'
152152
import consola from 'consola'
153+
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
153154
154155
@Component({
155156
components: {
@@ -399,7 +400,7 @@ export default class GcodePreviewCard extends Mixins(StateMixin, FilesMixin, Bro
399400
if (result) {
400401
const reqId = id.toUpperCase().replace(/\s/g, '_')
401402
402-
this.sendGcode(`EXCLUDE_OBJECT NAME=${reqId}`)
403+
this.sendGcode(`EXCLUDE_OBJECT NAME=${encodeGcodeParamValue(reqId)}`)
403404
}
404405
}
405406

src/components/widgets/macros/MacroBtn.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import { Component, Prop, Mixins } from 'vue-property-decorator'
8989
import StateMixin from '@/mixins/state'
9090
import type { Macro } from '@/store/macros/types'
9191
import gcodeMacroParams from '@/util/gcode-macro-params'
92-
import { gcodeCommandBuilder, isBasicGcodeCommand, getParamNameForRawGcodeCommand } from '@/util/gcode-command-builder'
92+
import { gcodeCommandBuilder, isBasicGcodeCommand, getParamNameForRawGcodeCommand } from '@/util/gcode-helpers'
9393
9494
type MacroParameter = {
9595
value: string | number

src/components/widgets/outputs/OutputFan.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator'
4343
import type { Fan } from '@/store/printer/types'
4444
import StateMixin from '@/mixins/state'
4545
import BrowserMixin from '@/mixins/browser'
46+
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
4647
4748
@Component({})
4849
export default class OutputFan extends Mixins(StateMixin, BrowserMixin) {
@@ -69,7 +70,7 @@ export default class OutputFan extends Mixins(StateMixin, BrowserMixin) {
6970
}
7071
if (this.fan.type === 'fan_generic') {
7172
target = target / 100
72-
this.sendGcode(`SET_FAN_SPEED FAN=${this.fan.name} SPEED=${target}`, `${this.$waits.onSetFanSpeed}${this.fan.name}`)
73+
this.sendGcode(`SET_FAN_SPEED FAN=${encodeGcodeParamValue(this.fan.name)} SPEED=${target}`, `${this.$waits.onSetFanSpeed}${this.fan.name}`)
7374
}
7475
}
7576

src/components/widgets/outputs/OutputLed.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator'
2929
import { IroColor } from '@irojs/iro-core'
3030
import StateMixin from '@/mixins/state'
3131
import type { Led } from '@/store/printer/types'
32+
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
3233
3334
type Rgbw = {
3435
r: number,
@@ -132,7 +133,7 @@ export default class OutputLed extends Mixins(StateMixin) {
132133
.map(channel => ` ${this.channelLookup[channel]}=${Math.round(color[channel] * 1000 / 255) / 1000}`)
133134
.join('')
134135
135-
this.sendGcode(`SET_LED LED=${this.led.name}${colorsString}`)
136+
this.sendGcode(`SET_LED LED=${encodeGcodeParamValue(this.led.name)}${colorsString}`)
136137
}
137138
}
138139
</script>

src/components/widgets/outputs/OutputPin.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator'
3030
import StateMixin from '@/mixins/state'
3131
import BrowserMixin from '@/mixins/browser'
3232
import type { OutputPin as IOutputPin } from '@/store/printer/types'
33+
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
3334
3435
@Component({})
3536
export default class OutputPin extends Mixins(StateMixin, BrowserMixin) {
@@ -67,7 +68,7 @@ export default class OutputPin extends Mixins(StateMixin, BrowserMixin) {
6768
target = Math.round(target * this.pin.scale) / 100
6869
}
6970
70-
this.sendGcode(`SET_PIN PIN=${this.pin.name} VALUE=${target}`, `${this.$waits.onSetOutputPin}${this.pin.name}`)
71+
this.sendGcode(`SET_PIN PIN=${encodeGcodeParamValue(this.pin.name)} VALUE=${target}`, `${this.$waits.onSetOutputPin}${this.pin.name}`)
7172
}
7273
}
7374
</script>

src/components/widgets/runout-sensors/RunoutSensorsCard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import { Component, Mixins, Prop } from 'vue-property-decorator'
5656
import StateMixin from '@/mixins/state'
5757
import type { RunoutSensor } from '@/store/printer/types'
58+
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
5859
5960
@Component({})
6061
export default class RunoutSensorsCard extends Mixins(StateMixin) {
@@ -66,7 +67,7 @@ export default class RunoutSensorsCard extends Mixins(StateMixin) {
6667
}
6768
6869
changeSensor (item: RunoutSensor, value: boolean) {
69-
this.sendGcode(`SET_FILAMENT_SENSOR SENSOR=${item.name} ENABLE=${+value}`)
70+
this.sendGcode(`SET_FILAMENT_SENSOR SENSOR=${encodeGcodeParamValue(item.name)} ENABLE=${+value}`)
7071
}
7172
}
7273
</script>

0 commit comments

Comments
 (0)