scottsilverlabs / raspberrystem

raspberrySTEM(TM) Educational and Hobbyist Development Kit based on the Raspberry Pi
www.raspberrystem.com
Apache License 2.0
3 stars 0 forks source link

Pins #79

Closed brian-silverman closed 9 years ago

brian-silverman commented 10 years ago

What is the rationale for this class? One thing that it has (which is useful and needed) is the validate_pin function, based on PINS. But I think it would make more sense to push this into the Pin class.

Thoughts?

jpsnyder commented 10 years ago

Are you talking about the Button class?

jpsnyder commented 10 years ago

Oh, sorry. I just realized your talking about the Pins (plural) class. I didn't touch this class too much besides renaming it from "Gpios". But yeah I agree, initializing all the pins can be wasteful and should be created as needed.

We could either make validate_pin() or have a check during initialization of a pin.

The only reason I could think of having something similar to this is if we wanted to initialize all the buttons for the gamer lid at once.

brian-silverman commented 10 years ago

I suspect I wrote this (class Pins), and I'm think now that my intent was to have a way to export a set of functions that worked for pre-initialized pins (and that the user would have to futz with a "Class"). This is perhaps kinda silly.

So the old way, to configure and set an output would have been (given the class Pins exists):

gpio.configure(2, gpio.OUTPUT)
gpio.set_level(2, 1)

whereas the new idea (with you're latest class Pin and some ):

p = g.Pin(2, g.OUT)
p.set_level(1)

I like the new way better, because you only configure the pin number once (its contained in the object).

Finally, I think having both a is_valid() function, AND raising an exception on init if its not valid would be good.

brian-silverman commented 9 years ago

Deprecated