Skip to content

Commit c4f014a

Browse files
authored
Merge pull request #21 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents e2836e9 + a82399d commit c4f014a

File tree

6 files changed

+159
-135
lines changed

6 files changed

+159
-135
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

adafruit_apds9960/apds9960.py

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -42,61 +42,61 @@
4242
# INTEGRATION_TIME_DEF = const(0x01)
4343
# GAIN_DEF = const(0x01)
4444

45-
#pylint: disable-msg=bad-whitespace
46-
#APDS9960_RAM = const(0x00)
47-
APDS9960_ENABLE = const(0x80)
48-
APDS9960_ATIME = const(0x81)
49-
#APDS9960_WTIME = const(0x83)
50-
#APDS9960_AILTIL = const(0x84)
45+
# pylint: disable-msg=bad-whitespace
46+
# APDS9960_RAM = const(0x00)
47+
APDS9960_ENABLE = const(0x80)
48+
APDS9960_ATIME = const(0x81)
49+
# APDS9960_WTIME = const(0x83)
50+
# APDS9960_AILTIL = const(0x84)
5151
# APDS9960_AILTH = const(0x85)
5252
# APDS9960_AIHTL = const(0x86)
5353
# APDS9960_AIHTH = const(0x87)
54-
APDS9960_PILT = const(0x89)
55-
APDS9960_PIHT = const(0x8B)
56-
APDS9960_PERS = const(0x8C)
54+
APDS9960_PILT = const(0x89)
55+
APDS9960_PIHT = const(0x8B)
56+
APDS9960_PERS = const(0x8C)
5757
# APDS9960_CONFIG1 = const(0x8D)
5858
# APDS9960_PPULSE = const(0x8E)
59-
APDS9960_CONTROL = const(0x8F)
59+
APDS9960_CONTROL = const(0x8F)
6060
# APDS9960_CONFIG2 = const(0x90)
61-
APDS9960_ID = const(0x92)
62-
APDS9960_STATUS = const(0x93)
63-
APDS9960_CDATAL = const(0x94)
61+
APDS9960_ID = const(0x92)
62+
APDS9960_STATUS = const(0x93)
63+
APDS9960_CDATAL = const(0x94)
6464
# APDS9960_CDATAH = const(0x95)
6565
# APDS9960_RDATAL = const(0x96)
6666
# APDS9960_RDATAH = const(0x97)
6767
# APDS9960_GDATAL = const(0x98)
6868
# APDS9960_GDATAH = const(0x99)
6969
# APDS9960_BDATAL = const(0x9A)
7070
# APDS9960_BDATAH = const(0x9B)
71-
APDS9960_PDATA = const(0x9C)
71+
APDS9960_PDATA = const(0x9C)
7272
# APDS9960_POFFSET_UR = const(0x9D)
7373
# APDS9960_POFFSET_DL = const(0x9E)
7474
# APDS9960_CONFIG3 = const(0x9F)
75-
APDS9960_GPENTH = const(0xA0)
75+
APDS9960_GPENTH = const(0xA0)
7676
# APDS9960_GEXTH = const(0xA1)
77-
APDS9960_GCONF1 = const(0xA2)
78-
APDS9960_GCONF2 = const(0xA3)
77+
APDS9960_GCONF1 = const(0xA2)
78+
APDS9960_GCONF2 = const(0xA3)
7979
# APDS9960_GOFFSET_U = const(0xA4)
8080
# APDS9960_GOFFSET_D = const(0xA5)
8181
# APDS9960_GOFFSET_L = const(0xA7)
8282
# APDS9960_GOFFSET_R = const(0xA9)
83-
APDS9960_GPULSE = const(0xA6)
84-
APDS9960_GCONF3 = const(0xAA)
85-
APDS9960_GCONF4 = const(0xAB)
86-
APDS9960_GFLVL = const(0xAE)
87-
APDS9960_GSTATUS = const(0xAF)
83+
APDS9960_GPULSE = const(0xA6)
84+
APDS9960_GCONF3 = const(0xAA)
85+
APDS9960_GCONF4 = const(0xAB)
86+
APDS9960_GFLVL = const(0xAE)
87+
APDS9960_GSTATUS = const(0xAF)
8888
# APDS9960_IFORCE = const(0xE4)
8989
# APDS9960_PICLEAR = const(0xE5)
9090
# APDS9960_CICLEAR = const(0xE6)
91-
APDS9960_AICLEAR = const(0xE7)
92-
APDS9960_GFIFO_U = const(0xFC)
91+
APDS9960_AICLEAR = const(0xE7)
92+
APDS9960_GFIFO_U = const(0xFC)
9393
# APDS9960_GFIFO_D = const(0xFD)
9494
# APDS9960_GFIFO_L = const(0xFE)
9595
# APDS9960_GFIFO_R = const(0xFF)
96-
#pylint: enable-msg=bad-whitespace
96+
# pylint: enable-msg=bad-whitespace
9797

9898

99-
#pylint: disable-msg=too-many-instance-attributes
99+
# pylint: disable-msg=too-many-instance-attributes
100100
class APDS9960:
101101
"""
102102
APDS9900 provide basic driver services for the ASDS9960 breakout board
@@ -107,12 +107,9 @@ class APDS9960:
107107
_gesture_mode = RWBit(APDS9960_GCONF4, 0)
108108
_proximity_persistance = RWBits(4, APDS9960_PERS, 4)
109109

110-
def __init__(self,
111-
i2c, *,
112-
interrupt_pin=None,
113-
address=0x39,
114-
integration_time=0x01,
115-
gain=0x01):
110+
def __init__(
111+
self, i2c, *, interrupt_pin=None, address=0x39, integration_time=0x01, gain=0x01
112+
):
116113

117114
self.buf129 = None
118115
self.buf2 = bytearray(2)
@@ -138,9 +135,9 @@ def __init__(self,
138135

139136
self.color_gain = gain
140137
self.integration_time = integration_time
141-
self.gesture_dimensions = 0x00 # all
142-
self.gesture_fifo_threshold = 0x01 # fifo 4
143-
self.gesture_gain = 0x02 # gain 4
138+
self.gesture_dimensions = 0x00 # all
139+
self.gesture_fifo_threshold = 0x01 # fifo 4
140+
self.gesture_gain = 0x02 # gain 4
144141
self.gesture_proximity_threshold = 50
145142
self._reset_counts()
146143

@@ -155,7 +152,6 @@ def _reset_counts(self):
155152
self._saw_left_start = 0
156153
self._saw_right_start = 0
157154

158-
159155
enable = RWBit(APDS9960_ENABLE, 0)
160156
"""Board enable. True to enable, False to disable"""
161157
enable_color = RWBit(APDS9960_ENABLE, 1)
@@ -186,7 +182,7 @@ def enable_gesture(self, enable_flag):
186182
self._gesture_mode = False
187183
self._gesture_enable = enable_flag
188184

189-
def gesture(self): #pylint: disable-msg=too-many-branches
185+
def gesture(self): # pylint: disable-msg=too-many-branches
190186
"""Returns gesture code if detected. =0 if no gesture detected
191187
=1 if an UP, =2 if a DOWN, =3 if an LEFT, =4 if a RIGHT
192188
"""
@@ -206,14 +202,19 @@ def gesture(self): #pylint: disable-msg=too-many-branches
206202
up_down_diff = 0
207203
left_right_diff = 0
208204
gesture_received = 0
209-
time.sleep(0.030) # 30 ms
205+
time.sleep(0.030) # 30 ms
210206

211207
n_recs = self._read8(APDS9960_GFLVL)
212208
if n_recs:
213209

214210
with self.i2c_device as i2c:
215-
i2c.write_then_readinto(buffer, buffer, out_end=1, in_start=1,
216-
in_end=min(129, 1 + n_recs * 4))
211+
i2c.write_then_readinto(
212+
buffer,
213+
buffer,
214+
out_end=1,
215+
in_start=1,
216+
in_end=min(129, 1 + n_recs * 4),
217+
)
217218
upp, down, left, right = buffer[1:5]
218219

219220
if abs(upp - down) > 13:
@@ -227,14 +228,14 @@ def gesture(self): #pylint: disable-msg=too-many-branches
227228
# either leading edge of down movement
228229
# or trailing edge of up movement
229230
if self._saw_up_start:
230-
gesture_received = 0x01 # up
231+
gesture_received = 0x01 # up
231232
else:
232233
self._saw_down_start += 1
233234
elif up_down_diff > 0:
234235
# either leading edge of up movement
235236
# or trailing edge of down movement
236237
if self._saw_down_start:
237-
gesture_received = 0x02 # down
238+
gesture_received = 0x02 # down
238239
else:
239240
self._saw_up_start += 1
240241

@@ -243,14 +244,14 @@ def gesture(self): #pylint: disable-msg=too-many-branches
243244
# either leading edge of right movement
244245
# trailing edge of left movement
245246
if self._saw_left_start:
246-
gesture_received = 0x03 # left
247+
gesture_received = 0x03 # left
247248
else:
248249
self._saw_right_start += 1
249250
elif left_right_diff > 0:
250251
# either leading edge of left movement
251252
# trailing edge of right movement
252253
if self._saw_right_start:
253-
gesture_received = 0x04 #right
254+
gesture_received = 0x04 # right
254255
else:
255256
self._saw_left_start += 1
256257

@@ -282,10 +283,12 @@ def color_data_ready(self):
282283
@property
283284
def color_data(self):
284285
"""Tuple containing r, g, b, c values"""
285-
return self._color_data16(APDS9960_CDATAL + 2), \
286-
self._color_data16(APDS9960_CDATAL + 4), \
287-
self._color_data16(APDS9960_CDATAL + 6), \
288-
self._color_data16(APDS9960_CDATAL)
286+
return (
287+
self._color_data16(APDS9960_CDATAL + 2),
288+
self._color_data16(APDS9960_CDATAL + 4),
289+
self._color_data16(APDS9960_CDATAL + 6),
290+
self._color_data16(APDS9960_CDATAL),
291+
)
289292

290293
### PROXIMITY
291294
@property
@@ -295,30 +298,31 @@ def proximity_interrupt_threshold(self):
295298
When setting the proximity interrupt threshold values using a tuple of
296299
zero to three values: low threshold, high threshold, persistance.
297300
persistance defaults to 4 if not provided"""
298-
return self._read8(APDS9960_PILT), \
299-
self._read8(APDS9960_PIHT), \
300-
self._proximity_persistance
301+
return (
302+
self._read8(APDS9960_PILT),
303+
self._read8(APDS9960_PIHT),
304+
self._proximity_persistance,
305+
)
301306

