aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/adxl345.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2023-12-17 02:10:43 -0500
committerKevin O'Connor <kevin@koconnor.net>2023-12-26 11:47:21 -0500
commit3f84501955c9eb6774f1a3ad0069dbda103bdbae (patch)
tree16257be50005aa50790ee49c6ff9462c2a89fb94 /klippy/extras/adxl345.py
parent43ce7c0b9ad4f30277c10b086b86a0937dbfebbc (diff)
downloadkutter-3f84501955c9eb6774f1a3ad0069dbda103bdbae.tar.gz
kutter-3f84501955c9eb6774f1a3ad0069dbda103bdbae.tar.xz
kutter-3f84501955c9eb6774f1a3ad0069dbda103bdbae.zip
adxl345: Add a read_axes_map() helper function
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/adxl345.py')
-rw-r--r--klippy/extras/adxl345.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/klippy/extras/adxl345.py b/klippy/extras/adxl345.py
index c15dca4b..be4a0eac 100644
--- a/klippy/extras/adxl345.py
+++ b/klippy/extras/adxl345.py
@@ -173,6 +173,15 @@ class AccelCommandHelper:
val = gcmd.get("VAL", minval=0, maxval=255, parser=lambda x: int(x, 0))
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)}
+ 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")
+ return [am[a.strip()] for a in axes_map]
+
MIN_MSG_TIME = 0.100
BYTES_PER_SAMPLE = 5
@@ -185,12 +194,7 @@ class ADXL345:
def __init__(self, config):
self.printer = config.get_printer()
AccelCommandHelper(config, self)
- 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)}
- 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 adxl345 axes_map parameter")
- self.axes_map = [am[a.strip()] for a in axes_map]
+ self.axes_map = read_axes_map(config)
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,))