Skip to content

enable non-PWM pins for backlight color, add kattni's pi-specific simpletest #16

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 5 commits into from
Oct 26, 2018

Conversation

brennen
Copy link
Contributor

@brennen brennen commented Oct 25, 2018

Rationale: pulseio isn't available on CPython Linux systems (i.e. the Pi), this mimics the design of the original Adafruit_Python_CharLCD.

Adds enable_pwm parameter (defaults to True) to Character_LCD_RGB constructor, and conditionalizes handling of the color pins on this value. If PWM is disabled, pins should be DigitalInOut instances.

It's entirely possible I've messed something up here, so close review is appreciated.

Rationale: pulseio isn't available on CPython Linux systems (i.e.
the Pi), this mimics the design of the original
Adafruit_Python_CharLCD.

Adds `enable_pwm` parameter to Character_LCD_RGB constructor, and
conditionalizes handling of the color pins on this value.

It's entirely possible I've messed something up here, so close
review is appreciated.
@ladyada
Copy link
Member

ladyada commented Oct 25, 2018

rather than enabling pwm, check the attrs?

@brennen
Copy link
Contributor Author

brennen commented Oct 25, 2018

yeah, i wasn't super comfortable with the enable_pwm thing, but i'm also not sure what the idiomatic thing to do is here - isinstance on the pin objects? still feels sort of hacky...

@ladyada
Copy link
Member

ladyada commented Oct 26, 2018

i know kattni's done a lot more of this with analog/pwm pins - i'll defer to her wisdom :D

@kattni
Copy link
Contributor

kattni commented Oct 26, 2018

I'm not super keen on this setup. We've discussed a couple of options such as creating a subclass for non-pwm pins or checking the object types (which also isn't great). Adding CircuitPython LIbrarians.

@kattni kattni requested a review from a team October 26, 2018 00:31
@caternuson
Copy link
Contributor

Why no love for isinstance? Seems like an OK way to me.

@brennen
Copy link
Contributor Author

brennen commented Oct 26, 2018

i've gotten a "that's how you do that but you shouldn't want to do that" vibe every time i've googled this in the past, but if it doesn't raise alarm bells for people more steeped in Python Aesthetic than i am, i'll just go that route. threading a bunch of logic around that sort of type check can get weird, but i guess we're not dealing with all that complex a piece of code here...

@sommersoft
Copy link
Collaborator

I would say isinstance() too. Additionally, even if enable_pwm was kept, I would still check the objects to make sure they matched expected behavior (even though set_color() would still raise an exception).

@brennen
Copy link
Contributor Author

brennen commented Oct 26, 2018

wrote the isinstance() version, then did a bit more googling and realized what ladyada meant about checking the attrs.

@caternuson
Copy link
Contributor

I like it. Do you need the check in __init__ at all? Just set direction to OUTPUT. The check in set_color takes care of it from there.

@brennen
Copy link
Contributor Author

brennen commented Oct 26, 2018

Do you need the check in init at all?

yeah, it at least needs to discern there between being a DigitalInOut or a PWMOut, since the latter doesn't have direction.

# Assume a digitalio.DigitalInOut or compatible interface:
pin.direction = digitalio.Direction.OUTPUT
else:
if not hasattr(pin, 'duty_cycle'):
Copy link
Member

Choose a reason for hiding this comment

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

Super minor but this can be:

elif not hasattr(pin, 'duty_cycle'):

@tannewt
Copy link
Member

tannewt commented Oct 26, 2018

hasattr looks good to me. 👍

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

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

Thanks for the input everyone! Looks great!

@kattni kattni merged commit 375ce69 into master Oct 26, 2018
@brennen brennen deleted the pi_rgb_toggle branch October 26, 2018 19:35
tannewt pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 27, 2018
Updating https://github.com/adafruit/Adafruit_CircuitPython_CharLCD to 2.4.0 from 2.3.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#16 from adafruit/pi_rgb_toggle
  > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#15 from kattni/rpi-example
  > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#14 from adafruit/kattni-patch-1
  > ignore the board module imports in .pylintrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants