adxl345: Add a read_axes_map() helper function
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
43ce7c0b9a
commit
3f84501955
|
@ -173,6 +173,15 @@ class AccelCommandHelper:
|
||||||
val = gcmd.get("VAL", minval=0, maxval=255, parser=lambda x: int(x, 0))
|
val = gcmd.get("VAL", minval=0, maxval=255, parser=lambda x: int(x, 0))
|
||||||
self.chip.set_reg(reg, val)
|
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
|
MIN_MSG_TIME = 0.100
|
||||||
|
|
||||||
BYTES_PER_SAMPLE = 5
|
BYTES_PER_SAMPLE = 5
|
||||||
|
@ -185,12 +194,7 @@ class ADXL345:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.printer = config.get_printer()
|
self.printer = config.get_printer()
|
||||||
AccelCommandHelper(config, self)
|
AccelCommandHelper(config, self)
|
||||||
am = {'x': (0, SCALE_XY), 'y': (1, SCALE_XY), 'z': (2, SCALE_Z),
|
self.axes_map = read_axes_map(config)
|
||||||
'-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.data_rate = config.getint('rate', 3200)
|
self.data_rate = config.getint('rate', 3200)
|
||||||
if self.data_rate not in QUERY_RATES:
|
if self.data_rate not in QUERY_RATES:
|
||||||
raise config.error("Invalid rate parameter: %d" % (self.data_rate,))
|
raise config.error("Invalid rate parameter: %d" % (self.data_rate,))
|
||||||
|
|
|
@ -42,12 +42,7 @@ class LIS2DW:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.printer = config.get_printer()
|
self.printer = config.get_printer()
|
||||||
adxl345.AccelCommandHelper(config, self)
|
adxl345.AccelCommandHelper(config, self)
|
||||||
am = {'x': (0, SCALE), 'y': (1, SCALE), 'z': (2, SCALE),
|
self.axes_map = adxl345.read_axes_map(config)
|
||||||
'-x': (0, -SCALE), '-y': (1, -SCALE), '-z': (2, -SCALE)}
|
|
||||||
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 lis2dw axes_map parameter")
|
|
||||||
self.axes_map = [am[a.strip()] for a in axes_map]
|
|
||||||
self.data_rate = 1600
|
self.data_rate = 1600
|
||||||
# Setup mcu sensor_lis2dw bulk query code
|
# Setup mcu sensor_lis2dw bulk query code
|
||||||
self.spi = bus.MCU_SPI_from_config(config, 3, default_speed=5000000)
|
self.spi = bus.MCU_SPI_from_config(config, 3, default_speed=5000000)
|
||||||
|
|
|
@ -59,12 +59,7 @@ class MPU9250:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.printer = config.get_printer()
|
self.printer = config.get_printer()
|
||||||
adxl345.AccelCommandHelper(config, self)
|
adxl345.AccelCommandHelper(config, self)
|
||||||
am = {'x': (0, SCALE), 'y': (1, SCALE), 'z': (2, SCALE),
|
self.axes_map = adxl345.read_axes_map(config)
|
||||||
'-x': (0, -SCALE), '-y': (1, -SCALE), '-z': (2, -SCALE)}
|
|
||||||
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 mpu9250 axes_map parameter")
|
|
||||||
self.axes_map = [am[a.strip()] for a in axes_map]
|
|
||||||
self.data_rate = config.getint('rate', 4000)
|
self.data_rate = config.getint('rate', 4000)
|
||||||
if self.data_rate not in SAMPLE_RATE_DIVS:
|
if self.data_rate not in SAMPLE_RATE_DIVS:
|
||||||
raise config.error("Invalid rate parameter: %d" % (self.data_rate,))
|
raise config.error("Invalid rate parameter: %d" % (self.data_rate,))
|
||||||
|
|
Loading…
Reference in New Issue