Skip to content

Commit 5ba760c

Browse files
author
Melissa LeBlanc-Williams
authored
Merge pull request #25 from caternuson/iss21_consts
Move Mode consts into an enum like class.
2 parents caba0ea + 8b6bb82 commit 5ba760c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

adafruit_ads1x15/ads1015.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
* Author(s): Carter Nelson
2929
"""
3030
import struct
31-
from .ads1x15 import ADS1x15
31+
#pylint: disable=unused-import
32+
from .ads1x15 import ADS1x15, Mode
3233

3334
# Data sample rates
3435
_ADS1015_CONFIG_DR = {

adafruit_ads1x15/ads1115.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
* Author(s): Carter Nelson
2929
"""
3030
import struct
31-
from .ads1x15 import ADS1x15
31+
#pylint: disable=unused-import
32+
from .ads1x15 import ADS1x15, Mode
3233

3334
# Data sample rates
3435
_ADS1115_CONFIG_DR = {

adafruit_ads1x15/ads1x15.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
_ADS1X15_POINTER_CONFIG = const(0x01)
4242
_ADS1X15_CONFIG_OS_SINGLE = const(0x8000)
4343
_ADS1X15_CONFIG_MUX_OFFSET = const(12)
44-
_ADS1X15_CONFIG_MODE_CONTINUOUS = const(0x0000)
45-
_ADS1X15_CONFIG_MODE_SINGLE = const(0x0100)
4644
_ADS1X15_CONFIG_COMP_QUE_DISABLE = const(0x0003)
4745
_ADS1X15_CONFIG_GAIN = {
4846
2/3: 0x0000,
@@ -54,10 +52,19 @@
5452
}
5553
# pylint: enable=bad-whitespace
5654

55+
class Mode:
56+
"""An enum-like class representing possible ADC operating modes."""
57+
# See datasheet "Operating Modes" section
58+
# values here are masks for setting MODE bit in Config Register
59+
#pylint: disable=too-few-public-methods
60+
CONTINUOUS = 0x0000
61+
SINGLE = 0x0100
62+
63+
5764
class ADS1x15(object):
5865
"""Base functionality for ADS1x15 analog to digital converters."""
5966

60-
def __init__(self, i2c, gain=1, data_rate=None, mode=_ADS1X15_CONFIG_MODE_SINGLE,
67+
def __init__(self, i2c, gain=1, data_rate=None, mode=Mode.SINGLE,
6168
address=_ADS1X15_DEFAULT_ADDRESS):
6269
#pylint: disable=too-many-arguments
6370
self.buf = bytearray(3)
@@ -115,7 +122,7 @@ def mode(self):
115122

116123
@mode.setter
117124
def mode(self, mode):
118-
if mode != _ADS1X15_CONFIG_MODE_CONTINUOUS and mode != _ADS1X15_CONFIG_MODE_SINGLE:
125+
if mode != Mode.CONTINUOUS and mode != Mode.SINGLE:
119126
raise ValueError("Unsupported mode.")
120127
self._mode = mode
121128

0 commit comments

Comments
 (0)