summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/fake/_webiopi/GPIO.py70
-rw-r--r--python/fake/_webiopi/__init__.py0
2 files changed, 70 insertions, 0 deletions
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 @@
1GPIO_COUNT = 54
2
3IN = 0
4OUT = 1
5ALT5 = 2
6ALT4 = 3
7ALT0 = 4
8ALT1 = 5
9ALT2 = 6
10ALT3 = 7
11PWM = 8
12
13LOW = 0
14HIGH = 1
15
16PUD_OFF = 0
17PUD_DOWN = 1
18PUD_UP = 2
19
20RATIO = 1
21ANGLE = 2
22
23FUNCTIONS = [ "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3", "PWM" ]
24PWM_MODES = [ "none", "ratio", "angle" ]
25
26_functions = {}
27_states = {}
28for i in range(0, GPIO_COUNT):
29 _functions[i] = IN
30 _states[i] = False
31
32def setFunction(channel, direction, pull_up_down=PUD_OFF):
33 if channel < 0 or channel > GPIO_COUNT:
34 raise InvalidChannelException("The GPIO channel is invalid")
35 _functions[channel] = direction
36 return None
37
38def getFunction(channel):
39 if channel < 0 or channel > GPIO_COUNT:
40 raise InvalidChannelException("The GPIO channel is invalid")
41 return _functions[channel]
42
43def getFunctionString(channel):
44 if channel < 0 or channel > GPIO_COUNT:
45 raise InvalidChannelException("The GPIO channel is invalid")
46 return FUNCTIONS[getFunction(channel)]
47
48def digitalWrite(channel, value):
49 return output(channel, value)
50def output(channel, value):
51 if channel < 0 or channel > GPIO_COUNT:
52 raise InvalidChannelException("The GPIO channel is invalid")
53 _states[channel] = value
54 return None
55
56def digitalRead(channel):
57 return input(channel)
58def input(channel):
59 if channel < 0 or channel > GPIO_COUNT:
60 raise InvalidChannelException("The GPIO channel is invalid")
61 return _states[channel]
62
63class SetupException(Exception):
64 pass
65class InvalidDirectionException(Exception):
66 pass
67class InvalidChannelException(Exception):
68 pass
69class InvalidPullException(Exception):
70 pass
diff --git a/python/fake/_webiopi/__init__.py b/python/fake/_webiopi/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/python/fake/_webiopi/__init__.py