Skip to content
Snippets Groups Projects
Unverified Commit 2f333a95 authored by Ellis Percival's avatar Ellis Percival Committed by GitHub
Browse files

Merge pull request #121 from tomas-petrauskas/develop

Add PCF8575 Module Support
parents d74f49a8 7b751595
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ GPIO Modules ...@@ -11,6 +11,7 @@ GPIO Modules
- Raspberry Pi GPIO (`raspberrypi`) - Raspberry Pi GPIO (`raspberrypi`)
- Orange Pi GPIO (`orangepi`) - Orange Pi GPIO (`orangepi`)
- PCF8574 IO chip (`pcf8574`) - PCF8574 IO chip (`pcf8574`)
- PCF8575 IO chip (`pcf8575`)
- PiFaceDigital 2 IO board (`piface2`) - PiFaceDigital 2 IO board (`piface2`)
- Beaglebone GPIO (`beaglebone`) - Beaglebone GPIO (`beaglebone`)
......
from __future__ import absolute_import
from pi_mqtt_gpio.modules import GenericGPIO, PinDirection, PinPullup
REQUIREMENTS = ("pcf8575",)
CONFIG_SCHEMA = {
"i2c_bus_num": {"type": "integer", "required": True, "empty": False},
"chip_addr": {"type": "integer", "required": True, "empty": False},
}
PULLUPS = None
class GPIO(GenericGPIO):
"""
Implementation of GPIO class for the pcf8575 IO expander chip.
"""
def __init__(self, config):
global PULLUPS
PULLUPS = {PinPullup.UP: True, PinPullup.DOWN: False}
from pcf8575 import pcf8575
self.io = pcf8575(config["i2c_bus_num"], config["chip_addr"])
def setup_pin(self, pin, direction, pullup, pin_config):
if direction == PinDirection.INPUT and pullup is not None:
self.io.port[pin] = PULLUPS[pullup]
initial = pin_config.get("initial")
if initial is not None:
if initial == "high":
self.set_pin(pin, True)
elif initial == "low":
self.set_pin(pin, False)
def set_pin(self, pin, value):
self.io.port[pin] = value
def get_pin(self, pin):
return self.io.port[pin]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment