Skip to content

Commit 0168375

Browse files
committed
pylint fixes
1 parent 5f676e6 commit 0168375

File tree

3 files changed

+52
-27
lines changed

3 files changed

+52
-27
lines changed

TFT_Spirit_Board/esp32s3_s2_tft_featherwing_480x320/code.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
88
Receive and display messages from the spirits.
99
"""
10+
# pylint: disable=import-error, invalid-name
1011
import os
1112
import displayio
1213
import board
1314
from digitalio import DigitalInOut
1415
import adafruit_connection_manager
1516
import wifi
1617
import adafruit_requests
17-
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
18+
from adafruit_io.adafruit_io import IO_HTTP
1819
from adafruit_hx8357 import HX8357 # TFT Featherwing 3.5" 480x320 display driver
19-
from spirit_board import SpiritBoard
2020
import adafruit_tsc2007
2121

22+
from spirit_board import SpiritBoard
23+
24+
2225

2326
# 3.5" TFT Featherwing is 480x320
2427
displayio.release_displays()
@@ -37,8 +40,7 @@
3740
# Initialize 3.5" TFT Featherwing Touchscreen
3841
ts_cs_pin = DigitalInOut(board.D6)
3942
i2c = board.I2C()
40-
irq_dio = None
41-
tsc = adafruit_tsc2007.TSC2007(i2c, irq=irq_dio)
43+
tsc = adafruit_tsc2007.TSC2007(i2c, irq=None)
4244

4345
# Initialize a requests session
4446
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)

TFT_Spirit_Board/shared/lib/anchored_tilegrid.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
AnchoredTilegrid helper class
3+
"""
14
try:
25
from typing import Tuple
36
except ImportError:
@@ -7,6 +10,10 @@
710

811

912
class AnchoredTileGrid(TileGrid):
13+
"""
14+
AnchoredTileGrid extends TileGrid and allows placing the TileGrid
15+
relative to an arbitrary anchor point.
16+
"""
1017
def __init__(self, bitmap, **kwargs):
1118
super().__init__(bitmap, **kwargs)
1219
self._anchor_point = (0, 0)
@@ -18,6 +25,10 @@ def __init__(self, bitmap, **kwargs):
1825

1926
@property
2027
def anchor_point(self):
28+
"""
29+
The anchor point. tuple containing x and y values ranging
30+
from 0 to 1.
31+
"""
2132
return self._anchor_point
2233

2334
@anchor_point.setter
@@ -35,11 +46,9 @@ def anchored_position(self) -> Tuple[int, int]:
3546
@anchored_position.setter
3647
def anchored_position(self, new_position: Tuple[int, int]) -> None:
3748
self._anchored_position = new_position
38-
# Calculate (x,y) position
39-
if (self._anchor_point is not None) and (self._anchored_position is not None):
40-
new_x = int(new_position[0]
41-
- round(self._anchor_point[0] * (self.tile_width * self.width)))
4249

