├── examples ├── RUN_THESE_WITH_SUDO ├── delay.py ├── callback.py ├── quick2wire-io.py ├── two-mcp23017.py ├── ladder-board.py ├── softpwm.py └── n5510-mcp23017.py ├── setup.cfg ├── _wiringpi2 ├── MANIFEST.in ├── README.txt ├── setup.py └── LICENSE.txt ├── .gitignore ├── .gitmodules ├── tests ├── piglow.py └── test.py ├── MANIFEST.in ├── Makefile ├── constants.py ├── CHANGES.txt ├── setup.py ├── generate-bindings.py ├── README.md ├── wiringpi-class.py ├── LICENSE.txt ├── bindings.i └── wiringpi.i /examples/RUN_THESE_WITH_SUDO: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | -------------------------------------------------------------------------------- /_wiringpi2/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.txt 2 | include LICENSE.txt 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.egg-info/ 3 | dist/ 4 | __pycache__ 5 | *.pyc 6 | wiringpi_wrap.c 7 | wiringpi.py 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "WiringPi"] 2 | path = WiringPi 3 | url = https://github.com/zhaolei/WiringOP.git 4 | -------------------------------------------------------------------------------- /tests/piglow.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) 3 | io.piGlowSetup() 4 | io.piGlowLeg(1,100) 5 | -------------------------------------------------------------------------------- /tests/test.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS) 3 | print io.digitalRead(1) 4 | print io.analogRead(1) 5 | -------------------------------------------------------------------------------- /_wiringpi2/README.txt: -------------------------------------------------------------------------------- 1 | # Wiring Pi 2 2 | 3 | This package has been deprecated in favour of using the name "WiringPi" which provides the same exact functionality. 4 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | graft WiringPi/wiringPi 2 | graft WiringPi/devLib 3 | include README.md 4 | include LICENSE.txt 5 | include setup.cfg 6 | include wiringpi.py 7 | include wiringpi_wrap.c 8 | -------------------------------------------------------------------------------- /examples/delay.py: -------------------------------------------------------------------------------- 1 | # Demonstrates use of Arduino-like delay function 2 | import wiringpi 3 | print 'Hello World' 4 | wiringpi.delay(1500) # Delay for 1.5 seconds 5 | print 'Hi again!' 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: bindings 2 | python setup.py build 3 | 4 | bindings: 5 | swig3.0 -python -threads wiringpi.i 6 | 7 | clean: 8 | rm -rf build/ 9 | rm -rf dist/ 10 | 11 | install: 12 | sudo python setup.py install 13 | -------------------------------------------------------------------------------- /examples/callback.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | PIN_TO_SENSE = 23 3 | 4 | def gpio_callback(): 5 | print "GPIO_CALLBACK!" 6 | 7 | wiringpi.wiringPiSetupGpio() 8 | wiringpi.pinMode(PIN_TO_SENSE, wiringpi.GPIO.INPUT) 9 | wiringpi.pullUpDnControl(PIN_TO_SENSE, wiringpi.GPIO.PUD_UP) 10 | 11 | wiringpi.wiringPiISR(PIN_TO_SENSE, wiringpi.GPIO.INT_EDGE_BOTH, gpio_callback) 12 | 13 | while True: 14 | wiringpi.delay(2000) 15 | -------------------------------------------------------------------------------- /examples/quick2wire-io.py: -------------------------------------------------------------------------------- 1 | # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) 2 | import wiringpi 3 | 4 | pin_base = 65 5 | i2c_addr = 0x20 6 | pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80] 7 | 8 | wiringpi.wiringPiSetup() 9 | wiringpi.mcp23017Setup(pin_base,i2c_addr) 10 | 11 | for pin in pins: 12 | wiringpi.pinMode(pin,1) 13 | wiringpi.digitalWrite(pin,1) 14 | # wiringpi.delay(1000) 15 | # wiringpi.digitalWrite(pin,0) 16 | -------------------------------------------------------------------------------- /examples/two-mcp23017.py: -------------------------------------------------------------------------------- 1 | # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) 2 | import wiringpi 3 | 4 | pin_base = 65 5 | i2c_addr = 0x20 6 | i2c_addr_2 = 0x21 7 | #pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80] 8 | 9 | wiringpi.wiringPiSetup() 10 | wiringpi.mcp23017Setup(pin_base,i2c_addr) 11 | wiringpi.mcp23017Setup(pin_base+16,i2c_addr_2) 12 | 13 | #for pin in pins: 14 | for pin in range(65,96): 15 | wiringpi.pinMode(pin,1) 16 | wiringpi.digitalWrite(pin,1) 17 | # wiringpi.delay(1000) 18 | # wiringpi.digitalWrite(pin,0) 19 | -------------------------------------------------------------------------------- /_wiringpi2/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup, find_packages, Extension 4 | 5 | setup( 6 | name = 'wiringpi2', 7 | version = '2.32.1', 8 | author = "Philip Howard", 9 | author_email = "phil@gadgetoid.com", 10 | url = 'https://github.com/WiringPi/WiringPi-Python/', 11 | description = """A python interface to WiringPi 2.0 library which allows for 12 | easily interfacing with the GPIO pins of the Raspberry Pi. Also supports 13 | i2c and SPI""", 14 | long_description=open('README.txt').read(), 15 | install_requires=['wiringpi>=2.23.1'], 16 | ) 17 | -------------------------------------------------------------------------------- /constants.py: -------------------------------------------------------------------------------- 1 | %pythoncode %{ 2 | # wiringPi modes 3 | 4 | WPI_MODE_PINS = 0; 5 | WPI_MODE_GPIO = 1; 6 | WPI_MODE_GPIO_SYS = 2; 7 | WPI_MODE_PHYS = 3; 8 | WPI_MODE_PIFACE = 4; 9 | WPI_MODE_UNINITIALISED = -1; 10 | 11 | # Pin modes 12 | 13 | INPUT = 0; 14 | OUTPUT = 1; 15 | PWM_OUTPUT = 2; 16 | GPIO_CLOCK = 3; 17 | SOFT_PWM_OUTPUT = 4; 18 | SOFT_TONE_OUTPUT = 5; 19 | PWM_TONE_OUTPUT = 6; 20 | 21 | LOW = 0; 22 | HIGH = 1; 23 | 24 | # Pull up/down/none 25 | 26 | PUD_OFF = 0; 27 | PUD_DOWN = 1; 28 | PUD_UP = 2; 29 | 30 | # PWM 31 | 32 | PWM_MODE_MS = 0; 33 | PWM_MODE_BAL = 1; 34 | 35 | # Interrupt levels 36 | 37 | INT_EDGE_SETUP = 0; 38 | INT_EDGE_FALLING = 1; 39 | INT_EDGE_RISING = 2; 40 | INT_EDGE_BOTH = 3; 41 | %} 42 | -------------------------------------------------------------------------------- /examples/ladder-board.py: -------------------------------------------------------------------------------- 1 | import wiringpi 2 | INPUT = 0 3 | OUTPUT = 1 4 | LOW = 0 5 | HIGH = 1 6 | BUTTONS = [13,12,10,11] 7 | LEDS = [0,1,2,3,4,5,6,7,8,9] 8 | PUD_UP = 2 9 | 10 | wiringpi.wiringPiSetup() 11 | 12 | for button in BUTTONS: 13 | wiringpi.pinMode(button,INPUT) 14 | wiringpi.pullUpDnControl(button,PUD_UP) 15 | 16 | for led in LEDS: 17 | wiringpi.pinMode(led,OUTPUT) 18 | 19 | while 1: 20 | for index,button in enumerate(BUTTONS): 21 | button_state = wiringpi.digitalRead(button) 22 | first_led = LEDS[index*2] 23 | second_led = LEDS[(index*2)+1] 24 | #print str(button) + ' ' + str(button_state) 25 | wiringpi.digitalWrite(first_led,1-button_state) 26 | wiringpi.digitalWrite(second_led,1-button_state) 27 | wiringpi.delay(20) 28 | -------------------------------------------------------------------------------- /examples/softpwm.py: -------------------------------------------------------------------------------- 1 | # Pulsates an LED connected to GPIO pin 1 with a suitable resistor 4 times using softPwm 2 | # softPwm uses a fixed frequency 3 | import wiringpi 4 | 5 | OUTPUT = 1 6 | 7 | PIN_TO_PWM = 1 8 | 9 | wiringpi.wiringPiSetup() 10 | wiringpi.pinMode(PIN_TO_PWM,OUTPUT) 11 | wiringpi.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters 12 | 13 | for time in range(0,4): 14 | for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on 15 | wiringpi.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle 16 | wiringpi.delay(10) # Delay for 0.2 seconds 17 | for brightness in reversed(range(0,100)): 18 | wiringpi.softPwmWrite(PIN_TO_PWM,brightness) 19 | wiringpi.delay(10) 20 | -------------------------------------------------------------------------------- /CHANGES.txt: -------------------------------------------------------------------------------- 1 | v1.0.0 -- Branched from original WiringPi to deliver new WiringPi 2 functionality 2 | v1.0.1 -- Fixed build problems involving missing header files 3 | v1.0.2 -- Fixed build issue with piNes.c 4 | v1.0.3 -- Fixed bug in physical pin assignment mode 5 | v1.0.4 -- Added class wrapper, plus analogRead/Write functions 6 | v1.0.5 -- Second attempt at pretty Pypi page 7 | v1.0.6 -- Fixed spelling error in softToneCreate - Thanks oevsegneev 8 | v1.0.7 -- Added LCD functionality 9 | v1.0.8 -- Updated manifest to include .rst and fix build error 10 | v1.0.9 -- Erroneous non-fix due to stupidity 11 | v1.0.10 -- Added I2CSetup and new I2C class 12 | v1.1.0 -- Synced to WiringPi as of 8th March 2015 13 | v1.1.1 -- Included devLib folder for headers 14 | v1.2.1 -- Synced to WIringPi as of 27th February 2016 15 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup, find_packages, Extension 4 | from glob import glob 5 | 6 | sources = glob('WiringPi/devLib/*.c') 7 | sources += glob('WiringPi/wiringPi/*.c') 8 | sources += ['wiringpi_wrap.c'] 9 | 10 | sources.remove('WiringPi/devLib/piFaceOld.c') 11 | 12 | _wiringpi = Extension( 13 | '_wiringpi', 14 | include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], 15 | sources=sources 16 | ) 17 | 18 | setup( 19 | name = 'wiringpi', 20 | version = '2.32.1', 21 | author = "Philip Howard", 22 | author_email = "phil@gadgetoid.com", 23 | url = 'https://github.com/WiringPi/WiringPi-Python/', 24 | description = """A python interface to WiringPi 2.0 library which allows for 25 | easily interfacing with the GPIO pins of the Raspberry Pi. Also supports 26 | i2c and SPI""", 27 | long_description=open('README.md').read(), 28 | ext_modules = [ _wiringpi ], 29 | py_modules = ["wiringpi"], 30 | install_requires=[], 31 | headers=glob('WiringPi/wiringPi/*.h')+glob('WiringPi/devLib/*.h') 32 | ) 33 | -------------------------------------------------------------------------------- /generate-bindings.py: -------------------------------------------------------------------------------- 1 | HEADERS = [] 2 | 3 | src = open("wiringpi.i").read().split('\n') 4 | 5 | for line in src: 6 | line = line.strip() 7 | if line.startswith('#include') and line.endswith('.h"'): 8 | HEADERS.append(line.replace('#include','').replace('"','').strip()) 9 | 10 | #print(HEADERS) 11 | 12 | def is_c_decl(line): 13 | for fn in ['wiringPiISR','wiringPiSetupPiFace','wiringPiSetupPiFaceForGpioProg']: 14 | if fn in line: 15 | return False 16 | for prefix in ['extern','void','int','uint8_t']: 17 | if line.startswith(prefix): 18 | return True 19 | 20 | print("// Generated by generate-bindings.py - do not edit manually!") 21 | 22 | for file in HEADERS: 23 | print("\n// Header file {}".format(file)) 24 | h = open(file).read().split('\n') 25 | extern = False 26 | cont = False 27 | if 'extern "C" {' not in h: 28 | extern = True 29 | for line in h: 30 | line = line.strip() 31 | if cont: 32 | print("\t{}".format(line)) 33 | cont = ";" not in line 34 | continue 35 | if line.startswith('extern "C"'): 36 | extern = True 37 | continue 38 | if is_c_decl(line) and extern: 39 | print(line) 40 | cont = ";" not in line 41 | -------------------------------------------------------------------------------- /examples/n5510-mcp23017.py: -------------------------------------------------------------------------------- 1 | # Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander ) 2 | import wiringpi 3 | 4 | PIN_BACKLIGHT = 67 # LED 5 | PIN_SCLK = 68 # Clock SCLK 6 | PIN_SDIN = 69 # DN(MOSI) 7 | PIN_DC = 70 # D/C 8 | PIN_RESET = 71 # RST Reset 9 | PIN_SCE = 72 # SCE 10 | 11 | #PIN_BACKLIGHT = 5 12 | #PIN_SCLK = 4 13 | #PIN_SDIN = 3 14 | #PIN_DC = 2 15 | #PIN_RESET = 1 16 | #PIN_SCE = 0 17 | 18 | OUTPUT = 1 19 | INPUT = 0 20 | HIGH = 1 21 | LOW = 0 22 | 23 | LCD_C = 0 24 | LCD_D = 1 25 | 26 | LCD_X = 84 27 | LCD_Y = 48 28 | LCD_SEGS = 504 29 | 30 | MSBFIRST = 1 31 | LSBFIRST = 0 32 | 33 | SLOW_DOWN = 400 34 | 35 | pin_base = 65 36 | i2c_addr = 0x21 37 | 38 | wiringpi.wiringPiSetup() 39 | wiringpi.mcp23017Setup(pin_base,i2c_addr) 40 | 41 | def slow_shift_out(data_pin, clock_pin, data): 42 | for bit in bin(data).replace('0b','').rjust(8,'0'): 43 | wiringpi.digitalWrite(clock_pin,LOW) 44 | wiringpi.delay(SLOW_DOWN) 45 | wiringpi.digitalWrite(data_pin,int(bit)) 46 | wiringpi.delay(SLOW_DOWN) 47 | wiringpi.digitalWrite(clock_pin,HIGH) 48 | wiringpi.delay(SLOW_DOWN) 49 | 50 | def lcd_write(dc, data): 51 | wiringpi.digitalWrite(PIN_DC, dc) 52 | wiringpi.digitalWrite(PIN_SCE, LOW) 53 | wiringpi.delay(SLOW_DOWN) 54 | #wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data) 55 | slow_shift_out(PIN_SDIN, PIN_SCLK, data) 56 | wiringpi.digitalWrite(PIN_SCE, HIGH) 57 | wiringpi.delay(SLOW_DOWN) 58 | #wiringpi.delay(2) 59 | 60 | def lcd_initialise(): 61 | wiringpi.pinMode(PIN_BACKLIGHT,OUTPUT) 62 | wiringpi.digitalWrite(PIN_BACKLIGHT, HIGH) 63 | wiringpi.pinMode(PIN_SCE, OUTPUT) 64 | wiringpi.pinMode(PIN_RESET, OUTPUT) 65 | wiringpi.pinMode(PIN_DC, OUTPUT) 66 | wiringpi.pinMode(PIN_SDIN, OUTPUT) 67 | wiringpi.pinMode(PIN_SCLK, OUTPUT) 68 | wiringpi.digitalWrite(PIN_RESET, LOW) 69 | wiringpi.delay(SLOW_DOWN) 70 | wiringpi.digitalWrite(PIN_RESET, HIGH) 71 | wiringpi.delay(SLOW_DOWN) 72 | lcd_write(LCD_C, 0x21 ) # LCD Extended Commands. 73 | lcd_write(LCD_C, 0xCC ) # Set LCD Vop (Contrast). 74 | lcd_write(LCD_C, 0x04 ) # Set Temp coefficent. //0x04 75 | lcd_write(LCD_C, 0x14 ) # LCD bias mode 1:48. //0x13 76 | lcd_write(LCD_C, 0x0C ) # LCD in normal mode. 77 | lcd_write(LCD_C, 0x20 ) 78 | lcd_write(LCD_C, 0x0C ) 79 | 80 | def lcd_clear(): 81 | for time in range(0, LCD_SEGS): 82 | lcd_write(LCD_D, 0x00) 83 | 84 | def lcd_fill(): 85 | for time in range(0, LCD_SEGS): 86 | lcd_write(LCD_D, 0xFF) 87 | 88 | 89 | lcd_initialise() 90 | 91 | for time in range(0,4): 92 | lcd_clear() 93 | wiringpi.delay(1000) 94 | lcd_fill() 95 | wiringpi.delay(1000) 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #WiringPi for Python 2 | 3 | WiringPi: An implementation of most of the Arduino Wiring 4 | functions for the Raspberry Pi 5 | 6 | WiringPi implements new functions for managing IO expanders. 7 | 8 | ##Testing 9 | Build with gcc version 4.6.3 (Debian 4.6.3-14+rpi1) 10 | Built against Python 2.7.2, Python 3.2.3 11 | 12 | ##Get/setup repo 13 | ```bash 14 | git clone --recursive https://github.com/lanefu/WiringPi-Python-OP.git 15 | cd WiringPi-Python-OP 16 | ``` 17 | 18 | ##Prerequisites 19 | To rebuild the bindings 20 | you **must** first have python-dev, python-setuptools and swig installed. 21 | ```bash 22 | sudo apt-get install python-dev python-setuptools swig 23 | ``` 24 | 25 | ##Build WiringPi 26 | ```bash 27 | cd WiringPi 28 | sudo ./build 29 | ``` 30 | 31 | ##Generate Bindings 32 | `swig2.0 -python wiringpi.i` 33 | or 34 | `swig3.0 -thread -python wiringpi.i` 35 | 36 | ##Build & install with 37 | `sudo python setup.py install` 38 | 39 | Or Python 3: 40 | `sudo python3 setup.py install` 41 | 42 | #Class-based Usage 43 | Description incoming! 44 | 45 | ##Usage 46 | 47 | import wiringpi 48 | 49 | wiringpi.wiringPiSetup() # For sequential pin numbering, one of these MUST be called before using IO functions 50 | # OR 51 | wiringpi.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering 52 | # OR 53 | wiringpi.wiringPiSetupGpio() # For GPIO pin numbering 54 | 55 | 56 | Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C): 57 | 58 | wiringpi.mcp23017Setup(65,0x20) 59 | wiringpi.pinMode(65,1) 60 | wiringpi.digitalWrite(65,1) 61 | 62 | **General IO:** 63 | 64 | wiringpi.pinMode(6,1) # Set pin 6 to 1 ( OUTPUT ) 65 | wiringpi.digitalWrite(6,1) # Write 1 ( HIGH ) to pin 6 66 | wiringpi.digitalRead(6) # Read pin 6 67 | 68 | **Setting up a peripheral:** 69 | WiringPi2 supports expanding your range of available "pins" by setting up a port expander. The implementation details of 70 | your port expander will be handled transparently, and you can write to the additional pins ( starting from PIN_OFFSET >= 64 ) 71 | as if they were normal pins on the Pi. 72 | 73 | wiringpi.mcp23017Setup(PIN_OFFSET,I2C_ADDR) 74 | 75 | **Soft Tone** 76 | 77 | Hook a speaker up to your Pi and generate music with softTone. Also useful for generating frequencies for other uses such as modulating A/C. 78 | 79 | wiringpi.softToneCreate(PIN) 80 | wiringpi.softToneWrite(PIN,FREQUENCY) 81 | 82 | **Bit shifting:** 83 | 84 | wiringpi.shiftOut(1,2,0,123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 85 | 86 | **Serial:** 87 | 88 | serial = wiringpi.serialOpen('/dev/ttyAMA0',9600) # Requires device/baud and returns an ID 89 | wiringpi.serialPuts(serial,"hello") 90 | wiringpi.serialClose(serial) # Pass in ID 91 | 92 | **Full details at:** 93 | http://www.wiringpi.com 94 | -------------------------------------------------------------------------------- /wiringpi-class.py: -------------------------------------------------------------------------------- 1 | %pythoncode %{ 2 | class nes(object): 3 | def setupNesJoystick(self,*args): 4 | return setupNesJoystick(*args) 5 | def readNesJoystick(self,*args): 6 | return readNesJoystick(*args) 7 | 8 | class Serial(object): 9 | device = '/dev/ttyAMA0' 10 | baud = 9600 11 | serial_id = 0 12 | def printf(self,*args): 13 | return serialPrintf(self.serial_id,*args) 14 | def dataAvail(self,*args): 15 | return serialDataAvail(self.serial_id,*args) 16 | def getchar(self,*args): 17 | return serialGetchar(self.serial_id,*args) 18 | def putchar(self,*args): 19 | return serialPutchar(self.serial_id,*args) 20 | def puts(self,*args): 21 | return serialPuts(self.serial_id,*args) 22 | def __init__(self,device,baud): 23 | self.device = device 24 | self.baud = baud 25 | self.serial_id = serialOpen(self.device,self.baud) 26 | def __del__(self): 27 | serialClose(self.serial_id) 28 | 29 | class I2C(object): 30 | def setupInterface(self,*args): 31 | return wiringPiI2CSetupInterface(*args) 32 | def setup(self,*args): 33 | return wiringPiI2CSetup(*args) 34 | def read(self,*args): 35 | return wiringPiI2CRead(*args) 36 | def readReg8(self,*args): 37 | return wiringPiI2CReadReg8(*args) 38 | def readReg16(self,*args): 39 | return wiringPiI2CReadReg16(*args) 40 | def write(self,*args): 41 | return wiringPiI2CWrite(*args) 42 | def writeReg8(self,*args): 43 | return wiringPiI2CWriteReg8(*args) 44 | def writeReg16(self,*args): 45 | return wiringPiI2CWriteReg16(*args) 46 | 47 | class GPIO(object): 48 | WPI_MODE_PINS = 0 49 | WPI_MODE_GPIO = 1 50 | WPI_MODE_GPIO_SYS = 2 51 | WPI_MODE_PHYS = 3 52 | WPI_MODE_PIFACE = 4 53 | WPI_MODE_UNINITIALISED = -1 54 | 55 | INPUT = 0 56 | OUTPUT = 1 57 | PWM_OUTPUT = 2 58 | GPIO_CLOCK = 3 59 | 60 | LOW = 0 61 | HIGH = 1 62 | 63 | PUD_OFF = 0 64 | PUD_DOWN = 1 65 | PUD_UP = 2 66 | 67 | PWM_MODE_MS = 0 68 | PWM_MODE_BAL = 1 69 | 70 | INT_EDGE_SETUP = 0 71 | INT_EDGE_FALLING = 1 72 | INT_EDGE_RISING = 2 73 | INT_EDGE_BOTH = 3 74 | 75 | LSBFIRST = 0 76 | MSBFIRST = 1 77 | 78 | MODE = 0 79 | def __init__(self,pinmode=0): 80 | self.MODE=pinmode 81 | if pinmode==self.WPI_MODE_PINS: 82 | wiringPiSetup() 83 | if pinmode==self.WPI_MODE_GPIO: 84 | wiringPiSetupGpio() 85 | if pinmode==self.WPI_MODE_GPIO_SYS: 86 | wiringPiSetupSys() 87 | if pinmode==self.WPI_MODE_PHYS: 88 | wiringPiSetupPhys() 89 | if pinmode==self.WPI_MODE_PIFACE: 90 | wiringPiSetupPiFace() 91 | 92 | def delay(self,*args): 93 | delay(*args) 94 | def delayMicroseconds(self,*args): 95 | delayMicroseconds(*args) 96 | def millis(self): 97 | return millis() 98 | def micros(self): 99 | return micros() 100 | 101 | def piHiPri(self,*args): 102 | return piHiPri(*args) 103 | 104 | def piBoardRev(self): 105 | return piBoardRev() 106 | def wpiPinToGpio(self,*args): 107 | return wpiPinToGpio(*args) 108 | def setPadDrive(self,*args): 109 | return setPadDrive(*args) 110 | def getAlt(self,*args): 111 | return getAlt(*args) 112 | def digitalWriteByte(self,*args): 113 | return digitalWriteByte(*args) 114 | 115 | def pwmSetMode(self,*args): 116 | pwmSetMode(*args) 117 | def pwmSetRange(self,*args): 118 | pwmSetRange(*args) 119 | def pwmSetClock(self,*args): 120 | pwmSetClock(*args) 121 | def gpioClockSet(self,*args): 122 | gpioClockSet(*args) 123 | def pwmWrite(self,*args): 124 | pwmWrite(*args) 125 | 126 | def pinMode(self,*args): 127 | pinMode(*args) 128 | 129 | def digitalWrite(self,*args): 130 | digitalWrite(*args) 131 | def digitalRead(self,*args): 132 | return digitalRead(*args) 133 | def digitalWriteByte(self,*args): 134 | digitalWriteByte(*args) 135 | 136 | def analogWrite(self,*args): 137 | analogWrite(*args) 138 | def analogRead(self,*args): 139 | return analogRead(*args) 140 | 141 | def shiftOut(self,*args): 142 | shiftOut(*args) 143 | def shiftIn(self,*args): 144 | return shiftIn(*args) 145 | 146 | def pullUpDnControl(self,*args): 147 | return pullUpDnControl(*args) 148 | 149 | def waitForInterrupt(self,*args): 150 | return waitForInterrupt(*args) 151 | def wiringPiISR(self,*args): 152 | return wiringPiISR(*args) 153 | 154 | def softPwmCreate(self,*args): 155 | return softPwmCreate(*args) 156 | def softPwmWrite(self,*args): 157 | return sofPwmWrite(*args) 158 | 159 | def softToneCreate(self,*args): 160 | return softToneCreate(*args) 161 | def softToneWrite(self,*args): 162 | return softToneWrite(*args) 163 | 164 | def lcdHome(self,*args): 165 | return lcdHome(self,*args) 166 | def lcdCLear(self,*args): 167 | return lcdClear(self,*args) 168 | def lcdSendCommand(self,*args): 169 | return lcdSendCommand(self,*args) 170 | def lcdPosition(self,*args): 171 | return lcdPosition(self,*args) 172 | def lcdPutchar(self,*args): 173 | return lcdPutchar(self,*args) 174 | def lcdPuts(self,*args): 175 | return lcdPuts(self,*args) 176 | def lcdPrintf(self,*args): 177 | return lcdPrintf(self,*args) 178 | def lcdInit(self,*args): 179 | return lcdInit(self,*args) 180 | def piGlowSetup(self,*args): 181 | return piGlowSetup(self,*args) 182 | def piGlow1(self,*args): 183 | return piGlow1(self,*args) 184 | def piGlowLeg(self,*args): 185 | return piGlowLeg(self,*args) 186 | def piGlowRing(self,*args): 187 | return piGlowRing(self,*args) 188 | %} 189 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /_wiringpi2/LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /bindings.i: -------------------------------------------------------------------------------- 1 | // Generated by generate-bindings.py - do not edit manually! 2 | 3 | // Header file WiringPi/wiringPi/wiringPi.h 4 | extern int wiringPiFailure (int fatal, const char *message, ...) ; 5 | extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ; 6 | extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ; 7 | extern int wiringPiSetup (void) ; 8 | extern int wiringPiSetupSys (void) ; 9 | extern int wiringPiSetupGpio (void) ; 10 | extern int wiringPiSetupPhys (void) ; 11 | extern void pinModeAlt (int pin, int mode) ; 12 | extern void pinMode (int pin, int mode) ; 13 | extern void pullUpDnControl (int pin, int pud) ; 14 | extern int digitalRead (int pin) ; 15 | extern void digitalWrite (int pin, int value) ; 16 | extern void pwmWrite (int pin, int value) ; 17 | extern int analogRead (int pin) ; 18 | extern void analogWrite (int pin, int value) ; 19 | extern int piBoardRev (void) ; 20 | extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ; 21 | extern int wpiPinToGpio (int wpiPin) ; 22 | extern int physPinToGpio (int physPin) ; 23 | extern void setPadDrive (int group, int value) ; 24 | extern int getAlt (int pin) ; 25 | extern void pwmToneWrite (int pin, int freq) ; 26 | extern void digitalWriteByte (int value) ; 27 | //extern unsigned int digitalReadByte (void) ; 28 | extern void pwmSetMode (int mode) ; 29 | extern void pwmSetRange (unsigned int range) ; 30 | extern void pwmSetClock (int divisor) ; 31 | extern void gpioClockSet (int pin, int freq) ; 32 | extern int waitForInterrupt (int pin, int mS) ; 33 | extern int piThreadCreate (void *(*fn)(void *)) ; 34 | extern void piLock (int key) ; 35 | extern void piUnlock (int key) ; 36 | extern int piHiPri (const int pri) ; 37 | extern void delay (unsigned int howLong) ; 38 | extern void delayMicroseconds (unsigned int howLong) ; 39 | extern unsigned int millis (void) ; 40 | extern unsigned int micros (void) ; 41 | 42 | // Header file WiringPi/wiringPi/wiringPiI2C.h 43 | extern int wiringPiI2CRead (int fd) ; 44 | extern int wiringPiI2CReadReg8 (int fd, int reg) ; 45 | extern int wiringPiI2CReadReg16 (int fd, int reg) ; 46 | extern int wiringPiI2CWrite (int fd, int data) ; 47 | extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ; 48 | extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ; 49 | extern int wiringPiI2CSetupInterface (const char *device, int devId) ; 50 | extern int wiringPiI2CSetup (const int devId) ; 51 | 52 | // Header file WiringPi/wiringPi/wiringPiSPI.h 53 | int wiringPiSPIGetFd (int channel) ; 54 | int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ; 55 | #int wiringPiSPISetupMode (int channel, int speed, int mode) ; 56 | #int wiringPiSPISetup (int channel, int speed) ; 57 | 58 | // Header file WiringPi/wiringPi/wiringSerial.h 59 | extern int serialOpen (const char *device, const int baud) ; 60 | extern void serialClose (const int fd) ; 61 | extern void serialFlush (const int fd) ; 62 | extern void serialPutchar (const int fd, const unsigned char c) ; 63 | extern void serialPuts (const int fd, const char *s) ; 64 | extern void serialPrintf (const int fd, const char *message, ...) ; 65 | extern int serialDataAvail (const int fd) ; 66 | extern int serialGetchar (const int fd) ; 67 | 68 | // Header file WiringPi/wiringPi/wiringShift.h 69 | extern uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) ; 70 | extern void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ; 71 | 72 | // Header file WiringPi/wiringPi/drcSerial.h 73 | extern int drcSetupSerial (const int pinBase, const int numPins, const char *device, const int baud) ; 74 | 75 | // Header file WiringPi/wiringPi/ads1115.h 76 | //extern int ads1115Setup (int pinBase, int i2cAddress) ; 77 | 78 | // Header file WiringPi/wiringPi/max31855.h 79 | extern int max31855Setup (int pinBase, int spiChannel) ; 80 | 81 | // Header file WiringPi/wiringPi/max5322.h 82 | extern int max5322Setup (int pinBase, int spiChannel) ; 83 | 84 | // Header file WiringPi/wiringPi/mcp23008.h 85 | extern int mcp23008Setup (const int pinBase, const int i2cAddress) ; 86 | 87 | // Header file WiringPi/wiringPi/mcp23016.h 88 | extern int mcp23016Setup (const int pinBase, const int i2cAddress) ; 89 | 90 | // Header file WiringPi/wiringPi/mcp23016reg.h 91 | 92 | // Header file WiringPi/wiringPi/mcp23017.h 93 | extern int mcp23017Setup (const int pinBase, const int i2cAddress) ; 94 | 95 | // Header file WiringPi/wiringPi/mcp23s08.h 96 | extern int mcp23s08Setup (const int pinBase, const int spiPort, const int devId) ; 97 | 98 | // Header file WiringPi/wiringPi/mcp23s17.h 99 | extern int mcp23s17Setup (int pinBase, int spiPort, int devId) ; 100 | 101 | // Header file WiringPi/wiringPi/mcp23x0817.h 102 | 103 | // Header file WiringPi/wiringPi/mcp23x08.h 104 | 105 | // Header file WiringPi/wiringPi/mcp3002.h 106 | extern int mcp3002Setup (int pinBase, int spiChannel) ; 107 | 108 | // Header file WiringPi/wiringPi/mcp3004.h 109 | extern int mcp3004Setup (int pinBase, int spiChannel) ; 110 | 111 | // Header file WiringPi/wiringPi/mcp3422.h 112 | extern int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) ; 113 | 114 | // Header file WiringPi/wiringPi/mcp4802.h 115 | extern int mcp4802Setup (int pinBase, int spiChannel) ; 116 | 117 | // Header file WiringPi/wiringPi/pcf8574.h 118 | extern int pcf8574Setup (const int pinBase, const int i2cAddress) ; 119 | 120 | // Header file WiringPi/wiringPi/pcf8591.h 121 | extern int pcf8591Setup (const int pinBase, const int i2cAddress) ; 122 | 123 | // Header file WiringPi/wiringPi/sn3218.h 124 | extern int sn3218Setup (int pinBase) ; 125 | 126 | // Header file WiringPi/wiringPi/softPwm.h 127 | extern int softPwmCreate (int pin, int value, int range) ; 128 | extern void softPwmWrite (int pin, int value) ; 129 | extern void softPwmStop (int pin) ; 130 | 131 | // Header file WiringPi/wiringPi/softServo.h 132 | extern void softServoWrite (int pin, int value) ; 133 | extern int softServoSetup (int p0, int p1, int p2, int p3, int p4, int p5, int p6, int p7) ; 134 | 135 | // Header file WiringPi/wiringPi/softTone.h 136 | extern int softToneCreate (int pin) ; 137 | extern void softToneStop (int pin) ; 138 | extern void softToneWrite (int pin, int freq) ; 139 | 140 | // Header file WiringPi/wiringPi/sr595.h 141 | extern int sr595Setup (const int pinBase, const int numPins, 142 | const int dataPin, const int clockPin, const int latchPin) ; 143 | 144 | // Header file WiringPi/devLib/ds1302.h 145 | extern unsigned int ds1302rtcRead (const int reg) ; 146 | extern void ds1302rtcWrite (const int reg, const unsigned int data) ; 147 | extern unsigned int ds1302ramRead (const int addr) ; 148 | extern void ds1302ramWrite (const int addr, const unsigned int data) ; 149 | extern void ds1302clockRead (int clockData [8]) ; 150 | extern void ds1302clockWrite (const int clockData [8]) ; 151 | extern void ds1302trickleCharge (const int diodes, const int resistors) ; 152 | extern void ds1302setup (const int clockPin, const int dataPin, const int csPin) ; 153 | 154 | // Header file WiringPi/devLib/font.h 155 | 156 | // Header file WiringPi/devLib/gertboard.h 157 | extern void gertboardAnalogWrite (const int chan, const int value) ; 158 | extern int gertboardAnalogRead (const int chan) ; 159 | extern int gertboardSPISetup (void) ; 160 | extern int gertboardAnalogSetup (const int pinBase) ; 161 | 162 | // Header file WiringPi/devLib/lcd128x64.h 163 | extern void lcd128x64setOrigin (int x, int y) ; 164 | extern void lcd128x64setOrientation (int orientation) ; 165 | extern void lcd128x64orientCoordinates (int *x, int *y) ; 166 | extern void lcd128x64getScreenSize (int *x, int *y) ; 167 | extern void lcd128x64point (int x, int y, int colour) ; 168 | extern void lcd128x64line (int x0, int y0, int x1, int y1, int colour) ; 169 | extern void lcd128x64lineTo (int x, int y, int colour) ; 170 | extern void lcd128x64rectangle (int x1, int y1, int x2, int y2, int colour, int filled) ; 171 | extern void lcd128x64circle (int x, int y, int r, int colour, int filled) ; 172 | extern void lcd128x64ellipse (int cx, int cy, int xRadius, int yRadius, int colour, int filled) ; 173 | extern void lcd128x64putchar (int x, int y, int c, int bgCol, int fgCol) ; 174 | extern void lcd128x64puts (int x, int y, const char *str, int bgCol, int fgCol) ; 175 | extern void lcd128x64update (void) ; 176 | extern void lcd128x64clear (int colour) ; 177 | extern int lcd128x64setup (void) ; 178 | 179 | // Header file WiringPi/devLib/lcd.h 180 | extern void lcdHome (const int fd) ; 181 | extern void lcdClear (const int fd) ; 182 | extern void lcdDisplay (const int fd, int state) ; 183 | extern void lcdCursor (const int fd, int state) ; 184 | extern void lcdCursorBlink (const int fd, int state) ; 185 | extern void lcdSendCommand (const int fd, unsigned char command) ; 186 | extern void lcdPosition (const int fd, int x, int y) ; 187 | extern void lcdCharDef (const int fd, int index, unsigned char data [8]) ; 188 | extern void lcdPutchar (const int fd, unsigned char data) ; 189 | extern void lcdPuts (const int fd, const char *string) ; 190 | extern void lcdPrintf (const int fd, const char *message, ...) ; 191 | extern int lcdInit (const int rows, const int cols, const int bits, 192 | const int rs, const int strb, 193 | const int d0, const int d1, const int d2, const int d3, const int d4, 194 | const int d5, const int d6, const int d7) ; 195 | 196 | // Header file WiringPi/devLib/maxdetect.h 197 | int maxDetectRead (const int pin, unsigned char buffer [4]) ; 198 | int readRHT03 (const int pin, int *temp, int *rh) ; 199 | 200 | // Header file WiringPi/devLib/piGlow.h 201 | extern void piGlow1 (const int leg, const int ring, const int intensity) ; 202 | extern void piGlowLeg (const int leg, const int intensity) ; 203 | extern void piGlowRing (const int ring, const int intensity) ; 204 | extern void piGlowSetup (int clear) ; 205 | 206 | // Header file WiringPi/devLib/piNes.h 207 | extern int setupNesJoystick (int dPin, int cPin, int lPin) ; 208 | extern unsigned int readNesJoystick (int joystick) ; 209 | 210 | // Header file WiringPi/devLib/scrollPhat.h 211 | //extern void scrollPhatPoint (int x, int y, int colour) ; 212 | //extern void scrollPhatLine (int x0, int y0, int x1, int y1, int colour) ; 213 | //extern void scrollPhatLineTo (int x, int y, int colour) ; 214 | //extern void scrollPhatRectangle (int x1, int y1, int x2, int y2, int colour, int filled) ; 215 | //extern void scrollPhatUpdate (void) ; 216 | //extern void scrollPhatClear (void) ; 217 | //extern int scrollPhatPutchar (int c) ; 218 | //extern void scrollPhatPuts (const char *str) ; 219 | //extern void scrollPhatPrintf (const char *message, ...) ; 220 | //extern void scrollPhatPrintSpeed (const int cps10) ; 221 | //extern void scrollPhatIntensity (const int percent) ; 222 | //extern int scrollPhatSetup (void) ; 223 | -------------------------------------------------------------------------------- /wiringpi.i: -------------------------------------------------------------------------------- 1 | %module wiringpi 2 | 3 | %{ 4 | #if PY_MAJOR_VERSION >= 3 5 | #define PyInt_AS_LONG PyLong_AsLong 6 | #define PyString_FromStringAndSize PyBytes_FromStringAndSize 7 | #endif 8 | 9 | #include "WiringPi/wiringPi/wiringPi.h" 10 | #include "WiringPi/wiringPi/wiringPiI2C.h" 11 | #include "WiringPi/wiringPi/wiringPiSPI.h" 12 | #include "WiringPi/wiringPi/wiringSerial.h" 13 | #include "WiringPi/wiringPi/wiringShift.h" 14 | #include "WiringPi/wiringPi/drcSerial.h" 15 | #include "WiringPi/wiringPi/max31855.h" 16 | #include "WiringPi/wiringPi/max5322.h" 17 | #include "WiringPi/wiringPi/mcp23008.h" 18 | #include "WiringPi/wiringPi/mcp23016.h" 19 | #include "WiringPi/wiringPi/mcp23016reg.h" 20 | #include "WiringPi/wiringPi/mcp23017.h" 21 | #include "WiringPi/wiringPi/mcp23s08.h" 22 | #include "WiringPi/wiringPi/mcp23s17.h" 23 | #include "WiringPi/wiringPi/mcp23x0817.h" 24 | #include "WiringPi/wiringPi/mcp23x08.h" 25 | #include "WiringPi/wiringPi/mcp3002.h" 26 | #include "WiringPi/wiringPi/mcp3004.h" 27 | #include "WiringPi/wiringPi/mcp3422.h" 28 | #include "WiringPi/wiringPi/mcp4802.h" 29 | #include "WiringPi/wiringPi/pcf8574.h" 30 | #include "WiringPi/wiringPi/pcf8591.h" 31 | #include "WiringPi/wiringPi/sn3218.h" 32 | #include "WiringPi/wiringPi/softPwm.h" 33 | #include "WiringPi/wiringPi/softServo.h" 34 | #include "WiringPi/wiringPi/softTone.h" 35 | #include "WiringPi/wiringPi/sr595.h" 36 | #include "WiringPi/devLib/ds1302.h" 37 | #include "WiringPi/devLib/font.h" 38 | #include "WiringPi/devLib/gertboard.h" 39 | #include "WiringPi/devLib/lcd128x64.h" 40 | #include "WiringPi/devLib/lcd.h" 41 | #include "WiringPi/devLib/maxdetect.h" 42 | #include "WiringPi/devLib/piGlow.h" 43 | #include "WiringPi/devLib/piNes.h" 44 | %} 45 | 46 | %apply unsigned char { uint8_t }; 47 | %typemap(in) (unsigned char *data, int len) { 48 | $1 = (unsigned char *) PyString_AsString($input); 49 | $2 = PyString_Size($input); 50 | }; 51 | 52 | // Grab a Python function object as a Python object. 53 | %typemap(in) PyObject *pyfunc { 54 | if (!PyCallable_Check($1)) { 55 | PyErr_SetString(PyExc_TypeError, "Need a callable object!"); 56 | return NULL; 57 | } 58 | $1 = $2; 59 | } 60 | 61 | %{ 62 | 63 | // we need to have our own callbacks array 64 | PyObject* event_callback[64] = {0,}; 65 | 66 | void _wiringPiISR_callback(int pinNumber) { 67 | PyObject *result; 68 | 69 | if (event_callback[pinNumber]) { 70 | // this will acquire the GIL 71 | SWIG_PYTHON_THREAD_BEGIN_BLOCK; 72 | 73 | result = PyObject_CallFunction(event_callback[pinNumber], NULL); 74 | if (result == NULL && PyErr_Occurred()) { 75 | PyErr_Print(); 76 | PyErr_Clear(); 77 | } 78 | Py_XDECREF(result); 79 | 80 | // release the GIL 81 | SWIG_PYTHON_THREAD_END_BLOCK; 82 | } 83 | } 84 | 85 | 86 | /* This is embarrasing, WiringPi does not support supplying args to the callback 87 | ... so we have to create callback function for each of the pins :( */ 88 | void _wiringPiISR_callback_pin0(void) { _wiringPiISR_callback(0); } 89 | void _wiringPiISR_callback_pin1(void) { _wiringPiISR_callback(1); } 90 | void _wiringPiISR_callback_pin2(void) { _wiringPiISR_callback(2); } 91 | void _wiringPiISR_callback_pin3(void) { _wiringPiISR_callback(3); } 92 | void _wiringPiISR_callback_pin4(void) { _wiringPiISR_callback(4); } 93 | void _wiringPiISR_callback_pin5(void) { _wiringPiISR_callback(5); } 94 | void _wiringPiISR_callback_pin6(void) { _wiringPiISR_callback(6); } 95 | void _wiringPiISR_callback_pin7(void) { _wiringPiISR_callback(7); } 96 | void _wiringPiISR_callback_pin8(void) { _wiringPiISR_callback(8); } 97 | void _wiringPiISR_callback_pin9(void) { _wiringPiISR_callback(9); } 98 | void _wiringPiISR_callback_pin10(void) { _wiringPiISR_callback(10); } 99 | void _wiringPiISR_callback_pin11(void) { _wiringPiISR_callback(11); } 100 | void _wiringPiISR_callback_pin12(void) { _wiringPiISR_callback(12); } 101 | void _wiringPiISR_callback_pin13(void) { _wiringPiISR_callback(13); } 102 | void _wiringPiISR_callback_pin14(void) { _wiringPiISR_callback(14); } 103 | void _wiringPiISR_callback_pin15(void) { _wiringPiISR_callback(15); } 104 | void _wiringPiISR_callback_pin16(void) { _wiringPiISR_callback(16); } 105 | void _wiringPiISR_callback_pin17(void) { _wiringPiISR_callback(17); } 106 | void _wiringPiISR_callback_pin18(void) { _wiringPiISR_callback(18); } 107 | void _wiringPiISR_callback_pin19(void) { _wiringPiISR_callback(19); } 108 | void _wiringPiISR_callback_pin20(void) { _wiringPiISR_callback(20); } 109 | void _wiringPiISR_callback_pin21(void) { _wiringPiISR_callback(21); } 110 | void _wiringPiISR_callback_pin22(void) { _wiringPiISR_callback(22); } 111 | void _wiringPiISR_callback_pin23(void) { _wiringPiISR_callback(23); } 112 | void _wiringPiISR_callback_pin24(void) { _wiringPiISR_callback(24); } 113 | void _wiringPiISR_callback_pin25(void) { _wiringPiISR_callback(25); } 114 | void _wiringPiISR_callback_pin26(void) { _wiringPiISR_callback(26); } 115 | void _wiringPiISR_callback_pin27(void) { _wiringPiISR_callback(27); } 116 | void _wiringPiISR_callback_pin28(void) { _wiringPiISR_callback(28); } 117 | void _wiringPiISR_callback_pin29(void) { _wiringPiISR_callback(29); } 118 | void _wiringPiISR_callback_pin30(void) { _wiringPiISR_callback(30); } 119 | void _wiringPiISR_callback_pin31(void) { _wiringPiISR_callback(31); } 120 | void _wiringPiISR_callback_pin32(void) { _wiringPiISR_callback(32); } 121 | void _wiringPiISR_callback_pin33(void) { _wiringPiISR_callback(33); } 122 | void _wiringPiISR_callback_pin34(void) { _wiringPiISR_callback(34); } 123 | void _wiringPiISR_callback_pin35(void) { _wiringPiISR_callback(35); } 124 | void _wiringPiISR_callback_pin36(void) { _wiringPiISR_callback(36); } 125 | void _wiringPiISR_callback_pin37(void) { _wiringPiISR_callback(37); } 126 | void _wiringPiISR_callback_pin38(void) { _wiringPiISR_callback(38); } 127 | void _wiringPiISR_callback_pin39(void) { _wiringPiISR_callback(39); } 128 | void _wiringPiISR_callback_pin40(void) { _wiringPiISR_callback(40); } 129 | void _wiringPiISR_callback_pin41(void) { _wiringPiISR_callback(41); } 130 | void _wiringPiISR_callback_pin42(void) { _wiringPiISR_callback(42); } 131 | void _wiringPiISR_callback_pin43(void) { _wiringPiISR_callback(43); } 132 | void _wiringPiISR_callback_pin44(void) { _wiringPiISR_callback(44); } 133 | void _wiringPiISR_callback_pin45(void) { _wiringPiISR_callback(45); } 134 | void _wiringPiISR_callback_pin46(void) { _wiringPiISR_callback(46); } 135 | void _wiringPiISR_callback_pin47(void) { _wiringPiISR_callback(47); } 136 | void _wiringPiISR_callback_pin48(void) { _wiringPiISR_callback(48); } 137 | void _wiringPiISR_callback_pin49(void) { _wiringPiISR_callback(49); } 138 | void _wiringPiISR_callback_pin50(void) { _wiringPiISR_callback(50); } 139 | void _wiringPiISR_callback_pin51(void) { _wiringPiISR_callback(51); } 140 | void _wiringPiISR_callback_pin52(void) { _wiringPiISR_callback(52); } 141 | void _wiringPiISR_callback_pin53(void) { _wiringPiISR_callback(53); } 142 | void _wiringPiISR_callback_pin54(void) { _wiringPiISR_callback(54); } 143 | void _wiringPiISR_callback_pin55(void) { _wiringPiISR_callback(55); } 144 | void _wiringPiISR_callback_pin56(void) { _wiringPiISR_callback(56); } 145 | void _wiringPiISR_callback_pin57(void) { _wiringPiISR_callback(57); } 146 | void _wiringPiISR_callback_pin58(void) { _wiringPiISR_callback(58); } 147 | void _wiringPiISR_callback_pin59(void) { _wiringPiISR_callback(59); } 148 | void _wiringPiISR_callback_pin60(void) { _wiringPiISR_callback(60); } 149 | void _wiringPiISR_callback_pin61(void) { _wiringPiISR_callback(61); } 150 | void _wiringPiISR_callback_pin62(void) { _wiringPiISR_callback(62); } 151 | void _wiringPiISR_callback_pin63(void) { _wiringPiISR_callback(63); } 152 | 153 | /* This function adds a new Python function object as a callback object */ 154 | 155 | static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc) { 156 | 157 | // remove the old callback if any 158 | if (event_callback[pin]) { 159 | Py_XDECREF(event_callback[pin]); 160 | } 161 | 162 | // put new callback function 163 | event_callback[pin] = PyFunc; 164 | Py_INCREF(PyFunc); 165 | 166 | // and now the ugly switch 167 | void (*func)(void); 168 | switch(pin) { 169 | case 0: func = &_wiringPiISR_callback_pin0; break; 170 | case 1: func = &_wiringPiISR_callback_pin1; break; 171 | case 2: func = &_wiringPiISR_callback_pin2; break; 172 | case 3: func = &_wiringPiISR_callback_pin3; break; 173 | case 4: func = &_wiringPiISR_callback_pin4; break; 174 | case 5: func = &_wiringPiISR_callback_pin5; break; 175 | case 6: func = &_wiringPiISR_callback_pin6; break; 176 | case 7: func = &_wiringPiISR_callback_pin7; break; 177 | case 8: func = &_wiringPiISR_callback_pin8; break; 178 | case 9: func = &_wiringPiISR_callback_pin9; break; 179 | case 10: func = &_wiringPiISR_callback_pin10; break; 180 | case 11: func = &_wiringPiISR_callback_pin11; break; 181 | case 12: func = &_wiringPiISR_callback_pin12; break; 182 | case 13: func = &_wiringPiISR_callback_pin13; break; 183 | case 14: func = &_wiringPiISR_callback_pin14; break; 184 | case 15: func = &_wiringPiISR_callback_pin15; break; 185 | case 16: func = &_wiringPiISR_callback_pin16; break; 186 | case 17: func = &_wiringPiISR_callback_pin17; break; 187 | case 18: func = &_wiringPiISR_callback_pin18; break; 188 | case 19: func = &_wiringPiISR_callback_pin19; break; 189 | case 20: func = &_wiringPiISR_callback_pin20; break; 190 | case 21: func = &_wiringPiISR_callback_pin21; break; 191 | case 22: func = &_wiringPiISR_callback_pin22; break; 192 | case 23: func = &_wiringPiISR_callback_pin23; break; 193 | case 24: func = &_wiringPiISR_callback_pin24; break; 194 | case 25: func = &_wiringPiISR_callback_pin25; break; 195 | case 26: func = &_wiringPiISR_callback_pin26; break; 196 | case 27: func = &_wiringPiISR_callback_pin27; break; 197 | case 28: func = &_wiringPiISR_callback_pin28; break; 198 | case 29: func = &_wiringPiISR_callback_pin29; break; 199 | case 30: func = &_wiringPiISR_callback_pin30; break; 200 | case 31: func = &_wiringPiISR_callback_pin31; break; 201 | case 32: func = &_wiringPiISR_callback_pin32; break; 202 | case 33: func = &_wiringPiISR_callback_pin33; break; 203 | case 34: func = &_wiringPiISR_callback_pin34; break; 204 | case 35: func = &_wiringPiISR_callback_pin35; break; 205 | case 36: func = &_wiringPiISR_callback_pin36; break; 206 | case 37: func = &_wiringPiISR_callback_pin37; break; 207 | case 38: func = &_wiringPiISR_callback_pin38; break; 208 | case 39: func = &_wiringPiISR_callback_pin39; break; 209 | case 40: func = &_wiringPiISR_callback_pin40; break; 210 | case 41: func = &_wiringPiISR_callback_pin41; break; 211 | case 42: func = &_wiringPiISR_callback_pin42; break; 212 | case 43: func = &_wiringPiISR_callback_pin43; break; 213 | case 44: func = &_wiringPiISR_callback_pin44; break; 214 | case 45: func = &_wiringPiISR_callback_pin45; break; 215 | case 46: func = &_wiringPiISR_callback_pin46; break; 216 | case 47: func = &_wiringPiISR_callback_pin47; break; 217 | case 48: func = &_wiringPiISR_callback_pin48; break; 218 | case 49: func = &_wiringPiISR_callback_pin49; break; 219 | case 50: func = &_wiringPiISR_callback_pin50; break; 220 | case 51: func = &_wiringPiISR_callback_pin51; break; 221 | case 52: func = &_wiringPiISR_callback_pin52; break; 222 | case 53: func = &_wiringPiISR_callback_pin53; break; 223 | case 54: func = &_wiringPiISR_callback_pin54; break; 224 | case 55: func = &_wiringPiISR_callback_pin55; break; 225 | case 56: func = &_wiringPiISR_callback_pin56; break; 226 | case 57: func = &_wiringPiISR_callback_pin57; break; 227 | case 58: func = &_wiringPiISR_callback_pin58; break; 228 | case 59: func = &_wiringPiISR_callback_pin59; break; 229 | case 60: func = &_wiringPiISR_callback_pin60; break; 230 | case 61: func = &_wiringPiISR_callback_pin61; break; 231 | case 62: func = &_wiringPiISR_callback_pin62; break; 232 | case 63: func = &_wiringPiISR_callback_pin63; break; 233 | } 234 | 235 | // register our dedicated function in WiringPi 236 | wiringPiISR(pin, mode, func); 237 | } 238 | 239 | %} 240 | 241 | // overlay normal function with our wrapper 242 | %rename("wiringPiISR") wiringPiISRWrapper (int pin, int mode, PyObject *PyFunc); 243 | static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc); 244 | 245 | %typemap(in) unsigned char data [8] { 246 | /* Check if is a list */ 247 | if (PyList_Check($input)) { 248 | if(PyList_Size($input) != 8){ 249 | PyErr_SetString(PyExc_TypeError,"must contain 8 items"); 250 | return NULL; 251 | } 252 | int i = 0; 253 | $1 = (unsigned char *) malloc(8); 254 | for (i = 0; i < 8; i++) { 255 | PyObject *o = PyList_GetItem($input,i); 256 | if (PyInt_Check(o) && PyInt_AsLong(PyList_GetItem($input,i)) <= 255 && PyInt_AsLong(PyList_GetItem($input,i)) >= 0) 257 | $1[i] = PyInt_AsLong(PyList_GetItem($input,i)); 258 | else { 259 | PyErr_SetString(PyExc_TypeError,"list must contain integers 0-255"); 260 | return NULL; 261 | } 262 | } 263 | } else { 264 | PyErr_SetString(PyExc_TypeError,"not a list"); 265 | return NULL; 266 | } 267 | }; 268 | 269 | %typemap(freearg) unsigned char data [8] { 270 | free((unsigned char *) $1); 271 | } 272 | 273 | %typemap(in) (unsigned char *data, int len) { 274 | $1 = (unsigned char *) PyString_AsString($input); 275 | $2 = PyString_Size($input); 276 | }; 277 | 278 | %typemap(argout) (unsigned char *data) { 279 | $result = SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char *) $1, result)); 280 | }; 281 | 282 | %include "bindings.i" 283 | %include "constants.py" 284 | %include "wiringpi-class.py" 285 | --------------------------------------------------------------------------------