Skip to content

Commit aba3114

Browse files
committed
re-export classes to package-level; extract out constants common to both
ads modules to the generic adsx module
1 parent 648ad4b commit aba3114

File tree

4 files changed

+53
-28
lines changed

4 files changed

+53
-28
lines changed

adafruit_ads1x15/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2018 Carter Nelson for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2025 Asadullah Shaikh <github.com/pantheraleo-7>
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
"""
7+
`adafruit_ads1x15`
8+
====================================================
9+
10+
Support for the ADS1x15 series of analog-to-digital converters.
11+
12+
* Author(s): Carter Nelson
13+
"""
14+
15+
from .ads1015 import ADS1015
16+
from .ads1115 import ADS1115
17+
from .analog_in import AnalogIn
18+
19+
__all__ = ["ADS1015", "ADS1115", "AnalogIn"]

adafruit_ads1x15/ads1015.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@
3333
3300: 0x00C0,
3434
}
3535

36-
# Pins
37-
P0 = 0
38-
"""Analog Pin 0"""
39-
P1 = 1
40-
"""Analog Pin 1"""
41-
P2 = 2
42-
"""Analog Pin 2"""
43-
P3 = 3
44-
"""Analog Pin 3"""
45-
4636

4737
class ADS1015(ADS1x15):
4838
"""Class for the ADS1015 12 bit ADC."""

adafruit_ads1x15/ads1115.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@
3434
860: 0x00E0,
3535
}
3636

37-
# Pins
38-
P0 = 0
39-
"""Analog Pin 0"""
40-
P1 = 1
41-
"""Analog Pin 1"""
42-
P2 = 2
43-
"""Analog Pin 2"""
44-
P3 = 3
45-
"""Analog Pin 3"""
46-
4737

4838
class ADS1115(ADS1x15):
4939
"""Class for the ADS1115 16 bit ADC."""

adafruit_ads1x15/ads1x15.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@
5353
16: 0x0A00,
5454
}
5555

56+
# Pins
57+
A0 = 0
58+
"""Analog Pin 0"""
59+
A1 = 1
60+
"""Analog Pin 1"""
61+
A2 = 2
62+
"""Analog Pin 2"""
63+
A3 = 3
64+
"""Analog Pin 3"""
65+
5666

5767
class Mode:
5868
"""An enum-like class representing possible ADC operating modes."""
@@ -141,7 +151,9 @@ def __init__(
141151
):
142152
self._last_pin_read = None
143153
self.buf = bytearray(3)
144-
self.initialized = False # Prevents writing to ADC until all values are initialized
154+
self.initialized = (
155+
False # Prevents writing to ADC until all values are initialized
156+
)
145157
self.i2c_device = I2CDevice(i2c, address)
146158
self.gain = gain
147159
self.data_rate = self._data_rate_default() if data_rate is None else data_rate
@@ -214,7 +226,9 @@ def comparator_queue_length(self) -> int:
214226
def comparator_queue_length(self, comparator_queue_length: int) -> None:
215227
possible_comp_queue_lengths = self.comparator_queue_lengths
216228
if comparator_queue_length not in possible_comp_queue_lengths:
217-
raise ValueError(f"Comparator Queue must be one of: {possible_comp_queue_lengths}")
229+
raise ValueError(
230+
f"Comparator Queue must be one of: {possible_comp_queue_lengths}"
231+
)
218232
self._comparator_queue_length = comparator_queue_length
219233
if self.initialized:
220234
self._write_config()
@@ -243,7 +257,9 @@ def comparator_low_threshold(self, value: int) -> None:
243257
:param int value: 16-bit signed integer to write to register
244258
"""
245259
if value < -32768 or value > 32767:
246-
raise ValueError("Comparator Threshold value must be between -32768 and 32767")
260+
raise ValueError(
261+
"Comparator Threshold value must be between -32768 and 32767"
262+
)
247263

248264
self._comparator_low_threshold = value
249265
self._write_register(_ADS1X15_POINTER_LO_THRES, self.comparator_low_threshold)
@@ -255,7 +271,9 @@ def comparator_high_threshold(self, value: int) -> None:
255271
:param int value: 16-bit signed integer to write to register
256272
"""
257273
if value < -32768 or value > 32767:
258-
raise ValueError("Comparator Threshold value must be between -32768 and 32767")
274+
raise ValueError(
275+
"Comparator Threshold value must be between -32768 and 32767"
276+
)
259277

260278
self._comparator_high_threshold = value
261279
self._write_register(_ADS1X15_POINTER_HI_THRES, self.comparator_high_threshold)
@@ -423,20 +441,28 @@ def _read_config(self) -> None:
423441
config_value = self._read_register(_ADS1X15_POINTER_CONFIG)
424442

425443
self.gain = next(
426-
key for key, value in _ADS1X15_CONFIG_GAIN.items() if value == (config_value & 0x0E00)
444+
key
445+
for key, value in _ADS1X15_CONFIG_GAIN.items()
446+
if value == (config_value & 0x0E00)
427447
)
428448
self.data_rate = next(
429-
key for key, value in self.rate_config.items() if value == (config_value & 0x00E0)
449+
key
450+
for key, value in self.rate_config.items()
451+
if value == (config_value & 0x00E0)
430452
)
431453
self.comparator_queue_length = next(
432454
key
433455
for key, value in _ADS1X15_CONFIG_COMP_QUEUE.items()
434456
if value == (config_value & 0x0003)
435457
)
436458
self.mode = Mode.SINGLE if config_value & 0x0100 else Mode.CONTINUOUS
437-
self.comparator_mode = Comp_Mode.WINDOW if config_value & 0x0010 else Comp_Mode.TRADITIONAL
459+
self.comparator_mode = (
460+
Comp_Mode.WINDOW if config_value & 0x0010 else Comp_Mode.TRADITIONAL
461+
)
438462
self.comparator_polarity = (
439-
Comp_Polarity.ACTIVE_HIGH if config_value & 0x0008 else Comp_Polarity.ACTIVE_LOW
463+
Comp_Polarity.ACTIVE_HIGH
464+
if config_value & 0x0008
465+
else Comp_Polarity.ACTIVE_LOW
440466
)
441467
self.comparator_latch = (
442468
Comp_Latch.LATCHING if config_value & 0x0004 else Comp_Latch.NONLATCHING

0 commit comments

Comments
 (0)