Skip to content

Commit

Permalink
Integrate a number of existing RPi.GPIO API examples and much more
Browse files Browse the repository at this point in the history
changes in this patch:
	.coveragerc:
	- report coverage information on RPi/core.py instead
	  of RPi/_GPIO.py due to file name change

	Makefile:
	- %s/unit-cov/test-cov/g
	- removed an extraneous comment

	RPi/GPIO/__init__.py:
	RPi/GPIO_DEVEL/__init__.py:
	- Added header docstrings
	- formatted and sorted API imports

	RPi/_GPIO.py -> RPi/core.py:
	- File renamed to clarify purpose
	- convert header to docstring format
	- sort and organize functions and constants
	- fix documentation errors and gramatical mistakes
	- add automatic invokation of cleanup() at interpreter exit
	- add RPi.GPIO.{RPI_INFO, RPI_REVISION, VERSION} constants
	- fix various cases of mishandling of iterable channel and value
	  lists
	- fix pwm thread never releasing lock if thread dies due to
	  exception when the main thread revokes access, however I
	  suspect that this actually be a surface fix for another bug,
	  will look into further (#29)
	- small tweaks to improve modularity
	- add support for single value and iterable lists of values for
	  RPi.GPIO.cleanup()
	- allow PwM to successfully start without explicitly setting up
	  a channel as an output because this library has a more relaxed
	  attitude about those things
	- add warn on invalid call to PWM.start()
	- fix board numbering mode being actually pretty broken due to
	  inconsistent mishandling of channel inputs of various forms
	- fix line_get_value being actually very broken and not
	  retuning anything and therefore always returning None
	- fix gpio_function() being actually entirely broken so it
	  returns the current function representing what is going on on
	  a GPIO channel as RPi.GPIO would, but this requires further
	  testing (#30)
	- fix RPi.GPIO.PWM.start() not returning the truth of whether a
	  PwM thread has been successfully started or not

	examples/callback2.py:
	- add shabang

	examples/flash18.py:
	- remove debuginfo output toggle

	examples/input_examples.py:
	examples/output_examples.py:
	examples/pwm2.py:
	examples/pwm_usage.py:
	examples/random_usage.py:
	examples/try_import.py:
	- copy example code from Ben Croston's RPi.GPIO wiki on
	  sourceforge
	- see the files for the sources
	- ensure that the code works with this library. I found quite a
	  few bugs integrating these files
	- fix a few mistakes in the code
	- fix style

	examples/morse.py:
	- update morse code to current API version
	- add basic input validation
	- fix style

	examples/pwm.py:
	- renamed to pwm1.py for consistency

	examples/pwm1.py:
	- add try except structure
	- this may be revelvant to (#29)

	examples/pwm3.py:
	examples/pwm4.py:
	- Copy example code from some forum
	- see the files for the sources

	non_root_permission.sh:
	- expand note on lack of persistence of effects post reboot

	spec/spec.tex:
	- fix some typos
	- tweak style and title
	- add entry for channel_valid_or_die
	- update some of the technical spec

	spec/sources.bib:
	- replace \url with \textt

	spec/spec.pdf:
	- regenerate document with 1 inch margins

	test-style.sh:
	- scan RPi/core.py instead of RPi/_GPIO.py due to name change
	- add scan of examples/morese.py since it is again working

	tests/test_gpio.py:
	- style tweaks
	- fix test_gpio_function by making it actually test for the
	  feature that now is possibly implemented correctly
	- modify test_setdebug info to turn it off before the next call
	  to Reset to avoid printing a lot of text to the terminal
	- extend test_cleanup to validate the new features of cleanup()

	tests/test_pwm.py:
	- more thoroughly test PWM.start()

Signed-off-by: Joel Savitz <[email protected]>
  • Loading branch information
theyoyojo committed Jun 18, 2020
1 parent 00e7588 commit 7aaeb2f
Show file tree
Hide file tree
Showing 25 changed files with 1,182 additions and 567 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[report]
include = RPi/_GPIO.py
include = RPi/core.py
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Makefile to automate common testing procedures for python3-libgpiod-rpi
# By Joel Savitz
# This is free software, see LICENSE for details

all: test

test: unit-cov style
#@echo "MAKE TEST PASS"
test: test-cov style

unit-cov:
test-cov:
@bash test-cov.sh -m && echo "FUNTIONAL PASS" || echo "FAILURE IN UNIT TEST"

style:
Expand Down
56 changes: 49 additions & 7 deletions RPi/GPIO/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
# The extended RPi.GPIO API
from RPi._GPIO import setup, cleanup, output, input, setmode, getmode, add_event_detect, remove_event_detect, event_detected, \
add_event_callback, wait_for_edge, gpio_function, setwarnings, \
getbias, setbias, getdirection, setdirection, getactive_state, setactive_state, \
channel_valid_or_die, \
BCM, BOARD, UNKNOWN, IN, OUT, RISING, FALLING, BOTH, PUD_UP, PUD_DOWN, PUD_OFF, PUD_DISABLE, \
HIGH, LOW, PWM, I2C, SPI, HARD_PWM, SERIAL
"""
The RPi.GPIO API
Originally created by Ben Croston
Reimplemented and extended by Joel Savitz and Fabrizio D'Angelo
This is free software, see LICENSE for details
"""

from RPi.core import\
BCM,\
BOARD,\
BOTH,\
FALLING,\
HARD_PWM,\
HIGH,\
I2C,\
IN,\
LOW,\
OUT,\
PUD_DISABLE,\
PUD_DOWN,\
PUD_OFF,\
PUD_UP,\
PWM,\
RISING,\
RPI_INFO,\
RPI_REVISION,\
SPI,\
UNKNOWN,\
VERSION,\
add_event_callback,\
add_event_detect,\
channel_valid_or_die,\
cleanup,\
event_detected, \
getactive_state,\
getbias,\
getdirection,\
getmode,\
gpio_function,\
input,\
output,\
remove_event_detect,\
setactive_state,\
setbias,\
setdirection,\
setmode,\
setup,\
setwarnings,\
wait_for_edge
24 changes: 21 additions & 3 deletions RPi/GPIO_DEVEL/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Development functions, not needed for normal use
from RPi._GPIO import Reset, State_Access, setdebuginfo, is_all_ints, is_all_bools_or_directions,\
is_iterable, line_get_mode, line_set_mode, _line_mode_none, _line_mode_out, _line_mode_in
"""
The new RPi.GPIO_DEVEL development and debug API
By Joel Savitz and Fabrizio D'Angelo
This is free software, see LICENSE for details
"""

# We have added functions and constants to this list as we have seen
# necesary but we are open to adding more if there is any interest

from RPi.core import\
is_all_bools_or_directions,\
is_all_ints,\
is_iterable,\
Reset,\
setdebuginfo,\
State_Access,\
line_get_mode,\
line_set_mode,\
_line_mode_in,\
_line_mode_none,\
_line_mode_out
Loading

0 comments on commit 7aaeb2f

Please sign in to comment.