Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various distance sensor fixes and enhancements #617

Merged
merged 5 commits into from Feb 19, 2018

Conversation

waveform80
Copy link
Member

See individual commits for details

About time we had a diagram for the distance sensor. Couldn't find any
reference to HC-SR04 in the Adafruit fritzing repo, but there was one
over in fritzing's project pages:

http://fritzing.org/projects/hc-sr04-project

(or rather in the comments on that page)
This fixes the issue with the DistanceSensor class constantly returning
the maximum distance value. The issue was caused by cab6cc8 which
changed the Pin.when_changed attribute to use weak references to all
handlers. DistanceSensor is the only thing that uses a local function
(not a bound method) as its pin handler. As the pin no longer kept a
reference to it, it disappeared after the constructor was complete and
the echo event never got set.

In addition, it introduces a class-level lock to prevent multiple
distance sensors from interfering with each other (it's the only current
"active" sensor, but this pattern should probably be followed with
future active sensors), and a brief delay between sensor reads to
prevent overlapping echo responses.

Note: this does *not* fix the issue with DistanceSensor operating
remotely over pigpio (which requires a change in the pin handlers); that
is currently scheduled for 1.5 and is why gpiozero#385 is remaining open for
now.
@codecov-io
Copy link

codecov-io commented Feb 16, 2018

Codecov Report

Merging #617 into master will decrease coverage by 0.01%.
The diff coverage is 92%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #617      +/-   ##
=========================================
- Coverage   84.71%   84.7%   -0.02%     
=========================================
  Files          36      36              
  Lines        6695    6700       +5     
=========================================
+ Hits         5672    5675       +3     
- Misses       1023    1025       +2
Impacted Files Coverage Δ
gpiozero/exc.py 100% <100%> (ø) ⬆️
gpiozero/input_devices.py 87.28% <91.66%> (-0.22%) ⬇️
gpiozero/mixins.py 77.35% <0%> (-0.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 458b4a8...a5b0ab2. Read the comment docs.

Ooops - left in a smaller value from oscilloscope testing, but the
larger value does permit better accuracy.
@waveform80 waveform80 added this to the v1.4.1 milestone Feb 19, 2018
@waveform80 waveform80 self-assigned this Feb 19, 2018
@waveform80 waveform80 merged commit 7a0654c into gpiozero:master Feb 19, 2018
@waveform80 waveform80 deleted the distance-sensor branch February 19, 2018 21:25
@tjguk tjguk mentioned this pull request Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants