adxl345: No need to implement is_measuring()
The APIDumpHelper class already ensures that the start/stop callbacks will only be called when needed. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
d6a4669ce0
commit
43ce7c0b9a
|
@ -185,7 +185,6 @@ 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)
|
||||||
self.query_rate = 0
|
|
||||||
am = {'x': (0, SCALE_XY), 'y': (1, SCALE_XY), 'z': (2, SCALE_Z),
|
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)}
|
'-x': (0, -SCALE_XY), '-y': (1, -SCALE_XY), '-z': (2, -SCALE_Z)}
|
||||||
axes_map = config.getlist('axes_map', ('x','y','z'), count=3)
|
axes_map = config.getlist('axes_map', ('x','y','z'), count=3)
|
||||||
|
@ -246,8 +245,6 @@ class ADXL345:
|
||||||
"(e.g. faulty wiring) or a faulty adxl345 chip." % (
|
"(e.g. faulty wiring) or a faulty adxl345 chip." % (
|
||||||
reg, val, stored_val))
|
reg, val, stored_val))
|
||||||
# Measurement collection
|
# Measurement collection
|
||||||
def is_measuring(self):
|
|
||||||
return self.query_rate > 0
|
|
||||||
def _extract_samples(self, raw_samples):
|
def _extract_samples(self, raw_samples):
|
||||||
# Load variables to optimize inner loop below
|
# Load variables to optimize inner loop below
|
||||||
(x_pos, x_scale), (y_pos, y_scale), (z_pos, z_scale) = self.axes_map
|
(x_pos, x_scale), (y_pos, y_scale), (z_pos, z_scale) = self.axes_map
|
||||||
|
@ -294,8 +291,6 @@ class ADXL345:
|
||||||
raise self.printer.command_error("Unable to query adxl345 fifo")
|
raise self.printer.command_error("Unable to query adxl345 fifo")
|
||||||
self.clock_updater.update_clock(params)
|
self.clock_updater.update_clock(params)
|
||||||
def _start_measurements(self):
|
def _start_measurements(self):
|
||||||
if self.is_measuring():
|
|
||||||
return
|
|
||||||
# In case of miswiring, testing ADXL345 device ID prevents treating
|
# In case of miswiring, testing ADXL345 device ID prevents treating
|
||||||
# noise or wrong signal as a correctly initialized device
|
# noise or wrong signal as a correctly initialized device
|
||||||
dev_id = self.read_reg(REG_DEVID)
|
dev_id = self.read_reg(REG_DEVID)
|
||||||
|
@ -317,7 +312,6 @@ class ADXL345:
|
||||||
print_time = self.mcu.estimated_print_time(systime) + MIN_MSG_TIME
|
print_time = self.mcu.estimated_print_time(systime) + MIN_MSG_TIME
|
||||||
reqclock = self.mcu.print_time_to_clock(print_time)
|
reqclock = self.mcu.print_time_to_clock(print_time)
|
||||||
rest_ticks = self.mcu.seconds_to_clock(4. / self.data_rate)
|
rest_ticks = self.mcu.seconds_to_clock(4. / self.data_rate)
|
||||||
self.query_rate = self.data_rate
|
|
||||||
self.query_adxl345_cmd.send([self.oid, reqclock, rest_ticks],
|
self.query_adxl345_cmd.send([self.oid, reqclock, rest_ticks],
|
||||||
reqclock=reqclock)
|
reqclock=reqclock)
|
||||||
logging.info("ADXL345 starting '%s' measurements", self.name)
|
logging.info("ADXL345 starting '%s' measurements", self.name)
|
||||||
|
@ -327,11 +321,8 @@ class ADXL345:
|
||||||
self.clock_updater.clear_duration_filter()
|
self.clock_updater.clear_duration_filter()
|
||||||
self.last_error_count = 0
|
self.last_error_count = 0
|
||||||
def _finish_measurements(self):
|
def _finish_measurements(self):
|
||||||
if not self.is_measuring():
|
|
||||||
return
|
|
||||||
# Halt bulk reading
|
# Halt bulk reading
|
||||||
params = self.query_adxl345_end_cmd.send([self.oid, 0, 0])
|
params = self.query_adxl345_end_cmd.send([self.oid, 0, 0])
|
||||||
self.query_rate = 0
|
|
||||||
self.bulk_queue.clear_samples()
|
self.bulk_queue.clear_samples()
|
||||||
logging.info("ADXL345 finished '%s' measurements", self.name)
|
logging.info("ADXL345 finished '%s' measurements", self.name)
|
||||||
# API interface
|
# API interface
|
||||||
|
|
|
@ -458,8 +458,6 @@ class Angle:
|
||||||
def get_status(self, eventtime=None):
|
def get_status(self, eventtime=None):
|
||||||
return {'temperature': self.sensor_helper.last_temperature}
|
return {'temperature': self.sensor_helper.last_temperature}
|
||||||
# Measurement collection
|
# Measurement collection
|
||||||
def is_measuring(self):
|
|
||||||
return self.start_clock != 0
|
|
||||||
def _extract_samples(self, raw_samples):
|
def _extract_samples(self, raw_samples):
|
||||||
# Load variables to optimize inner loop below
|
# Load variables to optimize inner loop below
|
||||||
sample_ticks = self.sample_ticks
|
sample_ticks = self.sample_ticks
|
||||||
|
@ -527,8 +525,6 @@ class Angle:
|
||||||
return {'data': samples, 'errors': error_count,
|
return {'data': samples, 'errors': error_count,
|
||||||
'position_offset': offset}
|
'position_offset': offset}
|
||||||
def _start_measurements(self):
|
def _start_measurements(self):
|
||||||
if self.is_measuring():
|
|
||||||
return
|
|
||||||
logging.info("Starting angle '%s' measurements", self.name)
|
logging.info("Starting angle '%s' measurements", self.name)
|
||||||
self.sensor_helper.start()
|
self.sensor_helper.start()
|
||||||
# Start bulk reading
|
# Start bulk reading
|
||||||
|
@ -542,11 +538,8 @@ class Angle:
|
||||||
self.query_spi_angle_cmd.send([self.oid, reqclock, rest_ticks,
|
self.query_spi_angle_cmd.send([self.oid, reqclock, rest_ticks,
|
||||||
self.time_shift], reqclock=reqclock)
|
self.time_shift], reqclock=reqclock)
|
||||||
def _finish_measurements(self):
|
def _finish_measurements(self):
|
||||||
if not self.is_measuring():
|
|
||||||
return
|
|
||||||
# Halt bulk reading
|
# Halt bulk reading
|
||||||
params = self.query_spi_angle_end_cmd.send([self.oid, 0, 0, 0])
|
params = self.query_spi_angle_end_cmd.send([self.oid, 0, 0, 0])
|
||||||
self.start_clock = 0
|
|
||||||
self.bulk_queue.clear_samples()
|
self.bulk_queue.clear_samples()
|
||||||
self.sensor_helper.last_temperature = None
|
self.sensor_helper.last_temperature = None
|
||||||
logging.info("Stopped angle '%s' measurements", self.name)
|
logging.info("Stopped angle '%s' measurements", self.name)
|
||||||
|
|
|
@ -42,7 +42,6 @@ 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)
|
||||||
self.query_rate = 0
|
|
||||||
am = {'x': (0, SCALE), 'y': (1, SCALE), 'z': (2, SCALE),
|
am = {'x': (0, SCALE), 'y': (1, SCALE), 'z': (2, SCALE),
|
||||||
'-x': (0, -SCALE), '-y': (1, -SCALE), '-z': (2, -SCALE)}
|
'-x': (0, -SCALE), '-y': (1, -SCALE), '-z': (2, -SCALE)}
|
||||||
axes_map = config.getlist('axes_map', ('x','y','z'), count=3)
|
axes_map = config.getlist('axes_map', ('x','y','z'), count=3)
|
||||||
|
@ -102,8 +101,6 @@ class LIS2DW:
|
||||||
"(e.g. faulty wiring) or a faulty lis2dw chip." % (
|
"(e.g. faulty wiring) or a faulty lis2dw chip." % (
|
||||||
reg, val, stored_val))
|
reg, val, stored_val))
|
||||||
# Measurement collection
|
# Measurement collection
|
||||||
def is_measuring(self):
|
|
||||||
return self.query_rate > 0
|
|
||||||
def _extract_samples(self, raw_samples):
|
def _extract_samples(self, raw_samples):
|
||||||
# Load variables to optimize inner loop below
|
# Load variables to optimize inner loop below
|
||||||
(x_pos, x_scale), (y_pos, y_scale), (z_pos, z_scale) = self.axes_map
|
(x_pos, x_scale), (y_pos, y_scale), (z_pos, z_scale) = self.axes_map
|
||||||
|
@ -145,8 +142,6 @@ class LIS2DW:
|
||||||
minclock=minclock)
|
minclock=minclock)
|
||||||
self.clock_updater.update_clock(params)
|
self.clock_updater.update_clock(params)
|
||||||
def _start_measurements(self):
|
def _start_measurements(self):
|
||||||
if self.is_measuring():
|
|
||||||
return
|
|
||||||
# In case of miswiring, testing LIS2DW device ID prevents treating
|
# In case of miswiring, testing LIS2DW device ID prevents treating
|
||||||
# noise or wrong signal as a correctly initialized device
|
# noise or wrong signal as a correctly initialized device
|
||||||
dev_id = self.read_reg(REG_LIS2DW_WHO_AM_I_ADDR)
|
dev_id = self.read_reg(REG_LIS2DW_WHO_AM_I_ADDR)
|
||||||
|
@ -173,7 +168,6 @@ class LIS2DW:
|
||||||
print_time = self.mcu.estimated_print_time(systime) + MIN_MSG_TIME
|
print_time = self.mcu.estimated_print_time(systime) + MIN_MSG_TIME
|
||||||
reqclock = self.mcu.print_time_to_clock(print_time)
|
reqclock = self.mcu.print_time_to_clock(print_time)
|
||||||
rest_ticks = self.mcu.seconds_to_clock(4. / self.data_rate)
|
rest_ticks = self.mcu.seconds_to_clock(4. / self.data_rate)
|
||||||
self.query_rate = self.data_rate
|
|
||||||
self.query_lis2dw_cmd.send([self.oid, reqclock, rest_ticks],
|
self.query_lis2dw_cmd.send([self.oid, reqclock, rest_ticks],
|
||||||
reqclock=reqclock)
|
reqclock=reqclock)
|
||||||
logging.info("LIS2DW starting '%s' measurements", self.name)
|
logging.info("LIS2DW starting '%s' measurements", self.name)
|
||||||
|
@ -183,11 +177,8 @@ class LIS2DW:
|
||||||
self.clock_updater.clear_duration_filter()
|
self.clock_updater.clear_duration_filter()
|
||||||
self.last_error_count = 0
|
self.last_error_count = 0
|
||||||
def _finish_measurements(self):
|
def _finish_measurements(self):
|
||||||
if not self.is_measuring():
|
|
||||||
return
|
|
||||||
# Halt bulk reading
|
# Halt bulk reading
|
||||||
params = self.query_lis2dw_end_cmd.send([self.oid, 0, 0])
|
params = self.query_lis2dw_end_cmd.send([self.oid, 0, 0])
|
||||||
self.query_rate = 0
|
|
||||||
self.bulk_queue.clear_samples()
|
self.bulk_queue.clear_samples()
|
||||||
logging.info("LIS2DW finished '%s' measurements", self.name)
|
logging.info("LIS2DW finished '%s' measurements", self.name)
|
||||||
self.set_reg(REG_LIS2DW_FIFO_CTRL, 0x00)
|
self.set_reg(REG_LIS2DW_FIFO_CTRL, 0x00)
|
||||||
|
|
|
@ -59,7 +59,6 @@ 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)
|
||||||
self.query_rate = 0
|
|
||||||
am = {'x': (0, SCALE), 'y': (1, SCALE), 'z': (2, SCALE),
|
am = {'x': (0, SCALE), 'y': (1, SCALE), 'z': (2, SCALE),
|
||||||
'-x': (0, -SCALE), '-y': (1, -SCALE), '-z': (2, -SCALE)}
|
'-x': (0, -SCALE), '-y': (1, -SCALE), '-z': (2, -SCALE)}
|
||||||
axes_map = config.getlist('axes_map', ('x','y','z'), count=3)
|
axes_map = config.getlist('axes_map', ('x','y','z'), count=3)
|
||||||
|
@ -116,8 +115,6 @@ class MPU9250:
|
||||||
self.i2c.i2c_write([reg, val & 0xFF], minclock=minclock)
|
self.i2c.i2c_write([reg, val & 0xFF], minclock=minclock)
|
||||||
|
|
||||||
# Measurement collection
|
# Measurement collection
|
||||||
def is_measuring(self):
|
|
||||||
return self.query_rate > 0
|
|
||||||
def _extract_samples(self, raw_samples):
|
def _extract_samples(self, raw_samples):
|
||||||
# Load variables to optimize inner loop below
|
# Load variables to optimize inner loop below
|
||||||
(x_pos, x_scale), (y_pos, y_scale), (z_pos, z_scale) = self.axes_map
|
(x_pos, x_scale), (y_pos, y_scale), (z_pos, z_scale) = self.axes_map
|
||||||
|
@ -157,8 +154,6 @@ class MPU9250:
|
||||||
minclock=minclock)
|
minclock=minclock)
|
||||||
self.clock_updater.update_clock(params)
|
self.clock_updater.update_clock(params)
|
||||||
def _start_measurements(self):
|
def _start_measurements(self):
|
||||||
if self.is_measuring():
|
|
||||||
return
|
|
||||||
# In case of miswiring, testing MPU9250 device ID prevents treating
|
# In case of miswiring, testing MPU9250 device ID prevents treating
|
||||||
# noise or wrong signal as a correctly initialized device
|
# noise or wrong signal as a correctly initialized device
|
||||||
dev_id = self.read_reg(REG_DEVID)
|
dev_id = self.read_reg(REG_DEVID)
|
||||||
|
@ -185,7 +180,6 @@ class MPU9250:
|
||||||
print_time = self.mcu.estimated_print_time(systime) + MIN_MSG_TIME
|
print_time = self.mcu.estimated_print_time(systime) + MIN_MSG_TIME
|
||||||
reqclock = self.mcu.print_time_to_clock(print_time)
|
reqclock = self.mcu.print_time_to_clock(print_time)
|
||||||
rest_ticks = self.mcu.seconds_to_clock(4. / self.data_rate)
|
rest_ticks = self.mcu.seconds_to_clock(4. / self.data_rate)
|
||||||
self.query_rate = self.data_rate
|
|
||||||
self.query_mpu9250_cmd.send([self.oid, reqclock, rest_ticks],
|
self.query_mpu9250_cmd.send([self.oid, reqclock, rest_ticks],
|
||||||
reqclock=reqclock)
|
reqclock=reqclock)
|
||||||
logging.info("MPU9250 starting '%s' measurements", self.name)
|
logging.info("MPU9250 starting '%s' measurements", self.name)
|
||||||
|
@ -195,11 +189,8 @@ class MPU9250:
|
||||||
self.clock_updater.clear_duration_filter()
|
self.clock_updater.clear_duration_filter()
|
||||||
self.last_error_count = 0
|
self.last_error_count = 0
|
||||||
def _finish_measurements(self):
|
def _finish_measurements(self):
|
||||||
if not self.is_measuring():
|
|
||||||
return
|
|
||||||
# Halt bulk reading
|
# Halt bulk reading
|
||||||
params = self.query_mpu9250_end_cmd.send([self.oid, 0, 0])
|
params = self.query_mpu9250_end_cmd.send([self.oid, 0, 0])
|
||||||
self.query_rate = 0
|
|
||||||
self.bulk_queue.clear_samples()
|
self.bulk_queue.clear_samples()
|
||||||
logging.info("MPU9250 finished '%s' measurements", self.name)
|
logging.info("MPU9250 finished '%s' measurements", self.name)
|
||||||
self.set_reg(REG_PWR_MGMT_1, SET_PWR_MGMT_1_SLEEP)
|
self.set_reg(REG_PWR_MGMT_1, SET_PWR_MGMT_1_SLEEP)
|
||||||
|
|
Loading…
Reference in New Issue