2
2
# SPDX-License-Identifier: MIT
3
3
4
4
"""
5
- touch_calibrator_built_in.py 2022-01-21 v2.1
5
+ touch_calibrator_built_in.py 2022-05-27 v2.2
6
6
7
7
Author(s): JG for Cedar Grove Maker Studios
8
8
@@ -47,19 +47,19 @@ class Colors:
47
47
WHITE = 0xFFFFFF # Text
48
48
49
49
50
- # Instantiate the built-in display.
50
+ # Instantiate the built-in display
51
51
display = board .DISPLAY
52
52
53
53
# Check rotation value and update display.
54
54
# Always set rotation before instantiating the touchscreen.
55
55
if DISPLAY_ROTATION is not None and DISPLAY_ROTATION in (0 , 90 , 180 , 270 ):
56
56
display .rotation = DISPLAY_ROTATION
57
57
else :
58
- print ("Warning: invalid rotation value -- defalting to zero" )
58
+ print ("Warning: invalid rotation value -- defaulting to zero" )
59
59
display .rotation = 0
60
60
time .sleep (1 )
61
61
62
- # Activate the display graphics unless REPL_ONLY=True.
62
+ # Activate the display graphics unless REPL_ONLY=True
63
63
if not REPL_ONLY :
64
64
display_group = displayio .Group ()
65
65
display .show (display_group )
@@ -107,7 +107,7 @@ class Colors:
107
107
else :
108
108
raise ValueError ("Rotation value must be 0, 90, 180, or 270" )
109
109
110
- # Define the graphic objects if REPL_ONLY = False.
110
+ # Define the graphic objects if REPL_ONLY = False
111
111
if not REPL_ONLY :
112
112
# Define the text graphic objects
113
113
font_0 = terminalio .FONT
@@ -134,7 +134,7 @@ class Colors:
134
134
board .DISPLAY .height // 4 - 30 ,
135
135
)
136
136
137
- # Define graphic objects for the screen fill, boundary, and touch pen.
137
+ # Define graphic objects for the screen fill, boundary, and touch pen
138
138
target_palette = displayio .Palette (1 )
139
139
target_palette [0 ] = Colors .BLUE_DK
140
140
screen_fill = vectorio .Rectangle (
@@ -170,7 +170,7 @@ class Colors:
170
170
display_group .append (display_rotation )
171
171
172
172
# 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
174
174
x_min = x_max = y_min = y_max = 65535 // 2
175
175
176
176
print ("Touchscreen Calibrator" )
@@ -185,11 +185,7 @@ class Colors:
185
185
time .sleep (0.100 )
186
186
touch = ts .touch_point # Check for touch
187
187
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
193
189
x_min = min (x_min , touch [0 ])
194
190
x_max = max (x_max , touch [0 ])
195
191
y_min = min (y_min , touch [1 ])
@@ -198,4 +194,6 @@ class Colors:
198
194
# Show the calibration tuple.
199
195
print (f"(({ x_min } , { x_max } ), ({ y_min } , { y_max } ))" )
200
196
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
201
199
coordinates .text = f"calib: (({ x_min } , { x_max } ), ({ y_min } , { y_max } ))"
0 commit comments