20 import _webiopi.GPIO
as GPIO
28 GPIOPort.__init__(self, 54)
40 params = params.split(
" ")
41 func = params[0].lower()
47 raise Exception(
"Unknown function")
51 value = int(params[1])
52 lst.append({
"gpio": gpio,
"func": func,
"value": value})
61 for (gpio, params)
in gpios:
65 for (gpio, params)
in gpios:
71 debug(
"Setup GPIO %d" % gpio)
72 GPIO.setFunction(gpio, g[
"func"])
73 if g[
"value"] >= 0
and GPIO.getFunction(gpio) == GPIO.OUT:
74 GPIO.digitalWrite(gpio, g[
"value"])
79 debug(
"Reset GPIO %d" % gpio)
80 GPIO.setFunction(gpio, g[
"func"])
81 if g[
"value"] >= 0
and GPIO.getFunction(gpio) == GPIO.OUT:
82 GPIO.digitalWrite(gpio, g[
"value"])
85 if not channel
in self.
export:
86 raise GPIO.InvalidChannelException(
"Channel %d is not allowed" % channel)
90 raise ValueError(
"POSTing function to native GPIO not allowed")
94 raise ValueError(
"POSTing value to native GPIO not allowed")
98 return GPIO.digitalRead(channel)
103 GPIO.digitalWrite(channel, value)
107 return GPIO.getFunction(channel)
112 GPIO.setFunction(channel, value)
117 value |= GPIO.digitalRead(i) << i
123 if GPIO.getFunction(i) == GPIO.OUT:
124 GPIO.digitalWrite(i, (value >> i) & 1)
126 raise Exception(
"Please limit exported GPIO to write integers")
142 func = GPIO.getFunction(i)
144 func = GPIO.getFunctionString(i)
145 values[i] = {f: func, v: int(GPIO.digitalRead(i))}
149 @
request(
"GET",
"%(channel)d/pulse",
"%s")
153 return GPIO.getPulse(channel)
155 @
request(
"POST",
"%(channel)d/sequence/%(args)s")
161 (period, sequence) = args.split(
",")
163 GPIO.outputSequence(channel, period, sequence)
164 return int(sequence[-1])
166 @
request(
"POST",
"%(channel)d/pulse/")
174 @
request(
"POST",
"%(channel)d/pulseRatio/%(value)f")
179 GPIO.pulseRatio(channel, value)
180 return GPIO.getPulse(channel)
182 @
request(
"POST",
"%(channel)d/pulseAngle/%(value)f")
187 GPIO.pulseAngle(channel, value)
188 return GPIO.getPulse(channel)
def checkPostingFunctionAllowed
def checkDigitalChannelExported
def checkPostingValueAllowed