Add multiple read to ir sensor

This commit is contained in:
root 2022-01-28 18:21:15 +00:00
parent fc64706b65
commit 2748290e30

View file

@ -36,6 +36,29 @@ class IRSensor(object):
MetricsLogging.put("Infrared", result, sensor)
return result
@staticmethod
def read_all():
"""Read all IR sensors at once.
This is faster than read as it only uses one SPI call for all sensors!
:return: Tuple of all current ir sensors
"""
sensors = Spi.read_array(Register.IR_1_H, 5 * 2)
sensor_1 = int.from_bytes(
sensors[0:2], byteorder='big', signed=False)
sensor_2 = int.from_bytes(
sensors[2:4], byteorder='big', signed=False)
sensor_3 = int.from_bytes(
sensors[4:6], byteorder='big', signed=False)
sensor_4 = int.from_bytes(
sensors[6:8], byteorder='big', signed=False)
sensor_5 = int.from_bytes(
sensors[8:10], byteorder='big', signed=False)
return (sensor_1, sensor_2, sensor_3, sensor_4, sensor_5)
@staticmethod
def set(sensor: int, on: bool):
"""Turn on / off a IR emitter