pyFirmata
pyFirmata copied to clipboard
Support for Ping (pulseIn Firmata) and other improvements
- Support for pulseIn compatible Firmata, needed for ultrasonic ranging sensors that use a pulse to measure distances: the new "ping" method to the Pin class returns the echo time. An utility function to convert to distance was also added.
- Improved the Board class, now it supports the Python "with" statement to be able to automagically manage the Iterator thread (autostarts the iterator, and takes care to call board.exit()).
- Better support for working with timeouts (useful when the communication with the board hangs -thought that should no longer happen if we use the new 'with' support-).
Hi, thanks for your extensive pull request. However, it is usually easier to implement features if they are small and contained. My reaction on these three proposals:
-
I can't find this anywhere in the https://github.com/firmata/arduino library, is that correct? Because I would like to keep this a lean library, and not add code for every different sensor out there. Implementing this should be fairly easy by extending the Board class in your own code. Or did you run into things that made this hard?
-
I really like the idea of running in a
with
block! However, to make it less "automagically" as you describe it somewhere I would be in favour of the following syntax, which is more explicit about what's happening:with Iterator(board): ...
Which is probably easiest implemented with an
_is_running
attribute on the Iterator. -
Instead of raising a different error, wouldn't it be better to check for the length of
self.sp.read()
before passing it intoord
alltogether? Or does this problem only occur when improperly exiting?
If you would like to move forward with one or more of these proposals, could you please do so in separate pull requests?
Also, please take PEP8 (https://www.python.org/dev/peps/pep-0008/) into account (use 4 spaces instead of tabs, etc.). I use flake8
to check this.
So, what's the status on this? any chance that pyFirmata will get ping support at some point?
This one would be really helpful, any chance we can provide pulse in through a special flag? without pulsein ultrasonic is not usable in firmata.
What can we do to make this PR successful?