Skip to content

Refactor to include CLUE #23

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

Merged
merged 15 commits into from
Feb 20, 2020
Merged

Conversation

kattni
Copy link
Contributor

@kattni kattni commented Feb 19, 2020

THIS IS A BREAKING CHANGE. Import is no longer the same and the library no longer requires instantiation. It is now:

from adafruit_pybadger import pyadger

All code beyond import and instantiation should function the same if library was instantiated as pybadger. To use features, simply include them as pybadger.foo, e.g.:

print(pybadger.acceleration)
pybadger.show_qr_code()

Updates:

  • No new features have been added.
  • Board type is automatically detected and applicable features are imported.
  • Features that are not supported on a given board throw a clear error.

Tested on PyBadge/LC, PyGamer and CLUE.

@nnja Feel free to test this with your code.

Copy link
Member

@ladyada ladyada left a comment

Choose a reason for hiding this comment

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

lgtm but did not test on hardware!

@caternuson
Copy link
Contributor

Want to update the README.rst also as part of this PR?

@kattni
Copy link
Contributor Author

kattni commented Feb 19, 2020

@caternuson Yes. I missed that. The example? Or is there more that needs to be updated.

@FoamyGuy
Copy link
Contributor

@kattni the sentence in the introduction section could mention CLUE along with pybadge and pygamers as devices the library is made to be used with.

@kattni
Copy link
Contributor Author

kattni commented Feb 19, 2020

@FoamyGuy Already fixed, thanks!

@caternuson
Copy link
Contributor

caternuson commented Feb 19, 2020

EDIT yah like that ⬆️

@kattni what @FoamyGuy said.

And also the example :)

@makermelissa
Copy link
Collaborator

I've been trying out the customizations to make sure they're looking good and so far they are.

843AD703-732E-4858-B092-04EE9D6E6F8D_1_105_c

@kattni
Copy link
Contributor Author

kattni commented Feb 19, 2020

@makermelissa Thank you so much for thorough testing!

@makermelissa
Copy link
Collaborator

You're welcome. I know it didn't get tested as thoroughly the first time we did PyBadger.

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

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

Code looks good to me. Tested on PyBadge, EdgeBadge, CLUE, and PyGamer.

@kattni
Copy link
Contributor Author

kattni commented Feb 19, 2020

@FoamyGuy Made a valid point regarding leaving in the d-pad treatment of the joystick on PyGamer. He's going to test this refactor tonight with a game example he wrote for PyBadge/PyGamer and let me know if it's worth keeping in. I removed it as it seemed redundant, but it allows for programs using the d-pad functionality to work on PyBadge and PyGamer with no changes, something I had not considered. He will reply here to let me know, and I may add that back in, meaning it will need to be tested again on PyGamer.

@makermelissa I will ping you as well if I make the change.

@makermelissa
Copy link
Collaborator

@kattni, are you saying we would add the joystick d-pad functionality back in, and retain the analog joystick function? I hope that's what you're saying, as I think having both would be very useful.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Looks great! Nice job!

@kattni
Copy link
Contributor Author

kattni commented Feb 19, 2020

@makermelissa Yes, both would remain in.


from adafruit_pybadger import PyBadger

pybadger = PyBadger()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think some of the comments still have the old style example usage instead of the new way:
from adafruit_pybadger import pybadger

pybadge and clue files have some as well this way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Thank you!

@FoamyGuy
Copy link
Contributor

I do think it's worth having the joystick to D-pad buttons treatment.

I tested this out with my game example on EdgeBadge and PyGamer, and it does break with the current code on the PyGamer. Users could implement this logic in the application layer like inside my game, but I do think it's nicer to have one simple interface across the PyGamer and PyBadge devices so potential app and game developers don't have to worry about the difference if they aren't using the joystick in a more analog way.

@kattni
Copy link
Contributor Author

kattni commented Feb 20, 2020

@FoamyGuy Please test the changes I pushed. Thanks!

@FoamyGuy
Copy link
Contributor

@kattni I'm getting this error on PyGamer now:

Traceback (most recent call last):
  File "code.py", line 504, in <module>
  File "code.py", line 372, in <module>
  File "/lib/adafruit_pybadger/pygamer.py", line 111, in button
NameError: name 'x' is not defined

@kattni
Copy link
Contributor Author

kattni commented Feb 20, 2020

@FoamyGuy I'll look into it.

@FoamyGuy
Copy link
Contributor

@kattni took a peek myself as well. Looks like it needs this:

x, y = self.joystick

I added that back in and it's working now.

@kattni
Copy link
Contributor Author

kattni commented Feb 20, 2020

@FoamyGuy Already pushed :)

@FoamyGuy
Copy link
Contributor

testing the new one now

@FoamyGuy
Copy link
Contributor

@kattni working perfectly now :) thank you!

@kattni
Copy link
Contributor Author

kattni commented Feb 20, 2020

@makermelissa If you could test the update as well, I'd appreciate it. Thanks!

@makermelissa
Copy link
Collaborator

Sure thing @kattni

@makermelissa
Copy link
Collaborator

It seems to be working great.

@kattni
Copy link
Contributor Author

kattni commented Feb 20, 2020

@makermelissa Thank you very much!

Copy link
Contributor

@nnja nnja left a comment

Choose a reason for hiding this comment

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

One question and one minor nit, otherwise LGTM 👍

digitalio.DigitalInOut(board.BUTTON_OUT),
digitalio.DigitalInOut(board.BUTTON_LATCH))

self._light_sensor = analogio.AnalogIn(board.A7)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to check if the light sensor isn't present, like for the pybadge LC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PyBadge LC has a light sensor. It's at the top, next to the reset button, with a hole over it to pass the front of the sensor through to the front of the board. From the back, it is white with a green symbol printed on it.

The lack of a light sensor would only be detectable in very specific situations (depending on whether the pin is connected to something else, has pull up or down, etc), and is a complicated process to do so. Knowing that the CLUE doesn't have the same light sensor, I included it in the unsupported list within the CLUE module. In the case of PyBadge vs. PyBadge LC, there's no way to tell the difference as they use the same CircuitPython build - there is no separate pin definition for PyBadge LC.

Copy link
Contributor

Choose a reason for hiding this comment

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

D'oh, I meant the accelerometer, not the light sensor.

If it's possible to auto detect that, then this line from the example could be modified or removed to make the experience on a PyBadge LC a little nicer.

pybadger.auto_dim_display(delay=10) # Remove or comment out this line if you have the PyBadge LC

Copy link
Contributor

@FoamyGuy FoamyGuy Feb 22, 2020

Choose a reason for hiding this comment

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

Try checking what pybadger.acceleration returns on the LC. I think it might end up as None on there but I don't have one to check with.

Along the same idea of improving the auto_dim: what if pressing any button would reset the dim timer. That would help all of the boards and allow for at least one type of auto_dim on the LC device.

@makermelissa makermelissa merged commit bf25d8b into adafruit:master Feb 20, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 21, 2020
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.

8 participants