Skip to content

Commit fa1d641

Browse files
authored
Merge pull request #54 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 566dbbd + f334eda commit fa1d641

File tree

12 files changed

+185
-164
lines changed

12 files changed

+185
-164
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

.pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ spelling-store-unknown-words=no
119119
[MISCELLANEOUS]
120120

121121
# List of note tags to take in consideration, separated by a comma.
122-
notes=FIXME,XXX,TODO
122+
# notes=FIXME,XXX,TODO
123+
notes=FIXME,XXX
123124

124125

125126
[TYPECHECK]

adafruit_ads1x15/ads1015.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@
2828
* Author(s): Carter Nelson
2929
"""
3030
import struct
31-
#pylint: disable=unused-import
31+
32+
# pylint: disable=unused-import
3233
from .ads1x15 import ADS1x15, Mode
3334

3435
# Data sample rates
3536
_ADS1015_CONFIG_DR = {
36-
128: 0x0000,
37-
250: 0x0020,
38-
490: 0x0040,
39-
920: 0x0060,
40-
1600: 0x0080,
41-
2400: 0x00A0,
42-
3300: 0x00C0
37+
128: 0x0000,
38+
250: 0x0020,
39+
490: 0x0040,
40+
920: 0x0060,
41+
1600: 0x0080,
42+
2400: 0x00A0,
43+
3300: 0x00C0,
4344
}
4445

4546
# Pins
@@ -48,6 +49,7 @@
4849
P2 = 2
4950
P3 = 3
5051

52+
5153
class ADS1015(ADS1x15):
5254
"""Class for the ADS1015 12 bit ADC."""
5355

adafruit_ads1x15/ads1115.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@
2828
* Author(s): Carter Nelson
2929
"""
3030
import struct
31-
#pylint: disable=unused-import
31+
32+
# pylint: disable=unused-import
3233
from .ads1x15 import ADS1x15, Mode
3334

3435
# Data sample rates
3536
_ADS1115_CONFIG_DR = {
36-
8: 0x0000,
37-
16: 0x0020,
38-
32: 0x0040,
39-
64: 0x0060,
40-
128: 0x0080,
41-
250: 0x00A0,
42-
475: 0x00C0,
43-
860: 0x00E0
37+
8: 0x0000,
38+
16: 0x0020,
39+
32: 0x0040,
40+
64: 0x0060,
41+
128: 0x0080,
42+
250: 0x00A0,
43+
475: 0x00C0,
44+
860: 0x00E0,
4445
}
4546

4647
# Pins
@@ -49,6 +50,7 @@
4950
P2 = 2
5051
P3 = 3
5152

53+
5254
class ADS1115(ADS1x15):
5355
"""Class for the ADS1115 16 bit ADC."""
5456

adafruit_ads1x15/ads1x15.py

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,45 @@
3535
from adafruit_bus_device.i2c_device import I2CDevice
3636

3737
# pylint: disable=bad-whitespace
38-
_ADS1X15_DEFAULT_ADDRESS = const(0x48)
39-
_ADS1X15_POINTER_CONVERSION = const(0x00)
40-
_ADS1X15_POINTER_CONFIG = const(0x01)
41-
_ADS1X15_CONFIG_OS_SINGLE = const(0x8000)
42-
_ADS1X15_CONFIG_MUX_OFFSET = const(12)
43-
_ADS1X15_CONFIG_COMP_QUE_DISABLE = const(0x0003)
38+
_ADS1X15_DEFAULT_ADDRESS = const(0x48)
39+
_ADS1X15_POINTER_CONVERSION = const(0x00)
40+
_ADS1X15_POINTER_CONFIG = const(0x01)
41+
_ADS1X15_CONFIG_OS_SINGLE = const(0x8000)
42+
_ADS1X15_CONFIG_MUX_OFFSET = const(12)
43+
_ADS1X15_CONFIG_COMP_QUE_DISABLE = const(0x0003)
4444
_ADS1X15_CONFIG_GAIN = {
45-
2/3: 0x0000,
46-
1: 0x0200,
47-
2: 0x0400,
48-
4: 0x0600,
49-
8: 0x0800,
50-
16: 0x0A00
45+
2 / 3: 0x0000,
46+
1: 0x0200,
47+
2: 0x0400,
48+
4: 0x0600,
49+
8: 0x0800,
50+
16: 0x0A00,
5151
}
5252
# pylint: enable=bad-whitespace
5353

54+
5455
class Mode:
5556
"""An enum-like class representing possible ADC operating modes."""
57+
5658
# See datasheet "Operating Modes" section
5759
# values here are masks for setting MODE bit in Config Register
58-
#pylint: disable=too-few-public-methods
60+
# pylint: disable=too-few-public-methods
5961
CONTINUOUS = 0x0000
6062
SINGLE = 0x0100
6163

6264

63-
class ADS1x15(object):
65+
class ADS1x15:
6466
"""Base functionality for ADS1x15 analog to digital converters."""
6567

66-
def __init__(self, i2c, gain=1, data_rate=None, mode=Mode.SINGLE,
67-
address=_ADS1X15_DEFAULT_ADDRESS):
68-
#pylint: disable=too-many-arguments
68+
def __init__(
69+
self,
70+
i2c,
71+
gain=1,
72+
data_rate=None,
73+
mode=Mode.SINGLE,
74+
address=_ADS1X15_DEFAULT_ADDRESS,
75+
):
76+
# pylint: disable=too-many-arguments
6977
self._last_pin_read = None
7078
self.buf = bytearray(3)
7179
self._data_rate = self._gain = self._mode = None
@@ -89,12 +97,12 @@ def data_rate(self, rate):
8997
@property
9098
def rates(self):
9199
"""Possible data rate settings."""
92-
raise NotImplementedError('Subclass must implement rates property.')
100+
raise NotImplementedError("Subclass must implement rates property.")
93101