302307
@proximity_interrupt_threshold.setter
303308
def proximity_interrupt_threshold(self, setting_tuple):
304309
if setting_tuple:
305310
self._write8(APDS9960_PILT, setting_tuple[0])
306311
if len(setting_tuple) > 1:
307312
self._write8(APDS9960_PIHT, setting_tuple[1])
308-
persist = 4 # default 4
313+
persist = 4 # default 4
309314
if len(setting_tuple) > 2:
310315
persist = min(setting_tuple[2], 7)
311316
self._proximity_persistance = persist
312317

313-
314318
@property
315319
def gesture_proximity_threshold(self):
316320
"""Proximity threshold value: range 0-255"""
317321
return self._read8(APDS9960_GPENTH)
318322

319323
@gesture_proximity_threshold.setter
320324
def gesture_proximity_threshold(self, thresh):
321-
self._write8(APDS9960_GPENTH, thresh & 0xff)
325+
self._write8(APDS9960_GPENTH, thresh & 0xFF)
322326

323327
@property
324328
def proximity(self):
@@ -336,7 +340,7 @@ def integration_time(self):
336340

337341
@integration_time.setter
338342
def integration_time(self, int_time):
339-
self._write8(APDS9960_ATIME, int_time & 0xff)
343+
self._write8(APDS9960_ATIME, int_time & 0xFF)
340344

341345
# method for reading and writing to I2C
342346
def _write8(self, command, abyte):

adafruit_apds9960/colorutility.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
__version__ = "0.0.0-auto.0"
3232
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_APDS9960.git"
3333

34+
3435
def calculate_color_temperature(r, g, b):
3536
"""Converts the raw R/G/B values to color temperature in degrees Kelvin"""
3637

@@ -55,6 +56,7 @@ def calculate_color_temperature(r, g, b):
5556
# Return the results in degrees Kelvin
5657
return cct
5758

59+
5860
def calculate_lux(r, g, b):
5961
"""Calculate ambient light values"""
6062
# This only uses RGB ... how can we integrate clear or calculate lux

0 commit comments

Comments
 (0)