50+
if (self._anchor_point is not None) and (self._anchored_position is not None):
51+
# Calculate (x,y) position
4352
self.x = int(
4453
new_position[0]
4554
- round(self._anchor_point[0] * (self.tile_width * self.width))

TFT_Spirit_Board/shared/spirit_board.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
"""
2+
SpiritBoard helper class
3+
"""
14
import math
25
import os
36
import random
47
import time
5-
68
import displayio
9+
10+
# pylint: disable=import-error
711
from anchored_tilegrid import AnchoredTileGrid
812

13+
914
class SpiritBoard(displayio.Group):
1015
"""
1116
DisplayIO Based SpiritBoard
1217
1318
Holds and manages everything needed to draw the spirit board and planchette, as well
1419
as move the planchette around to output messages from the spirits.
1520
"""
16-
1721
# Mapping of letters and words on the board to their pixel coordinates.
1822
# Points are centered on the target letter.
1923
# Words can contain a list of points, the planchette will move between them.
@@ -44,13 +48,16 @@ def __init__(self, display):
4448

4549
# board image file
4650
self.spirit_board_odb = displayio.OnDiskBitmap("spirit_board_480x320.bmp")
47-
self.spirit_board_tilegrid = displayio.TileGrid(bitmap=self.spirit_board_odb, pixel_shader=self.spirit_board_odb.pixel_shader)
51+
self.spirit_board_tilegrid = displayio.TileGrid(
52+
bitmap=self.spirit_board_odb, pixel_shader=self.spirit_board_odb.pixel_shader)
53+
4854
self.append(self.spirit_board_tilegrid)
4955

5056
# planchette image file
5157
self.planchette_odb = displayio.OnDiskBitmap("planchette_v1.bmp")
5258
self.planchette_odb.pixel_shader.make_transparent(0)
53-
self.planchette_tilegrid = AnchoredTileGrid(bitmap=self.planchette_odb, pixel_shader=self.planchette_odb.pixel_shader)
59+
self.planchette_tilegrid = AnchoredTileGrid(
60+
bitmap=self.planchette_odb, pixel_shader=self.planchette_odb.pixel_shader)
5461

5562
# AnchoredTileGrid is used so that we can move the planchette
5663
# relative to the cetner of the window.
@@ -66,15 +73,15 @@ def __init__(self, display):
6673
display.root_group = self
6774

6875
@staticmethod
69-
def dist(pointA, pointB):
76+
def dist(point_a, point_b):
7077
"""
7178
Calculate the distance between two points.
7279
73-
:param tuple pointA: x,y pair of the first point
74-
:param pointB: x,y pair of the second point
80+
:param tuple point_a: x,y pair of the first point
81+
:param point_b: x,y pair of the second point
7582
:return: the distance between the two points
7683
"""
77-
return math.sqrt((pointB[0] - pointA[0]) ** 2 + (pointB[1] - pointA[1]) ** 2)
84+
return math.sqrt((point_b[0] - point_a[0]) ** 2 + (point_b[1] - point_a[1]) ** 2)
7885

7986
def slide_planchette(self, target_location, delay=0.1, step_size=4):
8087
"""
@@ -114,12 +121,14 @@ def slide_planchette(self, target_location, delay=0.1, step_size=4):
114121
# variables used to calculate where the next point
115122
# between where we are at and where we are going is.
116123
distance_ratio = step_size / distance
117-
one_minus_distance_ratio = (1 - distance_ratio)
124+
one_minus_distance_ratio = 1 - distance_ratio
118125

119126
# calculate the next point
120127
next_point = (
121-
round(one_minus_distance_ratio * current_location[0] + distance_ratio * target_location[0]),
122-
round(one_minus_distance_ratio * current_location[1] + distance_ratio * target_location[1])
128+
round(one_minus_distance_ratio * current_location[0]
129+
+ distance_ratio * target_location[0]),
130+
round(one_minus_distance_ratio * current_location[1]
131+
+ distance_ratio * target_location[1])
123132
)
124133
# print(current_location)
125134
# print(next_point)
@@ -149,12 +158,14 @@ def slide_planchette(self, target_location, delay=0.1, step_size=4):
149158

150159
# distance ratio variables used to calculate next point
151160
distance_ratio = step_size / distance
152-
one_minus_distance_ratio = (1 - distance_ratio)
161+
one_minus_distance_ratio = 1 - distance_ratio
153162

154163
# calculate the next point
155164
next_point = (
156-
round(one_minus_distance_ratio * current_location[0] + distance_ratio * target_location[0]),
157-
round(one_minus_distance_ratio * current_location[1] + distance_ratio * target_location[1])
165+
round(one_minus_distance_ratio * current_location[0]
166+
+ distance_ratio * target_location[0]),
167+
round(one_minus_distance_ratio * current_location[1]
168+
+ distance_ratio * target_location[1])
158169
)
159170

160171
# if we have not arrived at the target location yet
@@ -219,7 +230,8 @@ def write_message(self, message, skip_spaces=True, step_size=6):
219230
# if the word has only a single point
220231
elif isinstance(SpiritBoard.LOCATIONS[word], tuple):
221232
# slide the planchette to the point
222-
self.slide_planchette(SpiritBoard.LOCATIONS[word], delay=0.02, step_size=step_size)
233+
self.slide_planchette(SpiritBoard.LOCATIONS[word],
234+
delay=0.02, step_size=step_size)
223235

224236
# pause at the point
225237
time.sleep(0.5)
@@ -230,7 +242,8 @@ def write_message(self, message, skip_spaces=True, step_size=6):
230242
# loop over each character in the word
231243
for character in word:
232244
# slide the planchette to the current characters location
233-
self.slide_planchette(SpiritBoard.LOCATIONS[character], delay=0.02, step_size=step_size)
245+
self.slide_planchette(SpiritBoard.LOCATIONS[character],
246+
delay=0.02, step_size=step_size)
234247

235248
# pause after we arrive
236249
time.sleep(0.5)
@@ -239,7 +252,8 @@ def write_message(self, message, skip_spaces=True, step_size=6):
239252
if not skip_spaces and index < len(message_words) - 1:
240253
# handle the space
241254
# slide the planchette to the empty space location.
242-
self.slide_planchette(SpiritBoard.LOCATIONS[" "], delay=0.02, step_size=step_size)
255+
self.slide_planchette(SpiritBoard.LOCATIONS[" "],
256+
delay=0.02, step_size=step_size)
243257

244258
# pause after we arrive
245259
time.sleep(0.5)
@@ -298,7 +312,7 @@ def read_local_messages_file(shuffle=False) -> list:
298312
# if the spirit_messages.txt file exists
299313
if "spirit_messages.txt" in os.listdir("/"):
300314
# open the file
301-
with open("/spirit_messages.txt", "r") as f:
315+
with open("/spirit_messages.txt", "r", encoding="utf-8") as f:
302316
# split on newline and set the messages found into the context
303317
messages = f.read().split("\n")
304318

@@ -311,7 +325,7 @@ def read_local_messages_file(shuffle=False) -> list:
311325
"messages to spirit_messages.txt.")
312326

313327
# if there are messages and we need to shuffle them
314-
elif shuffle:
328+
if shuffle:
315329
# temporary list to hold them
316330
shuffled_list = []
317331

0 commit comments

Comments
 (0)