Skip to content

Move consts related to user settings to class level. #21

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

Closed
caternuson opened this issue Dec 21, 2018 · 8 comments
Closed

Move consts related to user settings to class level. #21

caternuson opened this issue Dec 21, 2018 · 8 comments
Assignees

Comments

@caternuson
Copy link
Contributor

The register addresses are OK at the module level. But for things like mode (maybe that's the only one?) there is no convenient way to access them when using the recommended code setup:

import board, busio
import adafruit_ads1x15.ads1015 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

i2c = busio.I2C(board.SCL, board.SDA)
ads = ADS.ADS1015(i2c)
ads.mode = 0 # don't have access to _ADS1X15_CONFIG_MODE_CONTINUOUS  

Having these at the class level would allow:

ads.mode = ADS._ADS1X15_CONFIG_MODE_CONTINUOUS

May also want to change their names? Or just add new ones? So could:

ads.mode = ADS.CONTINUOUS
@tannewt
Copy link
Member

tannewt commented Jan 3, 2019

Module level is how I've seen it done in other places. The more proper way is to do it as a Python enum which is essentially an empty class with statics. So it'd be ads.mode = ADS.Mode.CONTINUOUS. digitalio.Pull is modeled this way.

@caternuson
Copy link
Contributor Author

Thanks. That make more sense. I'll try and implement something and PR it.

@caternuson caternuson self-assigned this Jan 4, 2019
@sommersoft
Copy link
Collaborator

Just tossing in my support/agreeance @caternuson. These could definitely be more useful at the class level, especially so that the user doesn't have to remember which integer matches a mode.

@caternuson
Copy link
Contributor Author

Yah, I totally did a sloppy job on this. I hit this myself when I was trying to help someone change mode and realized they didn't have anything convenient to use on the right hand side. They need to be able to do ads.mode = SOMETHING_OBVIOUS_AND_EASY_TO_REMEMBER

@caternuson
Copy link
Contributor Author

Done. See #25

@makermelissa
Copy link
Collaborator

Did you want to do the release?

@makermelissa
Copy link
Collaborator

Or I can... :)

@caternuson
Copy link
Contributor Author

Thanks!

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

No branches or pull requests

4 participants