Skip to content

Commit

Permalink
ConfigGen: support 'none' accelerometer option
Browse files Browse the repository at this point in the history
Github: #27
  • Loading branch information
miklschmidt committed Dec 26, 2024
1 parent 9b317e8 commit 836e381
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
27 changes: 17 additions & 10 deletions src/server/helpers/klipper-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof AccelerometerType> = 'adxl345';

if (accelerometerName === 'controlboard') {
return getAccelerometerWithType({ id: 'controlboard', title: 'Controlboard' }, null, null, config.controlboard);
}
Expand Down Expand Up @@ -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`);
Expand Down
5 changes: 4 additions & 1 deletion src/utils/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const getAccelerometerWithType = (
toolheadSuffix: ToolheadSuffix | null,
toolboard?: Toolboard | null,
controlboard?: Board | null,
): KlipperAccelSensorSchema => {
): KlipperAccelSensorSchema | null => {
let accelType: z.infer<typeof AccelerometerType> = 'adxl345';
if (accelerometer.id === 'toolboard') {
if (toolboard == null) {
Expand All @@ -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,
Expand Down

0 comments on commit 836e381

Please sign in to comment.