-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Ward
committed
Aug 28, 2018
1 parent
812b313
commit 2ca201a
Showing
5 changed files
with
51 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from RPi.GPIO import GPIO | ||
|
||
|
||
def pins_are_valid(pins, pin_numbering, force_selection=False): | ||
""" | ||
Check the pins specified are valid for pin numbering in use | ||
""" | ||
if pin_numbering == 'BOARD': # Set valid pins for BOARD | ||
valid_pins = [ | ||
7, 11, 12, 13, 15, 16, 18, 22, 29, 31, 32, 33, 36, 37 | ||
] | ||
elif pin_numbering == 'BCM': # Set valid pins for BCM | ||
valid_pins = [ | ||
4, 5, 6, 12, 13, 16, 17, 18, 22, 23, 24, 25, 26, 27 | ||
] | ||
else: # pin_numbering value invalid | ||
raise ValueError("pin_numbering must be either 'BOARD' or 'BCM'.") | ||
|
||
for pin in pins: | ||
pin_int = int(pin) | ||
if pin_int not in valid_pins and force_selection is False: | ||
err_str = ( | ||
"GPIO pin number must be from list of valid pins: %s" | ||
"\nTo use selected pins anyway, set force_selection=True " | ||
"in function call." % str(valid_pins)) | ||
raise ValueError(err_str) | ||
if pin in pins_in_use: | ||
raise ValueError('GPIO pin {} already in use.'.format(pin)) | ||
return True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters