From d8d072b3759a2b62de37efd4b8811d962a4d7e7c Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 29 Apr 2024 12:07:28 -0400 Subject: [PATCH] adxl345: Fix read_axes_map() for non-adxl345 accelerometers Commit 3f845019 unified the reading of the axes_map configuration variable, but broke the per-sensor scaling capabilities. Pass the scale parameters to read_axes_map() so that it can be implemented per-sensor. Reported by @Neko-vecter. Signed-off-by: Kevin O'Connor --- klippy/extras/adxl345.py | 8 ++++---- klippy/extras/lis2dw.py | 2 +- klippy/extras/mpu9250.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/klippy/extras/adxl345.py b/klippy/extras/adxl345.py index 5323be797..bbc9e32b8 100644 --- a/klippy/extras/adxl345.py +++ b/klippy/extras/adxl345.py @@ -176,9 +176,9 @@ class AccelCommandHelper: self.chip.set_reg(reg, val) # Helper to read the axes_map parameter from the config -def read_axes_map(config): - am = {'x': (0, SCALE_XY), 'y': (1, SCALE_XY), 'z': (2, SCALE_Z), - '-x': (0, -SCALE_XY), '-y': (1, -SCALE_XY), '-z': (2, -SCALE_Z)} +def read_axes_map(config, scale_x, scale_y, scale_z): + am = {'x': (0, scale_x), 'y': (1, scale_y), 'z': (2, scale_z), + '-x': (0, -scale_x), '-y': (1, -scale_y), '-z': (2, -scale_z)} axes_map = config.getlist('axes_map', ('x','y','z'), count=3) if any([a not in am for a in axes_map]): raise config.error("Invalid axes_map parameter") @@ -191,7 +191,7 @@ class ADXL345: def __init__(self, config): self.printer = config.get_printer() AccelCommandHelper(config, self) - self.axes_map = read_axes_map(config) + self.axes_map = read_axes_map(config, SCALE_XY, SCALE_XY, SCALE_Z) self.data_rate = config.getint('rate', 3200) if self.data_rate not in QUERY_RATES: raise config.error("Invalid rate parameter: %d" % (self.data_rate,)) diff --git a/klippy/extras/lis2dw.py b/klippy/extras/lis2dw.py index 3f17c1f4c..45c12ea1a 100644 --- a/klippy/extras/lis2dw.py +++ b/klippy/extras/lis2dw.py @@ -37,7 +37,7 @@ class LIS2DW: def __init__(self, config): self.printer = config.get_printer() adxl345.AccelCommandHelper(config, self) - self.axes_map = adxl345.read_axes_map(config) + self.axes_map = adxl345.read_axes_map(config, SCALE, SCALE, SCALE) self.data_rate = 1600 # Setup mcu sensor_lis2dw bulk query code self.spi = bus.MCU_SPI_from_config(config, 3, default_speed=5000000) diff --git a/klippy/extras/mpu9250.py b/klippy/extras/mpu9250.py index 9a07b705e..ff15fed41 100644 --- a/klippy/extras/mpu9250.py +++ b/klippy/extras/mpu9250.py @@ -59,7 +59,7 @@ class MPU9250: def __init__(self, config): self.printer = config.get_printer() adxl345.AccelCommandHelper(config, self) - self.axes_map = adxl345.read_axes_map(config) + self.axes_map = adxl345.read_axes_map(config, SCALE, SCALE, SCALE) self.data_rate = config.getint('rate', 4000) if self.data_rate not in SAMPLE_RATE_DIVS: raise config.error("Invalid rate parameter: %d" % (self.data_rate,))