94102
@property
95103
def rate_config(self):
96104
"""Rate configuration masks."""
97-
raise NotImplementedError('Subclass must implement rate_config property.')
105+
raise NotImplementedError("Subclass must implement rate_config property.")
98106

99107
@property
100108
def gain(self):
@@ -122,7 +130,7 @@ def mode(self):
122130

123131
@mode.setter
124132
def mode(self, mode):
125-
if mode != Mode.CONTINUOUS and mode != Mode.SINGLE:
133+
if mode not in (Mode.CONTINUOUS, Mode.SINGLE):
126134
raise ValueError("Unsupported mode.")
127135
self._mode = mode
128136

@@ -140,33 +148,32 @@ def _data_rate_default(self):
140148
"""Retrieve the default data rate for this ADC (in samples per second).
141149
Should be implemented by subclasses.
142150
"""
143-
raise NotImplementedError('Subclasses must implement _data_rate_default!')
151+
raise NotImplementedError("Subclasses must implement _data_rate_default!")
144152

145153
def _conversion_value(self, raw_adc):
146154
"""Subclasses should override this function that takes the 16 raw ADC
147155
values of a conversion result and returns a signed integer value.
148156
"""
149-
raise NotImplementedError('Subclass must implement _conversion_value function!')
157+
raise NotImplementedError("Subclass must implement _conversion_value function!")
150158

151159
def _read(self, pin):
152160
"""Perform an ADC read. Returns the signed integer result of the read."""
153161
if self.mode == Mode.CONTINUOUS and self._last_pin_read == pin:
154162
return self._conversion_value(self.get_last_result(True))
155-
else:
156-
self._last_pin_read = pin
157-
config = _ADS1X15_CONFIG_OS_SINGLE
158-
config |= (pin & 0x07) << _ADS1X15_CONFIG_MUX_OFFSET
159-
config |= _ADS1X15_CONFIG_GAIN[self.gain]
160-
config |= self.mode
161-
config |= self.rate_config[self.data_rate]
162-
config |= _ADS1X15_CONFIG_COMP_QUE_DISABLE
163-
self._write_register(_ADS1X15_POINTER_CONFIG, config)
164-
165-
if self.mode == Mode.SINGLE:
166-
while not self._conversion_complete():
167-
pass
168-
169-
return self._conversion_value(self.get_last_result(False))
163+
self._last_pin_read = pin
164+
config = _ADS1X15_CONFIG_OS_SINGLE
165+
config |= (pin & 0x07) << _ADS1X15_CONFIG_MUX_OFFSET
166+
config |= _ADS1X15_CONFIG_GAIN[self.gain]
167+
config |= self.mode
168+
config |= self.rate_config[self.data_rate]
169+
config |= _ADS1X15_CONFIG_COMP_QUE_DISABLE
170+
self._write_register(_ADS1X15_POINTER_CONFIG, config)
171+
172+
if self.mode == Mode.SINGLE:
173+
while not self._conversion_complete():
174+
pass
175+
176+
return self._conversion_value(self.get_last_result(False))
170177

171178
def _conversion_complete(self):
172179
"""Return status of ADC conversion."""

adafruit_ads1x15/analog_in.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,12 @@
2929
"""
3030

3131
# pylint: disable=bad-whitespace
32-
_ADS1X15_DIFF_CHANNELS = {
33-
(0, 1): 0,
34-
(0, 3): 1,
35-
(1, 3): 2,
36-
(2, 3): 3
37-
}
38-
_ADS1X15_PGA_RANGE = {
39-
2/3: 6.144,
40-
1: 4.096,
41-
2: 2.048,
42-
4: 1.024,
43-
8: 0.512,
44-
16: 0.256
45-
}
32+
_ADS1X15_DIFF_CHANNELS = {(0, 1): 0, (0, 3): 1, (1, 3): 2, (2, 3): 3}
33+
_ADS1X15_PGA_RANGE = {2 / 3: 6.144, 1: 4.096, 2: 2.048, 4: 1.024, 8: 0.512, 16: 0.256}
4634
# pylint: enable=bad-whitespace
4735

48-
class AnalogIn():
36+
37+
class AnalogIn:
4938
"""AnalogIn Mock Implementation for ADC Reads."""
5039

5140
def __init__(self, ads, positive_pin, negative_pin=None):
@@ -62,16 +51,20 @@ def __init__(self, ads, positive_pin, negative_pin=None):
6251
if negative_pin is not None:
6352
pins = (self._pin_setting, self._negative_pin)
6453
if pins not in _ADS1X15_DIFF_CHANNELS:
65-
raise ValueError("Differential channels must be one of: {}"
66-
.format(list(_ADS1X15_DIFF_CHANNELS.keys())))
54+
raise ValueError(
55+
"Differential channels must be one of: {}".format(
56+
list(_ADS1X15_DIFF_CHANNELS.keys())
57+
)
58+
)
6759
self._pin_setting = _ADS1X15_DIFF_CHANNELS[pins]
6860
self.is_differential = True
6961

7062
@property
7163
def value(self):
7264
"""Returns the value of an ADC pin as an integer."""
73-
return self._ads.read(self._pin_setting,
74-
is_differential=self.is_differential) << (16 - self._ads.bits)
65+
return self._ads.read(
66+
self._pin_setting, is_differential=self.is_differential
67+
) << (16 - self._ads.bits)
7568

7669
@property
7770
def voltage(self):

0 commit comments

Comments
 (0)