Skip to content

Commit 74f8167

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 74f8167

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-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: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@
2323
from typing import Dict, List, Optional
2424

2525
from busio import I2C
26-
from microcontroller import Pin
2726
except ImportError:
28-
# define Pin to avoid the error:
29-
# def read(self, pin: Pin, is_differential: bool = False) -> int:
30-
# NameError: name 'Pin' is not defined
31-
Pin = None
27+
pass
3228

3329
_ADS1X15_DEFAULT_ADDRESS = const(0x48)
3430
_ADS1X15_POINTER_CONVERSION = const(0x00)
@@ -54,6 +50,19 @@
5450
}
5551

5652

53+
class Pin:
54+
"""An enum-like class representing possible ADC pins."""
55+
56+
A0 = 0
57+
"""Analog Pin 0"""
58+
A1 = 1
59+
"""Analog Pin 1"""
60+
A2 = 2
61+
"""Analog Pin 2"""
62+
A3 = 3
63+
"""Analog Pin 3"""
64+
65+
5766
class Mode:
5867
"""An enum-like class representing possible ADC operating modes."""
5968

@@ -312,10 +321,10 @@ def comparator_latch(self, comp_latch: int) -> None:
312321
if self.initialized:
313322
self._write_config()
314323

315-
def read(self, pin: Pin) -> int:
324+
def read(self, pin: int) -> int:
316325
"""I2C Interface for ADS1x15-based ADCs reads.
317326
318-
:param ~microcontroller.Pin pin: individual or differential pin.
327+
:param int pin: individual or differential pin.
319328
:param bool is_differential: single-ended or differential read.
320329
"""
321330
return self._read(pin)
@@ -332,7 +341,7 @@ def _conversion_value(self, raw_adc: int) -> int:
332341
"""
333342
raise NotImplementedError("Subclass must implement _conversion_value function!")
334343

335-
def _read(self, pin: Pin) -> int:
344+
def _read(self, pin: int) -> int:
336345
"""Perform an ADC read. Returns the signed integer result of the read."""
337346
# Immediately return conversion register result if in CONTINUOUS mode
338347
# and pin has not changed

0 commit comments

Comments
 (0)