diff --git a/compLib/IRSensor.py b/compLib/IRSensor.py index 5f6f95d..3051124 100644 --- a/compLib/IRSensor.py +++ b/compLib/IRSensor.py @@ -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