Skip to content

Commit

Permalink
Version v0.8.5: modified to be compatible with WiringPi version 3.15
Browse files Browse the repository at this point in the history
  • Loading branch information
phylax2020 committed Feb 17, 2025
1 parent cf842b7 commit 4965bd2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change Log
==========
0.8.5
-----
Interrupt functions optimized >= 3.15

0.8.4
-----
Interrupt functions with debouncing >= 3.14
Expand Down
40 changes: 20 additions & 20 deletions INSTALL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ sudo apt purge wiringpi
# If returned aarch64 --> 64 Bit
#
# If 32 bit release Bookworm
wget https://github.com/phylax2020/WiringPi/releases/download/3.14/wiringpi_3.14_armhf.deb
sudo apt install ./wiringpi_3.14_armhf.deb
wget https://github.com/phylax2020/WiringPi/releases/download/3.14/wiringpi_3.15_armhf.deb
sudo apt install ./wiringpi_3.15_armhf.deb

# If 64 bit release Bookworm
wget https://github.com/phylax2020/WiringPi/releases/download/3.14/wiringpi_3.14_arm64.deb
sudo apt install ./wiringpi_3.14_arm64.deb
wget https://github.com/phylax2020/WiringPi/releases/download/3.14/wiringpi_3.15_arm64.deb
sudo apt install ./wiringpi_3.15_arm64.deb

# If you want to build your own version of WiringPi:

# update Pi-OS
sudo apt update
sudo apt upgrade

# install latest version (3.14) from source, it is a fork from https://github.com/WiringPi/WiringPi
# install latest version (3.15) from source, it is a fork from https://github.com/WiringPi/WiringPi
# Installing instructions can be found at https://github.com/phylax2020/WiringPi
# fetch the source
sudo apt install git
Expand All @@ -37,17 +37,17 @@ cd WiringPi
./build debian

# on Pi-OS 32 Bit:
mv debian-template/wiringpi_3.14_armhf.deb .
mv debian-template/wiringpi_3.15_armhf.deb .

# on Pi-OS 64 Bit
mv debian-template/wiringpi_3.14_arm64.deb .
mv debian-template/wiringpi_3.15_arm64.deb .

# install it
# on Pi-OS 32 Bit
sudo apt install ./wiringpi_3.14_armhf.deb
sudo apt install ./wiringpi_3.15_armhf.deb

# on Pi.OS 64 Bit
sudo apt install ./wiringpi_3.14_arm64.deb
sudo apt install ./wiringpi_3.15_arm64.deb

############################
# now install RPi.GPIO #
Expand All @@ -68,12 +68,12 @@ sudo pip3 uninstall RPi.GPIO --break-system-packages
# If returned aarch64 --> 64 Bit
#
# If 32 bit release Bookworm
wget https://github.com/phylax2020/RPi.GPIO/releases/download/v0.8.4/python3-rpi.gpio_0.8.4-1_armhf.deb
sudo apt install ./python3-rpi.gpio_0.8.4-1_armhf.deb
wget https://github.com/phylax2020/RPi.GPIO/releases/download/v0.8.5/python3-rpi.gpio_0.8.5-1_armhf.deb
sudo apt install ./python3-rpi.gpio_0.8.5-1_armhf.deb

# If 64 bit release Bookworm
wget https://github.com/phylax2020/RPi.GPIO/releases/download/v0.8.4/python3-rpi.gpio_0.8.4-1_arm64.deb
sudo apt install ./python3-rpi.gpio_0.8.4-1_arm64.deb
wget https://github.com/phylax2020/RPi.GPIO/releases/download/v0.8.5/python3-rpi.gpio_0.8.5-1_arm64.deb
sudo apt install ./python3-rpi.gpio_0.8.5-1_arm64.deb

###################################
# install from source #
Expand All @@ -88,7 +88,7 @@ sudo apt install python3-dev
# Install python3 build package
sudo apt install python3-build

# If you want install python3-rpi.gpio_0.8.4-1_arm<hf/64>.deb from source
# If you want install python3-rpi.gpio_0.8.5-1_arm<hf/64>.deb from source
# install stdeb and dependencies
sudo apt install python3-stdeb
sudo apt install dh-python
Expand All @@ -101,18 +101,18 @@ git clone https://github.com/phylax2020/RPi.GPIO.git
cd RPi.GPIO
python3 setup.py --command-packages=stdeb.command bdist_deb
cd deb_dist
sudo apt install ./python3-rpi.gpio_0.8.4-1_arm<hf/64>.deb
sudo apt install ./python3-rpi.gpio_0.8.5-1_arm<hf/64>.deb


# alternatively install RPi.GPIO using pip
# get assets RPi.GPIO-0.8.4.tar.gz or RPi.GPIO-0.8.4.zip from https://github.com/phylax2020/RPi.GPIO/archive/refs/tags/v0.8.4
# get assets RPi.GPIO-0.8.5.tar.gz or RPi.GPIO-0.8.5.zip from https://github.com/phylax2020/RPi.GPIO/archive/refs/tags/v0.8.5
cd ~
wget https://github.com/phylax2020/RPi.GPIO/archive/refs/tags/v0.8.4.tar.gz
tar -xvf v0.8.4.tar.gz
cd RPi.GPIO-0.8.4
wget https://github.com/phylax2020/RPi.GPIO/archive/refs/tags/v0.8.5.tar.gz
tar -xvf v0.8.5.tar.gz
cd RPi.GPIO-0.8.5
python3 -m build --sdist
cd dist
sudo pip3 install rpi_gpio-0.8.4.tar.gz --break-system-packages
sudo pip3 install rpi_gpio-0.8.5.tar.gz --break-system-packages

##########################
# test installation #
Expand Down
6 changes: 5 additions & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: RPi.GPIO
Version: 0.8.4
Version: 0.8.5
Summary: A module to control Raspberry Pi GPIO channels
Home-page: http://sourceforge.net/projects/raspberry-gpio-python/
Author: Ben Croston
Expand All @@ -23,6 +23,10 @@ Description: This package provides a Python module to control the GPIO on a Rasp

Change Log
==========
0.8.5
-----
Interrupt functions optimized >= 3.15

0.8.4
-----
Interrupt functions with debouncing >= 3.14
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Thanks to the developers of WiringPi, who did a lot of work to support all Raspb
import time
import RPi.GPIO as GPIO

btn_input = 16;
LED_output = 12;
IRQpin = 16;
OUTpin = 12;
toggle = False
bouncetime = 1000 # microseconds

Expand All @@ -36,54 +36,54 @@ def buttonEventHandler_falling (pin, timestamp):
print(f'Pin = {pin:d}, timestamp = {timestamp:d}')
if (toggle == True):
# turn LED on
GPIO.output(LED_output,True)
GPIO.output(OUTpin,True)
toggle = False
else:
# turn LED off
GPIO.output(LED_output, False)
GPIO.output(OUTpin, False)
toggle = True

# main function
def main():
GPIO.setmode(GPIO.BCM)

# GPIO btn_input set up as input.
GPIO.setup(btn_input, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(LED_output, GPIO.OUT)
# GPIO IRQpin set up as input.
GPIO.setup(IRQpin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(OUTpin, GPIO.OUT, initial=GPIO.HIGH)

print('Test add_event_detect without callback, check if event fired with event_detected function')
GPIO.add_event_detect(btn_input, GPIO.FALLING, bouncetime=bouncetime)
GPIO.add_event_detect(IRQpin, GPIO.FALLING, bouncetime=bouncetime)
print('loop with event_detected until button pressed')
print()
while GPIO.event_detected(btn_input) == False:
while GPIO.event_detected(IRQpin) == False:
pass
print('button pressed detected, now remove event detection')
GPIO.remove_event_detect(btn_input)
GPIO.remove_event_detect(IRQpin)
print()

print('Test wait_for_edge with timeout 10s')
time.sleep(1)
channel = GPIO.wait_for_edge(btn_input, GPIO.RISING, bouncetime=bouncetime, timeout=10000)
channel = GPIO.wait_for_edge(IRQpin, GPIO.RISING, bouncetime=bouncetime, timeout=10000)
if (channel == -1):
print('wait_for_edge timeout')
elif (channel == btn_input):
elif (channel == IRQpin):
print('wait_for_edge fired')
else:
print(f'wait_for_edge returned {channel:d}')
print(f'wait_for_edge returned None, Timeout!')

print()
print(f'Now starting add_event_detect with interrupt on falling edge with callback and bouncetime {bouncetime:d} microseconds')
GPIO.add_event_detect(btn_input, GPIO.FALLING, callback=buttonEventHandler_falling, bouncetime=bouncetime)
GPIO.add_event_detect(IRQpin, GPIO.FALLING, callback=buttonEventHandler_falling, bouncetime=bouncetime)

try:
while True :
time.sleep(1)

except (Exception, KeyboardInterrupt):
print('Interrupted')
GPIO.remove_event_detect(btn_input)
GPIO.cleanup(btn_input)
GPIO.cleanup(LED_output)
GPIO.remove_event_detect(IRQpin)
GPIO.cleanup(IRQpin)
GPIO.cleanup(OUTpin)

if __name__=="__main__":
main()
Expand Down
2 changes: 1 addition & 1 deletion RPi/GPIO/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

from RPi._GPIO import *

VERSION = '0.8.4'
VERSION = '0.8.5'
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'Topic :: System :: Hardware']

setup(name = 'RPi.GPIO',
version = '0.8.4',
version = '0.8.5',
author = 'Ben Croston',
author_email = 'ben@croston.org',
description = 'A module to control Raspberry Pi GPIO channels',
Expand All @@ -45,4 +45,4 @@
url = 'http://sourceforge.net/projects/raspberry-gpio-python/',
classifiers = classifiers,
packages = ['RPi','RPi.GPIO'],
ext_modules = [Extension('RPi._GPIO', ['source/py_gpio.c', 'source/c_gpio.c', 'source/cpuinfo.c', 'source/event_gpio.c', 'source/soft_pwm.c', 'source/py_pwm.c', 'source/common.c', 'source/constants.c'], libraries=['wiringPi'])])
ext_modules = [Extension('RPi._GPIO', ['source/py_gpio.c', 'source/cpuinfo.c', 'source/event_gpio.c', 'source/soft_pwm.c', 'source/py_pwm.c', 'source/common.c', 'source/constants.c'], libraries=['wiringPi'])])
3 changes: 2 additions & 1 deletion source/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SOFTWARE.
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <inttypes.h>
#include "cpuinfo.h"

int get_rpi_info(rpi_info *info)
Expand Down Expand Up @@ -148,7 +149,7 @@ int get_rpi_info(rpi_info *info)
strcpy(info->revision, revision);

uint64_t rev;
sscanf(revision, "%llx", &rev);
sscanf(revision, "%"PRIx64 , &rev);
rev = rev & 0xefffffff; // ignore preceeding 1000 for overvolt

if (rev == 0x0002 || rev == 0x0003) {
Expand Down
11 changes: 6 additions & 5 deletions source/py_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SOFTWARE.
*/

#include "Python.h"
#include "c_gpio.h"
// #include "c_gpio.h"
#include "event_gpio.h"
#include "py_pwm.h"
#include "cpuinfo.h"
Expand Down Expand Up @@ -778,12 +778,12 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k
return NULL;

// check channel is set up as an input
if (gpio_direction[gpio] != INPUT)
/* if (gpio_direction[gpio] != INPUT)
{
PyErr_SetString(PyExc_RuntimeError, "You must setup() the GPIO channel as an input first");
return NULL;
}

*/
// is edge valid value
edge -= PY_EVENT_CONST_OFFSET;
if (edge != RISING_EDGE && edge != FALLING_EDGE && edge != BOTH_EDGE)
Expand Down Expand Up @@ -964,13 +964,14 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args, PyObject *kwar

result = waitForInterrupt(gpio, wiringPi_edge, timeout, bouncetime);

waitForInterruptClose( gpio );
// waitForInterruptClose( gpio );

if (result < 0LL) {
PyErr_SetString(PyExc_RuntimeError, "Error waiting for edge");
return NULL;
}
else if (result == 0LL) { // timeout
return Py_BuildValue("i", -1);
return Py_BuildValue(""); // return none
}
else {
return Py_BuildValue("i", gpio);
Expand Down

0 comments on commit 4965bd2

Please sign in to comment.