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

Merge pull request #83 from yozik04/orangepi-support

Orangepi support
parents 66b50762 9f62fb67
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ GPIO Modules ...@@ -9,6 +9,7 @@ GPIO Modules
------------ ------------
- Raspberry Pi GPIO (`raspberrypi`) - Raspberry Pi GPIO (`raspberrypi`)
- Orange Pi GPIO (`orangepi`)
- PCF8574 IO chip (`pcf8574`) - PCF8574 IO chip (`pcf8574`)
- PiFaceDigital 2 IO board (`piface2`) - PiFaceDigital 2 IO board (`piface2`)
- Beaglebone GPIO (`beaglebone`) - Beaglebone GPIO (`beaglebone`)
...@@ -162,6 +163,18 @@ sensor_inputs: ...@@ -162,6 +163,18 @@ sensor_inputs:
digits: 2 digits: 2
``` ```
### OrangePi boards
You need to specify what OrangePi board you use
```yaml
gpio_modules:
- name: orangepi
module: orangepi
board: zero # Supported: ZERO, R1, ZEROPLUS, ZEROPLUS2H5, ZEROPLUS2H3, PCPCPLUS, ONE, LITE, PLUS2E, PC2, PRIME
mode: board
```
#### SSL/TLS #### SSL/TLS
You may want to connect to a remote server, in which case it's a good idea to use an encrypted connection. If the server supports this, then you can supply the relevant config values for the [tls_set()](https://github.com/eclipse/paho.mqtt.python#tls_set) command. You may want to connect to a remote server, in which case it's a good idea to use an encrypted connection. If the server supports this, then you can supply the relevant config values for the [tls_set()](https://github.com/eclipse/paho.mqtt.python#tls_set) command.
...@@ -242,6 +255,11 @@ gpio_modules: ...@@ -242,6 +255,11 @@ gpio_modules:
i2c_bus_num: 1 i2c_bus_num: 1
chip_addr: 0x20 chip_addr: 0x20
- name: orangepi
module: orangepi
board: r1
mode: board
digital_inputs: digital_inputs:
- name: button - name: button
module: raspberrypi module: raspberrypi
......
...@@ -18,6 +18,11 @@ gpio_modules: ...@@ -18,6 +18,11 @@ gpio_modules:
module: stdio module: stdio
cleanup: no cleanup: no
- name: orangepi
module: orangepi
board: zero
mode: board
sensor_modules: sensor_modules:
- name: lm75 - name: lm75
module: lm75 module: lm75
......
from pi_mqtt_gpio.modules import GenericGPIO, PinDirection, PinPullup
ALLOWED_BOARDS = [
'zero', 'r1', 'zeroplus', 'zeroplus2h5', 'zeroplus2h3',
'pcpcplus', 'one', 'lite', 'plus2e', 'pc2', 'prime'
]
ALLOWED_MODES = ['bcm', 'board', 'mode_soc']
REQUIREMENTS = ("OrangePi.GPIO",)
CONFIG_SCHEMA = {
"board": {
"type": "string",
"required": True,
"empty": False,
"allowed": ALLOWED_BOARDS + list(map(str.upper, ALLOWED_BOARDS))
},
"mode": {
"type": "string",
"required": True,
"empty": False,
"default": "bcm",
"allowed": ALLOWED_MODES + list(map(str.upper, ALLOWED_MODES))
}
}
DIRECTIONS = None
PULLUPS = None
class GPIO(GenericGPIO):
"""
Implementation of GPIO class for Orange Pi native GPIO.
"""
def __init__(self, config):
global DIRECTIONS, PULLUPS
import OPi.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,
}
board = config["board"].upper()
mode = config["mode"].upper()
if not hasattr(gpio, board):
raise AssertionError("%s board not found" % board)
gpio.setboard(getattr(gpio, board))
gpio.setmode(getattr(gpio, mode))
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")]
try:
self.io.setup(pin, direction, pull_up_down=pullup, initial=initial)
except ValueError as e:
raise IOError("channel %d setup failed" % pin) from e
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment