angle: Report tle5012b temperature

Export the tle5012b temperature readings when performing measurements.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-03-19 19:28:00 -04:00
parent f9d505e376
commit 1b08553a42
2 changed files with 18 additions and 0 deletions

View File

@ -10,6 +10,15 @@ attribute be sure to review the
[Config Changes document](Config_Changes.md) when upgrading the [Config Changes document](Config_Changes.md) when upgrading the
Klipper software. Klipper software.
## angle
The following information is available in
[angle some_name](Config_Reference.md#angle) objects:
- `temperature`: The last temperature reading (in Celsius) from a
tle5012b magnetic hall sensor. This value is only available if the
angle sensor is a tle5012b chip and if measurements are in progress
(otherwise it reports `None`).
## bed_mesh ## bed_mesh
The following information is available in the The following information is available in the

View File

@ -264,6 +264,7 @@ class HelperA1333:
def __init__(self, config, spi, oid): def __init__(self, config, spi, oid):
self.spi = spi self.spi = spi
self.is_tcode_absolute = False self.is_tcode_absolute = False
self.last_temperature = None
def get_static_delay(self): def get_static_delay(self):
return .000001 return .000001
def start(self): def start(self):
@ -276,6 +277,7 @@ class HelperAS5047D:
def __init__(self, config, spi, oid): def __init__(self, config, spi, oid):
self.spi = spi self.spi = spi
self.is_tcode_absolute = False self.is_tcode_absolute = False
self.last_temperature = None
def get_static_delay(self): def get_static_delay(self):
return .000100 return .000100
def start(self): def start(self):
@ -292,6 +294,7 @@ class HelperTLE5012B:
self.spi = spi self.spi = spi
self.oid = oid self.oid = oid
self.is_tcode_absolute = True self.is_tcode_absolute = True
self.last_temperature = None
self.mcu = spi.get_mcu() self.mcu = spi.get_mcu()
self.mcu.register_config_callback(self._build_config) self.mcu.register_config_callback(self._build_config)
self.spi_angle_transfer_cmd = None self.spi_angle_transfer_cmd = None
@ -333,6 +336,9 @@ class HelperTLE5012B:
resp = bytearray(params['response']) resp = bytearray(params['response'])
mcu_clock = self.mcu.clock32_to_clock64(params['clock']) mcu_clock = self.mcu.clock32_to_clock64(params['clock'])
chip_clock = ((resp[2] & 0x7e) << 9) | ((resp[4] & 0x3e) << 4) chip_clock = ((resp[2] & 0x7e) << 9) | ((resp[4] & 0x3e) << 4)
# Calculate temperature
temper = resp[5] - ((resp[4] & 0x01) << 8)
self.last_temperature = (temper + 152) / 2.776
return mcu_clock, chip_clock return mcu_clock, chip_clock
def update_clock(self): def update_clock(self):
mcu_clock, chip_clock = self._query_clock() mcu_clock, chip_clock = self._query_clock()
@ -407,6 +413,8 @@ class Angle:
self.query_spi_angle_end_cmd = self.mcu.lookup_query_command( self.query_spi_angle_end_cmd = self.mcu.lookup_query_command(
"query_spi_angle oid=%c clock=%u rest_ticks=%u time_shift=%c", "query_spi_angle oid=%c clock=%u rest_ticks=%u time_shift=%c",
"spi_angle_end oid=%c sequence=%hu", oid=self.oid, cq=cmdqueue) "spi_angle_end oid=%c sequence=%hu", oid=self.oid, cq=cmdqueue)
def get_status(self, eventtime=None):
return {'temperature': self.sensor_helper.last_temperature}
# Measurement collection # Measurement collection
def is_measuring(self): def is_measuring(self):
return self.start_clock != 0 return self.start_clock != 0
@ -507,6 +515,7 @@ class Angle:
self.start_clock = 0 self.start_clock = 0
with self.lock: with self.lock:
self.raw_samples = [] self.raw_samples = []
self.sensor_helper.last_temperature = None
logging.info("Stopped angle '%s' measurements", self.name) logging.info("Stopped angle '%s' measurements", self.name)
def _api_startstop(self, is_start): def _api_startstop(self, is_start):
if is_start: if is_start: