Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit 4f2ea83

Browse files
committedJan 3, 2015
Add GPIO cleanup function to remove event detection.
1 parent 60c66d4 commit 4f2ea83

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed
 

‎Adafruit_GPIO/GPIO.py

+24
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ def wait_for_edge(self, pin, edge):
121121
FALLING or BOTH."""
122122
raise NotImplementedError
123123

124+
def cleanup(self, pin=None):
125+
"""Clean up GPIO event detection for specific pin, or all pins if none
126+
is specified.
127+
"""
128+
raise NotImplementedError
129+
124130
class RPiGPIOAdapter(BaseGPIO):
125131
"""GPIO implementation for the Raspberry Pi using the RPi.GPIO library."""
126132

@@ -203,6 +209,15 @@ def wait_for_edge(self, pin, edge):
203209
"""
204210
self.rpi_gpio.wait_for_edge(pin, self._edge_mapping[edge])
205211

212+
def cleanup(self, pin=None):
213+
"""Clean up GPIO event detection for specific pin, or all pins if none
214+
is specified.
215+
"""
216+
if pin is None:
217+
self.rpi_gpio.cleanup()
218+
else:
219+
self.rpi_gpio.cleanup(pin)
220+
206221
class AdafruitBBIOAdapter(BaseGPIO):
207222
"""GPIO implementation for the Beaglebone Black using the Adafruit_BBIO
208223
library.
@@ -281,6 +296,15 @@ def wait_for_edge(self, pin, edge):
281296
"""
282297
self.bbio_gpio.wait_for_edge(pin, self._edge_mapping[edge])
283298

299+
def cleanup(self, pin=None):
300+
"""Clean up GPIO event detection for specific pin, or all pins if none
301+
is specified.
302+
"""
303+
if pin is None:
304+
self.bbio_gpio.cleanup()
305+
else:
306+
self.bbio_gpio.cleanup(pin)
307+
284308

285309
def get_platform_gpio(**keywords):
286310
"""Attempt to return a GPIO instance for the platform which the code is being

‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
requires.append('spidev')
1212

1313
setup(name = 'Adafruit_GPIO',
14-
version = '0.7',
14+
version = '0.7.1',
1515
author = 'Tony DiCola',
1616
author_email = 'tdicola@adafruit.com',
1717
description = 'Library to provide a cross-platform GPIO interface on the Raspberry Pi and Beaglebone Black using the RPi.GPIO and Adafruit_BBIO libraries.',

‎test/test_GPIO.py

+24
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ def test_wait_for_edge(self):
118118
adapter.wait_for_edge(1, GPIO.FALLING)
119119
rpi_gpio.wait_for_edge.assert_called_with(1, rpi_gpio.FALLING)
120120

121+
def test_cleanup(self):
122+
rpi_gpio = Mock()
123+
adapter = GPIO.AdafruitBBIOAdapter(rpi_gpio)
124+
adapter.cleanup()
125+
rpi_gpio.cleanup.assert_called()
126+
127+
def test_cleanup_pin(self):
128+
rpi_gpio = Mock()
129+
adapter = GPIO.AdafruitBBIOAdapter(rpi_gpio)
130+
adapter.cleanup(1)
131+
rpi_gpio.cleanup.assert_called_with(1)
132+
121133

122134
class TestAdafruitBBIOAdapter(unittest.TestCase):
123135
def test_setup(self):
@@ -184,6 +196,18 @@ def test_wait_for_edge(self):
184196
adapter.wait_for_edge(1, GPIO.FALLING)
185197
bbio_gpio.wait_for_edge.assert_called_with(1, bbio_gpio.FALLING)
186198

199+
def test_cleanup(self):
200+
bbio_gpio = Mock()
201+
adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)
202+
adapter.cleanup()
203+
bbio_gpio.cleanup.assert_called()
204+
205+
def test_cleanup_pin(self):
206+
bbio_gpio = Mock()
207+
adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio)
208+
adapter.cleanup(1)
209+
bbio_gpio.cleanup.assert_called_with(1)
210+
187211

188212
class TestGetPlatformGPIO(unittest.TestCase):
189213
@patch.dict('sys.modules', {'RPi': Mock(), 'RPi.GPIO': Mock()})

0 commit comments

Comments
 (0)
This repository has been archived.