temperature_host: Rename rpi_temperature and add support for custom paths
Signed-off-by: Evgenii Shavrin <shavrin0591@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
267a2f3a38
commit
3d35c003db
|
@ -267,7 +267,7 @@ The following are common printer attributes:
|
|||
from the sensor.
|
||||
- `printer["lm75 <sensor_name>"].temperature`: The last read
|
||||
temperature from the sensor.
|
||||
- `printer["rpi_temperature <sensor_name>"].temperature`: The last read
|
||||
- `printer["temperature_host <sensor_name>"].temperature`: The last read
|
||||
temperature from the sensor.
|
||||
- `printer["temperature_sensor <config_name>"].temperature`: The last read
|
||||
temperature from the sensor.
|
||||
|
|
|
@ -6,6 +6,12 @@ All dates in this document are approximate.
|
|||
|
||||
# Changes
|
||||
|
||||
20210219: The `rpi_temperature` module has been renamed to
|
||||
`temperature_host`. Replace any occurrences of `sensor_type:
|
||||
rpi_temperature` with `sensor_type: temperature_host`. The
|
||||
`rpi_temperature` name is deprecated and will be removed in the near
|
||||
future.
|
||||
|
||||
20210201: The `TEST_RESONANCES` command will now disable input shaping
|
||||
if it was previously enabled (and re-enable it after the test). In order
|
||||
to override this behavior and keep the input shaping enabled, one can
|
||||
|
|
|
@ -2145,12 +2145,16 @@ sensor_type: temperature_mcu
|
|||
# micro-controller specification.
|
||||
```
|
||||
|
||||
## RPi temperature sensor
|
||||
## Host temperature sensor
|
||||
|
||||
CPU temperature from the Raspberry Pi running the host software.
|
||||
Temperature from the machine (eg Raspberry Pi) running the host software.
|
||||
|
||||
```
|
||||
sensor_type: rpi_temperature
|
||||
sensor_type: temperature_host
|
||||
#path:
|
||||
# The path to temperature system file. The default is
|
||||
# "/sys/class/thermal/thermal_zone0/temp" which is the temperature
|
||||
# system file on a Raspberry Pi computer.
|
||||
```
|
||||
|
||||
## DS18B20 temperature sensor
|
||||
|
|
|
@ -264,7 +264,7 @@ class PrinterHeaters:
|
|||
return self.heaters[heater_name]
|
||||
def setup_sensor(self, config):
|
||||
modules = ["thermistor", "adc_temperature", "spi_temperature",
|
||||
"bme280", "htu21d", "lm75", "rpi_temperature",
|
||||
"bme280", "htu21d", "lm75", "temperature_host",
|
||||
"temperature_mcu", "ds18b20"]
|
||||
|
||||
for module_name in modules:
|
||||
|
|
|
@ -6,27 +6,29 @@
|
|||
|
||||
import logging
|
||||
|
||||
RPI_REPORT_TIME = 1.0
|
||||
PROC_TEMP_FILE = "/sys/class/thermal/thermal_zone0/temp"
|
||||
HOST_REPORT_TIME = 1.0
|
||||
RPI_PROC_TEMP_FILE = "/sys/class/thermal/thermal_zone0/temp"
|
||||
|
||||
class RPiTemperature:
|
||||
class Temperature_HOST:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
self.reactor = self.printer.get_reactor()
|
||||
self.name = config.get_name().split()[-1]
|
||||
self.path = config.get("path", RPI_PROC_TEMP_FILE)
|
||||
|
||||
self.temp = self.min_temp = self.max_temp = 0.0
|
||||
|
||||
self.printer.add_object("rpi_temperature " + self.name, self)
|
||||
self.printer.add_object("rpi_temperature " + self.name, self) # XXX
|
||||
self.printer.add_object("temperature_host " + self.name, self)
|
||||
if self.printer.get_start_args().get('debugoutput') is not None:
|
||||
return
|
||||
self.sample_timer = self.reactor.register_timer(
|
||||
self._sample_pi_temperature)
|
||||
try:
|
||||
self.file_handle = open(PROC_TEMP_FILE, "r")
|
||||
self.file_handle = open(self.path, "r")
|
||||
except:
|
||||
raise config.error("Unable to open temperature file '%s'"
|
||||
% (PROC_TEMP_FILE,))
|
||||
% (self.path,))
|
||||
|
||||
self.printer.register_event_handler("klippy:connect",
|
||||
self.handle_connect)
|
||||
|
@ -42,30 +44,30 @@ class RPiTemperature:
|
|||
self._callback = cb
|
||||
|
||||
def get_report_time_delta(self):
|
||||
return RPI_REPORT_TIME
|
||||
return HOST_REPORT_TIME
|
||||
|
||||
def _sample_pi_temperature(self, eventtime):
|
||||
try:
|
||||
self.file_handle.seek(0)
|
||||
self.temp = float(self.file_handle.read())/1000.0
|
||||
except Exception:
|
||||
logging.exception("rpi_temperature: Error reading data")
|
||||
logging.exception("temperature_host: Error reading data")
|
||||
self.temp = 0.0
|
||||
return self.reactor.NEVER
|
||||
|
||||
if self.temp < self.min_temp:
|
||||
self.printer.invoke_shutdown(
|
||||
"RPi temperature %0.1f below minimum temperature of %0.1f."
|
||||
"HOST temperature %0.1f below minimum temperature of %0.1f."
|
||||
% (self.temp, self.min_temp,))
|
||||
if self.temp > self.max_temp:
|
||||
self.printer.invoke_shutdown(
|
||||
"RPi temperature %0.1f above maximum temperature of %0.1f."
|
||||
"HOST temperature %0.1f above maximum temperature of %0.1f."
|
||||
% (self.temp, self.max_temp,))
|
||||
|
||||
mcu = self.printer.lookup_object('mcu')
|
||||
measured_time = self.reactor.monotonic()
|
||||
self._callback(mcu.estimated_print_time(measured_time), self.temp)
|
||||
return measured_time + RPI_REPORT_TIME
|
||||
return measured_time + HOST_REPORT_TIME
|
||||
|
||||
def get_status(self, eventtime):
|
||||
return {
|
||||
|
@ -76,4 +78,5 @@ class RPiTemperature:
|
|||
def load_config(config):
|
||||
# Register sensor
|
||||
pheaters = config.get_printer().load_object(config, "heaters")
|
||||
pheaters.add_sensor_factory("rpi_temperature", RPiTemperature)
|
||||
pheaters.add_sensor_factory("temperature_host", Temperature_HOST)
|
||||
pheaters.add_sensor_factory("rpi_temperature", Temperature_HOST) # XXX
|
Loading…
Reference in New Issue