This repository has been archived on 2025-06-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
compLIB/compLib/IRSensor.py
2021-08-22 18:37:20 +02:00

40 lines
1.1 KiB
Python

from compLib.LogstashLogging import Logging
from compLib.Spi import Spi, Register
import spidev
SENSOR_COUNT = 5
class IRSensor(object):
"""Access the different IR Sensors of the robot
"""
@staticmethod
def read(sensor: int) -> int:
if sensor <= 0 or sensor > SENSOR_COUNT:
raise IndexError("Invalid sensor specified!")
if sensor == 1:
return Spi.read(Register.IR_1_H, 2)
elif sensor == 2:
return Spi.read(Register.IR_2_H, 2)
elif sensor == 3:
return Spi.read(Register.IR_3_H, 2)
elif sensor == 4:
return Spi.read(Register.IR_4_H, 2)
return 0
@staticmethod
def set(sensor: int, on: bool):
if sensor <= 0 or sensor > SENSOR_COUNT:
raise IndexError("Invalid sensor specified!")
if sensor == 1:
Spi.write(Register.IR_1_LED, on)
elif sensor == 2:
Spi.write(Register.IR_2_LED, on)
elif sensor == 3:
Spi.write(Register.IR_3_LED, on)
elif sensor == 4:
Spi.write(Register.IR_4_LED, on)