Skip to content

Commit 41cff4a

Browse files
update and refactor with @FoamyGuy's suggestions
1 parent 81b5c69 commit 41cff4a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

examples/touch_calibrator_built_in.py renamed to examples/touchscreen_calibrator_built_in.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44
"""
5-
touch_calibrator_built_in.py 2022-01-21 v2.1
5+
touch_calibrator_built_in.py 2022-05-27 v2.2
66
77
Author(s): JG for Cedar Grove Maker Studios
88
@@ -47,19 +47,19 @@ class Colors:
4747
WHITE = 0xFFFFFF # Text
4848

4949

50-
# Instantiate the built-in display.
50+
# Instantiate the built-in display
5151
display = board.DISPLAY
5252

5353
# Check rotation value and update display.
5454
# Always set rotation before instantiating the touchscreen.
5555
if DISPLAY_ROTATION is not None and DISPLAY_ROTATION in (0, 90, 180, 270):
5656
display.rotation = DISPLAY_ROTATION
5757
else:
58-
print("Warning: invalid rotation value -- defalting to zero")
58+
print("Warning: invalid rotation value -- defaulting to zero")
5959
display.rotation = 0
6060
time.sleep(1)
6161

62-
# Activate the display graphics unless REPL_ONLY=True.
62+
# Activate the display graphics unless REPL_ONLY=True
6363
if not REPL_ONLY:
6464
display_group = displayio.Group()
6565
display.show(display_group)
@@ -107,7 +107,7 @@ class Colors:
107107
else:
108108
raise ValueError("Rotation value must be 0, 90, 180, or 270")
109109

110-
# Define the graphic objects if REPL_ONLY = False.
110+
# Define the graphic objects if REPL_ONLY = False
111111
if not REPL_ONLY:
112112
# Define the text graphic objects
113113
font_0 = terminalio.FONT
@@ -134,7 +134,7 @@ class Colors:
134134
board.DISPLAY.height // 4 - 30,
135135
)
136136

137-
# Define graphic objects for the screen fill, boundary, and touch pen.
137+
# Define graphic objects for the screen fill, boundary, and touch pen
138138
target_palette = displayio.Palette(1)
139139
target_palette[0] = Colors.BLUE_DK
140140
screen_fill = vectorio.Rectangle(
@@ -170,7 +170,7 @@ class Colors:
170170
display_group.append(display_rotation)
171171

172172
# pylint: disable=invalid-name
173-
# Reset x and y values to raw touchscreen mid-point before measurement.
173+
# Reset x and y values to raw touchscreen mid-point before measurement
174174
x_min = x_max = y_min = y_max = 65535 // 2
175175

176176
print("Touchscreen Calibrator")
@@ -185,11 +185,7 @@ class Colors:
185185
time.sleep(0.100)
186186
touch = ts.touch_point # Check for touch
187187
if touch:
188-
if not REPL_ONLY:
189-
pen.x = int(map_range(touch[0], x_min, x_max, 0, board.DISPLAY.width)) - 5
190-
pen.y = int(map_range(touch[1], y_min, y_max, 0, board.DISPLAY.height)) - 5
191-
192-
# Remember minimum and maximum values for the calibration tuple.
188+
# Remember minimum and maximum values for the calibration tuple
193189
x_min = min(x_min, touch[0])
194190
x_max = max(x_max, touch[0])
195191
y_min = min(y_min, touch[1])
@@ -198,4 +194,6 @@ class Colors:
198194
# Show the calibration tuple.
199195
print(f"(({x_min}, {x_max}), ({y_min}, {y_max}))")
200196
if not REPL_ONLY:
197+
pen.x = int(map_range(touch[0], x_min, x_max, 0, board.DISPLAY.width)) - 5
198+
pen.y = int(map_range(touch[1], y_min, y_max, 0, board.DISPLAY.height)) - 5
201199
coordinates.text = f"calib: (({x_min}, {x_max}), ({y_min}, {y_max}))"

0 commit comments

Comments
 (0)