From 4306c0ed8d95bbaca875f4f1d9badb436cb4e2b9 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 25 Dec 2013 14:56:10 +0100 Subject: adding fake GPIO module --- python/fake/_webiopi/GPIO.py | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 python/fake/_webiopi/GPIO.py (limited to 'python/fake/_webiopi/GPIO.py') diff --git a/python/fake/_webiopi/GPIO.py b/python/fake/_webiopi/GPIO.py new file mode 100644 index 0000000..18ba633 --- /dev/null +++ b/python/fake/_webiopi/GPIO.py @@ -0,0 +1,70 @@ +GPIO_COUNT = 54 + +IN = 0 +OUT = 1 +ALT5 = 2 +ALT4 = 3 +ALT0 = 4 +ALT1 = 5 +ALT2 = 6 +ALT3 = 7 +PWM = 8 + +LOW = 0 +HIGH = 1 + +PUD_OFF = 0 +PUD_DOWN = 1 +PUD_UP = 2 + +RATIO = 1 +ANGLE = 2 + +FUNCTIONS = [ "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3", "PWM" ] +PWM_MODES = [ "none", "ratio", "angle" ] + +_functions = {} +_states = {} +for i in range(0, GPIO_COUNT): + _functions[i] = IN + _states[i] = False + +def setFunction(channel, direction, pull_up_down=PUD_OFF): + if channel < 0 or channel > GPIO_COUNT: + raise InvalidChannelException("The GPIO channel is invalid") + _functions[channel] = direction + return None + +def getFunction(channel): + if channel < 0 or channel > GPIO_COUNT: + raise InvalidChannelException("The GPIO channel is invalid") + return _functions[channel] + +def getFunctionString(channel): + if channel < 0 or channel > GPIO_COUNT: + raise InvalidChannelException("The GPIO channel is invalid") + return FUNCTIONS[getFunction(channel)] + +def digitalWrite(channel, value): + return output(channel, value) +def output(channel, value): + if channel < 0 or channel > GPIO_COUNT: + raise InvalidChannelException("The GPIO channel is invalid") + _states[channel] = value + return None + +def digitalRead(channel): + return input(channel) +def input(channel): + if channel < 0 or channel > GPIO_COUNT: + raise InvalidChannelException("The GPIO channel is invalid") + return _states[channel] + +class SetupException(Exception): + pass +class InvalidDirectionException(Exception): + pass +class InvalidChannelException(Exception): + pass +class InvalidPullException(Exception): + pass -- cgit v1.2.3