Skip to content

Move Mode consts into an enum like class. #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion adafruit_ads1x15/ads1015.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
* Author(s): Carter Nelson
"""
import struct
from .ads1x15 import ADS1x15
#pylint: disable=unused-import
from .ads1x15 import ADS1x15, Mode

# Data sample rates
_ADS1015_CONFIG_DR = {
Expand Down
3 changes: 2 additions & 1 deletion adafruit_ads1x15/ads1115.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
* Author(s): Carter Nelson
"""
import struct
from .ads1x15 import ADS1x15
#pylint: disable=unused-import
from .ads1x15 import ADS1x15, Mode

# Data sample rates
_ADS1115_CONFIG_DR = {
Expand Down
15 changes: 11 additions & 4 deletions adafruit_ads1x15/ads1x15.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
_ADS1X15_POINTER_CONFIG = const(0x01)
_ADS1X15_CONFIG_OS_SINGLE = const(0x8000)
_ADS1X15_CONFIG_MUX_OFFSET = const(12)
_ADS1X15_CONFIG_MODE_CONTINUOUS = const(0x0000)
_ADS1X15_CONFIG_MODE_SINGLE = const(0x0100)
_ADS1X15_CONFIG_COMP_QUE_DISABLE = const(0x0003)
_ADS1X15_CONFIG_GAIN = {
2/3: 0x0000,
Expand All @@ -54,10 +52,19 @@
}
# pylint: enable=bad-whitespace

class Mode:
"""An enum-like class representing possible ADC operating modes."""
# See datasheet "Operating Modes" section
# values here are masks for setting MODE bit in Config Register
#pylint: disable=too-few-public-methods
CONTINUOUS = 0x0000
SINGLE = 0x0100


class ADS1x15(object):
"""Base functionality for ADS1x15 analog to digital converters."""

def __init__(self, i2c, gain=1, data_rate=None, mode=_ADS1X15_CONFIG_MODE_SINGLE,
def __init__(self, i2c, gain=1, data_rate=None, mode=Mode.SINGLE,
address=_ADS1X15_DEFAULT_ADDRESS):
#pylint: disable=too-many-arguments
self.buf = bytearray(3)
Expand Down Expand Up @@ -115,7 +122,7 @@ def mode(self):

@mode.setter
def mode(self, mode):
if mode != _ADS1X15_CONFIG_MODE_CONTINUOUS and mode != _ADS1X15_CONFIG_MODE_SINGLE:
if mode != Mode.CONTINUOUS and mode != Mode.SINGLE:
raise ValueError("Unsupported mode.")
self._mode = mode

Expand Down