Add multiple read to ir sensor
This commit is contained in:
parent
fc64706b65
commit
2748290e30
1 changed files with 23 additions and 0 deletions
|
@ -36,6 +36,29 @@ class IRSensor(object):
|
||||||
MetricsLogging.put("Infrared", result, sensor)
|
MetricsLogging.put("Infrared", result, sensor)
|
||||||
return result
|
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
|
@staticmethod
|
||||||
def set(sensor: int, on: bool):
|
def set(sensor: int, on: bool):
|
||||||
"""Turn on / off a IR emitter
|
"""Turn on / off a IR emitter
|
||||||
|
|
Reference in a new issue