├── .gitignore
├── .gitmodules
├── CHANGES.txt
├── LICENSE.txt
├── MANIFEST.in
├── README.rst
├── _wiringpi2
├── LICENSE.txt
├── MANIFEST.in
├── README.txt
└── setup.py
├── bindings.i
├── constants.py
├── examples
├── RUN_THESE_WITH_SUDO
├── callback.py
├── delay.py
├── ladder-board.py
├── n5510-mcp23017.py
├── quick2wire-io.py
├── softpwm.py
├── softtone.py
└── two-mcp23017.py
├── generate-bindings.py
├── setup.cfg
├── setup.py
├── tests
├── piglow.py
└── test.py
├── wiringpi-class.py
└── wiringpi.i
/.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/wiringPi/WiringPi
4 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | recursive-include WiringPi *.h
2 | include README.rst
3 | include LICENSE.txt
4 | include bindings.i
5 | include constants.py
6 | include wiringpi-class.py
7 | include wiringpi.i
8 | include wiringpi_wrap.c
9 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | :Warning: WiringPi was deprecated by its author in August 2019. As of 31st October 2023 nobody has shown an interest in properly maintaining it. Between this, and changes to GPIO in Rasberry Pi OS Bookworm and on the Raspberry Pi 5, this project is going nowhere. It has been archived to more clearly indicate this status.
2 |
3 | Note
4 | ~~~~
5 |
6 | This is an unofficial port of Gordon's WiringPi library. Please do not
7 | email Gordon if you have issues, he will not be able to help.
8 |
9 | For support, comments, questions, etc please join the WiringPi Discord
10 | channel: https://discord.gg/SM4WUVG
11 |
12 | WiringPi for Python
13 | ~~~~~~~~~~~~~~~~~~~
14 |
15 | WiringPi: An implementation of most of the Arduino Wiring functions for
16 | the Raspberry Pi.
17 |
18 | WiringPi implements new functions for managing IO expanders.
19 |
20 | **Alternative**
21 |
22 | * `GPIO Zero `_ is another Python library for controlling GPIO. It is installed by default in Raspberry Pi OS and is used in the `Raspberry Pi GPIO documentation `_.
23 |
24 | Quick Install
25 | =============
26 |
27 | .. image:: https://badge.fury.io/py/wiringpi.svg
28 | :alt: PyPI version badge
29 | :target: https://pypi.org/project/wiringpi/
30 |
31 | The library is packaged on PyPI and can be installed with pip:
32 |
33 | ``pip install wiringpi``
34 |
35 | Usage
36 | =====
37 |
38 | .. code:: python
39 |
40 | import wiringpi
41 |
42 | # One of the following MUST be called before using IO functions:
43 | wiringpi.wiringPiSetup() # For sequential pin numbering
44 | # OR
45 | wiringpi.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering
46 | # OR
47 | wiringpi.wiringPiSetupGpio() # For GPIO pin numbering
48 |
49 | **General IO:**
50 |
51 | .. code:: python
52 |
53 | wiringpi.pinMode(6, 1) # Set pin 6 to 1 ( OUTPUT )
54 | wiringpi.digitalWrite(6, 1) # Write 1 ( HIGH ) to pin 6
55 | wiringpi.digitalRead(6) # Read pin 6
56 |
57 | **Setting up a peripheral:**
58 |
59 | WiringPi supports expanding your range of available "pins" by setting up
60 | a port expander. The implementation details of your port expander will
61 | be handled transparently, and you can write to the additional pins
62 | (starting from PIN\_OFFSET >= 64) as if they were normal pins on the Pi.
63 |
64 | .. code:: python
65 |
66 | wiringpi.mcp23017Setup(PIN_OFFSET, I2C_ADDR)
67 |
68 | This example was tested on a quick2wire board with one digital IO
69 | expansion board connected via I2C:
70 |
71 | .. code:: python
72 |
73 | wiringpi.mcp23017Setup(65, 0x20)
74 | wiringpi.pinMode(65, 1)
75 | wiringpi.digitalWrite(65, 1)
76 |
77 | **Soft Tone:**
78 |
79 | Hook a speaker up to your Pi and generate music with softTone. Also
80 | useful for generating frequencies for other uses such as modulating A/C.
81 |
82 | .. code:: python
83 |
84 | wiringpi.softToneCreate(PIN)
85 | wiringpi.softToneWrite(PIN, FREQUENCY)
86 |
87 | **Bit shifting:**
88 |
89 | .. code:: python
90 |
91 | wiringpi.shiftOut(1, 2, 0, 123) # Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2
92 |
93 | **Serial:**
94 |
95 | .. code:: python
96 |
97 | serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600) # Requires device/baud and returns an ID
98 | wiringpi.serialPuts(serial, "hello")
99 | wiringpi.serialClose(serial) # Pass in ID
100 |
101 | **SPI:**
102 |
103 | The ``wiringPiSPIDataRW()`` function needs to be passed a ``bytes``
104 | object in Python 3. In Python 2, it takes a string. The following should
105 | work in either Python 2 or 3:
106 |
107 | .. code:: python
108 |
109 | wiringpi.wiringPiSPISetup(channel, speed)
110 | buf = bytes([your data here])
111 | retlen, retdata = wiringpi.wiringPiSPIDataRW(0, buf)
112 |
113 | Now, ``retlen`` will contain the number of bytes received/read by the
114 | call. ``retdata`` will contain the data itself, and in Python 3, ``buf``
115 | will have been modified to contain it as well (that won't happen in
116 | Python 2, because then ``buf`` is a string, and strings are immutable).
117 |
118 | **Full details of the API at:** http://www.wiringpi.com
119 |
120 | Manual Build
121 | ============
122 |
123 | Get/setup repo
124 | --------------
125 |
126 | .. code:: bash
127 |
128 | git clone --recursive https://github.com/WiringPi/WiringPi-Python.git
129 | cd WiringPi-Python
130 |
131 | Don't forget the ``--recursive``; it is required to also pull in the
132 | WiringPi C code from its own repository.
133 |
134 | Prerequisites
135 | -------------
136 |
137 | To rebuild the bindings you **must** first have installed ``swig``,
138 | ``python-dev``, and ``python-setuptools`` (or their ``python3-``
139 | equivalents). WiringPi should also be installed system-wide for access
140 | to the ``gpio`` tool.
141 |
142 | .. code:: bash
143 |
144 | sudo apt-get install python-dev python-setuptools swig wiringpi
145 |
146 | Build & install with
147 | --------------------
148 |
149 | ``sudo python setup.py install``
150 |
151 | Or Python 3:
152 |
153 | ``sudo python3 setup.py install``
154 |
155 |
--------------------------------------------------------------------------------
/_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 |
--------------------------------------------------------------------------------
/_wiringpi2/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include README.txt
2 | include LICENSE.txt
3 |
--------------------------------------------------------------------------------
/_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 |
--------------------------------------------------------------------------------
/_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 |
--------------------------------------------------------------------------------
/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 void wiringPiVersion (int *major, int *minor) ;
8 | extern int wiringPiSetup (void) ;
9 | extern int wiringPiSetupSys (void) ;
10 | extern int wiringPiSetupGpio (void) ;
11 | extern int wiringPiSetupPhys (void) ;
12 | extern void pinModeAlt (int pin, int mode) ;
13 | extern void pinMode (int pin, int mode) ;
14 | extern void pullUpDnControl (int pin, int pud) ;
15 | extern int digitalRead (int pin) ;
16 | extern void digitalWrite (int pin, int value) ;
17 | extern void pwmWrite (int pin, int value) ;
18 | extern int analogRead (int pin) ;
19 | extern void analogWrite (int pin, int value) ;
20 | extern int piGpioLayout (void) ;
21 | extern int piBoardRev (void) ; // Deprecated
22 | extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
23 | extern int wpiPinToGpio (int wpiPin) ;
24 | extern int physPinToGpio (int physPin) ;
25 | extern void setPadDrive (int group, int value) ;
26 | extern int getAlt (int pin) ;
27 | extern void pwmToneWrite (int pin, int freq) ;
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 unsigned int digitalReadByte (void) ;
33 | extern unsigned int digitalReadByte2 (void) ;
34 | extern void digitalWriteByte (int value) ;
35 | extern void digitalWriteByte2 (int value) ;
36 | extern int waitForInterrupt (int pin, int mS) ;
37 | extern int piThreadCreate (void *(*fn)(void *)) ;
38 | extern void piLock (int key) ;
39 | extern void piUnlock (int key) ;
40 | extern int piHiPri (const int pri) ;
41 | extern void delay (unsigned int howLong) ;
42 | extern void delayMicroseconds (unsigned int howLong) ;
43 | extern unsigned int millis (void) ;
44 | extern unsigned int micros (void) ;
45 |
46 | // Header file WiringPi/wiringPi/wiringPiI2C.h
47 | extern int wiringPiI2CRead (int fd) ;
48 | extern int wiringPiI2CReadReg8 (int fd, int reg) ;
49 | extern int wiringPiI2CReadReg16 (int fd, int reg) ;
50 | extern int wiringPiI2CWrite (int fd, int data) ;
51 | extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
52 | extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
53 | extern int wiringPiI2CSetupInterface (const char *device, int devId) ;
54 | extern int wiringPiI2CSetup (const int devId) ;
55 |
56 | // Header file WiringPi/wiringPi/wiringPiSPI.h
57 | int wiringPiSPIGetFd (int channel) ;
58 | int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
59 | int wiringPiSPISetupMode (int channel, int speed, int mode) ;
60 | int wiringPiSPISetup (int channel, int speed) ;
61 |
62 | // Header file WiringPi/wiringPi/wiringSerial.h
63 | extern int serialOpen (const char *device, const int baud) ;
64 | extern void serialClose (const int fd) ;
65 | extern void serialFlush (const int fd) ;
66 | extern void serialPutchar (const int fd, const unsigned char c) ;
67 | extern void serialPuts (const int fd, const char *s) ;
68 | extern void serialPrintf (const int fd, const char *message, ...) ;
69 | extern int serialDataAvail (const int fd) ;
70 | extern int serialGetchar (const int fd) ;
71 |
72 | // Header file WiringPi/wiringPi/wiringShift.h
73 | extern uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) ;
74 | extern void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ;
75 |
76 | // Header file WiringPi/wiringPi/drcSerial.h
77 | extern int drcSetupSerial (const int pinBase, const int numPins, const char *device, const int baud) ;
78 |
79 | // Header file WiringPi/wiringPi/ads1115.h
80 | extern int ads1115Setup (int pinBase, int i2cAddress) ;
81 |
82 | // Header file WiringPi/wiringPi/max31855.h
83 | extern int max31855Setup (int pinBase, int spiChannel) ;
84 |
85 | // Header file WiringPi/wiringPi/max5322.h
86 | extern int max5322Setup (int pinBase, int spiChannel) ;
87 |
88 | // Header file WiringPi/wiringPi/mcp23008.h
89 | extern int mcp23008Setup (const int pinBase, const int i2cAddress) ;
90 |
91 | // Header file WiringPi/wiringPi/mcp23016.h
92 | extern int mcp23016Setup (const int pinBase, const int i2cAddress) ;
93 |
94 | // Header file WiringPi/wiringPi/mcp23016reg.h
95 |
96 | // Header file WiringPi/wiringPi/mcp23017.h
97 | extern int mcp23017Setup (const int pinBase, const int i2cAddress) ;
98 |
99 | // Header file WiringPi/wiringPi/mcp23s08.h
100 | extern int mcp23s08Setup (const int pinBase, const int spiPort, const int devId) ;
101 |
102 | // Header file WiringPi/wiringPi/mcp23s17.h
103 | extern int mcp23s17Setup (int pinBase, int spiPort, int devId) ;
104 |
105 | // Header file WiringPi/wiringPi/mcp23x0817.h
106 |
107 | // Header file WiringPi/wiringPi/mcp23x08.h
108 |
109 | // Header file WiringPi/wiringPi/mcp3002.h
110 | extern int mcp3002Setup (int pinBase, int spiChannel) ;
111 |
112 | // Header file WiringPi/wiringPi/mcp3004.h
113 | extern int mcp3004Setup (int pinBase, int spiChannel) ;
114 |
115 | // Header file WiringPi/wiringPi/mcp3422.h
116 | extern int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) ;
117 |
118 | // Header file WiringPi/wiringPi/mcp4802.h
119 | extern int mcp4802Setup (int pinBase, int spiChannel) ;
120 |
121 | // Header file WiringPi/wiringPi/pcf8574.h
122 | extern int pcf8574Setup (const int pinBase, const int i2cAddress) ;
123 |
124 | // Header file WiringPi/wiringPi/pcf8591.h
125 | extern int pcf8591Setup (const int pinBase, const int i2cAddress) ;
126 |
127 | // Header file WiringPi/wiringPi/sn3218.h
128 | extern int sn3218Setup (int pinBase) ;
129 |
130 | // Header file WiringPi/wiringPi/softPwm.h
131 | extern int softPwmCreate (int pin, int value, int range) ;
132 | extern void softPwmWrite (int pin, int value) ;
133 | extern void softPwmStop (int pin) ;
134 |
135 | // Header file WiringPi/wiringPi/softServo.h
136 | extern void softServoWrite (int pin, int value) ;
137 | extern int softServoSetup (int p0, int p1, int p2, int p3, int p4, int p5, int p6, int p7) ;
138 |
139 | // Header file WiringPi/wiringPi/softTone.h
140 | extern int softToneCreate (int pin) ;
141 | extern void softToneStop (int pin) ;
142 | extern void softToneWrite (int pin, int freq) ;
143 |
144 | // Header file WiringPi/wiringPi/sr595.h
145 | extern int sr595Setup (const int pinBase, const int numPins,
146 | const int dataPin, const int clockPin, const int latchPin) ;
147 |
148 | // Header file WiringPi/wiringPi/bmp180.h
149 | extern int bmp180Setup (const int pinBase) ;
150 |
151 | // Header file WiringPi/wiringPi/drcNet.h
152 | extern int drcSetupNet (const int pinBase, const int numPins, const char *ipAddress, const char *port, const char *password) ;
153 |
154 | // Header file WiringPi/wiringPi/ds18b20.h
155 | extern int ds18b20Setup (const int pinBase, const char *serialNum) ;
156 |
157 | // Header file WiringPi/wiringPi/htu21d.h
158 | extern int htu21dSetup (const int pinBase) ;
159 |
160 | // Header file WiringPi/wiringPi/pseudoPins.h
161 | extern int pseudoPinsSetup (const int pinBase) ;
162 |
163 | // Header file WiringPi/wiringPi/rht03.h
164 | extern int rht03Setup (const int pinBase, const int devicePin) ;
165 |
166 | // Header file WiringPi/wiringPi/wpiExtensions.h
167 | extern int loadWPiExtension (char *progName, char *extensionData, int verbose) ;
168 |
169 | // Header file WiringPi/devLib/ds1302.h
170 | extern unsigned int ds1302rtcRead (const int reg) ;
171 | extern void ds1302rtcWrite (const int reg, const unsigned int data) ;
172 | extern unsigned int ds1302ramRead (const int addr) ;
173 | extern void ds1302ramWrite (const int addr, const unsigned int data) ;
174 | extern void ds1302clockRead (int clockData [8]) ;
175 | extern void ds1302clockWrite (const int clockData [8]) ;
176 | extern void ds1302trickleCharge (const int diodes, const int resistors) ;
177 | extern void ds1302setup (const int clockPin, const int dataPin, const int csPin) ;
178 |
179 | // Header file WiringPi/devLib/font.h
180 |
181 | // Header file WiringPi/devLib/gertboard.h
182 | extern void gertboardAnalogWrite (const int chan, const int value) ;
183 | extern int gertboardAnalogRead (const int chan) ;
184 | extern int gertboardSPISetup (void) ;
185 | extern int gertboardAnalogSetup (const int pinBase) ;
186 |
187 | // Header file WiringPi/devLib/lcd128x64.h
188 | extern void lcd128x64setOrigin (int x, int y) ;
189 | extern void lcd128x64setOrientation (int orientation) ;
190 | extern void lcd128x64orientCoordinates (int *x, int *y) ;
191 | extern void lcd128x64getScreenSize (int *x, int *y) ;
192 | extern void lcd128x64point (int x, int y, int colour) ;
193 | extern void lcd128x64line (int x0, int y0, int x1, int y1, int colour) ;
194 | extern void lcd128x64lineTo (int x, int y, int colour) ;
195 | extern void lcd128x64rectangle (int x1, int y1, int x2, int y2, int colour, int filled) ;
196 | extern void lcd128x64circle (int x, int y, int r, int colour, int filled) ;
197 | extern void lcd128x64ellipse (int cx, int cy, int xRadius, int yRadius, int colour, int filled) ;
198 | extern void lcd128x64putchar (int x, int y, int c, int bgCol, int fgCol) ;
199 | extern void lcd128x64puts (int x, int y, const char *str, int bgCol, int fgCol) ;
200 | extern void lcd128x64update (void) ;
201 | extern void lcd128x64clear (int colour) ;
202 | extern int lcd128x64setup (void) ;
203 |
204 | // Header file WiringPi/devLib/lcd.h
205 | extern void lcdHome (const int fd) ;
206 | extern void lcdClear (const int fd) ;
207 | extern void lcdDisplay (const int fd, int state) ;
208 | extern void lcdCursor (const int fd, int state) ;
209 | extern void lcdCursorBlink (const int fd, int state) ;
210 | extern void lcdSendCommand (const int fd, unsigned char command) ;
211 | extern void lcdPosition (const int fd, int x, int y) ;
212 | extern void lcdCharDef (const int fd, int index, unsigned char data [8]) ;
213 | extern void lcdPutchar (const int fd, unsigned char data) ;
214 | extern void lcdPuts (const int fd, const char *string) ;
215 | extern void lcdPrintf (const int fd, const char *message, ...) ;
216 | extern int lcdInit (const int rows, const int cols, const int bits,
217 | const int rs, const int strb,
218 | const int d0, const int d1, const int d2, const int d3, const int d4,
219 | const int d5, const int d6, const int d7) ;
220 |
221 | // Header file WiringPi/devLib/maxdetect.h
222 | int maxDetectRead (const int pin, unsigned char buffer [4]) ;
223 | int readRHT03 (const int pin, int *temp, int *rh) ;
224 |
225 | // Header file WiringPi/devLib/piGlow.h
226 | extern void piGlow1 (const int leg, const int ring, const int intensity) ;
227 | extern void piGlowLeg (const int leg, const int intensity) ;
228 | extern void piGlowRing (const int ring, const int intensity) ;
229 | extern void piGlowSetup (int clear) ;
230 |
231 | // Header file WiringPi/devLib/piNes.h
232 | extern int setupNesJoystick (int dPin, int cPin, int lPin) ;
233 | extern unsigned int readNesJoystick (int joystick) ;
234 |
235 | // Header file WiringPi/devLib/scrollPhat.h
236 | extern void scrollPhatPoint (int x, int y, int colour) ;
237 | extern void scrollPhatLine (int x0, int y0, int x1, int y1, int colour) ;
238 | extern void scrollPhatLineTo (int x, int y, int colour) ;
239 | extern void scrollPhatRectangle (int x1, int y1, int x2, int y2, int colour, int filled) ;
240 | extern void scrollPhatUpdate (void) ;
241 | extern void scrollPhatClear (void) ;
242 | extern int scrollPhatPutchar (int c) ;
243 | extern void scrollPhatPuts (const char *str) ;
244 | extern void scrollPhatPrintf (const char *message, ...) ;
245 | extern void scrollPhatPrintSpeed (const int cps10) ;
246 | extern void scrollPhatIntensity (const int percent) ;
247 | extern int scrollPhatSetup (void) ;
248 |
249 | // Header file WiringPi/devLib/piFace.h
250 | extern int piFaceSetup (const int pinBase) ;
251 |
--------------------------------------------------------------------------------
/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 | # Shifting (from wiringShift.h)
43 |
44 | LSBFIRST = 0;
45 | MSBFIRST = 1;
46 |
47 | %}
48 |
--------------------------------------------------------------------------------
/examples/RUN_THESE_WITH_SUDO:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WiringPi/WiringPi-Python/6d3c9e704e60bac837aecec2c8db95b0cd0f57d0/examples/RUN_THESE_WITH_SUDO
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/examples/softtone.py:
--------------------------------------------------------------------------------
1 | # Test of the softTone module in wiringPi
2 | # Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v
3 | import wiringpi
4 |
5 | PIN = 3
6 |
7 | SCALE = [262, 294, 330, 349, 392, 440, 494, 525]
8 |
9 | wiringpi.wiringPiSetup()
10 | wiringpi.softToneCreate(PIN)
11 |
12 | while True:
13 | for idx in range(8):
14 | print(idx)
15 | wiringpi.softToneWrite(PIN, SCALE[idx])
16 | wiringpi.delay(500)
17 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [metadata]
2 | author = Philip Howard
3 | author_email = phil@gadgetoid.com
4 | url = https://github.com/WiringPi/WiringPi-Python/
5 | description = A python interface to WiringPi 2.0 library which allows for easily interfacing with the GPIO pins of the Raspberry Pi. Also supports i2c and SPI.
6 | long_description = file:README.rst
7 | license = LGPL
8 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import os
4 | import sys
5 |
6 | from setuptools import setup, Extension
7 | from setuptools.command.build_py import build_py
8 | from setuptools.command.sdist import sdist
9 | from distutils.spawn import find_executable
10 | from glob import glob
11 |
12 | sources = glob('WiringPi/devLib/*.c')
13 | sources += glob('WiringPi/wiringPi/*.c')
14 | # If we have swig, use it. Otherwise, use the pre-generated
15 | # wrapper from the source distribution.
16 | if find_executable('swig'):
17 | sources += ['wiringpi.i']
18 | elif os.path.exists('wiringpi_wrap.c'):
19 | sources += ['wiringpi_wrap.c']
20 | else:
21 | print("Error: Building this module requires either that swig is installed\n"
22 | " (e.g., 'sudo apt install swig') or that wiringpi_wrap.c from the\n"
23 | " source distribution (on pypi) is available.")
24 | sys.exit(1)
25 |
26 | try:
27 | sources.remove('WiringPi/devLib/piFaceOld.c')
28 | except ValueError:
29 | # the file is already excluded in the source distribution
30 | pass
31 |
32 |
33 | # Fix so that build_ext runs before build_py
34 | # Without this, wiringpi.py is generated too late and doesn't
35 | # end up in the distribution when running setup.py bdist or bdist_wheel.
36 | # Based on:
37 | # https://stackoverflow.com/a/29551581/7938656
38 | # and
39 | # https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/
40 | class build_py_ext_first(build_py):
41 | def run(self):
42 | self.run_command("build_ext")
43 | return build_py.run(self)
44 |
45 |
46 | # Make sure wiringpi_wrap.c is available for the source dist, also.
47 | class sdist_ext_first(sdist):
48 | def run(self):
49 | self.run_command("build_ext")
50 | return sdist.run(self)
51 |
52 |
53 | _wiringpi = Extension(
54 | '_wiringpi',
55 | include_dirs=['WiringPi/wiringPi','WiringPi/devLib'],
56 | sources=sources,
57 | swig_opts=['-threads'],
58 | extra_link_args=['-lcrypt', '-lrt']
59 | )
60 |
61 | setup(
62 | name = 'wiringpi',
63 | version = '2.60.1',
64 | ext_modules = [ _wiringpi ],
65 | py_modules = ["wiringpi"],
66 | install_requires=[],
67 | cmdclass = {'build_py' : build_py_ext_first, 'sdist' : sdist_ext_first},
68 | )
69 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 softPwmWrite(*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 |
--------------------------------------------------------------------------------
/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/ads1115.h"
16 | #include "WiringPi/wiringPi/max31855.h"
17 | #include "WiringPi/wiringPi/max5322.h"
18 | #include "WiringPi/wiringPi/mcp23008.h"
19 | #include "WiringPi/wiringPi/mcp23016.h"
20 | #include "WiringPi/wiringPi/mcp23016reg.h"
21 | #include "WiringPi/wiringPi/mcp23017.h"
22 | #include "WiringPi/wiringPi/mcp23s08.h"
23 | #include "WiringPi/wiringPi/mcp23s17.h"
24 | #include "WiringPi/wiringPi/mcp23x0817.h"
25 | #include "WiringPi/wiringPi/mcp23x08.h"
26 | #include "WiringPi/wiringPi/mcp3002.h"
27 | #include "WiringPi/wiringPi/mcp3004.h"
28 | #include "WiringPi/wiringPi/mcp3422.h"
29 | #include "WiringPi/wiringPi/mcp4802.h"
30 | #include "WiringPi/wiringPi/pcf8574.h"
31 | #include "WiringPi/wiringPi/pcf8591.h"
32 | #include "WiringPi/wiringPi/sn3218.h"
33 | #include "WiringPi/wiringPi/softPwm.h"
34 | #include "WiringPi/wiringPi/softServo.h"
35 | #include "WiringPi/wiringPi/softTone.h"
36 | #include "WiringPi/wiringPi/sr595.h"
37 | #include "WiringPi/wiringPi/bmp180.h"
38 | #include "WiringPi/wiringPi/drcNet.h"
39 | #include "WiringPi/wiringPi/ds18b20.h"
40 | #include "WiringPi/wiringPi/htu21d.h"
41 | #include "WiringPi/wiringPi/pseudoPins.h"
42 | #include "WiringPi/wiringPi/rht03.h"
43 | #include "WiringPi/wiringPi/wpiExtensions.h"
44 | #include "WiringPi/devLib/ds1302.h"
45 | #include "WiringPi/devLib/font.h"
46 | #include "WiringPi/devLib/gertboard.h"
47 | #include "WiringPi/devLib/lcd128x64.h"
48 | #include "WiringPi/devLib/lcd.h"
49 | #include "WiringPi/devLib/maxdetect.h"
50 | #include "WiringPi/devLib/piGlow.h"
51 | #include "WiringPi/devLib/piNes.h"
52 | #include "WiringPi/devLib/scrollPhat.h"
53 | #include "WiringPi/devLib/piFace.h"
54 | %}
55 |
56 | %apply unsigned char { uint8_t };
57 | %typemap(in) (unsigned char *data, int len) {
58 | $1 = (unsigned char *) PyString_AsString($input);
59 | $2 = PyString_Size($input);
60 | };
61 |
62 | // Grab a Python function object as a Python object.
63 | %typemap(in) PyObject *PyFunc {
64 | if (!PyCallable_Check($input)) {
65 | PyErr_SetString(PyExc_TypeError, "Need a callable object!");
66 | return NULL;
67 | }
68 | $1 = $input;
69 | }
70 |
71 | %{
72 |
73 | // we need to have our own callbacks array
74 | PyObject* event_callback[64] = {0,};
75 |
76 | void _wiringPiISR_callback(int pinNumber) {
77 | PyObject *result;
78 |
79 | if (event_callback[pinNumber]) {
80 | // this will acquire the GIL
81 | SWIG_PYTHON_THREAD_BEGIN_BLOCK;
82 |
83 | result = PyObject_CallFunction(event_callback[pinNumber], NULL);
84 | if (result == NULL && PyErr_Occurred()) {
85 | PyErr_Print();
86 | PyErr_Clear();
87 | }
88 | Py_XDECREF(result);
89 |
90 | // release the GIL
91 | SWIG_PYTHON_THREAD_END_BLOCK;
92 | }
93 | }
94 |
95 |
96 | /* This is embarrasing, WiringPi does not support supplying args to the callback
97 | ... so we have to create callback function for each of the pins :( */
98 | void _wiringPiISR_callback_pin0(void) { _wiringPiISR_callback(0); }
99 | void _wiringPiISR_callback_pin1(void) { _wiringPiISR_callback(1); }
100 | void _wiringPiISR_callback_pin2(void) { _wiringPiISR_callback(2); }
101 | void _wiringPiISR_callback_pin3(void) { _wiringPiISR_callback(3); }
102 | void _wiringPiISR_callback_pin4(void) { _wiringPiISR_callback(4); }
103 | void _wiringPiISR_callback_pin5(void) { _wiringPiISR_callback(5); }
104 | void _wiringPiISR_callback_pin6(void) { _wiringPiISR_callback(6); }
105 | void _wiringPiISR_callback_pin7(void) { _wiringPiISR_callback(7); }
106 | void _wiringPiISR_callback_pin8(void) { _wiringPiISR_callback(8); }
107 | void _wiringPiISR_callback_pin9(void) { _wiringPiISR_callback(9); }
108 | void _wiringPiISR_callback_pin10(void) { _wiringPiISR_callback(10); }
109 | void _wiringPiISR_callback_pin11(void) { _wiringPiISR_callback(11); }
110 | void _wiringPiISR_callback_pin12(void) { _wiringPiISR_callback(12); }
111 | void _wiringPiISR_callback_pin13(void) { _wiringPiISR_callback(13); }
112 | void _wiringPiISR_callback_pin14(void) { _wiringPiISR_callback(14); }
113 | void _wiringPiISR_callback_pin15(void) { _wiringPiISR_callback(15); }
114 | void _wiringPiISR_callback_pin16(void) { _wiringPiISR_callback(16); }
115 | void _wiringPiISR_callback_pin17(void) { _wiringPiISR_callback(17); }
116 | void _wiringPiISR_callback_pin18(void) { _wiringPiISR_callback(18); }
117 | void _wiringPiISR_callback_pin19(void) { _wiringPiISR_callback(19); }
118 | void _wiringPiISR_callback_pin20(void) { _wiringPiISR_callback(20); }
119 | void _wiringPiISR_callback_pin21(void) { _wiringPiISR_callback(21); }
120 | void _wiringPiISR_callback_pin22(void) { _wiringPiISR_callback(22); }
121 | void _wiringPiISR_callback_pin23(void) { _wiringPiISR_callback(23); }
122 | void _wiringPiISR_callback_pin24(void) { _wiringPiISR_callback(24); }
123 | void _wiringPiISR_callback_pin25(void) { _wiringPiISR_callback(25); }
124 | void _wiringPiISR_callback_pin26(void) { _wiringPiISR_callback(26); }
125 | void _wiringPiISR_callback_pin27(void) { _wiringPiISR_callback(27); }
126 | void _wiringPiISR_callback_pin28(void) { _wiringPiISR_callback(28); }
127 | void _wiringPiISR_callback_pin29(void) { _wiringPiISR_callback(29); }
128 | void _wiringPiISR_callback_pin30(void) { _wiringPiISR_callback(30); }
129 | void _wiringPiISR_callback_pin31(void) { _wiringPiISR_callback(31); }
130 | void _wiringPiISR_callback_pin32(void) { _wiringPiISR_callback(32); }
131 | void _wiringPiISR_callback_pin33(void) { _wiringPiISR_callback(33); }
132 | void _wiringPiISR_callback_pin34(void) { _wiringPiISR_callback(34); }
133 | void _wiringPiISR_callback_pin35(void) { _wiringPiISR_callback(35); }
134 | void _wiringPiISR_callback_pin36(void) { _wiringPiISR_callback(36); }
135 | void _wiringPiISR_callback_pin37(void) { _wiringPiISR_callback(37); }
136 | void _wiringPiISR_callback_pin38(void) { _wiringPiISR_callback(38); }
137 | void _wiringPiISR_callback_pin39(void) { _wiringPiISR_callback(39); }
138 | void _wiringPiISR_callback_pin40(void) { _wiringPiISR_callback(40); }
139 | void _wiringPiISR_callback_pin41(void) { _wiringPiISR_callback(41); }
140 | void _wiringPiISR_callback_pin42(void) { _wiringPiISR_callback(42); }
141 | void _wiringPiISR_callback_pin43(void) { _wiringPiISR_callback(43); }
142 | void _wiringPiISR_callback_pin44(void) { _wiringPiISR_callback(44); }
143 | void _wiringPiISR_callback_pin45(void) { _wiringPiISR_callback(45); }
144 | void _wiringPiISR_callback_pin46(void) { _wiringPiISR_callback(46); }
145 | void _wiringPiISR_callback_pin47(void) { _wiringPiISR_callback(47); }
146 | void _wiringPiISR_callback_pin48(void) { _wiringPiISR_callback(48); }
147 | void _wiringPiISR_callback_pin49(void) { _wiringPiISR_callback(49); }
148 | void _wiringPiISR_callback_pin50(void) { _wiringPiISR_callback(50); }
149 | void _wiringPiISR_callback_pin51(void) { _wiringPiISR_callback(51); }
150 | void _wiringPiISR_callback_pin52(void) { _wiringPiISR_callback(52); }
151 | void _wiringPiISR_callback_pin53(void) { _wiringPiISR_callback(53); }
152 | void _wiringPiISR_callback_pin54(void) { _wiringPiISR_callback(54); }
153 | void _wiringPiISR_callback_pin55(void) { _wiringPiISR_callback(55); }
154 | void _wiringPiISR_callback_pin56(void) { _wiringPiISR_callback(56); }
155 | void _wiringPiISR_callback_pin57(void) { _wiringPiISR_callback(57); }
156 | void _wiringPiISR_callback_pin58(void) { _wiringPiISR_callback(58); }
157 | void _wiringPiISR_callback_pin59(void) { _wiringPiISR_callback(59); }
158 | void _wiringPiISR_callback_pin60(void) { _wiringPiISR_callback(60); }
159 | void _wiringPiISR_callback_pin61(void) { _wiringPiISR_callback(61); }
160 | void _wiringPiISR_callback_pin62(void) { _wiringPiISR_callback(62); }
161 | void _wiringPiISR_callback_pin63(void) { _wiringPiISR_callback(63); }
162 |
163 | /* This function adds a new Python function object as a callback object */
164 |
165 | static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc) {
166 |
167 | // remove the old callback if any
168 | if (event_callback[pin]) {
169 | Py_XDECREF(event_callback[pin]);
170 | }
171 |
172 | // put new callback function
173 | event_callback[pin] = PyFunc;
174 | Py_INCREF(PyFunc);
175 |
176 | // and now the ugly switch
177 | void (*func)(void);
178 | switch(pin) {
179 | case 0: func = &_wiringPiISR_callback_pin0; break;
180 | case 1: func = &_wiringPiISR_callback_pin1; break;
181 | case 2: func = &_wiringPiISR_callback_pin2; break;
182 | case 3: func = &_wiringPiISR_callback_pin3; break;
183 | case 4: func = &_wiringPiISR_callback_pin4; break;
184 | case 5: func = &_wiringPiISR_callback_pin5; break;
185 | case 6: func = &_wiringPiISR_callback_pin6; break;
186 | case 7: func = &_wiringPiISR_callback_pin7; break;
187 | case 8: func = &_wiringPiISR_callback_pin8; break;
188 | case 9: func = &_wiringPiISR_callback_pin9; break;
189 | case 10: func = &_wiringPiISR_callback_pin10; break;
190 | case 11: func = &_wiringPiISR_callback_pin11; break;
191 | case 12: func = &_wiringPiISR_callback_pin12; break;
192 | case 13: func = &_wiringPiISR_callback_pin13; break;
193 | case 14: func = &_wiringPiISR_callback_pin14; break;
194 | case 15: func = &_wiringPiISR_callback_pin15; break;
195 | case 16: func = &_wiringPiISR_callback_pin16; break;
196 | case 17: func = &_wiringPiISR_callback_pin17; break;
197 | case 18: func = &_wiringPiISR_callback_pin18; break;
198 | case 19: func = &_wiringPiISR_callback_pin19; break;
199 | case 20: func = &_wiringPiISR_callback_pin20; break;
200 | case 21: func = &_wiringPiISR_callback_pin21; break;
201 | case 22: func = &_wiringPiISR_callback_pin22; break;
202 | case 23: func = &_wiringPiISR_callback_pin23; break;
203 | case 24: func = &_wiringPiISR_callback_pin24; break;
204 | case 25: func = &_wiringPiISR_callback_pin25; break;
205 | case 26: func = &_wiringPiISR_callback_pin26; break;
206 | case 27: func = &_wiringPiISR_callback_pin27; break;
207 | case 28: func = &_wiringPiISR_callback_pin28; break;
208 | case 29: func = &_wiringPiISR_callback_pin29; break;
209 | case 30: func = &_wiringPiISR_callback_pin30; break;
210 | case 31: func = &_wiringPiISR_callback_pin31; break;
211 | case 32: func = &_wiringPiISR_callback_pin32; break;
212 | case 33: func = &_wiringPiISR_callback_pin33; break;
213 | case 34: func = &_wiringPiISR_callback_pin34; break;
214 | case 35: func = &_wiringPiISR_callback_pin35; break;
215 | case 36: func = &_wiringPiISR_callback_pin36; break;
216 | case 37: func = &_wiringPiISR_callback_pin37; break;
217 | case 38: func = &_wiringPiISR_callback_pin38; break;
218 | case 39: func = &_wiringPiISR_callback_pin39; break;
219 | case 40: func = &_wiringPiISR_callback_pin40; break;
220 | case 41: func = &_wiringPiISR_callback_pin41; break;
221 | case 42: func = &_wiringPiISR_callback_pin42; break;
222 | case 43: func = &_wiringPiISR_callback_pin43; break;
223 | case 44: func = &_wiringPiISR_callback_pin44; break;
224 | case 45: func = &_wiringPiISR_callback_pin45; break;
225 | case 46: func = &_wiringPiISR_callback_pin46; break;
226 | case 47: func = &_wiringPiISR_callback_pin47; break;
227 | case 48: func = &_wiringPiISR_callback_pin48; break;
228 | case 49: func = &_wiringPiISR_callback_pin49; break;
229 | case 50: func = &_wiringPiISR_callback_pin50; break;
230 | case 51: func = &_wiringPiISR_callback_pin51; break;
231 | case 52: func = &_wiringPiISR_callback_pin52; break;
232 | case 53: func = &_wiringPiISR_callback_pin53; break;
233 | case 54: func = &_wiringPiISR_callback_pin54; break;
234 | case 55: func = &_wiringPiISR_callback_pin55; break;
235 | case 56: func = &_wiringPiISR_callback_pin56; break;
236 | case 57: func = &_wiringPiISR_callback_pin57; break;
237 | case 58: func = &_wiringPiISR_callback_pin58; break;
238 | case 59: func = &_wiringPiISR_callback_pin59; break;
239 | case 60: func = &_wiringPiISR_callback_pin60; break;
240 | case 61: func = &_wiringPiISR_callback_pin61; break;
241 | case 62: func = &_wiringPiISR_callback_pin62; break;
242 | case 63: func = &_wiringPiISR_callback_pin63; break;
243 | }
244 |
245 | // register our dedicated function in WiringPi
246 | wiringPiISR(pin, mode, func);
247 | }
248 |
249 | %}
250 |
251 | // overlay normal function with our wrapper
252 | %rename("wiringPiISR") wiringPiISRWrapper (int pin, int mode, PyObject *PyFunc);
253 | static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc);
254 |
255 | %typemap(in) unsigned char data [8] {
256 | /* Check if is a list */
257 | if (PyList_Check($input)) {
258 | if(PyList_Size($input) != 8){
259 | PyErr_SetString(PyExc_TypeError,"must contain 8 items");
260 | return NULL;
261 | }
262 | int i = 0;
263 | $1 = (unsigned char *) malloc(8);
264 | for (i = 0; i < 8; i++) {
265 | PyObject *o = PyList_GetItem($input,i);
266 | if (PyInt_Check(o) && PyInt_AsLong(PyList_GetItem($input,i)) <= 255 && PyInt_AsLong(PyList_GetItem($input,i)) >= 0)
267 | $1[i] = PyInt_AsLong(PyList_GetItem($input,i));
268 | else {
269 | PyErr_SetString(PyExc_TypeError,"list must contain integers 0-255");
270 | return NULL;
271 | }
272 | }
273 | } else {
274 | PyErr_SetString(PyExc_TypeError,"not a list");
275 | return NULL;
276 | }
277 | };
278 |
279 | %typemap(freearg) unsigned char data [8] {
280 | free((unsigned char *) $1);
281 | }
282 |
283 | %typemap(in) (unsigned char *data, int len) {
284 | $1 = (unsigned char *) PyString_AsString($input);
285 | $2 = PyString_Size($input);
286 | };
287 |
288 | %typemap(argout) (unsigned char *data) {
289 | $result = SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char *) $1, result));
290 | };
291 |
292 | %include "bindings.i"
293 | %include "constants.py"
294 | %include "wiringpi-class.py"
295 |
--------------------------------------------------------------------------------