-
Notifications
You must be signed in to change notification settings - Fork 693
Conversation
This change includes two common drivers: 1) Button - A GPIO-based button driver that automatically debounces the GPIO signal. 2) LED - A GPIO- and PWM-based LED driver that supports a set of simple LED patterns. Tested: Manually tested on a RPi3 + VoiceHat.
Codecov Report
@@ Coverage Diff @@
## master #90 +/- ##
===========================================
+ Coverage 9.95% 65.83% +55.87%
===========================================
Files 3 2 -1
Lines 1727 161 -1566
Branches 297 16 -281
===========================================
- Hits 172 106 -66
+ Misses 1543 52 -1491
+ Partials 12 3 -9
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice start!
Let's see what @ensonic thinks, as he knows more about the LED service.
src/aiy/common.py
Outdated
# limitations under the License. | ||
"""This library provides common drivers for the AIY projects. | ||
|
||
Drivers in this module requires GPIO.setmode(GPIO.BCM). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call this in the code (eg after importing or in __init__
) then it is enforced in code. setmode
can safely be called multiple times with the same mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return True | ||
|
||
|
||
class LED: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a plan for how this will be used? Currently we have a status-led
service that animates even when the voice recognizer isn't running (eg during bootup). If we're going to keep that, maybe it would be better to have an API for the service here, instead of a second implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for avoiding two implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea is to have the status-led service call this API instead. The benefit of having a standalone API for LEDs is potential users may utilize this API for their own app, not just a global LED service.
So no there won't be two implementations. And yes the status-led service will still be available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. status-led now calls into aiy.common directly, eliminating the duplicate implementation of the LED driver.
src/aiy/common.py
Outdated
def start(self): | ||
"""Starts the LED driver.""" | ||
with self.lock: | ||
if not self.running: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would we need the lock here? If it is not running, there is no concurrency. If it is running we change a boolean which does not require a lock in python (GIL)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I am wrong, but I think there could be contentions here. Changing the boolean is fine. But self.pwm.start(0) could be called after self.animator.start()
Two threads calling my_led.start()
(#1) self.running = True
(#2) self.running = True
self.pwm.start(0)
self.animator.start()
(#1) self.pwm.start(0)
src/aiy/common.py
Outdated
return | ||
if state: | ||
if not self._parse_state(state): | ||
print('unsupported state: %d' % state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use logging instead of printf or raise a ValueError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a few comments from my side as well.
The status-led service will now call into aiy.common.LED. Also raise a ValueError when an unexpected state is passed to aiy.common.LED.set_state. Tested: Tried src/main.py and observed expected LED animations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL thanks!
src/led.py
Outdated
import RPi.GPIO as GPIO | ||
|
||
logger = logging.getLogger('led') | ||
logger = logging.getLogger("led") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I though we use single quotes for string literals in most of the places. Please keep those as they were.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was changed by pyformat.
src/led.py
Outdated
"--gpio-pin", | ||
default=25, | ||
type=int, | ||
help="GPIO pin for the LED (default: 25)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of reformatting is not helpful. I see that both calls used different wrapping styles (new line for each args or not), but here you just flip it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not manually reformat the code, but pyformat did. At some point we have to automate this with some tool, preferably pyformat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a few nits left
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This change includes two common drivers:
Button - A GPIO-based button driver that automatically debounces the
GPIO signal.
LED - A GPIO- and PWM-based LED driver that supports a set of simple
LED patterns.
Tested:
Manually tested on a RPi3 + VoiceHat.