-
Notifications
You must be signed in to change notification settings - Fork 58
Description
Currently, these constants are repeated in both the ads1015
and ads1115
modules. This leads to not only duplication but also weird import statements.
To access these constants the ads1015
/ads1115
module is imported as ADS
(because we want to name the object of the ADS1015
/ADS1115
class as ads
). This is in violation of PEP8 as module names are not written in all caps, and also leads to inconsistent import patterns since the AnalogIn
class is directly imported from its module (from .. import ..) whereas the ADS1015
or ADS1115
classes are not (import .. as ADS; ADS.ADS1015).
So I propose that these four constants should be copied over to ads1x15
module.
I see that various "enum-like" classes are already defined in the common ads1x15
module. So we could also do this:
class Pin:
ZERO = 0
ONE = 1
TWO = 2
THREE = 3
After this [backwards-compatible (as we are not removing these constants from their original locations)] implementation, I see the following improvements in the import/usage pattern:
import board
import busio
from adafruit_ads1x15 import Pin # or ads1x15
from adafruit_ads1x15.ads1115 import ADS1115
from adafruit_ads1x15.analog_in import AnalogIn
i2c = busio.I2C(board.SCL, board.SDA)
ads = ADS1115(i2c)
chan = AnalogIn(ads, Pin.ZERO) # or ads1x15.P0
as opposed to the current usage style.
Currently, the best workaround is from adafruit_ads1x15.ads1115 import ADS1115, P0
but I haven't seen any precedence for this nor does it seem like a good idea to import a constant directly.