You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
classPin:
ZERO=0ONE=1TWO=2THREE=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:
importboardimportbusiofromadafruit_ads1x15importPin# or ads1x15fromadafruit_ads1x15.ads1115importADS1115fromadafruit_ads1x15.analog_inimportAnalogIni2c=busio.I2C(board.SCL, board.SDA)
ads=ADS1115(i2c)
chan=AnalogIn(ads, Pin.ZERO) # or ads1x15.P0
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.
The text was updated successfully, but these errors were encountered:
pantheraleo-7
changed the title
Pin constants (P0, P1, P2 & P4) are common to both the ADCs, and should be extracted into a common module
Pin constants (P0, P1, P2 & P3) are common to both the ADCs, and should be extracted into a common module
Dec 7, 2024
Currently, these constants are repeated in both the
ads1015
andads1115
modules. This leads to not only duplication but also weird import statements.To access these constants the
ads1015
/ads1115
module is imported asADS
(because we want to name the object of theADS1015
/ADS1115
class asads
). This is in violation of PEP8 as module names are not written in all caps, and also leads to inconsistent import patterns since theAnalogIn
class is directly imported from its module (from .. import ..) whereas theADS1015
orADS1115
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: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:
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.The text was updated successfully, but these errors were encountered: