Skip to content

Commit d24dc2e

Browse files
authored
Merge pull request #24 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 2798887 + 05b9809 commit d24dc2e

File tree

8 files changed

+186
-157
lines changed

8 files changed

+186
-157
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: 3 additions & 2 deletions
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]
@@ -300,7 +301,7 @@ function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
300301

301302
# Good variable names which should always be accepted, separated by a comma
302303
# good-names=i,j,k,ex,Run,_
303-
good-names=r,g,b,i,j,k,n,x,y,z,ex,ok,Run,_
304+
good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_
304305

305306
# Include a hint for the correct naming format with invalid-name
306307
include-naming-hint=no

adafruit_mpr121.py

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,49 @@
4242
# Register addresses. Unused registers commented out to save memory.
4343
# pylint: disable=bad-whitespace
4444
MPR121_I2CADDR_DEFAULT = const(0x5A)
45-
MPR121_TOUCHSTATUS_L = const(0x00)
46-
#MPR121_TOUCHSTATUS_H = const(0x01)
47-
MPR121_FILTDATA_0L = const(0x04)
48-
#MPR121_FILTDATA_0H = const(0x05)
49-
MPR121_BASELINE_0 = const(0x1E)
50-
MPR121_MHDR = const(0x2B)
51-
MPR121_NHDR = const(0x2C)
52-
MPR121_NCLR = const(0x2D)
53-
MPR121_FDLR = const(0x2E)
54-
MPR121_MHDF = const(0x2F)
55-
MPR121_NHDF = const(0x30)
56-
MPR121_NCLF = const(0x31)
57-
MPR121_FDLF = const(0x32)
58-
MPR121_NHDT = const(0x33)
59-
MPR121_NCLT = const(0x34)
60-
MPR121_FDLT = const(0x35)
61-
MPR121_TOUCHTH_0 = const(0x41)
62-
MPR121_RELEASETH_0 = const(0x42)
63-
MPR121_DEBOUNCE = const(0x5B)
64-
MPR121_CONFIG1 = const(0x5C)
65-
MPR121_CONFIG2 = const(0x5D)
66-
#MPR121_CHARGECURR_0 = const(0x5F)
67-
#MPR121_CHARGETIME_1 = const(0x6C)
68-
MPR121_ECR = const(0x5E)
69-
#MPR121_AUTOCONFIG0 = const(0x7B)
70-
#MPR121_AUTOCONFIG1 = const(0x7C)
71-
#MPR121_UPLIMIT = const(0x7D)
72-
#MPR121_LOWLIMIT = const(0x7E)
73-
#MPR121_TARGETLIMIT = const(0x7F)
74-
#MPR121_GPIODIR = const(0x76)
75-
#MPR121_GPIOEN = const(0x77)
76-
#MPR121_GPIOSET = const(0x78)
77-
#MPR121_GPIOCLR = const(0x79)
78-
#MPR121_GPIOTOGGLE = const(0x7A)
79-
MPR121_SOFTRESET = const(0x80)
45+
MPR121_TOUCHSTATUS_L = const(0x00)
46+
# MPR121_TOUCHSTATUS_H = const(0x01)
47+
MPR121_FILTDATA_0L = const(0x04)
48+
# MPR121_FILTDATA_0H = const(0x05)
49+
MPR121_BASELINE_0 = const(0x1E)
50+
MPR121_MHDR = const(0x2B)
51+
MPR121_NHDR = const(0x2C)
52+
MPR121_NCLR = const(0x2D)
53+
MPR121_FDLR = const(0x2E)
54+
MPR121_MHDF = const(0x2F)
55+
MPR121_NHDF = const(0x30)
56+
MPR121_NCLF = const(0x31)
57+
MPR121_FDLF = const(0x32)
58+
MPR121_NHDT = const(0x33)
59+
MPR121_NCLT = const(0x34)
60+
MPR121_FDLT = const(0x35)
61+
MPR121_TOUCHTH_0 = const(0x41)
62+
MPR121_RELEASETH_0 = const(0x42)
63+
MPR121_DEBOUNCE = const(0x5B)
64+
MPR121_CONFIG1 = const(0x5C)
65+
MPR121_CONFIG2 = const(0x5D)
66+
# MPR121_CHARGECURR_0 = const(0x5F)
67+
# MPR121_CHARGETIME_1 = const(0x6C)
68+
MPR121_ECR = const(0x5E)
69+
# MPR121_AUTOCONFIG0 = const(0x7B)
70+
# MPR121_AUTOCONFIG1 = const(0x7C)
71+
# MPR121_UPLIMIT = const(0x7D)
72+
# MPR121_LOWLIMIT = const(0x7E)
73+
# MPR121_TARGETLIMIT = const(0x7F)
74+
# MPR121_GPIODIR = const(0x76)
75+
# MPR121_GPIOEN = const(0x77)
76+
# MPR121_GPIOSET = const(0x78)
77+
# MPR121_GPIOCLR = const(0x79)
78+
# MPR121_GPIOTOGGLE = const(0x7A)
79+
MPR121_SOFTRESET = const(0x80)
8080
# pylint: enable=bad-whitespace
8181

82-
class MPR121_Channel():
82+
83+
class MPR121_Channel:
8384
# pylint: disable=protected-access
8485
"""Helper class to represent a touch channel on the MPR121. Not meant to
8586
be used directly."""
87+
8688
def __init__(self, mpr121, channel):
8789
self._mpr121 = mpr121
8890
self._channel = channel
@@ -101,23 +103,25 @@ def raw_value(self):
101103
def threshold(self):
102104
"""The touch threshold."""
103105
buf = bytearray(1)
104-
self._mpr121._read_register_bytes(MPR121_TOUCHTH_0 + 2*self._channel, buf, 1)
106+
self._mpr121._read_register_bytes(MPR121_TOUCHTH_0 + 2 * self._channel, buf, 1)
105107
return buf[0]
106108

107109
@threshold.setter
108110
def threshold(self, value):
109-
self._mpr121._write_register_byte(MPR121_TOUCHTH_0 + 2*self._channel, value)
111+
self._mpr121._write_register_byte(MPR121_TOUCHTH_0 + 2 * self._channel, value)
110112

111113
@property
112114
def release_threshold(self):
113115
"""The release threshold."""
114116
buf = bytearray(1)
115-
self._mpr121._read_register_bytes(MPR121_RELEASETH_0 + 2*self._channel, buf, 1)
117+
self._mpr121._read_register_bytes(
118+
MPR121_RELEASETH_0 + 2 * self._channel, buf, 1
119+
)
116120
return buf[0]
117121

118122
@release_threshold.setter
119123
def release_threshold(self, value):
120-
self._mpr121._write_register_byte(MPR121_RELEASETH_0 + 2*self._channel, value)
124+
self._mpr121._write_register_byte(MPR121_RELEASETH_0 + 2 * self._channel, value)
121125

122126

123127
class MPR121:
@@ -126,12 +130,12 @@ class MPR121:
126130
def __init__(self, i2c, address=MPR121_I2CADDR_DEFAULT):
127131
self._i2c = i2c_device.I2CDevice(i2c, address)
128132
self._buffer = bytearray(2)
129-
self._channels = [None]*12
133+
self._channels = [None] * 12
130134
self.reset()
131135

132136
def __getitem__(self, key):
133137
if key < 0 or key > 11:
134-
raise IndexError('Pin must be a value 0-11.')
138+
raise IndexError("Pin must be a value 0-11.")
135139
if self._channels[key] is None:
136140
self._channels[key] = MPR121_Channel(self, key)
137141
return self._channels[key]
@@ -169,17 +173,19 @@ def reset(self):
169173
"""
170174
# Write to the reset register.
171175
self._write_register_byte(MPR121_SOFTRESET, 0x63)
172-
time.sleep(0.001) # This 1ms delay here probably isn't necessary but can't hurt.
176+
time.sleep(
177+
0.001
178+
) # This 1ms delay here probably isn't necessary but can't hurt.
173179
# Set electrode configuration to default values.
174180
self._write_register_byte(MPR121_ECR, 0x00)
175181
# Check CDT, SFI, ESI configuration is at default values.
176182
self._read_register_bytes(MPR121_CONFIG2, self._buffer, 1)
177183
if self._buffer[0] != 0x24:
178-
raise RuntimeError('Failed to find MPR121 in expected config state!')
184+
raise RuntimeError("Failed to find MPR121 in expected config state!")
179185
# Default touch and release thresholds
180186
for i in range(12):
181-
self._write_register_byte(MPR121_TOUCHTH_0 + 2*i, 12)
182-
self._write_register_byte(MPR121_RELEASETH_0 + 2*i, 6)
187+
self._write_register_byte(MPR121_TOUCHTH_0 + 2 * i, 12)
188+
self._write_register_byte(MPR121_RELEASETH_0 + 2 * i, 6)
183189
# Configure baseline filtering control registers.
184190
self._write_register_byte(MPR121_MHDR, 0x01)
185191
self._write_register_byte(MPR121_NHDR, 0x01)
@@ -194,26 +200,28 @@ def reset(self):
194200
self._write_register_byte(MPR121_FDLT, 0x00)
195201
# Set other configuration registers.
196202
self._write_register_byte(MPR121_DEBOUNCE, 0)
197-
self._write_register_byte(MPR121_CONFIG1, 0x10) # default, 16uA charge current
198-
self._write_register_byte(MPR121_CONFIG2, 0x20) # 0.5uS encoding, 1ms period
203+
self._write_register_byte(MPR121_CONFIG1, 0x10) # default, 16uA charge current
204+
self._write_register_byte(MPR121_CONFIG2, 0x20) # 0.5uS encoding, 1ms period
199205
# Enable all electrodes.
200-
self._write_register_byte(MPR121_ECR, 0x8F) # start with first 5 bits of baseline tracking
206+
self._write_register_byte(
207+
MPR121_ECR, 0x8F
208+
) # start with first 5 bits of baseline tracking
201209

202210
def filtered_data(self, pin):
203211
"""Return filtered data register value for the provided pin (0-11).
204212
Useful for debugging.
205213
"""
206214
if pin < 0 or pin > 11:
207-
raise ValueError('Pin must be a value 0-11.')
208-
self._read_register_bytes(MPR121_FILTDATA_0L + pin*2, self._buffer)
215+
raise ValueError("Pin must be a value 0-11.")
216+
self._read_register_bytes(MPR121_FILTDATA_0L + pin * 2, self._buffer)
209217
return ((self._buffer[1] << 8) | (self._buffer[0])) & 0xFFFF
210218

211219
def baseline_data(self, pin):
212220
"""Return baseline data register value for the provided pin (0-11).
213221
Useful for debugging.
214222
"""
215223
if pin < 0 or pin > 11:
216-
raise ValueError('Pin must be a value 0-11.')
224+
raise ValueError("Pin must be a value 0-11.")
217225
self._read_register_bytes(MPR121_BASELINE_0 + pin, self._buffer, 1)
218226
return self._buffer[0] << 2
219227

@@ -229,6 +237,6 @@ def is_touched(self, pin):
229237
False.
230238
"""
231239
if pin < 0 or pin > 11:
232-
raise ValueError('Pin must be a value 0-11.')
240+
raise ValueError("Pin must be a value 0-11.")
233241
touches = self.touched()
234242
return (touches & (1 << pin)) > 0

0 commit comments

Comments
 (0)