mirror of https://github.com/Desuuuu/klipper.git
adxl345: Allow multiple simultaneous clients
It is now possible to have multiple tools gathering adxl345 data at the same time. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
404b64fd62
commit
0b4fbc78a8
|
@ -104,13 +104,11 @@ class ADXLCommandHelper:
|
||||||
desc=self.cmd_ADXL345_DEBUG_WRITE_help)
|
desc=self.cmd_ADXL345_DEBUG_WRITE_help)
|
||||||
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):
|
||||||
if not self.chip.is_measuring():
|
if self.bg_client is None:
|
||||||
# Start measurements
|
# Start measurements
|
||||||
self.bg_client = self.chip.start_internal_client()
|
self.bg_client = self.chip.start_internal_client()
|
||||||
gcmd.respond_info("adxl345 measurements started")
|
gcmd.respond_info("adxl345 measurements started")
|
||||||
return
|
return
|
||||||
if self.bg_client is None:
|
|
||||||
raise gcmd.error("adxl345 measurements in progress")
|
|
||||||
# End measurements
|
# End measurements
|
||||||
name = gcmd.get("NAME", time.strftime("%Y%m%d_%H%M%S"))
|
name = gcmd.get("NAME", time.strftime("%Y%m%d_%H%M%S"))
|
||||||
if not name.replace('-', '').replace('_', '').isalnum():
|
if not name.replace('-', '').replace('_', '').isalnum():
|
||||||
|
@ -128,8 +126,6 @@ class ADXLCommandHelper:
|
||||||
% (filename,))
|
% (filename,))
|
||||||
cmd_ACCELEROMETER_QUERY_help = "Query accelerometer for the current values"
|
cmd_ACCELEROMETER_QUERY_help = "Query accelerometer for the current values"
|
||||||
def cmd_ACCELEROMETER_QUERY(self, gcmd):
|
def cmd_ACCELEROMETER_QUERY(self, gcmd):
|
||||||
if self.chip.is_measuring():
|
|
||||||
raise gcmd.error("adxl345 measurements in progress")
|
|
||||||
aclient = self.chip.start_internal_client()
|
aclient = self.chip.start_internal_client()
|
||||||
self.printer.lookup_object('toolhead').dwell(1.)
|
self.printer.lookup_object('toolhead').dwell(1.)
|
||||||
aclient.finish_measurements()
|
aclient.finish_measurements()
|
||||||
|
@ -141,15 +137,11 @@ class ADXLCommandHelper:
|
||||||
% (accel_x, accel_y, accel_z))
|
% (accel_x, accel_y, accel_z))
|
||||||
cmd_ADXL345_DEBUG_READ_help = "Query accelerometer register (for debugging)"
|
cmd_ADXL345_DEBUG_READ_help = "Query accelerometer register (for debugging)"
|
||||||
def cmd_ADXL345_DEBUG_READ(self, gcmd):
|
def cmd_ADXL345_DEBUG_READ(self, gcmd):
|
||||||
if self.chip.is_measuring():
|
|
||||||
raise gcmd.error("adxl345 measurements in progress")
|
|
||||||
reg = gcmd.get("REG", minval=29, maxval=57, parser=lambda x: int(x, 0))
|
reg = gcmd.get("REG", minval=29, maxval=57, parser=lambda x: int(x, 0))
|
||||||
val = self.chip.read_reg(reg)
|
val = self.chip.read_reg(reg)
|
||||||
gcmd.respond_info("ADXL345 REG[0x%x] = 0x%x" % (reg, val))
|
gcmd.respond_info("ADXL345 REG[0x%x] = 0x%x" % (reg, val))
|
||||||
cmd_ADXL345_DEBUG_WRITE_help = "Set accelerometer register (for debugging)"
|
cmd_ADXL345_DEBUG_WRITE_help = "Set accelerometer register (for debugging)"
|
||||||
def cmd_ADXL345_DEBUG_WRITE(self, gcmd):
|
def cmd_ADXL345_DEBUG_WRITE(self, gcmd):
|
||||||
if self.chip.is_measuring():
|
|
||||||
raise gcmd.error("adxl345 measurements in progress")
|
|
||||||
reg = gcmd.get("REG", minval=29, maxval=57, parser=lambda x: int(x, 0))
|
reg = gcmd.get("REG", minval=29, maxval=57, parser=lambda x: int(x, 0))
|
||||||
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)
|
||||||
|
@ -413,9 +405,6 @@ class ADXL345:
|
||||||
hdr = ('time', 'x_acceleration', 'y_acceleration', 'z_acceleration')
|
hdr = ('time', 'x_acceleration', 'y_acceleration', 'z_acceleration')
|
||||||
web_request.send({'header': hdr})
|
web_request.send({'header': hdr})
|
||||||
def start_internal_client(self):
|
def start_internal_client(self):
|
||||||
if self.is_measuring():
|
|
||||||
raise self.printer.command_error(
|
|
||||||
"ADXL345 measurement already in progress")
|
|
||||||
cconn = self.api_dump.add_internal_client()
|
cconn = self.api_dump.add_internal_client()
|
||||||
return ADXL345QueryHelper(self.printer, cconn)
|
return ADXL345QueryHelper(self.printer, cconn)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue