Skip to content

Commit 653e02a

Browse files
authored
Merge pull request #21 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 652c34d + 27b9f29 commit 653e02a

File tree

5 files changed

+161
-146
lines changed

5 files changed

+161
-146
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_drv2605.py

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,57 +38,58 @@
3838

3939
# pylint: disable=bad-whitespace
4040
# Internal constants:
41-
_DRV2605_ADDR = const(0x5A)
42-
_DRV2605_REG_STATUS = const(0x00)
43-
_DRV2605_REG_MODE = const(0x01)
44-
_DRV2605_REG_RTPIN = const(0x02)
45-
_DRV2605_REG_LIBRARY = const(0x03)
46-
_DRV2605_REG_WAVESEQ1 = const(0x04)
47-
_DRV2605_REG_WAVESEQ2 = const(0x05)
48-
_DRV2605_REG_WAVESEQ3 = const(0x06)
49-
_DRV2605_REG_WAVESEQ4 = const(0x07)
50-
_DRV2605_REG_WAVESEQ5 = const(0x08)
51-
_DRV2605_REG_WAVESEQ6 = const(0x09)
52-
_DRV2605_REG_WAVESEQ7 = const(0x0A)
53-
_DRV2605_REG_WAVESEQ8 = const(0x0B)
54-
_DRV2605_REG_GO = const(0x0C)
55-
_DRV2605_REG_OVERDRIVE = const(0x0D)
56-
_DRV2605_REG_SUSTAINPOS = const(0x0E)
57-
_DRV2605_REG_SUSTAINNEG = const(0x0F)
58-
_DRV2605_REG_BREAK = const(0x10)
59-
_DRV2605_REG_AUDIOCTRL = const(0x11)
60-
_DRV2605_REG_AUDIOLVL = const(0x12)
61-
_DRV2605_REG_AUDIOMAX = const(0x13)
62-
_DRV2605_REG_RATEDV = const(0x16)
63-
_DRV2605_REG_CLAMPV = const(0x17)
64-
_DRV2605_REG_AUTOCALCOMP = const(0x18)
65-
_DRV2605_REG_AUTOCALEMP = const(0x19)
66-
_DRV2605_REG_FEEDBACK = const(0x1A)
67-
_DRV2605_REG_CONTROL1 = const(0x1B)
68-
_DRV2605_REG_CONTROL2 = const(0x1C)
69-
_DRV2605_REG_CONTROL3 = const(0x1D)
70-
_DRV2605_REG_CONTROL4 = const(0x1E)
71-
_DRV2605_REG_VBAT = const(0x21)
72-
_DRV2605_REG_LRARESON = const(0x22)
41+
_DRV2605_ADDR = const(0x5A)
42+
_DRV2605_REG_STATUS = const(0x00)
43+
_DRV2605_REG_MODE = const(0x01)
44+
_DRV2605_REG_RTPIN = const(0x02)
45+
_DRV2605_REG_LIBRARY = const(0x03)
46+
_DRV2605_REG_WAVESEQ1 = const(0x04)
47+
_DRV2605_REG_WAVESEQ2 = const(0x05)
48+
_DRV2605_REG_WAVESEQ3 = const(0x06)
49+
_DRV2605_REG_WAVESEQ4 = const(0x07)
50+
_DRV2605_REG_WAVESEQ5 = const(0x08)
51+
_DRV2605_REG_WAVESEQ6 = const(0x09)
52+
_DRV2605_REG_WAVESEQ7 = const(0x0A)
53+
_DRV2605_REG_WAVESEQ8 = const(0x0B)
54+
_DRV2605_REG_GO = const(0x0C)
55+
_DRV2605_REG_OVERDRIVE = const(0x0D)
56+
_DRV2605_REG_SUSTAINPOS = const(0x0E)
57+
_DRV2605_REG_SUSTAINNEG = const(0x0F)
58+
_DRV2605_REG_BREAK = const(0x10)
59+
_DRV2605_REG_AUDIOCTRL = const(0x11)
60+
_DRV2605_REG_AUDIOLVL = const(0x12)
61+
_DRV2605_REG_AUDIOMAX = const(0x13)
62+
_DRV2605_REG_RATEDV = const(0x16)
63+
_DRV2605_REG_CLAMPV = const(0x17)
64+
_DRV2605_REG_AUTOCALCOMP = const(0x18)
65+
_DRV2605_REG_AUTOCALEMP = const(0x19)
66+
_DRV2605_REG_FEEDBACK = const(0x1A)
67+
_DRV2605_REG_CONTROL1 = const(0x1B)
68+
_DRV2605_REG_CONTROL2 = const(0x1C)
69+
_DRV2605_REG_CONTROL3 = const(0x1D)
70+
_DRV2605_REG_CONTROL4 = const(0x1E)
71+
_DRV2605_REG_VBAT = const(0x21)
72+
_DRV2605_REG_LRARESON = const(0x22)
7373

7474
# User-facing mode value constants:
75-
MODE_INTTRIG = 0x00
76-
MODE_EXTTRIGEDGE = 0x01
77-
MODE_EXTTRIGLVL = 0x02
78-
MODE_PWMANALOG = 0x03
79-
MODE_AUDIOVIBE = 0x04
80-
MODE_REALTIME = 0x05
81-
MODE_DIAGNOS = 0x06
82-
MODE_AUTOCAL = 0x07
83-
LIBRARY_EMPTY = 0x00
84-
LIBRARY_TS2200A = 0x01
85-
LIBRARY_TS2200B = 0x02
86-
LIBRARY_TS2200C = 0x03
87-
LIBRARY_TS2200D = 0x04
88-
LIBRARY_TS2200E = 0x05
89-
LIBRARY_LRA = 0x06
75+
MODE_INTTRIG = 0x00
76+
MODE_EXTTRIGEDGE = 0x01
77+
MODE_EXTTRIGLVL = 0x02
78+
MODE_PWMANALOG = 0x03
79+
MODE_AUDIOVIBE = 0x04
80+
MODE_REALTIME = 0x05
81+
MODE_DIAGNOS = 0x06
82+
MODE_AUTOCAL = 0x07
83+
LIBRARY_EMPTY = 0x00
84+
LIBRARY_TS2200A = 0x01
85+
LIBRARY_TS2200B = 0x02
86+
LIBRARY_TS2200C = 0x03
87+
LIBRARY_TS2200D = 0x04
88+
LIBRARY_TS2200E = 0x05
89+
LIBRARY_LRA = 0x06
9090
# pylint: enable=bad-whitespace
9191

92+
9293
class DRV2605:
9394
"""TI DRV2605 haptic feedback motor driver module."""
9495

@@ -103,13 +104,13 @@ def __init__(self, i2c, address=_DRV2605_ADDR):
103104
status = self._read_u8(_DRV2605_REG_STATUS)
104105
device_id = (status >> 5) & 0x07
105106
if device_id not in (3, 7):
106-
raise RuntimeError('Failed to find DRV2605, check wiring!')
107+
raise RuntimeError("Failed to find DRV2605, check wiring!")
107108
# Configure registers to initialize chip.
108-
self._write_u8(_DRV2605_REG_MODE, 0x00) # out of standby
109-
self._write_u8(_DRV2605_REG_RTPIN, 0x00) # no real-time-playback
110-
self._write_u8(_DRV2605_REG_WAVESEQ1, 1) # strong click
109+
self._write_u8(_DRV2605_REG_MODE, 0x00) # out of standby
110+
self._write_u8(_DRV2605_REG_RTPIN, 0x00) # no real-time-playback
111+
self._write_u8(_DRV2605_REG_WAVESEQ1, 1) # strong click
111112
self._write_u8(_DRV2605_REG_WAVESEQ2, 0)
112-
self._write_u8(_DRV2605_REG_OVERDRIVE, 0) # no overdrive
113+
self._write_u8(_DRV2605_REG_OVERDRIVE, 0) # no overdrive
113114
self._write_u8(_DRV2605_REG_SUSTAINPOS, 0)
114115
self._write_u8(_DRV2605_REG_SUSTAINNEG, 0)
115116
self._write_u8(_DRV2605_REG_BREAK, 0)
@@ -168,7 +169,7 @@ def mode(self):
168169
@mode.setter
169170
def mode(self, val):
170171
if not 0 <= val <= 7:
171-
raise ValueError('Mode must be a value within 0-7!')
172+
raise ValueError("Mode must be a value within 0-7!")
172173
self._write_u8(_DRV2605_REG_MODE, val)
173174

174175
@property
@@ -193,7 +194,7 @@ def library(self):
193194
@library.setter
194195
def library(self, val):
195196
if not 0 <= val <= 6:
196-
raise ValueError('Library must be a value within 0-6!')
197+
raise ValueError("Library must be a value within 0-6!")
197198
self._write_u8(_DRV2605_REG_LIBRARY, val)
198199

199200
@property
@@ -215,9 +216,9 @@ def set_waveform(self, effect_id, slot=0):
215216
waveform / effect.
216217
"""
217218
if not 0 <= effect_id <= 123:
218-
raise ValueError('Effect ID must be a value within 0-123!')
219+
raise ValueError("Effect ID must be a value within 0-123!")
219220
if not 0 <= slot <= 6:
220-
raise ValueError('Slot must be a value within 0-6!')
221+
raise ValueError("Slot must be a value within 0-6!")
221222
self._write_u8(_DRV2605_REG_WAVESEQ1 + slot, effect_id)
222223

223224
# pylint: disable=invalid-name
@@ -233,9 +234,9 @@ def use_LRM(self):
233234
self._write_u8(_DRV2605_REG_FEEDBACK, feedback | 0x80)
234235

235236

236-
237237
class Effect:
238238
"""DRV2605 waveform sequence effect."""
239+
239240
def __init__(self, effect_id):
240241
self._effect_id = 0
241242
# pylint: disable=invalid-name
@@ -257,16 +258,16 @@ def id(self):
257258
def id(self, effect_id):
258259
"""Set the effect ID."""
259260
if not 0 <= effect_id <= 123:
260-
raise ValueError('Effect ID must be a value within 0-123!')
261+
raise ValueError("Effect ID must be a value within 0-123!")
261262
self._effect_id = effect_id
262263

263264
def __repr__(self):
264265
return "{}({})".format(type(self).__qualname__, self.id)
265266

266267

267-
268268
class Pause:
269269
"""DRV2605 waveform sequence timed delay."""
270+
270271
def __init__(self, duration):
271272
# Bit 7 must be set for a slot to be interpreted as a delay
272273
self._duration = 0x80
@@ -281,43 +282,43 @@ def raw_value(self):
281282
def duration(self):
282283
"""Pause duration in seconds."""
283284
# Remove wait time flag bit and convert duration to seconds
284-
return (self._duration & 0x7f) / 100.0
285+
return (self._duration & 0x7F) / 100.0
285286

286287
@duration.setter
287288
def duration(self, duration):
288289
"""Set the pause duration in seconds."""
289290
if not 0.0 <= duration <= 1.27:
290-
raise ValueError('Pause duration must be a value within 0.0-1.27!')
291+
raise ValueError("Pause duration must be a value within 0.0-1.27!")
291292
# Add wait time flag bit and convert duration to centiseconds
292293
self._duration = 0x80 | round(duration * 100.0)
293294

294295
def __repr__(self):
295296
return "{}({})".format(type(self).__qualname__, self.duration)
296297

297298

298-
299299
class _DRV2605_Sequence:
300300
"""Class to enable List-like indexing of the waveform sequence slots."""
301+
301302
def __init__(self, DRV2605_instance):
302303
self._drv2605 = DRV2605_instance
303304

304305
def __setitem__(self, slot, effect):
305306
"""Write an Effect or Pause to a slot."""
306307
if not 0 <= slot <= 6:
307-
raise IndexError('Slot must be a value within 0-6!')
308+
raise IndexError("Slot must be a value within 0-6!")
308309
if not isinstance(effect, (Effect, Pause)):
309-
raise TypeError('Effect must be either an Effect() or Pause()!')
310+
raise TypeError("Effect must be either an Effect() or Pause()!")
310311
# pylint: disable=protected-access
311312
self._drv2605._write_u8(_DRV2605_REG_WAVESEQ1 + slot, effect.raw_value)
312313

313314
def __getitem__(self, slot):
314315
"""Read an effect ID from a slot. Returns either a Pause or Effect class."""
315316
if not 0 <= slot <= 6:
316-
raise IndexError('Slot must be a value within 0-6!')
317+
raise IndexError("Slot must be a value within 0-6!")
317318
# pylint: disable=protected-access
318319
slot_contents = self._drv2605._read_u8(_DRV2605_REG_WAVESEQ1 + slot)
319320
if slot_contents & 0x80:
320-
return Pause((slot_contents & 0x7f) / 100.0)
321+
return Pause((slot_contents & 0x7F) / 100.0)
321322
return Effect(slot_contents)
322323

323324
def __iter__(self):
@@ -327,4 +328,4 @@ def __iter__(self):
327328

328329
def __repr__(self):
329330
"""Return a string representation of all slot's effects."""
330-
return repr([effect for effect in self])
331+
return repr(list(self))

0 commit comments

Comments
 (0)