adxl345: Add new start_internal_client() function and use in callers

Introduce a new start_internal_client() function and change all client
code to use that instead of manually calling start_measurements() and
finish_measurements().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-08-11 23:09:49 -04:00
parent 8cfaed441d
commit d87f7a77c3
2 changed files with 58 additions and 45 deletions

View file

@ -164,26 +164,25 @@ class ResonanceTester:
if len(axes) > 1:
gcmd.respond_info("Testing axis %s" % axis.get_name())
for chip_axis, chip in self.accel_chips:
if axis.matches(chip_axis):
chip.start_measurements()
# Generate moves
self.test.run_test(axis, gcmd)
raw_values = []
for chip_axis, chip in self.accel_chips:
if axis.matches(chip_axis):
results = chip.finish_measurements()
if raw_name_suffix is not None:
raw_name = self.get_filename(
'raw_data', raw_name_suffix, axis,
point if len(test_points) > 1 else None)
results.write_to_file(raw_name)
gcmd.respond_info(
"Writing raw accelerometer data to "
"%s file" % (raw_name,))
raw_values.append((chip_axis, results))
gcmd.respond_info("%s-axis accelerometer stats: %s" % (
chip_axis, results.get_stats(),))
aclient = chip.start_internal_client()
raw_values.append((chip_axis, aclient))
# Generate moves
self.test.run_test(axis, gcmd)
for chip_axis, aclient in raw_values:
aclient.finish_measurements()
if raw_name_suffix is not None:
raw_name = self.get_filename(
'raw_data', raw_name_suffix, axis,
point if len(test_points) > 1 else None)
aclient.write_to_file(raw_name)
gcmd.respond_info(
"Writing raw accelerometer data to "
"%s file" % (raw_name,))
gcmd.respond_info("%s-axis accelerometer stats: %s" % (
chip_axis, aclient.get_stats(),))
if helper is None:
continue
for chip_axis, chip_values in raw_values:
@ -281,14 +280,14 @@ class ResonanceTester:
"Measures noise of all enabled accelerometer chips")
def cmd_MEASURE_AXES_NOISE(self, gcmd):
meas_time = gcmd.get_float("MEAS_TIME", 2.)
for _, chip in self.accel_chips:
chip.start_measurements()
self.printer.lookup_object('toolhead').dwell(meas_time)
raw_values = [(chip_axis, chip.finish_measurements())
raw_values = [(chip_axis, chip.start_internal_client())
for chip_axis, chip in self.accel_chips]
self.printer.lookup_object('toolhead').dwell(meas_time)
for chip_axis, aclient in raw_values:
aclient.finish_measurements()
helper = shaper_calibrate.ShaperCalibrate(self.printer)
for chip_axis, raw_data in raw_values:
data = helper.process_accelerometer_data(raw_data)
for chip_axis, aclient in raw_values:
data = helper.process_accelerometer_data(aclient)
vx = data.psd_x.mean()
vy = data.psd_y.mean()
vz = data.psd_z.mean()