Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Add AIY common drivers. #90

Merged
merged 4 commits into from
Jun 29, 2017
Merged

Add AIY common drivers. #90

merged 4 commits into from
Jun 29, 2017

Conversation

enetor
Copy link
Contributor

@enetor enetor commented Jun 27, 2017

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.

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.
@enetor enetor self-assigned this Jun 27, 2017
@enetor enetor requested review from drigz and ensonic June 27, 2017 00:52
@codecov-io
Copy link

codecov-io commented Jun 27, 2017

Codecov Report

Merging #90 into master will increase coverage by 55.87%.
The diff coverage is n/a.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
src/triggers/__init__.py

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 4875227...7fcc47e. Read the comment docs.

Copy link
Member

@drigz drigz left a 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.

# limitations under the License.
"""This library provides common drivers for the AIY projects.

Drivers in this module requires GPIO.setmode(GPIO.BCM).
Copy link
Member

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.

Copy link
Contributor Author

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:
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

def start(self):
"""Starts the LED driver."""
with self.lock:
if not self.running:
Copy link
Contributor

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)

Copy link
Contributor Author

@enetor enetor Jun 27, 2017

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)

return
if state:
if not self._parse_state(state):
print('unsupported state: %d' % state)
Copy link
Contributor

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.

Copy link
Contributor

@ensonic ensonic left a 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.
Copy link
Contributor Author

@enetor enetor left a 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")
Copy link
Contributor

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.

Copy link
Contributor Author

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)")
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@ensonic ensonic left a 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

Copy link
Contributor

@ensonic ensonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@enetor enetor merged commit 5245e12 into master Jun 29, 2017
@enetor enetor deleted the aiy_common branch June 29, 2017 18:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants