adxl345: Add accelerometer chip name to the raw data file name

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This commit is contained in:
Dmitry Butyugin 2021-01-29 19:35:33 +01:00 committed by KevinOConnor
parent 891852ed9c
commit 0fb2449be0
3 changed files with 20 additions and 10 deletions

View File

@ -6,6 +6,10 @@ All dates in this document are approximate.
# Changes # Changes
20210201: The `ACCELEROMETER_MEASURE` command will now append the name
of the accelerometer chip to the output file name if the chip was given
a name in the corresponding adxl345 section of the printer.cfg.
20201222: The `step_distance` setting in the stepper config sections 20201222: The `step_distance` setting in the stepper config sections
is deprecated. It is advised to update the config to use the is deprecated. It is advised to update the config to use the
[`rotation_distance`](Rotation_Distance.md) setting. Support for [`rotation_distance`](Rotation_Distance.md) setting. Support for

View File

@ -704,10 +704,13 @@ The following commands are available when an
the first time, it starts the measurements, next execution stops the first time, it starts the measurements, next execution stops
them. If RATE is not specified, then the default value is used them. If RATE is not specified, then the default value is used
(either from `printer.cfg` or `3200` default value). The results of (either from `printer.cfg` or `3200` default value). The results of
measurements are written to a file named `/tmp/adxl345-<name>.csv` measurements are written to a file named
where `<name>` is the optional NAME parameter. If NAME is not `/tmp/adxl345-<chip>-<name>.csv` where `<chip>` is the name of the
specified it defaults to the current time in "YYYYMMDD_HHMMSS" accelerometer chip (`my_chip_name` from `[adxl345 my_chip_name]`) and
format. `<name>` is the optional NAME parameter. If NAME is not specified it
defaults to the current time in "YYYYMMDD_HHMMSS" format. If the
accelerometer does not have a name in its config section (simply
`[adxl345]`) <chip> part of the name is not generated.
- `ACCELEROMETER_QUERY [CHIP=<config_name>] [RATE=<value>]`: queries - `ACCELEROMETER_QUERY [CHIP=<config_name>] [RATE=<value>]`: queries
accelerometer for the current value. If CHIP is not specified it accelerometer for the current value. If CHIP is not specified it
defaults to "default". If RATE is not specified, the default value defaults to "default". If RATE is not specified, the default value

View File

@ -125,17 +125,17 @@ class ADXL345:
mcu.register_response(self._handle_adxl345_start, "adxl345_start", oid) mcu.register_response(self._handle_adxl345_start, "adxl345_start", oid)
mcu.register_response(self._handle_adxl345_data, "adxl345_data", oid) mcu.register_response(self._handle_adxl345_data, "adxl345_data", oid)
# Register commands # Register commands
name = "default" self.name = "default"
if len(config.get_name().split()) > 1: if len(config.get_name().split()) > 1:
name = config.get_name().split()[1] self.name = config.get_name().split()[1]
gcode = self.printer.lookup_object('gcode') gcode = self.printer.lookup_object('gcode')
gcode.register_mux_command("ACCELEROMETER_MEASURE", "CHIP", name, gcode.register_mux_command("ACCELEROMETER_MEASURE", "CHIP", self.name,
self.cmd_ACCELEROMETER_MEASURE, self.cmd_ACCELEROMETER_MEASURE,
desc=self.cmd_ACCELEROMETER_MEASURE_help) desc=self.cmd_ACCELEROMETER_MEASURE_help)
gcode.register_mux_command("ACCELEROMETER_QUERY", "CHIP", name, gcode.register_mux_command("ACCELEROMETER_QUERY", "CHIP", self.name,
self.cmd_ACCELEROMETER_QUERY, self.cmd_ACCELEROMETER_QUERY,
desc=self.cmd_ACCELEROMETER_QUERY_help) desc=self.cmd_ACCELEROMETER_QUERY_help)
if name == "default": if self.name == "default":
gcode.register_mux_command("ACCELEROMETER_MEASURE", "CHIP", None, gcode.register_mux_command("ACCELEROMETER_MEASURE", "CHIP", None,
self.cmd_ACCELEROMETER_MEASURE) self.cmd_ACCELEROMETER_MEASURE)
gcode.register_mux_command("ACCELEROMETER_QUERY", "CHIP", None, gcode.register_mux_command("ACCELEROMETER_QUERY", "CHIP", None,
@ -229,7 +229,10 @@ class ADXL345:
return return
res = self.finish_measurements() res = self.finish_measurements()
# Write data to file # Write data to file
filename = "/tmp/adxl345-%s.csv" % (name,) if self.name == "default":
filename = "/tmp/adxl345-%s.csv" % (name,)
else:
filename = "/tmp/adxl345-%s-%s.csv" % (self.name, name,)
res.write_to_file(filename) res.write_to_file(filename)
cmd_ACCELEROMETER_MEASURE_help = "Start/stop accelerometer" cmd_ACCELEROMETER_MEASURE_help = "Start/stop accelerometer"
def cmd_ACCELEROMETER_MEASURE(self, gcmd): def cmd_ACCELEROMETER_MEASURE(self, gcmd):