Use PIGPIO_ADDR and PIGPIO_PORT environment variable if they exist to configure PiGPIO, otherwise it use the default value 'localhost' and 8888. This is the same behaviour as the pigpio library for initialisation.

This commit is contained in:
BuildTools
2016-07-26 22:45:38 +02:00
parent 23e153df50
commit 23fabb68ce

View File

@@ -8,6 +8,7 @@ str = type('')
import warnings import warnings
import pigpio import pigpio
import os
from . import Pin from . import Pin
from .data import pi_info from .data import pi_info
@@ -98,7 +99,7 @@ class PiGPIOPin(Pin):
GPIO_PULL_UP_NAMES = {v: k for (k, v) in GPIO_PULL_UPS.items()} GPIO_PULL_UP_NAMES = {v: k for (k, v) in GPIO_PULL_UPS.items()}
GPIO_EDGES_NAMES = {v: k for (k, v) in GPIO_EDGES.items()} GPIO_EDGES_NAMES = {v: k for (k, v) in GPIO_EDGES.items()}
def __new__(cls, number, host='localhost', port=8888): def __new__(cls, number, host=os.getenv("PIGPIO_ADDR", 'localhost'), port=os.getenv("PIGPIO_PORT", 8888)):
try: try:
return cls._PINS[(host, port, number)] return cls._PINS[(host, port, number)]
except KeyError: except KeyError: