diff --git a/config.schema.yml b/config.schema.yml index f32768cec137a9f5ec1de8465beb6739063f094c..133374eff92e996e7ae65f3de7f4696ad834aa8f 100644 --- a/config.schema.yml +++ b/config.schema.yml @@ -148,9 +148,11 @@ digital_inputs: required: yes empty: no pin: - type: integer + type: + - string + - integer required: yes - min: 0 + empty: no on_payload: type: string required: yes @@ -186,9 +188,11 @@ digital_outputs: type: string required: yes pin: - type: integer + type: + - string + - integer required: yes - min: 0 + empty: no on_payload: type: string required: no diff --git a/pi_mqtt_gpio/__init__.py b/pi_mqtt_gpio/__init__.py index b1d9bd58377d59a41fedb2656eb7a05606261044..65cc2cbf8f5334e15d69afbc22a1d5295d3f0564 100644 --- a/pi_mqtt_gpio/__init__.py +++ b/pi_mqtt_gpio/__init__.py @@ -1,7 +1,6 @@ import yaml -CONFIG_SCHEMA = yaml.safe_load( - """ +CONFIG_SCHEMA = yaml.safe_load(""" mqtt: type: dict required: yes @@ -152,9 +151,11 @@ digital_inputs: required: yes empty: no pin: - type: integer + type: + - string + - integer required: yes - min: 0 + empty: no on_payload: type: string required: yes @@ -190,9 +191,11 @@ digital_outputs: type: string required: yes pin: - type: integer + type: + - string + - integer required: yes - min: 0 + empty: no on_payload: type: string required: no @@ -246,5 +249,4 @@ sensor_inputs: default: 2 min: 0 -""" -) +""") diff --git a/pi_mqtt_gpio/__init__.py.template b/pi_mqtt_gpio/__init__.py.template index ce1c782e538208f8ee75e2957468580f5162f7a5..42eeee567dfc4f3ab2bf31eedbd467345b38e0e6 100644 --- a/pi_mqtt_gpio/__init__.py.template +++ b/pi_mqtt_gpio/__init__.py.template @@ -1,5 +1,5 @@ import yaml -CONFIG_SCHEMA = yaml.load(""" +CONFIG_SCHEMA = yaml.safe_load(""" $config_schema """) diff --git a/pi_mqtt_gpio/modules/beaglebone.py b/pi_mqtt_gpio/modules/beaglebone.py new file mode 100644 index 0000000000000000000000000000000000000000..1c1acd43ea4bb266c8295af2da131fb1582ec8d6 --- /dev/null +++ b/pi_mqtt_gpio/modules/beaglebone.py @@ -0,0 +1,46 @@ +from pi_mqtt_gpio.modules import GenericGPIO, PinDirection, PinPullup + + +REQUIREMENTS = ("Adafruit_BBIO",) + +DIRECTIONS = None +PULLUPS = None + + +class GPIO(GenericGPIO): + """ + Implementation of GPIO class for Beaglebone native GPIO. + """ + + def __init__(self, config): + global DIRECTIONS, PULLUPS + import Adafruit_BBIO.GPIO as gpio + + self.io = gpio + DIRECTIONS = {PinDirection.INPUT: gpio.IN, PinDirection.OUTPUT: gpio.OUT} + + PULLUPS = { + PinPullup.OFF: gpio.PUD_OFF, + PinPullup.UP: gpio.PUD_UP, + PinPullup.DOWN: gpio.PUD_DOWN, + } + + def setup_pin(self, pin, direction, pullup, pin_config): + direction = DIRECTIONS[direction] + + if pullup is None: + pullup = PULLUPS[PinPullup.OFF] + else: + pullup = PULLUPS[pullup] + + initial = {None: -1, "low": 0, "high": 1}[pin_config.get("initial")] + self.io.setup(pin, direction, pull_up_down=pullup, initial=initial) + + def set_pin(self, pin, value): + self.io.output(pin, value) + + def get_pin(self, pin): + return self.io.input(pin) + + def cleanup(self): + self.io.cleanup()