forked from Gadgetoid/WiringPi-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiringpi.py
363 lines (287 loc) · 9.09 KB
/
wiringpi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 2.0.7
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_wiringpi', [dirname(__file__)])
except ImportError:
import _wiringpi
return _wiringpi
if fp is not None:
try:
_mod = imp.load_module('_wiringpi', fp, pathname, description)
finally:
fp.close()
return _mod
_wiringpi = swig_import_helper()
del swig_import_helper
else:
import _wiringpi
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)
def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
def wiringPiSetup():
return _wiringpi.wiringPiSetup()
wiringPiSetup = _wiringpi.wiringPiSetup
def wiringPiSetupSys():
return _wiringpi.wiringPiSetupSys()
wiringPiSetupSys = _wiringpi.wiringPiSetupSys
def wiringPiSetupGpio():
return _wiringpi.wiringPiSetupGpio()
wiringPiSetupGpio = _wiringpi.wiringPiSetupGpio
def pullUpDnControl(*args):
return _wiringpi.pullUpDnControl(*args)
pullUpDnControl = _wiringpi.pullUpDnControl
def pinMode(*args):
return _wiringpi.pinMode(*args)
pinMode = _wiringpi.pinMode
def digitalWrite(*args):
return _wiringpi.digitalWrite(*args)
digitalWrite = _wiringpi.digitalWrite
def pwmWrite(*args):
return _wiringpi.pwmWrite(*args)
pwmWrite = _wiringpi.pwmWrite
def pwmSetMode(*args):
return _wiringpi.pwmSetMode(*args)
pwmSetMode = _wiringpi.pwmSetMode
def pwmSetRange(*args):
return _wiringpi.pwmSetRange(*args)
pwmSetRange = _wiringpi.pwmSetRange
def pwmSetClock(*args):
return _wiringpi.pwmSetClock(*args)
pwmSetClock = _wiringpi.pwmSetClock
def digitalRead(*args):
return _wiringpi.digitalRead(*args)
digitalRead = _wiringpi.digitalRead
def shiftOut(*args):
return _wiringpi.shiftOut(*args)
shiftOut = _wiringpi.shiftOut
def shiftIn(*args):
return _wiringpi.shiftIn(*args)
shiftIn = _wiringpi.shiftIn
def delay(*args):
return _wiringpi.delay(*args)
delay = _wiringpi.delay
def delayMicroseconds(*args):
return _wiringpi.delayMicroseconds(*args)
delayMicroseconds = _wiringpi.delayMicroseconds
def millis():
return _wiringpi.millis()
millis = _wiringpi.millis
def serialOpen(*args):
return _wiringpi.serialOpen(*args)
serialOpen = _wiringpi.serialOpen
def serialClose(*args):
return _wiringpi.serialClose(*args)
serialClose = _wiringpi.serialClose
def serialPutchar(*args):
return _wiringpi.serialPutchar(*args)
serialPutchar = _wiringpi.serialPutchar
def serialPuts(*args):
return _wiringpi.serialPuts(*args)
serialPuts = _wiringpi.serialPuts
def serialDataAvail(*args):
return _wiringpi.serialDataAvail(*args)
serialDataAvail = _wiringpi.serialDataAvail
def serialGetchar(*args):
return _wiringpi.serialGetchar(*args)
serialGetchar = _wiringpi.serialGetchar
def serialPrintf(*args):
return _wiringpi.serialPrintf(*args)
serialPrintf = _wiringpi.serialPrintf
def wiringPiSPIGetFd(*args):
return _wiringpi.wiringPiSPIGetFd(*args)
wiringPiSPIGetFd = _wiringpi.wiringPiSPIGetFd
def wiringPiSPIDataRW(*args):
return _wiringpi.wiringPiSPIDataRW(*args)
wiringPiSPIDataRW = _wiringpi.wiringPiSPIDataRW
def wiringPiSPISetup(*args):
return _wiringpi.wiringPiSPISetup(*args)
wiringPiSPISetup = _wiringpi.wiringPiSPISetup
def gertboardAnalogWrite(*args):
return _wiringpi.gertboardAnalogWrite(*args)
gertboardAnalogWrite = _wiringpi.gertboardAnalogWrite
def gertboardAnalogRead(*args):
return _wiringpi.gertboardAnalogRead(*args)
gertboardAnalogRead = _wiringpi.gertboardAnalogRead
def gertboardSPISetup():
return _wiringpi.gertboardSPISetup()
gertboardSPISetup = _wiringpi.gertboardSPISetup
def setupNesJoystick(*args):
return _wiringpi.setupNesJoystick(*args)
setupNesJoystick = _wiringpi.setupNesJoystick
def readNesJoystick(*args):
return _wiringpi.readNesJoystick(*args)
readNesJoystick = _wiringpi.readNesJoystick
def softPwmCreate(*args):
return _wiringpi.softPwmCreate(*args)
softPwmCreate = _wiringpi.softPwmCreate
def softPwmWrite(*args):
return _wiringpi.softPwmWrite(*args)
softPwmWrite = _wiringpi.softPwmWrite
def waitForInterrupt(*args):
return _wiringpi.waitForInterrupt(*args)
waitForInterrupt = _wiringpi.waitForInterrupt
# This file is compatible with both classic and new-style classes.
HIGH = 1
LOW = 0
MSBFIRST = 1
LSBFIRST = 0
WPI_MODE_PINS = 0
WPI_MODE_GPIO = 1
WPI_MODE_SYS = 2
MODE_PINS = 0
MODE_GPIO = 1
MODE_SYS = 2
INPUT = 0
OUTPUT = 1
PWM_OUTPUT = 2
PUD_OFF = 0
PUD_DOWN = 1
PUD_UP = 2
class NES(object):
def setupNesJoystick(self,*args):
return setupNesJoystick(*args)
def readNesJoystick(self,*args):
return readNesJoystick(*args)
class Serial(object):
device = '/dev/ttyAMA0'
baud = 9600
serial_id = 0
def printf(self,*args):
return serialPrintf(self.serial_id,*args)
def dataAvail(self,*args):
return serialDataAvail(self.serial_id,*args)
def getchar(self,*args):
return serialGetchar(self.serial_id,*args)
def putchar(self,*args):
return serialPutchar(self.serial_id,*args)
def puts(self,*args):
return serialPuts(self.serial_id,*args)
def __init__(self,device,baud):
self.device = device
self.baud = baud
self.serial_id = serialOpen(self.device,self.baud)
def __del__(self):
serialClose(self.serial_id)
class Pin(object):
PIN_ID = -1
PIN_MODE = OUTPUT
def __init__(self,pin_id,pin_mode=OUTPUT):
self.PIN_ID = pin_id
self.PIN_MODE = pin_mode
pinMode(self.PIN_ID, self.PIN_MODE)
def read(self):
return digitalRead(self.PIN_ID)
def write(self,value):
return digitalWrite(self.PIN_ID,value)
def pwmWrite(self,value):
return pwmWrite(self.PIN_ID,value)
def mode(self,pin_mode):
self.PIN_MODE = pin_mode
pinMode(self.PIN_ID,self.PIN_MODE)
class Shift(object):
DATA_PIN = 0
CLOCK_PIN = 0
LATCH_PIN = 0
def __init__(self,data_pin,clock_pin,latch_pin):
self.DATA_PIN = data_pin
self.CLOCK_PIN = clock_pin
self.LATCH_PIN = latch_pin
self.DATA_PIN.mode(OUTPUT)
self.CLOCK_PIN.mode(OUTPUT)
self.LATCH_PIN.mode(OUTPUT)
def write(self,value,byte_order=MSBFIRST):
digitalWrite(self.LATCH_PIN.PIN_ID,LOW)
shiftOut(self.DATA_PIN.PIN_ID,self.CLOCK_PIN.PIN_ID,byte_order,value)
digitalWrite(self.LATCH_PIN.PIN_ID,HIGH)
class GPIO(object):
HIGH = 1
LOW = 0
MSBFIRST = 1
LSBFIRST = 0
WPI_MODE_PINS = 0
WPI_MODE_GPIO = 1
WPI_MODE_SYS = 2
MODE_PINS = 0
MODE_GPIO = 1
MODE_SYS = 2
INPUT = 0
OUTPUT = 1
PWM_OUTPUT = 2
PUD_OFF = 0
PUD_DOWN = 1
PUD_UP = 2
MODE = 0
def __init__(self,pinmode=WPI_MODE_PINS):
self.MODE = pinmode
if pinmode == 0:
wiringPiSetup()
elif pinmode == 1:
wiringPiSetupGpio()
elif pinmode == 2:
wiringPiSetupSys()
def delay(self,*args):
delay(*args)
def delayMicroseconds(self,*args):
delayMicroseconds(*args)
def millis(self):
return millis()
def pinMode(self,*args):
pinMode(*args)
def digitalWrite(self,*args):
digitalWrite(*args)
def pwmWrite(self,*args):
pwmWrite(*args)
def digitalRead(self,*args):
return digitalRead(*args)
def shiftOut(self,*args):
shiftOut(*args)
def shiftOutWithDelay(self,*args):
shiftOutWithDelay(*args)
def shiftIn(self,*args):
return shiftIn(*args)
def pullUpDnControl(self,*args):
return pullUpDnControl(*args)
def softPwmCreate(*args):
return softPwmCrate(*args)
def softPwmWrite(*args):
return sofPwmWrite(*args)