Added support for new analog IR sensors
This commit is contained in:
parent
ee9432317a
commit
0ddc8e6c74
1 changed files with 40 additions and 0 deletions
|
@ -2,6 +2,7 @@ import pigpio
|
||||||
|
|
||||||
from compLib.ADC import ADC
|
from compLib.ADC import ADC
|
||||||
from compLib.LogstashLogging import Logging
|
from compLib.LogstashLogging import Logging
|
||||||
|
import spidev
|
||||||
|
|
||||||
TOP_LEFT_CHANNEL = 0
|
TOP_LEFT_CHANNEL = 0
|
||||||
TOP_RIGHT_CHANNEL = 1
|
TOP_RIGHT_CHANNEL = 1
|
||||||
|
@ -14,6 +15,9 @@ BOTTOM_MIDDLE_PIN = 15
|
||||||
BOTTOM_RIGHT_PIN = 23
|
BOTTOM_RIGHT_PIN = 23
|
||||||
|
|
||||||
adc = ADC()
|
adc = ADC()
|
||||||
|
spi = spidev.SpiDev()
|
||||||
|
spi.open(0, 0)
|
||||||
|
spi.max_speed_hz = 1000000
|
||||||
|
|
||||||
# GPIO.setmode(GPIO.BCM)
|
# GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
|
@ -89,3 +93,39 @@ class IRSensor(object):
|
||||||
"""
|
"""
|
||||||
return states[str(BOTTOM_RIGHT_PIN)]
|
return states[str(BOTTOM_RIGHT_PIN)]
|
||||||
# return GPIO.read(BOTTOM_RIGHT_PIN)
|
# return GPIO.read(BOTTOM_RIGHT_PIN)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def bottom_left_analog() -> int:
|
||||||
|
"""Get bottom left infrared sensor value: ranges from 0 to 1023
|
||||||
|
|
||||||
|
:return: 10-bit brightness value
|
||||||
|
:rtype: int
|
||||||
|
"""
|
||||||
|
channel = 2
|
||||||
|
spi.writebytes([channel << 3, 0])
|
||||||
|
bytes = spi.readbytes(2)
|
||||||
|
return (bytes[0] * 256 + bytes[1]) >> 2
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def bottom_middle_analog() -> int:
|
||||||
|
"""Get bottom middle infrared sensor value: ranges from 0 to 1023
|
||||||
|
|
||||||
|
:return: 10-bit brightness value
|
||||||
|
:rtype: int
|
||||||
|
"""
|
||||||
|
channel = 1
|
||||||
|
spi.writebytes([channel << 3, 0])
|
||||||
|
bytes = spi.readbytes(2)
|
||||||
|
return (bytes[0] * 256 + bytes[1]) >> 2
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def bottom_right_analog() -> int:
|
||||||
|
"""Get bottom right infrared sensor value: ranges from 0 to 1023
|
||||||
|
|
||||||
|
:return: 10-bit brightness value
|
||||||
|
:rtype: int
|
||||||
|
"""
|
||||||
|
channel = 0
|
||||||
|
spi.writebytes([channel << 3, 0])
|
||||||
|
bytes = spi.readbytes(2)
|
||||||
|
return (bytes[0] * 256 + bytes[1]) >> 2
|
Reference in a new issue