New build
This commit is contained in:
commit
1a7244f81e
14
CHANGES.txt
Normal file
14
CHANGES.txt
Normal file
@ -0,0 +1,14 @@
|
||||
v1.0.0 -- Branched from original WiringPi to deliver new WiringPi 2 functionality
|
||||
v1.0.1 -- Fixed build problems involving missing header files
|
||||
v1.0.2 -- Fixed build issue with piNes.c
|
||||
v1.0.3 -- Fixed bug in physical pin assignment mode
|
||||
v1.0.4 -- Added class wrapper, plus analogRead/Write functions
|
||||
v1.0.5 -- Second attempt at pretty Pypi page
|
||||
v1.0.6 -- Fixed spelling error in softToneCreate - Thanks oevsegneev
|
||||
v1.0.7 -- Added LCD functionality
|
||||
v1.0.8 -- Updated manifest to include .rst and fix build error
|
||||
v1.0.9 -- Erroneous non-fix due to stupidity
|
||||
v1.0.10 -- Added I2CSetup and new I2C class
|
||||
v1.1.0 -- Synced to WiringPi as of 8th March 2015
|
||||
v1.1.1 -- Included devLib folder for headers
|
||||
v1.2.1 -- Synced to WIringPi as of 27th February 2016
|
||||
165
LICENSE.txt
Normal file
165
LICENSE.txt
Normal file
@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
7
MANIFEST.in
Normal file
7
MANIFEST.in
Normal file
@ -0,0 +1,7 @@
|
||||
graft wiringOP/wiringPi
|
||||
graft wiringOP/devLib
|
||||
include README.rst
|
||||
include LICENSE.txt
|
||||
include setup.cfg
|
||||
include wiringpi.py
|
||||
include wiringpi_wrap.c
|
||||
15
Makefile
Normal file
15
Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
all: bindings
|
||||
python3 setup.py build
|
||||
|
||||
bindings:
|
||||
python3 generate-bindings.py > bindings.i
|
||||
|
||||
clean:
|
||||
rm -rf build dist wiringpi.egg-info
|
||||
rm -rf wiringpi.py wiringpi_wrap.c
|
||||
|
||||
install: bindings
|
||||
sudo python3 setup.py install
|
||||
|
||||
test:
|
||||
pytest tests
|
||||
64
README.rst
Normal file
64
README.rst
Normal file
@ -0,0 +1,64 @@
|
||||
Note
|
||||
~~~~
|
||||
|
||||
wiringOP for Python
|
||||
===================
|
||||
|
||||
wiringOP: An implementation of most of the Arduino Wiring functions for
|
||||
the Orange Pi.
|
||||
|
||||
Supported boards
|
||||
===================
|
||||
tested on:
|
||||
``Orange Pi Zero2``
|
||||
``Orange Pi 3 LTS``
|
||||
``Orange Pi 4 LTS``
|
||||
|
||||
Manual Build
|
||||
============
|
||||
|
||||
Get/setup repo
|
||||
--------------
|
||||
|
||||
.. code:: bash
|
||||
|
||||
git clone --recursive https://github.com/orangepi-xunlong/wiringOP-Python.git
|
||||
cd wiringOP-Python
|
||||
|
||||
Don't forget the --recursive; it is required to also pull in the WiringPi C code from its own repository.
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
To rebuild the bindings you **must** first have installed ``swig``,
|
||||
``python3-dev``, and ``python3-setuptools``. wiringOP should also be installed system-wide for access
|
||||
to the ``gpio`` tool.
|
||||
|
||||
.. code:: bash
|
||||
|
||||
sudo apt-get install swig python3-dev python3-setuptools
|
||||
|
||||
Build & install with
|
||||
--------------------
|
||||
|
||||
``python3 generate-bindings.py > bindings.i``
|
||||
|
||||
``sudo python3 setup.py install``
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
.. code:: python
|
||||
|
||||
import wiringpi
|
||||
|
||||
# One of the following MUST be called before using IO functions:
|
||||
wiringpi.wiringPiSetup() # For sequential pin numbering
|
||||
|
||||
**General IO:**
|
||||
|
||||
.. code:: python
|
||||
|
||||
wiringpi.pinMode(6, 1) # Set pin 6 to 1 ( OUTPUT )
|
||||
wiringpi.digitalWrite(6, 1) # Write 1 ( HIGH ) to pin 6
|
||||
wiringpi.digitalRead(6) # Read pin 6
|
||||
47
constants.py
Normal file
47
constants.py
Normal file
@ -0,0 +1,47 @@
|
||||
%pythoncode %{
|
||||
# wiringPi modes
|
||||
|
||||
WPI_MODE_PINS = 0;
|
||||
WPI_MODE_GPIO = 1;
|
||||
WPI_MODE_GPIO_SYS = 2;
|
||||
WPI_MODE_PHYS = 3;
|
||||
WPI_MODE_PIFACE = 4;
|
||||
WPI_MODE_UNINITIALISED = -1;
|
||||
|
||||
# Pin modes
|
||||
|
||||
INPUT = 0;
|
||||
OUTPUT = 1;
|
||||
PWM_OUTPUT = 2;
|
||||
GPIO_CLOCK = 3;
|
||||
SOFT_PWM_OUTPUT = 4;
|
||||
SOFT_TONE_OUTPUT = 5;
|
||||
PWM_TONE_OUTPUT = 6;
|
||||
|
||||
LOW = 0;
|
||||
HIGH = 1;
|
||||
|
||||
# Pull up/down/none
|
||||
|
||||
PUD_OFF = 0;
|
||||
PUD_DOWN = 1;
|
||||
PUD_UP = 2;
|
||||
|
||||
# PWM
|
||||
|
||||
PWM_MODE_MS = 0;
|
||||
PWM_MODE_BAL = 1;
|
||||
|
||||
# Interrupt levels
|
||||
|
||||
INT_EDGE_SETUP = 0;
|
||||
INT_EDGE_FALLING = 1;
|
||||
INT_EDGE_RISING = 2;
|
||||
INT_EDGE_BOTH = 3;
|
||||
|
||||
# Shifting (from wiringShift.h)
|
||||
|
||||
LSBFIRST = 0;
|
||||
MSBFIRST = 1;
|
||||
|
||||
%}
|
||||
0
examples/RUN_THESE_WITH_SUDO
Normal file
0
examples/RUN_THESE_WITH_SUDO
Normal file
22
examples/blink.py
Normal file
22
examples/blink.py
Normal file
@ -0,0 +1,22 @@
|
||||
import wiringpi
|
||||
import time
|
||||
import sys
|
||||
from wiringpi import GPIO
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
NUM = wiringpi.getGpioNum()
|
||||
|
||||
for i in range(0, NUM):
|
||||
wiringpi.pinMode(i, GPIO.OUTPUT) ;
|
||||
|
||||
while True:
|
||||
try:
|
||||
for i in range(0, NUM):
|
||||
wiringpi.digitalWrite(i, GPIO.HIGH)
|
||||
time.sleep(1)
|
||||
for i in range(0, NUM):
|
||||
wiringpi.digitalWrite(i, GPIO.LOW)
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
14
examples/callback.py
Normal file
14
examples/callback.py
Normal file
@ -0,0 +1,14 @@
|
||||
import wiringpi
|
||||
PIN_TO_SENSE = 23
|
||||
|
||||
def gpio_callback():
|
||||
print "GPIO_CALLBACK!"
|
||||
|
||||
wiringpi.wiringPiSetupGpio()
|
||||
wiringpi.pinMode(PIN_TO_SENSE, wiringpi.GPIO.INPUT)
|
||||
wiringpi.pullUpDnControl(PIN_TO_SENSE, wiringpi.GPIO.PUD_UP)
|
||||
|
||||
wiringpi.wiringPiISR(PIN_TO_SENSE, wiringpi.GPIO.INT_EDGE_BOTH, gpio_callback)
|
||||
|
||||
while True:
|
||||
wiringpi.delay(2000)
|
||||
5
examples/delay.py
Normal file
5
examples/delay.py
Normal file
@ -0,0 +1,5 @@
|
||||
# Demonstrates use of Arduino-like delay function
|
||||
import wiringpi
|
||||
print 'Hello World'
|
||||
wiringpi.delay(1500) # Delay for 1.5 seconds
|
||||
print 'Hi again!'
|
||||
133
examples/ds1307.py
Normal file
133
examples/ds1307.py
Normal file
@ -0,0 +1,133 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from datetime import datetime
|
||||
import operator
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='i2c')
|
||||
parser.add_argument("--device", type=str, default="/dev/i2c-0", help='specify the i2c node')
|
||||
args = parser.parse_args()
|
||||
|
||||
i2caddr = 0x68
|
||||
|
||||
def b2s(bcd, mask):
|
||||
bcd &= mask
|
||||
b1 = bcd & 0x0F
|
||||
b2 = ((bcd >> 4) & 0x0F)*10
|
||||
return b1 + b2
|
||||
|
||||
def decCompensation(units):
|
||||
unitsU = units%10
|
||||
if units >= 50:
|
||||
units = 0x50 + unitsU
|
||||
elif units >= 40:
|
||||
units = 0x40 + unitsU
|
||||
elif units >= 30:
|
||||
units = 0x30 + unitsU
|
||||
elif units >= 20:
|
||||
units = 0x20 + unitsU
|
||||
elif units >= 10:
|
||||
units = 0x10 + unitsU
|
||||
return units
|
||||
|
||||
def getHours():
|
||||
HH = time.strftime("%H")
|
||||
return decCompensation(int(HH))
|
||||
|
||||
def getMins():
|
||||
MM = time.strftime("%M")
|
||||
return decCompensation(int(MM))
|
||||
|
||||
def getSecs():
|
||||
SS = time.strftime("%S")
|
||||
return decCompensation(int(SS))
|
||||
|
||||
def getWeeks():
|
||||
WW = time.strftime("%w")
|
||||
return decCompensation(int(WW))
|
||||
|
||||
def getDays():
|
||||
DD = time.strftime("%d")
|
||||
return decCompensation(int(DD))
|
||||
|
||||
def getMons():
|
||||
MON = time.strftime("%m")
|
||||
return decCompensation(int(MON))
|
||||
|
||||
def getYear():
|
||||
YY = time.strftime("%Y")
|
||||
return decCompensation(int(YY))
|
||||
|
||||
def ds1307_write_byte(fd, reg, byte):
|
||||
if wiringpi.wiringPiI2CWriteReg8(fd, reg, byte) < 0:
|
||||
print("Error write byte to ds1307")
|
||||
return -1
|
||||
return 0
|
||||
|
||||
def ds1307_read_byte(fd, reg):
|
||||
byte = wiringpi.wiringPiI2CReadReg8(fd, reg)
|
||||
if byte < 0:
|
||||
print("Error read byte from ds1307")
|
||||
return -1
|
||||
return byte
|
||||
|
||||
def sys2rtcSet(fd):
|
||||
ds1307_write_byte(fd, 0x02, getHours())
|
||||
ds1307_write_byte(fd, 0x01, getMins())
|
||||
ds1307_write_byte(fd, 0x00, getSecs())
|
||||
ds1307_write_byte(fd, 0x03, getWeeks())
|
||||
ds1307_write_byte(fd, 0x04, getDays())
|
||||
ds1307_write_byte(fd, 0x05, getMons())
|
||||
ds1307_write_byte(fd, 0x06, getYear())
|
||||
|
||||
def read_register(fd):
|
||||
byte = ds1307_read_byte(fd, 0x0)
|
||||
if byte >> 7:
|
||||
ds1307_write_byte(fd, 0x0, 0x0)
|
||||
second = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
|
||||
|
||||
byte = ds1307_read_byte(fd, 0x01)
|
||||
minute = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
|
||||
|
||||
byte = ds1307_read_byte(fd, 0x02)
|
||||
hour = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
|
||||
|
||||
week = ds1307_read_byte(fd, 0x03)
|
||||
|
||||
byte = ds1307_read_byte(fd, 0x04)
|
||||
day = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
|
||||
|
||||
byte = ds1307_read_byte(fd, 0x05)
|
||||
month = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10
|
||||
|
||||
byte = ds1307_read_byte(fd, 0x06)
|
||||
year = operator.mod(byte, 16) + operator.floordiv(byte, 16) * 10 + 1970
|
||||
|
||||
if year == 2000 or month > 12 or month<1 or day < 1 or day > 31:
|
||||
return False
|
||||
|
||||
if second > 59:
|
||||
return False
|
||||
return datetime(year,month,day,hour,minute,second)
|
||||
|
||||
def main():
|
||||
wiringpi.wiringPiSetup()
|
||||
fd = wiringpi.wiringPiI2CSetupInterface(args.device, i2caddr)
|
||||
try:
|
||||
sys2rtcSet(fd)
|
||||
while True:
|
||||
time.sleep(1)
|
||||
dt = read_register(fd)
|
||||
if not dt:
|
||||
continue
|
||||
else:
|
||||
str_time = dt.strftime("%a %Y-%m-%d %H:%M:%S")
|
||||
print("%s"%(str_time))
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
27
examples/ladder-board.py
Normal file
27
examples/ladder-board.py
Normal file
@ -0,0 +1,27 @@
|
||||
import wiringpi
|
||||
INPUT = 0
|
||||
OUTPUT = 1
|
||||
LOW = 0
|
||||
HIGH = 1
|
||||
BUTTONS = [13,12,10,11]
|
||||
LEDS = [0,1,2,3,4,5,6,7,8,9]
|
||||
PUD_UP = 2
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
|
||||
for button in BUTTONS:
|
||||
wiringpi.pinMode(button,INPUT)
|
||||
wiringpi.pullUpDnControl(button,PUD_UP)
|
||||
|
||||
for led in LEDS:
|
||||
wiringpi.pinMode(led,OUTPUT)
|
||||
|
||||
while 1:
|
||||
for index,button in enumerate(BUTTONS):
|
||||
button_state = wiringpi.digitalRead(button)
|
||||
first_led = LEDS[index*2]
|
||||
second_led = LEDS[(index*2)+1]
|
||||
#print str(button) + ' ' + str(button_state)
|
||||
wiringpi.digitalWrite(first_led,1-button_state)
|
||||
wiringpi.digitalWrite(second_led,1-button_state)
|
||||
wiringpi.delay(20)
|
||||
95
examples/n5510-mcp23017.py
Normal file
95
examples/n5510-mcp23017.py
Normal file
@ -0,0 +1,95 @@
|
||||
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
|
||||
import wiringpi
|
||||
|
||||
PIN_BACKLIGHT = 67 # LED
|
||||
PIN_SCLK = 68 # Clock SCLK
|
||||
PIN_SDIN = 69 # DN(MOSI)
|
||||
PIN_DC = 70 # D/C
|
||||
PIN_RESET = 71 # RST Reset
|
||||
PIN_SCE = 72 # SCE
|
||||
|
||||
#PIN_BACKLIGHT = 5
|
||||
#PIN_SCLK = 4
|
||||
#PIN_SDIN = 3
|
||||
#PIN_DC = 2
|
||||
#PIN_RESET = 1
|
||||
#PIN_SCE = 0
|
||||
|
||||
OUTPUT = 1
|
||||
INPUT = 0
|
||||
HIGH = 1
|
||||
LOW = 0
|
||||
|
||||
LCD_C = 0
|
||||
LCD_D = 1
|
||||
|
||||
LCD_X = 84
|
||||
LCD_Y = 48
|
||||
LCD_SEGS = 504
|
||||
|
||||
MSBFIRST = 1
|
||||
LSBFIRST = 0
|
||||
|
||||
SLOW_DOWN = 400
|
||||
|
||||
pin_base = 65
|
||||
i2c_addr = 0x21
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.mcp23017Setup(pin_base,i2c_addr)
|
||||
|
||||
def slow_shift_out(data_pin, clock_pin, data):
|
||||
for bit in bin(data).replace('0b','').rjust(8,'0'):
|
||||
wiringpi.digitalWrite(clock_pin,LOW)
|
||||
wiringpi.delay(SLOW_DOWN)
|
||||
wiringpi.digitalWrite(data_pin,int(bit))
|
||||
wiringpi.delay(SLOW_DOWN)
|
||||
wiringpi.digitalWrite(clock_pin,HIGH)
|
||||
wiringpi.delay(SLOW_DOWN)
|
||||
|
||||
def lcd_write(dc, data):
|
||||
wiringpi.digitalWrite(PIN_DC, dc)
|
||||
wiringpi.digitalWrite(PIN_SCE, LOW)
|
||||
wiringpi.delay(SLOW_DOWN)
|
||||
#wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data)
|
||||
slow_shift_out(PIN_SDIN, PIN_SCLK, data)
|
||||
wiringpi.digitalWrite(PIN_SCE, HIGH)
|
||||
wiringpi.delay(SLOW_DOWN)
|
||||
#wiringpi.delay(2)
|
||||
|
||||
def lcd_initialise():
|
||||
wiringpi.pinMode(PIN_BACKLIGHT,OUTPUT)
|
||||
wiringpi.digitalWrite(PIN_BACKLIGHT, HIGH)
|
||||
wiringpi.pinMode(PIN_SCE, OUTPUT)
|
||||
wiringpi.pinMode(PIN_RESET, OUTPUT)
|
||||
wiringpi.pinMode(PIN_DC, OUTPUT)
|
||||
wiringpi.pinMode(PIN_SDIN, OUTPUT)
|
||||
wiringpi.pinMode(PIN_SCLK, OUTPUT)
|
||||
wiringpi.digitalWrite(PIN_RESET, LOW)
|
||||
wiringpi.delay(SLOW_DOWN)
|
||||
wiringpi.digitalWrite(PIN_RESET, HIGH)
|
||||
wiringpi.delay(SLOW_DOWN)
|
||||
lcd_write(LCD_C, 0x21 ) # LCD Extended Commands.
|
||||
lcd_write(LCD_C, 0xCC ) # Set LCD Vop (Contrast).
|
||||
lcd_write(LCD_C, 0x04 ) # Set Temp coefficent. //0x04
|
||||
lcd_write(LCD_C, 0x14 ) # LCD bias mode 1:48. //0x13
|
||||
lcd_write(LCD_C, 0x0C ) # LCD in normal mode.
|
||||
lcd_write(LCD_C, 0x20 )
|
||||
lcd_write(LCD_C, 0x0C )
|
||||
|
||||
def lcd_clear():
|
||||
for time in range(0, LCD_SEGS):
|
||||
lcd_write(LCD_D, 0x00)
|
||||
|
||||
def lcd_fill():
|
||||
for time in range(0, LCD_SEGS):
|
||||
lcd_write(LCD_D, 0xFF)
|
||||
|
||||
|
||||
lcd_initialise()
|
||||
|
||||
for time in range(0,4):
|
||||
lcd_clear()
|
||||
wiringpi.delay(1000)
|
||||
lcd_fill()
|
||||
wiringpi.delay(1000)
|
||||
28
examples/orangepi-sensors/IO-expand.py
Normal file
28
examples/orangepi-sensors/IO-expand.py
Normal file
@ -0,0 +1,28 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x38
|
||||
BASE = 100
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pcf8574Setup(BASE, I2C_ADDR)
|
||||
|
||||
i = 0
|
||||
while i < 8:
|
||||
wiringpi.pinMode(BASE + i, GPIO.OUTPUT)
|
||||
i += 1
|
||||
|
||||
wiringpi.pinMode(BASE + 0, GPIO.OUTPUT)
|
||||
|
||||
while True:
|
||||
try:
|
||||
wiringpi.digitalWrite(BASE + 0, GPIO.HIGH)
|
||||
time.sleep(1)
|
||||
wiringpi.digitalWrite(BASE + 0, GPIO.LOW)
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print('\nExit')
|
||||
sys.exit(0)
|
||||
|
||||
19
examples/orangepi-sensors/Light_Sensor.py
Normal file
19
examples/orangepi-sensors/Light_Sensor.py
Normal file
@ -0,0 +1,19 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x48
|
||||
BASE = 64
|
||||
A0 = BASE+0
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pcf8591Setup(BASE, I2C_ADDR)
|
||||
while True:
|
||||
try:
|
||||
value = wiringpi.analogRead(A0)
|
||||
print("value: %d"%value)
|
||||
time.sleep(2)
|
||||
except KeyboardInterrupt:
|
||||
print('\nExit')
|
||||
sys.exit(0)
|
||||
67
examples/orangepi-sensors/dht11.py
Normal file
67
examples/orangepi-sensors/dht11.py
Normal file
@ -0,0 +1,67 @@
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
pin = 6
|
||||
|
||||
def getval(pin):
|
||||
tl=[]
|
||||
tb=[]
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(pin, GPIO.OUTPUT)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.delay(1)
|
||||
wiringpi.digitalWrite(pin, GPIO.LOW)
|
||||
wiringpi.delay(25)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.delayMicroseconds(20)
|
||||
wiringpi.pinMode(pin, GPIO.INPUT)
|
||||
while(wiringpi.digitalRead(pin)==1): pass
|
||||
|
||||
for i in range(45):
|
||||
tc=wiringpi.micros()
|
||||
'''
|
||||
'''
|
||||
while(wiringpi.digitalRead(pin)==0): pass
|
||||
while(wiringpi.digitalRead(pin)==1):
|
||||
if wiringpi.micros()-tc>500:
|
||||
break
|
||||
if wiringpi.micros()-tc>500:
|
||||
break
|
||||
tl.append(wiringpi.micros()-tc)
|
||||
|
||||
tl=tl[1:]
|
||||
for i in tl:
|
||||
if i>100:
|
||||
tb.append(1)
|
||||
else:
|
||||
tb.append(0)
|
||||
|
||||
return tb
|
||||
|
||||
def GetResult(pin):
|
||||
for i in range(10):
|
||||
SH=0;SL=0;TH=0;TL=0;C=0
|
||||
result=getval(pin)
|
||||
|
||||
if len(result)==40:
|
||||
for i in range(8):
|
||||
SH*=2;SH+=result[i] # humi Integer
|
||||
SL*=2;SL+=result[i+8] # humi decimal
|
||||
TH*=2;TH+=result[i+16] # temp Integer
|
||||
TL*=2;TL+=result[i+24] # temp decimal
|
||||
C*=2;C+=result[i+32] # Checksum
|
||||
if ((SH+SL+TH+TL)%256)==C and C!=0:
|
||||
break
|
||||
else:
|
||||
print("Read Sucess,But checksum error! retrying")
|
||||
|
||||
else:
|
||||
print("Read failer! Retrying")
|
||||
break
|
||||
wiringpi.delay(200)
|
||||
return SH,SL,TH,TL
|
||||
|
||||
SH,SL,TH,TL=GetResult(pin)
|
||||
print("humi:",SH,SL,"temp:",TH,TL)
|
||||
|
||||
|
||||
88
examples/orangepi-sensors/ds18b20.py
Normal file
88
examples/orangepi-sensors/ds18b20.py
Normal file
@ -0,0 +1,88 @@
|
||||
#import sys
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
PIN = 6
|
||||
|
||||
def oneWireReset(pin):
|
||||
wiringpi.pinMode(pin, GPIO.OUTPUT)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.digitalWrite(pin, GPIO.LOW)
|
||||
wiringpi.delayMicroseconds(500)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.delayMicroseconds(60)
|
||||
wiringpi.pinMode(pin, GPIO.INPUT)
|
||||
if not wiringpi.digitalRead(pin):
|
||||
ack = 1
|
||||
else:
|
||||
ack = 0
|
||||
wiringpi.delayMicroseconds(500)
|
||||
return ack
|
||||
|
||||
def writeBit(pin, bit):
|
||||
wiringpi.pinMode(pin, GPIO.OUTPUT)
|
||||
wiringpi.digitalWrite(pin, GPIO.LOW)
|
||||
wiringpi.delayMicroseconds(2)
|
||||
wiringpi.digitalWrite(pin, bit)
|
||||
wiringpi.delayMicroseconds(80)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.delayMicroseconds(1)
|
||||
|
||||
def oneWireSendComm(pin, byte):
|
||||
i = 0
|
||||
while i < 8:
|
||||
sta = byte & 0x01
|
||||
writeBit(pin, sta)
|
||||
byte >>= 1
|
||||
i += 1
|
||||
|
||||
def readBit(pin):
|
||||
wiringpi.pinMode(pin, GPIO.OUTPUT)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.digitalWrite(pin, GPIO.LOW)
|
||||
wiringpi.delayMicroseconds(2)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
|
||||
wiringpi.pinMode(pin, GPIO.INPUT)
|
||||
wiringpi.delayMicroseconds(2)
|
||||
|
||||
tmp = wiringpi.digitalRead(pin)
|
||||
wiringpi.delayMicroseconds(40)
|
||||
return tmp
|
||||
|
||||
def oneWireReceive(pin):
|
||||
i = 0
|
||||
k = 0
|
||||
while i < 8:
|
||||
j = readBit(pin)
|
||||
k = (j << 7) | (k >> 1)
|
||||
i += 1
|
||||
k = k & 0x00FF
|
||||
return k
|
||||
|
||||
def tempchange(lsb, msb):
|
||||
if (msb >= 0xF0):
|
||||
msb = 255 - msb
|
||||
lsb = 256 - lsb
|
||||
tem = -(msb*16*16 + lsb)
|
||||
else:
|
||||
tem = (msb*16*16 + lsb)
|
||||
temp = tem*0.0625
|
||||
print("Current Temp: %.2f"%(temp))
|
||||
|
||||
def main():
|
||||
wiringpi.wiringPiSetup()
|
||||
if oneWireReset(PIN):
|
||||
oneWireSendComm(PIN, 0xcc)
|
||||
oneWireSendComm(PIN, 0x44)
|
||||
if oneWireReset(PIN):
|
||||
oneWireSendComm(PIN, 0xcc)
|
||||
oneWireSendComm(PIN, 0xbe)
|
||||
lsb = oneWireReceive(PIN)
|
||||
msb = oneWireReceive(PIN)
|
||||
tempchange(lsb, msb)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
27
examples/orangepi-sensors/joystick.py
Normal file
27
examples/orangepi-sensors/joystick.py
Normal file
@ -0,0 +1,27 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x48
|
||||
BASE = 64
|
||||
A0 = BASE+0
|
||||
A1 = BASE+1
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pcf8591Setup(BASE, I2C_ADDR)
|
||||
|
||||
while True:
|
||||
try:
|
||||
i = 0
|
||||
while i < 2:
|
||||
if 0 == i:
|
||||
x = wiringpi.analogRead(A0)
|
||||
if 1 == i:
|
||||
y = wiringpi.analogRead(A1)
|
||||
i += 1
|
||||
print("X=%d Y=%d"%(x,y))
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print('\nExit')
|
||||
sys.exit(0)
|
||||
22
examples/orangepi-sensors/light.py
Normal file
22
examples/orangepi-sensors/light.py
Normal file
@ -0,0 +1,22 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
PIN = 6
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(PIN, GPIO.OUTPUT)
|
||||
|
||||
while True:
|
||||
try:
|
||||
wiringpi.digitalWrite(PIN, GPIO.HIGH)
|
||||
print(wiringpi.digitalRead(PIN))
|
||||
time.sleep(1)
|
||||
wiringpi.digitalWrite(PIN, GPIO.LOW)
|
||||
print(wiringpi.digitalRead(PIN))
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
320
examples/orangepi-sensors/oled_ssd1306.py
Normal file
320
examples/orangepi-sensors/oled_ssd1306.py
Normal file
@ -0,0 +1,320 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x3c
|
||||
fd = 0
|
||||
yi = [' ',' ',' ',' ']
|
||||
zi = [
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//0
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//1
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//2
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//3
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//4
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//5
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//6
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//7
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//8
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//9
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//10
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//11
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//12
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//13
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//14
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//15
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//16
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//17
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//18
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//19
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//20
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//21
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//22
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//23
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//24
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//25
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//26
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//27
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//28
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//29
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//30
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//31
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//32
|
||||
|
||||
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,#//33
|
||||
|
||||
0x00,0x10,0x0C,0x02,0x10,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//34
|
||||
|
||||
0x00,0x40,0xC0,0x78,0x40,0xC0,0x78,0x00,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x00,#//35
|
||||
|
||||
0x00,0x70,0x88,0x88,0xFC,0x08,0x30,0x00,0x00,0x18,0x20,0x20,0xFF,0x21,0x1E,0x00,#//36
|
||||
|
||||
0xF0,0x08,0xF0,0x80,0x60,0x18,0x00,0x00,0x00,0x31,0x0C,0x03,0x1E,0x21,0x1E,0x00,#//37
|
||||
|
||||
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x2C,0x19,0x27,0x21,0x10,#//38
|
||||
|
||||
0x00,0x12,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//39
|
||||
|
||||
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,#//40
|
||||
|
||||
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,#//41
|
||||
|
||||
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,#//42
|
||||
|
||||
0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x0F,0x01,0x01,0x01,#//43
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x70,0x00,0x00,0x00,0x00,0x00,#//44
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,#//45
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,#//46
|
||||
|
||||
0x00,0x00,0x00,0x00,0xC0,0x38,0x04,0x00,0x00,0x60,0x18,0x07,0x00,0x00,0x00,0x00,#//47
|
||||
|
||||
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,#//48
|
||||
|
||||
0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,#//49
|
||||
|
||||
0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,#//50
|
||||
|
||||
0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00,#//51
|
||||
|
||||
0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24,#//52
|
||||
|
||||
0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00,#//53
|
||||
|
||||
0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00,#//54
|
||||
|
||||
0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00,#//55
|
||||
|
||||
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,#//56
|
||||
|
||||
0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00,#//57
|
||||
|
||||
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,#//58
|
||||
|
||||
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,#//59
|
||||
|
||||
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,#//60
|
||||
|
||||
0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x00,#//61
|
||||
|
||||
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,#//62
|
||||
|
||||
0x00,0x70,0x48,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x30,0x37,0x00,0x00,0x00,#//63
|
||||
|
||||
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x28,0x2F,0x28,0x17,0x00,#//64
|
||||
|
||||
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,#//65
|
||||
|
||||
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,#//66
|
||||
|
||||
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,#//67
|
||||
|
||||
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,#//68
|
||||
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,#//69
|
||||
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,#//70
|
||||
|
||||
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,#//71
|
||||
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,#//72
|
||||
|
||||
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//73
|
||||
|
||||
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,#//74
|
||||
|
||||
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,#//75
|
||||
|
||||
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,#//76
|
||||
|
||||
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x01,0x3E,0x01,0x3F,0x20,0x00,#//77
|
||||
|
||||
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,#//78
|
||||
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,#//79
|
||||
|
||||
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,#//80
|
||||
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x28,0x28,0x30,0x50,0x4F,0x00,#//81
|
||||
|
||||
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,#//82
|
||||
|
||||
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,#//83
|
||||
|
||||
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#//84
|
||||
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#//85
|
||||
|
||||
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,#//86
|
||||
|
||||
0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00,#//87
|
||||
|
||||
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,#//88
|
||||
|
||||
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#//89
|
||||
|
||||
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,#//90
|
||||
|
||||
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,#//91
|
||||
|
||||
0x00,0x04,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,#//92
|
||||
|
||||
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,#//93
|
||||
|
||||
0x00,0x00,0x04,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//94
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,#//95
|
||||
|
||||
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//96
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00,#//97
|
||||
|
||||
0x10,0xF0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,#//98
|
||||
|
||||
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,#//99
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x90,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,#//100
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x24,0x24,0x24,0x24,0x17,0x00,#//101
|
||||
|
||||
0x00,0x80,0x80,0xE0,0x90,0x90,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//102
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,#//103
|
||||
|
||||
0x10,0xF0,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#//104
|
||||
|
||||
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//105
|
||||
|
||||
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,#//106
|
||||
|
||||
0x10,0xF0,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x06,0x29,0x30,0x20,0x00,#//107
|
||||
|
||||
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//108
|
||||
|
||||
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,#//109
|
||||
|
||||
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#//110
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#//111
|
||||
|
||||
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0x91,0x20,0x20,0x11,0x0E,0x00,#//112
|
||||
|
||||
0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0x91,0xFF,0x80,#//113
|
||||
|
||||
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,#//114
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,#//115
|
||||
|
||||
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x10,0x00,#//116
|
||||
|
||||
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,#//117
|
||||
|
||||
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,#//118
|
||||
|
||||
0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x01,0x0E,0x30,0x0C,0x07,0x38,0x06,0x01,#//119
|
||||
|
||||
0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x20,0x31,0x0E,0x2E,0x31,0x20,0x00,#//120
|
||||
|
||||
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00,#//121
|
||||
|
||||
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,#//122
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x02,0x00,0x00,0x00,0x00,0x01,0x3E,0x40,0x40,#//122
|
||||
|
||||
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,#//124
|
||||
|
||||
0x02,0x02,0xFC,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x3E,0x01,0x00,0x00,0x00,0x00,#//125
|
||||
|
||||
0x00,0x02,0x01,0x02,0x02,0x04,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//126
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//127
|
||||
]
|
||||
|
||||
def full_string(s):
|
||||
while len(s) < 16:
|
||||
s += ' '
|
||||
return s
|
||||
|
||||
def main():
|
||||
#init
|
||||
wiringpi.wiringPiSetup()
|
||||
fd = wiringpi.wiringPiI2CSetup(I2C_ADDR)
|
||||
if not fd:
|
||||
return False;
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa1)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xc8)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x8d)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x14)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa6)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x21)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x00)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x7f)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xaf)
|
||||
|
||||
#clear oled
|
||||
for a in range(8):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0 + a)
|
||||
for b in range(128):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x40, 0x00)
|
||||
|
||||
while True:
|
||||
try:
|
||||
#get time
|
||||
yi[0] = full_string("++++OrangePi++++")
|
||||
#yi[1] = full_string(time.strftime("%m/%d %w"))
|
||||
yi[1] = full_string(time.strftime("%m/%d %a"))
|
||||
yi[2] = full_string(time.strftime("%H:%M"))
|
||||
yi[3] = full_string("SSD1306 I2C OLED")
|
||||
|
||||
#write
|
||||
for zt3 in range(4):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0+(zt3*2))
|
||||
for zt4 in range(16):
|
||||
for zt in range(8):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x40, zi[ord(yi[zt3][zt4])*16+zt])
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0+(zt3*2)+1)
|
||||
for zt4 in range(16):
|
||||
for zt in range(8):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x40, zi[ord(yi[zt3][zt4])*16+zt+8])
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
46
examples/orangepi-sensors/rotary_encoder.py
Normal file
46
examples/orangepi-sensors/rotary_encoder.py
Normal file
@ -0,0 +1,46 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
SIA = 9
|
||||
SIB= 10
|
||||
SW = 6
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(SW, GPIO.INPUT)
|
||||
wiringpi.pinMode(SIA, GPIO.INPUT)
|
||||
wiringpi.pinMode(SIB, GPIO.INPUT)
|
||||
|
||||
flag = 0
|
||||
resetflag = 0
|
||||
globalCount = 0
|
||||
|
||||
while True:
|
||||
try:
|
||||
lastSib = wiringpi.digitalRead(SIB)
|
||||
while not wiringpi.digitalRead(SW):
|
||||
resetflag = 1
|
||||
while not wiringpi.digitalRead(SIA):
|
||||
currentSib = wiringpi.digitalRead(SIB)
|
||||
flag =1
|
||||
|
||||
if resetflag:
|
||||
globalCount = 0
|
||||
resetflag = 0
|
||||
print ('Count reset\ncurrent = 0')
|
||||
continue
|
||||
if flag:
|
||||
if lastSib == 0 and currentSib == 1:
|
||||
print ('Anticlockwise rotation')
|
||||
globalCount += 1
|
||||
if lastSib == 1 and currentSib == 0:
|
||||
print ('clockwise rotation')
|
||||
globalCount -=1
|
||||
|
||||
flag =0
|
||||
print ('current = %s' % globalCount)
|
||||
except KeyboardInterrupt:
|
||||
print('\nExit')
|
||||
sys.exit(0)
|
||||
|
||||
103
examples/orangepi-sensors/rtc.py
Normal file
103
examples/orangepi-sensors/rtc.py
Normal file
@ -0,0 +1,103 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
#from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x68
|
||||
|
||||
def b2s(bcd, mask):
|
||||
bcd &= mask
|
||||
b1 = bcd & 0x0F
|
||||
b2 = ((bcd >> 4) & 0x0F)*10
|
||||
return b1 + b2
|
||||
|
||||
def decCompensation(units):
|
||||
unitsU = units%10
|
||||
if units >= 50:
|
||||
units = 0x50 + unitsU
|
||||
elif units >= 40:
|
||||
units = 0x40 + unitsU
|
||||
elif units >= 30:
|
||||
units = 0x30 + unitsU
|
||||
elif units >= 20:
|
||||
units = 0x20 + unitsU
|
||||
elif units >= 10:
|
||||
units = 0x10 + unitsU
|
||||
return units
|
||||
|
||||
def getHours():
|
||||
HH = time.strftime("%H")
|
||||
return decCompensation(int(HH))
|
||||
|
||||
def getMins():
|
||||
MM = time.strftime("%M")
|
||||
return decCompensation(int(MM))
|
||||
|
||||
def getSecs():
|
||||
SS = time.strftime("%S")
|
||||
return decCompensation(int(SS))
|
||||
|
||||
def getWeeks():
|
||||
WW = time.strftime("%w")
|
||||
return decCompensation(int(WW))
|
||||
|
||||
def getDays():
|
||||
DD = time.strftime("%d")
|
||||
return decCompensation(int(DD))
|
||||
|
||||
def getMons():
|
||||
MON = time.strftime("%m")
|
||||
return decCompensation(int(MON))
|
||||
|
||||
def getYear():
|
||||
YY = time.strftime("%Y")
|
||||
return decCompensation(int(YY))
|
||||
|
||||
def clear_register(fd):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x02, 0b0) # hours
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x01, 0b0) # mins
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0b10000000) # secs
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x03, 0b0) # weeks
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x04, 0b0) # days
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x05, 0b0) # mons
|
||||
|
||||
def sys2rtcSet(fd):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x02, getHours())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x01, getMins())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, getSecs()+0b10000000)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x03, getWeeks())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x04, getDays())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x05, getMons())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x06, getYear())
|
||||
|
||||
def read_register(fd):
|
||||
secs = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x00), 0x7F)
|
||||
mins = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x01), 0x7F)
|
||||
hours = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x02) - 0b10000000, 0x3F)
|
||||
week = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x03), 0x3F)
|
||||
day = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x04), 0x1F)
|
||||
mon = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x05), 0x07)
|
||||
year = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x06), 0xFF) + 1970
|
||||
print("week:%d mon:%d day:%d hours:%d mins:%d secs:%d year:%d"%(week,mon,day,hours,mins,secs,year))
|
||||
|
||||
def main():
|
||||
wiringpi.wiringPiSetup()
|
||||
fd = wiringpi.wiringPiI2CSetup(I2C_ADDR)
|
||||
if not fd:
|
||||
return False;
|
||||
while True:
|
||||
try:
|
||||
# clear RTC Register
|
||||
clear_register(fd)
|
||||
# set sys time to RTC Register
|
||||
sys2rtcSet(fd)
|
||||
# read RTC Register
|
||||
read_register(fd)
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
21
examples/orangepi-sensors/sensor_control_led.py
Normal file
21
examples/orangepi-sensors/sensor_control_led.py
Normal file
@ -0,0 +1,21 @@
|
||||
import sys
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
LED = 6
|
||||
PIN = 16
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(LED, GPIO.OUTPUT)
|
||||
wiringpi.pinMode(PIN, GPIO.INPUT)
|
||||
|
||||
while True:
|
||||
try:
|
||||
if wiringpi.digitalRead(PIN):
|
||||
wiringpi.digitalWrite(LED, GPIO.LOW)
|
||||
else:
|
||||
wiringpi.digitalWrite(LED, GPIO.HIGH)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
15
examples/quick2wire-io.py
Normal file
15
examples/quick2wire-io.py
Normal file
@ -0,0 +1,15 @@
|
||||
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
|
||||
import wiringpi
|
||||
|
||||
pin_base = 65
|
||||
i2c_addr = 0x20
|
||||
pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.mcp23017Setup(pin_base,i2c_addr)
|
||||
|
||||
for pin in pins:
|
||||
wiringpi.pinMode(pin,1)
|
||||
wiringpi.digitalWrite(pin,1)
|
||||
# wiringpi.delay(1000)
|
||||
# wiringpi.digitalWrite(pin,0)
|
||||
29
examples/serialTest.py
Normal file
29
examples/serialTest.py
Normal file
@ -0,0 +1,29 @@
|
||||
import wiringpi
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='')
|
||||
parser.add_argument("--device", type=str, default="/dev/ttyS4", help='specify the serial node')
|
||||
args = parser.parse_args()
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
serial = wiringpi.serialOpen(args.device, 115200)
|
||||
if serial < 0:
|
||||
print("Unable to open serial device: %s"% args.device)
|
||||
sys.exit(-1)
|
||||
|
||||
for count in range(0, 256):
|
||||
try:
|
||||
print("\nOut: %3d:" % count, end="")
|
||||
wiringpi.serialFlush(serial)
|
||||
wiringpi.serialPutchar(serial, count)
|
||||
wiringpi.delayMicroseconds(300000)
|
||||
|
||||
while wiringpi.serialDataAvail(serial):
|
||||
print(" -> %3d" % wiringpi.serialGetchar(serial), end="")
|
||||
wiringpi.serialFlush(serial)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
wiringpi.serialClose(serial) # Pass in ID
|
||||
19
examples/softpwm.py
Normal file
19
examples/softpwm.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Pulsates an LED connected to GPIO pin 1 with a suitable resistor 4 times using softPwm
|
||||
# softPwm uses a fixed frequency
|
||||
import wiringpi
|
||||
|
||||
OUTPUT = 1
|
||||
|
||||
PIN_TO_PWM = 1
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(PIN_TO_PWM,OUTPUT)
|
||||
wiringpi.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters
|
||||
|
||||
for time in range(0,4):
|
||||
for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on
|
||||
wiringpi.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle
|
||||
wiringpi.delay(10) # Delay for 0.2 seconds
|
||||
for brightness in reversed(range(0,100)):
|
||||
wiringpi.softPwmWrite(PIN_TO_PWM,brightness)
|
||||
wiringpi.delay(10)
|
||||
16
examples/softtone.py
Normal file
16
examples/softtone.py
Normal file
@ -0,0 +1,16 @@
|
||||
# Test of the softTone module in wiringPi
|
||||
# Plays a scale out on pin 3 - connect pizeo disc to pin 3 & 0v
|
||||
import wiringpi
|
||||
|
||||
PIN = 3
|
||||
|
||||
SCALE = [262, 294, 330, 349, 392, 440, 494, 525]
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.softToneCreate(PIN)
|
||||
|
||||
while True:
|
||||
for idx in range(8):
|
||||
print(idx)
|
||||
wiringpi.softToneWrite(PIN, SCALE[idx])
|
||||
wiringpi.delay(500)
|
||||
39
examples/spidev_test.py
Normal file
39
examples/spidev_test.py
Normal file
@ -0,0 +1,39 @@
|
||||
import wiringpi
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='')
|
||||
parser.add_argument("--channel", type=int, default=1, help='specify the spi channel')
|
||||
parser.add_argument("--port", type=int, default=0, help='specify the spi port')
|
||||
parser.add_argument("--speed", type=int, default=500000, help='specify the spi speed')
|
||||
parser.add_argument("--mode", type=int, default=0, help='specify the spi mode')
|
||||
args = parser.parse_args()
|
||||
|
||||
default_tx = [
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xF0, 0x0D,
|
||||
]
|
||||
|
||||
def hexdump(src, line_size, prefix):
|
||||
result = []
|
||||
digits = 4 if isinstance(src, str) else 2
|
||||
|
||||
for i in range(0, len(src), line_size):
|
||||
s = src[i:i + line_size]
|
||||
hexa = ' '.join([hex(x)[2:].upper().zfill(digits) for x in s])
|
||||
text = ''.join([chr(x) if 0x20 <= x < 0x7F else '.' for x in s])
|
||||
result.append(prefix + ' | ' + hexa.ljust(line_size * (digits + 1)) + ' |' + "{0}".format(text) + '|')
|
||||
|
||||
return '\n'.join(result)
|
||||
|
||||
print("spi mode: 0x%x" % args.mode);
|
||||
print("max speed: %d Hz (%d KHz)\n" %(args.speed, args.speed / 1000), end='');
|
||||
|
||||
wiringpi.wiringPiSPISetupMode(args.channel, args.port, args.speed, args.mode)
|
||||
revlen, recvData = wiringpi.wiringPiSPIDataRW(args.channel, bytes(default_tx))
|
||||
|
||||
print(hexdump(bytes(default_tx), 32, "TX"))
|
||||
print(hexdump(bytes(recvData), 32, "RX"))
|
||||
18
examples/two-mcp23017.py
Normal file
18
examples/two-mcp23017.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
|
||||
import wiringpi
|
||||
|
||||
pin_base = 65
|
||||
i2c_addr = 0x20
|
||||
i2c_addr_2 = 0x21
|
||||
#pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.mcp23017Setup(pin_base,i2c_addr)
|
||||
wiringpi.mcp23017Setup(pin_base+16,i2c_addr_2)
|
||||
|
||||
#for pin in pins:
|
||||
for pin in range(65,96):
|
||||
wiringpi.pinMode(pin,1)
|
||||
wiringpi.digitalWrite(pin,1)
|
||||
# wiringpi.delay(1000)
|
||||
# wiringpi.digitalWrite(pin,0)
|
||||
3
fixUndefFunc.c
Normal file
3
fixUndefFunc.c
Normal file
@ -0,0 +1,3 @@
|
||||
#include <wiringPi.h>
|
||||
unsigned int digitalRead8 (int pin) { return 0;}
|
||||
void digitalWrite8 (int pin, int value) {}
|
||||
42
generate-bindings.py
Normal file
42
generate-bindings.py
Normal file
@ -0,0 +1,42 @@
|
||||
HEADERS = []
|
||||
|
||||
src = open("wiringpi.i").read().split('\n')
|
||||
|
||||
print("extern unsigned char getGpioNum(void);")
|
||||
|
||||
for line in src:
|
||||
line = line.strip()
|
||||
if line.startswith('#include') and line.endswith('.h"'):
|
||||
HEADERS.append(line.replace('#include','').replace('"','').strip())
|
||||
|
||||
def is_c_decl(line):
|
||||
for fn in ['wiringPiISR','wiringPiSetupPiFace','wiringPiSetupPiFaceForGpioProg']:
|
||||
if fn in line:
|
||||
return False
|
||||
for prefix in ['extern','void','int','uint8_t']:
|
||||
if line.startswith(prefix):
|
||||
return True
|
||||
|
||||
print("// Generated by generate-bindings.py - do not edit manually!")
|
||||
|
||||
for file in HEADERS:
|
||||
print("\n// Header file {}".format(file))
|
||||
if file == "wiringOP/devLib/font.h":
|
||||
continue # continue here
|
||||
h = open(file).read().split('\n')
|
||||
extern = False
|
||||
cont = False
|
||||
if 'extern "C" {' not in h:
|
||||
extern = True
|
||||
for line in h:
|
||||
line = line.strip()
|
||||
if cont:
|
||||
print("\t{}".format(line))
|
||||
cont = ";" not in line
|
||||
continue
|
||||
if line.startswith('extern "C"'):
|
||||
extern = True
|
||||
continue
|
||||
if is_c_decl(line) and extern:
|
||||
print(line)
|
||||
cont = ";" not in line
|
||||
7
setup.cfg
Normal file
7
setup.cfg
Normal file
@ -0,0 +1,7 @@
|
||||
[metadata]
|
||||
author = Philip Howard
|
||||
author_email = phil@gadgetoid.com
|
||||
url = https://github.com/WiringPi/WiringPi-Python/
|
||||
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.
|
||||
long_description = file:README.rst
|
||||
license = LGPL
|
||||
60
setup.py
Executable file
60
setup.py
Executable file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
from setuptools import setup, Extension
|
||||
from setuptools.command.build_py import build_py
|
||||
from setuptools.command.sdist import sdist
|
||||
from distutils.spawn import find_executable
|
||||
from glob import glob
|
||||
from subprocess import Popen, PIPE
|
||||
import re
|
||||
|
||||
sources = glob('wiringOP/devLib/*.c')
|
||||
sources += ['wiringOP/examples/blink.c']
|
||||
sources += glob('wiringOP/wiringPi/*.c')
|
||||
sources += ['wiringpi.i']
|
||||
sources += ['fixUndefFunc.c']
|
||||
try:
|
||||
sources.remove('wiringOP/devLib/piFaceOld.c')
|
||||
except ValueError:
|
||||
# the file is already excluded in the source distribution
|
||||
pass
|
||||
|
||||
# Fix so that build_ext runs before build_py
|
||||
# Without this, wiringpi.py is generated too late and doesn't
|
||||
# end up in the distribution when running setup.py bdist or bdist_wheel.
|
||||
# Based on:
|
||||
# https://stackoverflow.com/a/29551581/7938656
|
||||
# and
|
||||
# https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/
|
||||
|
||||
|
||||
class build_py_ext_first(build_py):
|
||||
def run(self):
|
||||
self.run_command("build_ext")
|
||||
return build_py.run(self)
|
||||
|
||||
# Make sure wiringpi_wrap.c is available for the source dist, also.
|
||||
|
||||
|
||||
class sdist_ext_first(sdist):
|
||||
def run(self):
|
||||
self.run_command("build_ext")
|
||||
return sdist.run(self)
|
||||
|
||||
_wiringpi = Extension(
|
||||
'_wiringpi',
|
||||
include_dirs=['wiringOP', 'wiringOP/wiringPi', 'wiringOP/devLib'],
|
||||
swig_opts=['-threads'],
|
||||
extra_link_args=['-lcrypt', '-lrt'],
|
||||
sources=sources
|
||||
)
|
||||
|
||||
setup(
|
||||
name='wiringpi',
|
||||
version='2.60.1',
|
||||
ext_modules=[_wiringpi],
|
||||
py_modules=["wiringpi"],
|
||||
install_requires=[],
|
||||
cmdclass={'build_py': build_py_ext_first, 'sdist': sdist_ext_first}
|
||||
)
|
||||
4
tests/piglow.py
Normal file
4
tests/piglow.py
Normal file
@ -0,0 +1,4 @@
|
||||
import wiringpi
|
||||
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
|
||||
io.piGlowSetup()
|
||||
io.piGlowLeg(1,100)
|
||||
4
tests/test.py
Normal file
4
tests/test.py
Normal file
@ -0,0 +1,4 @@
|
||||
import wiringpi
|
||||
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
|
||||
print io.digitalRead(1)
|
||||
print io.analogRead(1)
|
||||
9
tests/test_wiringPi_GPIO.py
Normal file
9
tests/test_wiringPi_GPIO.py
Normal file
@ -0,0 +1,9 @@
|
||||
import wiringpi
|
||||
|
||||
def test_wiringPiSetup():
|
||||
assert wiringpi.wiringPiSetup() == 0
|
||||
|
||||
def test_digitalRead():
|
||||
assert wiringpi.digitalRead(1) != None
|
||||
def test_digitalWrite():
|
||||
assert wiringpi.digitalWrite(1,0) == None
|
||||
188
wiringpi-class.py
Normal file
188
wiringpi-class.py
Normal file
@ -0,0 +1,188 @@
|
||||
%pythoncode %{
|
||||
class nes(object):
|
||||
def setupNesJoystick(self,*args):
|
||||
return setupNesJoystick(*args)
|
||||
def readNesJoystick(self,*args):
|
||||
return readNesJoystick(*args)
|
||||
|
||||
class Serial(object):
|
||||
device = '/dev/ttyAMA0'
|
||||
baud = 9600
|
||||
serial_id = 0
|
||||
def printf(self,*args):
|
||||
return serialPrintf(self.serial_id,*args)
|
||||
def dataAvail(self,*args):
|
||||
return serialDataAvail(self.serial_id,*args)
|
||||
def getchar(self,*args):
|
||||
return serialGetchar(self.serial_id,*args)
|
||||
def putchar(self,*args):
|
||||
return serialPutchar(self.serial_id,*args)
|
||||
def puts(self,*args):
|
||||
return serialPuts(self.serial_id,*args)
|
||||
def __init__(self,device,baud):
|
||||
self.device = device
|
||||
self.baud = baud
|
||||
self.serial_id = serialOpen(self.device,self.baud)
|
||||
def __del__(self):
|
||||
serialClose(self.serial_id)
|
||||
|
||||
class I2C(object):
|
||||
def setupInterface(self,*args):
|
||||
return wiringPiI2CSetupInterface(*args)
|
||||
def setup(self,*args):
|
||||
return wiringPiI2CSetup(*args)
|
||||
def read(self,*args):
|
||||
return wiringPiI2CRead(*args)
|
||||
def readReg8(self,*args):
|
||||
return wiringPiI2CReadReg8(*args)
|
||||
def readReg16(self,*args):
|
||||
return wiringPiI2CReadReg16(*args)
|
||||
def write(self,*args):
|
||||
return wiringPiI2CWrite(*args)
|
||||
def writeReg8(self,*args):
|
||||
return wiringPiI2CWriteReg8(*args)
|
||||
def writeReg16(self,*args):
|
||||
return wiringPiI2CWriteReg16(*args)
|
||||
|
||||
class GPIO(object):
|
||||
WPI_MODE_PINS = 0
|
||||
WPI_MODE_GPIO = 1
|
||||
WPI_MODE_GPIO_SYS = 2
|
||||
WPI_MODE_PHYS = 3
|
||||
WPI_MODE_PIFACE = 4
|
||||
WPI_MODE_UNINITIALISED = -1
|
||||
|
||||
INPUT = 0
|
||||
OUTPUT = 1
|
||||
PWM_OUTPUT = 2
|
||||
GPIO_CLOCK = 3
|
||||
|
||||
LOW = 0
|
||||
HIGH = 1
|
||||
|
||||
PUD_OFF = 0
|
||||
PUD_DOWN = 1
|
||||
PUD_UP = 2
|
||||
|
||||
PWM_MODE_MS = 0
|
||||
PWM_MODE_BAL = 1
|
||||
|
||||
INT_EDGE_SETUP = 0
|
||||
INT_EDGE_FALLING = 1
|
||||
INT_EDGE_RISING = 2
|
||||
INT_EDGE_BOTH = 3
|
||||
|
||||
LSBFIRST = 0
|
||||
MSBFIRST = 1
|
||||
|
||||
MODE = 0
|
||||
def __init__(self,pinmode=0):
|
||||
self.MODE=pinmode
|
||||
if pinmode==self.WPI_MODE_PINS:
|
||||
wiringPiSetup()
|
||||
if pinmode==self.WPI_MODE_GPIO:
|
||||
wiringPiSetupGpio()
|
||||
if pinmode==self.WPI_MODE_GPIO_SYS:
|
||||
wiringPiSetupSys()
|
||||
if pinmode==self.WPI_MODE_PHYS:
|
||||
wiringPiSetupPhys()
|
||||
if pinmode==self.WPI_MODE_PIFACE:
|
||||
wiringPiSetupPiFace()
|
||||
|
||||
def delay(self,*args):
|
||||
delay(*args)
|
||||
def delayMicroseconds(self,*args):
|
||||
delayMicroseconds(*args)
|
||||
def millis(self):
|
||||
return millis()
|
||||
def micros(self):
|
||||
return micros()
|
||||
|
||||
def piHiPri(self,*args):
|
||||
return piHiPri(*args)
|
||||
|
||||
def wpiPinToGpio(self,*args):
|
||||
return wpiPinToGpio(*args)
|
||||
def setPadDrive(self,*args):
|
||||
return setPadDrive(*args)
|
||||
def getAlt(self,*args):
|
||||
return getAlt(*args)
|
||||
def digitalWriteByte(self,*args):
|
||||
return digitalWriteByte(*args)
|
||||
|
||||
def pwmSetMode(self,*args):
|
||||
pwmSetMode(*args)
|
||||
def pwmSetRange(self,*args):
|
||||
pwmSetRange(*args)
|
||||
def pwmSetClock(self,*args):
|
||||
pwmSetClock(*args)
|
||||
def gpioClockSet(self,*args):
|
||||
gpioClockSet(*args)
|
||||
def pwmWrite(self,*args):
|
||||
pwmWrite(*args)
|
||||
|
||||
def pinMode(self,*args):
|
||||
pinMode(*args)
|
||||
|
||||
def digitalWrite(self,*args):
|
||||
digitalWrite(*args)
|
||||
def digitalRead(self,*args):
|
||||
return digitalRead(*args)
|
||||
def digitalWriteByte(self,*args):
|
||||
digitalWriteByte(*args)
|
||||
|
||||
def analogWrite(self,*args):
|
||||
analogWrite(*args)
|
||||
def analogRead(self,*args):
|
||||
return analogRead(*args)
|
||||
|
||||
def shiftOut(self,*args):
|
||||
shiftOut(*args)
|
||||
def shiftIn(self,*args):
|
||||
return shiftIn(*args)
|
||||
|
||||
def pullUpDnControl(self,*args):
|
||||
return pullUpDnControl(*args)
|
||||
|
||||
def waitForInterrupt(self,*args):
|
||||
return waitForInterrupt(*args)
|
||||
def wiringPiISR(self,*args):
|
||||
return wiringPiISR(*args)
|
||||
|
||||
def softPwmCreate(self,*args):
|
||||
return softPwmCreate(*args)
|
||||
def softPwmWrite(self,*args):
|
||||
return softPwmWrite(*args)
|
||||
|
||||
def softToneCreate(self,*args):
|
||||
return softToneCreate(*args)
|
||||
def softToneWrite(self,*args):
|
||||
return softToneWrite(*args)
|
||||
|
||||
def lcdHome(self,*args):
|
||||
return lcdHome(self,*args)
|
||||
def lcdCLear(self,*args):
|
||||
return lcdClear(self,*args)
|
||||
def lcdSendCommand(self,*args):
|
||||
return lcdSendCommand(self,*args)
|
||||
def lcdPosition(self,*args):
|
||||
return lcdPosition(self,*args)
|
||||
def lcdPutchar(self,*args):
|
||||
return lcdPutchar(self,*args)
|
||||
def lcdPuts(self,*args):
|
||||
return lcdPuts(self,*args)
|
||||
def lcdPrintf(self,*args):
|
||||
return lcdPrintf(self,*args)
|
||||
def lcdInit(self,*args):
|
||||
return lcdInit(self,*args)
|
||||
def piGlowSetup(self,*args):
|
||||
return piGlowSetup(self,*args)
|
||||
def piGlow1(self,*args):
|
||||
return piGlow1(self,*args)
|
||||
def piGlowLeg(self,*args):
|
||||
return piGlowLeg(self,*args)
|
||||
def piGlowRing(self,*args):
|
||||
return piGlowRing(self,*args)
|
||||
def getGpioNum(self):
|
||||
return getGpioNum()
|
||||
%}
|
||||
294
wiringpi.i
Normal file
294
wiringpi.i
Normal file
@ -0,0 +1,294 @@
|
||||
%module wiringpi
|
||||
|
||||
%{
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define PyInt_AS_LONG PyLong_AsLong
|
||||
#define PyString_FromStringAndSize PyBytes_FromStringAndSize
|
||||
#endif
|
||||
|
||||
#include "wiringOP/wiringPi/wiringPi.h"
|
||||
#include "wiringOP/wiringPi/wiringPiI2C.h"
|
||||
#include "wiringOP/wiringPi/wiringPiSPI.h"
|
||||
#include "wiringOP/wiringPi/wiringSerial.h"
|
||||
#include "wiringOP/wiringPi/wiringShift.h"
|
||||
#include "wiringOP/wiringPi/drcSerial.h"
|
||||
#include "wiringOP/wiringPi/ads1115.h"
|
||||
#include "wiringOP/wiringPi/max31855.h"
|
||||
#include "wiringOP/wiringPi/max5322.h"
|
||||
#include "wiringOP/wiringPi/mcp23008.h"
|
||||
#include "wiringOP/wiringPi/mcp23016.h"
|
||||
#include "wiringOP/wiringPi/mcp23016reg.h"
|
||||
#include "wiringOP/wiringPi/mcp23017.h"
|
||||
#include "wiringOP/wiringPi/mcp23s08.h"
|
||||
#include "wiringOP/wiringPi/mcp23s17.h"
|
||||
#include "wiringOP/wiringPi/mcp23x0817.h"
|
||||
#include "wiringOP/wiringPi/mcp23x08.h"
|
||||
#include "wiringOP/wiringPi/mcp3002.h"
|
||||
#include "wiringOP/wiringPi/mcp3004.h"
|
||||
#include "wiringOP/wiringPi/mcp3422.h"
|
||||
#include "wiringOP/wiringPi/mcp4802.h"
|
||||
#include "wiringOP/wiringPi/pcf8574.h"
|
||||
#include "wiringOP/wiringPi/pcf8591.h"
|
||||
#include "wiringOP/wiringPi/sn3218.h"
|
||||
#include "wiringOP/wiringPi/softPwm.h"
|
||||
#include "wiringOP/wiringPi/softServo.h"
|
||||
#include "wiringOP/wiringPi/softTone.h"
|
||||
#include "wiringOP/wiringPi/sr595.h"
|
||||
#include "wiringOP/wiringPi/bmp180.h"
|
||||
#include "wiringOP/wiringPi/drcNet.h"
|
||||
#include "wiringOP/wiringPi/ds18b20.h"
|
||||
#include "wiringOP/wiringPi/htu21d.h"
|
||||
#include "wiringOP/wiringPi/pseudoPins.h"
|
||||
#include "wiringOP/wiringPi/rht03.h"
|
||||
#include "wiringOP/wiringPi/wpiExtensions.h"
|
||||
#include "wiringOP/devLib/ds1302.h"
|
||||
#include "wiringOP/devLib/font.h"
|
||||
#include "wiringOP/devLib/gertboard.h"
|
||||
#include "wiringOP/devLib/lcd128x64.h"
|
||||
#include "wiringOP/devLib/lcd.h"
|
||||
#include "wiringOP/devLib/maxdetect.h"
|
||||
#include "wiringOP/devLib/piGlow.h"
|
||||
#include "wiringOP/devLib/piNes.h"
|
||||
#include "wiringOP/devLib/scrollPhat.h"
|
||||
#include "wiringOP/devLib/piFace.h"
|
||||
%}
|
||||
|
||||
%apply unsigned char { uint8_t };
|
||||
%typemap(in) (unsigned char *data, int len) {
|
||||
$1 = (unsigned char *) PyString_AsString($input);
|
||||
$2 = PyString_Size($input);
|
||||
};
|
||||
|
||||
// Grab a Python function object as a Python object.
|
||||
%typemap(in) PyObject *PyFunc {
|
||||
if (!PyCallable_Check($input)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Need a callable object!");
|
||||
return NULL;
|
||||
}
|
||||
$1 = $input;
|
||||
}
|
||||
|
||||
%{
|
||||
|
||||
// we need to have our own callbacks array
|
||||
PyObject* event_callback[64] = {0,};
|
||||
|
||||
void _wiringPiISR_callback(int pinNumber) {
|
||||
PyObject *result;
|
||||
|
||||
if (event_callback[pinNumber]) {
|
||||
// this will acquire the GIL
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
|
||||
result = PyObject_CallFunction(event_callback[pinNumber], NULL);
|
||||
if (result == NULL && PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
Py_XDECREF(result);
|
||||
|
||||
// release the GIL
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* This is embarrasing, WiringPi does not support supplying args to the callback
|
||||
... so we have to create callback function for each of the pins :( */
|
||||
void _wiringPiISR_callback_pin0(void) { _wiringPiISR_callback(0); }
|
||||
void _wiringPiISR_callback_pin1(void) { _wiringPiISR_callback(1); }
|
||||
void _wiringPiISR_callback_pin2(void) { _wiringPiISR_callback(2); }
|
||||
void _wiringPiISR_callback_pin3(void) { _wiringPiISR_callback(3); }
|
||||
void _wiringPiISR_callback_pin4(void) { _wiringPiISR_callback(4); }
|
||||
void _wiringPiISR_callback_pin5(void) { _wiringPiISR_callback(5); }
|
||||
void _wiringPiISR_callback_pin6(void) { _wiringPiISR_callback(6); }
|
||||
void _wiringPiISR_callback_pin7(void) { _wiringPiISR_callback(7); }
|
||||
void _wiringPiISR_callback_pin8(void) { _wiringPiISR_callback(8); }
|
||||
void _wiringPiISR_callback_pin9(void) { _wiringPiISR_callback(9); }
|
||||
void _wiringPiISR_callback_pin10(void) { _wiringPiISR_callback(10); }
|
||||
void _wiringPiISR_callback_pin11(void) { _wiringPiISR_callback(11); }
|
||||
void _wiringPiISR_callback_pin12(void) { _wiringPiISR_callback(12); }
|
||||
void _wiringPiISR_callback_pin13(void) { _wiringPiISR_callback(13); }
|
||||
void _wiringPiISR_callback_pin14(void) { _wiringPiISR_callback(14); }
|
||||
void _wiringPiISR_callback_pin15(void) { _wiringPiISR_callback(15); }
|
||||
void _wiringPiISR_callback_pin16(void) { _wiringPiISR_callback(16); }
|
||||
void _wiringPiISR_callback_pin17(void) { _wiringPiISR_callback(17); }
|
||||
void _wiringPiISR_callback_pin18(void) { _wiringPiISR_callback(18); }
|
||||
void _wiringPiISR_callback_pin19(void) { _wiringPiISR_callback(19); }
|
||||
void _wiringPiISR_callback_pin20(void) { _wiringPiISR_callback(20); }
|
||||
void _wiringPiISR_callback_pin21(void) { _wiringPiISR_callback(21); }
|
||||
void _wiringPiISR_callback_pin22(void) { _wiringPiISR_callback(22); }
|
||||
void _wiringPiISR_callback_pin23(void) { _wiringPiISR_callback(23); }
|
||||
void _wiringPiISR_callback_pin24(void) { _wiringPiISR_callback(24); }
|
||||
void _wiringPiISR_callback_pin25(void) { _wiringPiISR_callback(25); }
|
||||
void _wiringPiISR_callback_pin26(void) { _wiringPiISR_callback(26); }
|
||||
void _wiringPiISR_callback_pin27(void) { _wiringPiISR_callback(27); }
|
||||
void _wiringPiISR_callback_pin28(void) { _wiringPiISR_callback(28); }
|
||||
void _wiringPiISR_callback_pin29(void) { _wiringPiISR_callback(29); }
|
||||
void _wiringPiISR_callback_pin30(void) { _wiringPiISR_callback(30); }
|
||||
void _wiringPiISR_callback_pin31(void) { _wiringPiISR_callback(31); }
|
||||
void _wiringPiISR_callback_pin32(void) { _wiringPiISR_callback(32); }
|
||||
void _wiringPiISR_callback_pin33(void) { _wiringPiISR_callback(33); }
|
||||
void _wiringPiISR_callback_pin34(void) { _wiringPiISR_callback(34); }
|
||||
void _wiringPiISR_callback_pin35(void) { _wiringPiISR_callback(35); }
|
||||
void _wiringPiISR_callback_pin36(void) { _wiringPiISR_callback(36); }
|
||||
void _wiringPiISR_callback_pin37(void) { _wiringPiISR_callback(37); }
|
||||
void _wiringPiISR_callback_pin38(void) { _wiringPiISR_callback(38); }
|
||||
void _wiringPiISR_callback_pin39(void) { _wiringPiISR_callback(39); }
|
||||
void _wiringPiISR_callback_pin40(void) { _wiringPiISR_callback(40); }
|
||||
void _wiringPiISR_callback_pin41(void) { _wiringPiISR_callback(41); }
|
||||
void _wiringPiISR_callback_pin42(void) { _wiringPiISR_callback(42); }
|
||||
void _wiringPiISR_callback_pin43(void) { _wiringPiISR_callback(43); }
|
||||
void _wiringPiISR_callback_pin44(void) { _wiringPiISR_callback(44); }
|
||||
void _wiringPiISR_callback_pin45(void) { _wiringPiISR_callback(45); }
|
||||
void _wiringPiISR_callback_pin46(void) { _wiringPiISR_callback(46); }
|
||||
void _wiringPiISR_callback_pin47(void) { _wiringPiISR_callback(47); }
|
||||
void _wiringPiISR_callback_pin48(void) { _wiringPiISR_callback(48); }
|
||||
void _wiringPiISR_callback_pin49(void) { _wiringPiISR_callback(49); }
|
||||
void _wiringPiISR_callback_pin50(void) { _wiringPiISR_callback(50); }
|
||||
void _wiringPiISR_callback_pin51(void) { _wiringPiISR_callback(51); }
|
||||
void _wiringPiISR_callback_pin52(void) { _wiringPiISR_callback(52); }
|
||||
void _wiringPiISR_callback_pin53(void) { _wiringPiISR_callback(53); }
|
||||
void _wiringPiISR_callback_pin54(void) { _wiringPiISR_callback(54); }
|
||||
void _wiringPiISR_callback_pin55(void) { _wiringPiISR_callback(55); }
|
||||
void _wiringPiISR_callback_pin56(void) { _wiringPiISR_callback(56); }
|
||||
void _wiringPiISR_callback_pin57(void) { _wiringPiISR_callback(57); }
|
||||
void _wiringPiISR_callback_pin58(void) { _wiringPiISR_callback(58); }
|
||||
void _wiringPiISR_callback_pin59(void) { _wiringPiISR_callback(59); }
|
||||
void _wiringPiISR_callback_pin60(void) { _wiringPiISR_callback(60); }
|
||||
void _wiringPiISR_callback_pin61(void) { _wiringPiISR_callback(61); }
|
||||
void _wiringPiISR_callback_pin62(void) { _wiringPiISR_callback(62); }
|
||||
void _wiringPiISR_callback_pin63(void) { _wiringPiISR_callback(63); }
|
||||
|
||||
/* This function adds a new Python function object as a callback object */
|
||||
|
||||
static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc) {
|
||||
|
||||
// remove the old callback if any
|
||||
if (event_callback[pin]) {
|
||||
Py_XDECREF(event_callback[pin]);
|
||||
}
|
||||
|
||||
// put new callback function
|
||||
event_callback[pin] = PyFunc;
|
||||
Py_INCREF(PyFunc);
|
||||
|
||||
// and now the ugly switch
|
||||
void (*func)(void);
|
||||
switch(pin) {
|
||||
case 0: func = &_wiringPiISR_callback_pin0; break;
|
||||
case 1: func = &_wiringPiISR_callback_pin1; break;
|
||||
case 2: func = &_wiringPiISR_callback_pin2; break;
|
||||
case 3: func = &_wiringPiISR_callback_pin3; break;
|
||||
case 4: func = &_wiringPiISR_callback_pin4; break;
|
||||
case 5: func = &_wiringPiISR_callback_pin5; break;
|
||||
case 6: func = &_wiringPiISR_callback_pin6; break;
|
||||
case 7: func = &_wiringPiISR_callback_pin7; break;
|
||||
case 8: func = &_wiringPiISR_callback_pin8; break;
|
||||
case 9: func = &_wiringPiISR_callback_pin9; break;
|
||||
case 10: func = &_wiringPiISR_callback_pin10; break;
|
||||
case 11: func = &_wiringPiISR_callback_pin11; break;
|
||||
case 12: func = &_wiringPiISR_callback_pin12; break;
|
||||
case 13: func = &_wiringPiISR_callback_pin13; break;
|
||||
case 14: func = &_wiringPiISR_callback_pin14; break;
|
||||
case 15: func = &_wiringPiISR_callback_pin15; break;
|
||||
case 16: func = &_wiringPiISR_callback_pin16; break;
|
||||
case 17: func = &_wiringPiISR_callback_pin17; break;
|
||||
case 18: func = &_wiringPiISR_callback_pin18; break;
|
||||
case 19: func = &_wiringPiISR_callback_pin19; break;
|
||||
case 20: func = &_wiringPiISR_callback_pin20; break;
|
||||
case 21: func = &_wiringPiISR_callback_pin21; break;
|
||||
case 22: func = &_wiringPiISR_callback_pin22; break;
|
||||
case 23: func = &_wiringPiISR_callback_pin23; break;
|
||||
case 24: func = &_wiringPiISR_callback_pin24; break;
|
||||
case 25: func = &_wiringPiISR_callback_pin25; break;
|
||||
case 26: func = &_wiringPiISR_callback_pin26; break;
|
||||
case 27: func = &_wiringPiISR_callback_pin27; break;
|
||||
case 28: func = &_wiringPiISR_callback_pin28; break;
|
||||
case 29: func = &_wiringPiISR_callback_pin29; break;
|
||||
case 30: func = &_wiringPiISR_callback_pin30; break;
|
||||
case 31: func = &_wiringPiISR_callback_pin31; break;
|
||||
case 32: func = &_wiringPiISR_callback_pin32; break;
|
||||
case 33: func = &_wiringPiISR_callback_pin33; break;
|
||||
case 34: func = &_wiringPiISR_callback_pin34; break;
|
||||
case 35: func = &_wiringPiISR_callback_pin35; break;
|
||||
case 36: func = &_wiringPiISR_callback_pin36; break;
|
||||
case 37: func = &_wiringPiISR_callback_pin37; break;
|
||||
case 38: func = &_wiringPiISR_callback_pin38; break;
|
||||
case 39: func = &_wiringPiISR_callback_pin39; break;
|
||||
case 40: func = &_wiringPiISR_callback_pin40; break;
|
||||
case 41: func = &_wiringPiISR_callback_pin41; break;
|
||||
case 42: func = &_wiringPiISR_callback_pin42; break;
|
||||
case 43: func = &_wiringPiISR_callback_pin43; break;
|
||||
case 44: func = &_wiringPiISR_callback_pin44; break;
|
||||
case 45: func = &_wiringPiISR_callback_pin45; break;
|
||||
case 46: func = &_wiringPiISR_callback_pin46; break;
|
||||
case 47: func = &_wiringPiISR_callback_pin47; break;
|
||||
case 48: func = &_wiringPiISR_callback_pin48; break;
|
||||
case 49: func = &_wiringPiISR_callback_pin49; break;
|
||||
case 50: func = &_wiringPiISR_callback_pin50; break;
|
||||
case 51: func = &_wiringPiISR_callback_pin51; break;
|
||||
case 52: func = &_wiringPiISR_callback_pin52; break;
|
||||
case 53: func = &_wiringPiISR_callback_pin53; break;
|
||||
case 54: func = &_wiringPiISR_callback_pin54; break;
|
||||
case 55: func = &_wiringPiISR_callback_pin55; break;
|
||||
case 56: func = &_wiringPiISR_callback_pin56; break;
|
||||
case 57: func = &_wiringPiISR_callback_pin57; break;
|
||||
case 58: func = &_wiringPiISR_callback_pin58; break;
|
||||
case 59: func = &_wiringPiISR_callback_pin59; break;
|
||||
case 60: func = &_wiringPiISR_callback_pin60; break;
|
||||
case 61: func = &_wiringPiISR_callback_pin61; break;
|
||||
case 62: func = &_wiringPiISR_callback_pin62; break;
|
||||
case 63: func = &_wiringPiISR_callback_pin63; break;
|
||||
}
|
||||
|
||||
// register our dedicated function in WiringPi
|
||||
wiringPiISR(pin, mode, func);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
// overlay normal function with our wrapper
|
||||
%rename("wiringPiISR") wiringPiISRWrapper (int pin, int mode, PyObject *PyFunc);
|
||||
static void wiringPiISRWrapper(int pin, int mode, PyObject *PyFunc);
|
||||
|
||||
%typemap(in) unsigned char data [8] {
|
||||
/* Check if is a list */
|
||||
if (PyList_Check($input)) {
|
||||
if(PyList_Size($input) != 8){
|
||||
PyErr_SetString(PyExc_TypeError,"must contain 8 items");
|
||||
return NULL;
|
||||
}
|
||||
int i = 0;
|
||||
$1 = (unsigned char *) malloc(8);
|
||||
for (i = 0; i < 8; i++) {
|
||||
PyObject *o = PyList_GetItem($input,i);
|
||||
if (PyInt_Check(o) && PyInt_AsLong(PyList_GetItem($input,i)) <= 255 && PyInt_AsLong(PyList_GetItem($input,i)) >= 0)
|
||||
$1[i] = PyInt_AsLong(PyList_GetItem($input,i));
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError,"list must contain integers 0-255");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError,"not a list");
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
%typemap(freearg) unsigned char data [8] {
|
||||
free((unsigned char *) $1);
|
||||
}
|
||||
|
||||
%typemap(in) (unsigned char *data, int len) {
|
||||
$1 = (unsigned char *) PyString_AsString($input);
|
||||
$2 = PyString_Size($input);
|
||||
};
|
||||
|
||||
%typemap(argout) (unsigned char *data) {
|
||||
$result = SWIG_Python_AppendOutput($result, PyString_FromStringAndSize((char *) $1, result));
|
||||
};
|
||||
|
||||
%include "bindings.i"
|
||||
%include "constants.py"
|
||||
%include "wiringpi-class.py"
|
||||
Loading…
x
Reference in New Issue
Block a user