From 836e381c527fe53c6e684034b6cbc13ff9f9cbfc Mon Sep 17 00:00:00 2001 From: Mikkel Schmidt Date: Thu, 26 Dec 2024 11:13:05 +0100 Subject: [PATCH] ConfigGen: support 'none' accelerometer option Github: #27 --- src/server/helpers/klipper-config.ts | 27 +++++++++++++++++---------- src/utils/serialization.ts | 5 ++++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/server/helpers/klipper-config.ts b/src/server/helpers/klipper-config.ts index 8210304c..f6f8811c 100644 --- a/src/server/helpers/klipper-config.ts +++ b/src/server/helpers/klipper-config.ts @@ -307,8 +307,6 @@ export const constructKlipperConfigUtils = async (config: PrinterConfiguration) return this.renderCommentHeader(header ?? rail.axis.toUpperCase(), section); }, getAccelWithType(accelerometerName: KlipperAccelSensorName) { - let accelType: z.infer = 'adxl345'; - if (accelerometerName === 'controlboard') { return getAccelerometerWithType({ id: 'controlboard', title: 'Controlboard' }, null, null, config.controlboard); } @@ -853,16 +851,25 @@ export const constructKlipperConfigHelpers = async ( } const xAccel = utils.getAccelWithType(xToolhead.getXAccelerometerName()); const yAccel = utils.getAccelWithType(xToolhead.getYAccelerometerName()); + if (xAccel == null && yAccel == null) { + return ''; + } result.push('[resonance_tester]'); - if (xAccel.type === 'beacon') { - result.push(`accel_chip_x: ${xAccel.type}`); - } else { - result.push(`accel_chip_x: ${xAccel.type} ${xAccel.name}`); + if (xAccel != null) { + const prefix = yAccel != null ? 'accel_chip_x' : 'accel_chip'; + if (xAccel.type === 'beacon') { + result.push(`${prefix}: ${xAccel.type}`); + } else { + result.push(`${prefix}: ${xAccel.type} ${xAccel.name}`); + } } - if (yAccel.type === 'beacon') { - result.push(`accel_chip_y: ${yAccel.type}`); - } else { - result.push(`accel_chip_y: ${yAccel.type} ${yAccel.name}`); + if (yAccel != null) { + const prefix = xAccel != null ? 'accel_chip_y' : 'accel_chip'; + if (yAccel.type === 'beacon') { + result.push(`${prefix}: ${yAccel.type}`); + } else { + result.push(`${prefix}: ${yAccel.type} ${yAccel.name}`); + } } result.push('probe_points:'); result.push(`\t${printerSize.x / 2},${printerSize.y / 2},20`); diff --git a/src/utils/serialization.ts b/src/utils/serialization.ts index c5d8fa7d..fe82cab2 100644 --- a/src/utils/serialization.ts +++ b/src/utils/serialization.ts @@ -157,7 +157,7 @@ export const getAccelerometerWithType = ( toolheadSuffix: ToolheadSuffix | null, toolboard?: Toolboard | null, controlboard?: Board | null, -): KlipperAccelSensorSchema => { +): KlipperAccelSensorSchema | null => { let accelType: z.infer = 'adxl345'; if (accelerometer.id === 'toolboard') { if (toolboard == null) { @@ -184,6 +184,9 @@ export const getAccelerometerWithType = ( } else if (accelerometer.id === 'sbc') { accelType = 'adxl345'; } + if (accelerometer.id === 'none') { + return null; + } return klipperAccelSensorSchema.parse({ name: accelerometerIdToKlipperAccelSensorName(accelerometer, toolheadSuffix, toolboard, controlboard), type: accelType,