Skip to content

Commit 99225f0

Browse files
authored
Merge pull request #12 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 906578a + df363c6 commit 99225f0

File tree

5 files changed

+137
-115
lines changed

5 files changed

+137
-115
lines changed

.github/workflows/build.yml

+1-1
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_stmpe610.py

+38-34
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_STMPE610.git"
3939

4040

41-
4241
_STMPE_ADDR = const(0x41)
4342
_STMPE_VERSION = const(0x0811)
4443

@@ -60,7 +59,6 @@
6059
_STMPE_INT_CTRL_DISABLE = const(0x00)
6160

6261

63-
6462
_STMPE_INT_EN = const(0x0A)
6563
_STMPE_INT_EN_TOUCHDET = const(0x01)
6664
_STMPE_INT_EN_FIFOTH = const(0x02)
@@ -129,35 +127,40 @@
129127
_STMPE_GPIO_ALT_FUNCT = const(0x17)
130128

131129

132-
133130
class Adafruit_STMPE610:
134131
"""
135132
A driver for the STMPE610 Resistive Touch sensor.
136133
"""
134+
137135
def __init__(self):
138136
"""Reset the controller"""
139137
self._write_register_byte(_STMPE_SYS_CTRL1, _STMPE_SYS_CTRL1_RESET)
140-
time.sleep(.001)
138+
time.sleep(0.001)
141139

142-
143-
self._write_register_byte(_STMPE_SYS_CTRL2, 0x0) # turn on clocks!
140+
self._write_register_byte(_STMPE_SYS_CTRL2, 0x0) # turn on clocks!
144141
self._write_register_byte(
145-
_STMPE_TSC_CTRL, _STMPE_TSC_CTRL_XYZ | _STMPE_TSC_CTRL_EN) # XYZ and enable!
142+
_STMPE_TSC_CTRL, _STMPE_TSC_CTRL_XYZ | _STMPE_TSC_CTRL_EN
143+
) # XYZ and enable!
146144
self._write_register_byte(_STMPE_INT_EN, _STMPE_INT_EN_TOUCHDET)
147145
self._write_register_byte(
148-
_STMPE_ADC_CTRL1, _STMPE_ADC_CTRL1_10BIT | (0x6 << 4)) # 96 clocks per conversion
146+
_STMPE_ADC_CTRL1, _STMPE_ADC_CTRL1_10BIT | (0x6 << 4)
147+
) # 96 clocks per conversion
149148
self._write_register_byte(_STMPE_ADC_CTRL2, _STMPE_ADC_CTRL2_6_5MHZ)
150149
self._write_register_byte(
151-
_STMPE_TSC_CFG, _STMPE_TSC_CFG_4SAMPLE | _STMPE_TSC_CFG_DELAY_1MS
152-
| _STMPE_TSC_CFG_SETTLE_5MS)
150+
_STMPE_TSC_CFG,
151+
_STMPE_TSC_CFG_4SAMPLE
152+
| _STMPE_TSC_CFG_DELAY_1MS
153+
| _STMPE_TSC_CFG_SETTLE_5MS,
154+
)
153155
self._write_register_byte(_STMPE_TSC_FRACTION_Z, 0x6)
154156
self._write_register_byte(_STMPE_FIFO_TH, 1)
155157
self._write_register_byte(_STMPE_FIFO_STA, _STMPE_FIFO_STA_RESET)
156-
self._write_register_byte(_STMPE_FIFO_STA, 0) # unreset
158+
self._write_register_byte(_STMPE_FIFO_STA, 0) # unreset
157159
self._write_register_byte(_STMPE_TSC_I_DRIVE, _STMPE_TSC_I_DRIVE_50MA)
158-
self._write_register_byte(_STMPE_INT_STA, 0xFF) # reset all ints
160+
self._write_register_byte(_STMPE_INT_STA, 0xFF) # reset all ints
159161
self._write_register_byte(
160-
_STMPE_INT_CTRL, _STMPE_INT_CTRL_POL_HIGH | _STMPE_INT_CTRL_ENABLE)
162+
_STMPE_INT_CTRL, _STMPE_INT_CTRL_POL_HIGH | _STMPE_INT_CTRL_ENABLE
163+
)
161164

162165
def read_data(self):
163166
"""Request next stored reading - return tuple containing (x,y,pressure) """
@@ -188,7 +191,6 @@ def _write_register_byte(self, register, value):
188191
# Subclasses MUST implement this!
189192
raise NotImplementedError
190193

191-
192194
@property
193195
def touches(self):
194196
"""
@@ -198,27 +200,25 @@ def touches(self):
198200
touchpoints = []
199201
while (len(touchpoints) < 4) and not self.buffer_empty:
200202
(x_loc, y_loc, pressure) = self.read_data()
201-
point = {'x':x_loc, 'y':y_loc, 'pressure':pressure}
203+
point = {"x": x_loc, "y": y_loc, "pressure": pressure}
202204
touchpoints.append(point)
203205
return touchpoints
204206

205-
206207
@property
207208
def get_version(self):
208209
"Read the version number from the sensosr"
209210
v_1 = self._read_byte(0)
210211
v_2 = self._read_byte(1)
211-
version = v_1<<8 | v_2
212-
#print("version ",hex(version))
212+
version = v_1 << 8 | v_2
213+
# print("version ",hex(version))
213214
return version
214215

215216
@property
216217
def touched(self):
217218
"Report if any touches have been detectd"
218-
touch = self._read_byte(_STMPE_TSC_CTRL)&0x80
219+
touch = self._read_byte(_STMPE_TSC_CTRL) & 0x80
219220
return touch == 0x80
220221

221-
222222
@property
223223
def buffer_size(self):
224224
"The amount of touch data in the buffer"
@@ -230,33 +230,31 @@ def buffer_empty(self):
230230
empty = self._read_byte(_STMPE_FIFO_STA) & _STMPE_FIFO_STA_EMPTY
231231
return empty != 0
232232

233-
234-
235233
@property
236234
def get_point(self):
237235
"Read one touch from the buffer"
238236
(x_loc, y_loc, pressure) = self.read_data()
239-
point = {'x':x_loc, 'y':y_loc, 'pressure':pressure}
240-
return point
241-
242-
237+
point = {"x": x_loc, "y": y_loc, "pressure": pressure}
238+
return point
243239

244240

245241
class Adafruit_STMPE610_I2C(Adafruit_STMPE610):
246242
"""
247243
I2C driver for the STMPE610 Resistive Touch sensor.
248244
"""
245+
249246
def __init__(self, i2c, address=_STMPE_ADDR):
250247
"""
251248
Check the STMPE610 was founnd
252249
Default address is 0x41 but another address can be passed in as an argument
253250
"""
254-
import adafruit_bus_device.i2c_device as i2cdev
251+
import adafruit_bus_device.i2c_device as i2cdev # pylint: disable=import-outside-toplevel
252+
255253
self._i2c = i2cdev.I2CDevice(i2c, address)
256254
# Check device version.
257255
version = self.get_version
258256
if _STMPE_VERSION != version:
259-
raise RuntimeError('Failed to find STMPE610! Chip Version 0x%x' % version)
257+
raise RuntimeError("Failed to find STMPE610! Chip Version 0x%x" % version)
260258
super().__init__()
261259

262260
def _read_register(self, register, length):
@@ -265,34 +263,40 @@ def _read_register(self, register, length):
265263
i2c.write(bytearray([register & 0xFF]))
266264
result = bytearray(length)
267265
i2c.readinto(result)
268-
#print("$%02X => %s" % (register, [hex(i) for i in result]))
266+
# print("$%02X => %s" % (register, [hex(i) for i in result]))
269267
return result
270268

271269
def _write_register_byte(self, register, value):
272270
"""Low level register writing over I2C, writes one 8-bit value"""
273271
with self._i2c as i2c:
274272
i2c.write(bytes([register & 0xFF, value & 0xFF]))
275-
#print("$%02X <= 0x%02X" % (register, value))
273+
# print("$%02X <= 0x%02X" % (register, value))
276274

277275

278276
class Adafruit_STMPE610_SPI(Adafruit_STMPE610):
279277
"""
280278
SPI driver for the STMPE610 Resistive Touch sensor.
281279
"""
280+
282281
def __init__(self, spi, cs, baudrate=1000000):
283282
"""
284283
Check the STMPE610 was found,Default clock rate 1000000 - can be changed with 'baudrate'
285284
"""
286-
import adafruit_bus_device.spi_device as spidev
285+
import adafruit_bus_device.spi_device as spidev # pylint: disable=import-outside-toplevel
286+
287287
self._spi = spidev.SPIDevice(spi, cs, baudrate=baudrate)
288288
# Check device version.
289289
version = self.get_version
290290
if _STMPE_VERSION != version:
291291
# if it fails try SPI MODE 1 -- that is what Arduino does
292-
self._spi = spidev.SPIDevice(spi, cs, baudrate=baudrate, polarity=0, phase=1)
292+
self._spi = spidev.SPIDevice(
293+
spi, cs, baudrate=baudrate, polarity=0, phase=1
294+
)
293295
version = self.get_version
294296
if _STMPE_VERSION != version:
295-
raise RuntimeError('Failed to find STMPE610! Chip Version 0x%x' % version)
297+
raise RuntimeError(
298+
"Failed to find STMPE610! Chip Version 0x%x" % version
299+
)
296300
super().__init__()
297301

298302
# pylint: disable=no-member
@@ -304,7 +308,7 @@ def _read_register(self, register, length):
304308
spi.write(bytearray([register]))
305309
result = bytearray(length)
306310
spi.readinto(result)
307-
# print("$%02X => %s" % (register, [hex(i) for i in result]))
311+
# print("$%02X => %s" % (register, [hex(i) for i in result]))
308312
return result
309313

310314
def _write_register_byte(self, register, value):

0 commit comments

Comments
 (0)