1
- # Thermal_Cam_v31 .py
2
- # 2020-01-28 v3.1
1
+ # Thermal_Cam_v32 .py
2
+ # 2020-01-29 v3.2
3
3
# (c) 2020 Jan Goolsbey for Adafruit Industries
4
4
5
5
import time
6
- from collections import namedtuple
7
6
import board
8
7
import displayio
9
8
from simpleio import map_range
77
76
param_list = [("ALARM" , WHITE ), ("RANGE" , RED ), ("RANGE" , CYAN )]
78
77
79
78
### Helpers ###
80
- Coords = namedtuple ("Point" , "x y" ) # Used by element_grid()
81
-
82
79
def element_grid (col , row ): # Determine display coordinates for column, row
83
- return Coords (int (ELEMENT_SIZE * col + 30 ), int (ELEMENT_SIZE * row + 1 ))
80
+ x = int (ELEMENT_SIZE * col + 30 ) # x coord + margin
81
+ y = int (ELEMENT_SIZE * row + 1 ) # y coord + margin
82
+ return x , y # Return display coordinates
84
83
85
84
def flash_status (text = "" , duration = 0.05 ): # Flash status message once
86
85
status_label .color = WHITE
@@ -160,7 +159,7 @@ def setup_mode(): # Set alarm threshold and minimum/maximum range values
160
159
# Select parameter to set
161
160
while not panel .button .start :
162
161
while (not panel .button .a ) and (not panel .button .start ):
163
- left , right , up , down = move_buttons (joystick = panel .has_joystick )
162
+ up , down = move_buttons (joystick = panel .has_joystick )
164
163
if up :
165
164
param_index = param_index - 1
166
165
if down :
@@ -182,7 +181,7 @@ def setup_mode(): # Set alarm threshold and minimum/maximum range values
182
181
# Adjust parameter value
183
182
param_value = int (image_group [param_index + 70 ].text )
184
183
while (not panel .button .a ) and (not panel .button .start ):
185
- left , right , up , down = move_buttons (joystick = panel .has_joystick )
184
+ up , down = move_buttons (joystick = panel .has_joystick )
186
185
if up :
187
186
param_value = param_value + 1
188
187
if down :
@@ -217,27 +216,18 @@ def setup_mode(): # Set alarm threshold and minimum/maximum range values
217
216
return int (alarm_value .text ), int (max_value .text ), int (min_value .text )
218
217
219
218
def move_buttons (joystick = False ): # Read position buttons and joystick
220
- move_r = move_l = False
221
219
move_u = move_d = False
222
220
if joystick : # For PyGamer: interpret joystick as buttons
223
- if panel .joystick [0 ] > 44000 :
224
- move_r = True
225
- elif panel .joystick [0 ] < 20000 :
226
- move_l = True
227
221
if panel .joystick [1 ] < 20000 :
228
222
move_u = True
229
223
elif panel .joystick [1 ] > 44000 :
230
224
move_d = True
231
225
else : # For PyBadge read the buttons
232
- if panel .button .right :
233
- move_r = True
234
- if panel .button .left :
235
- move_l = True
236
226
if panel .button .up :
237
227
move_u = True
238
228
if panel .button .down :
239
229
move_d = True
240
- return move_r , move_l , move_u , move_d
230
+ return move_u , move_d
241
231
242
232
### Define the display group ###
243
233
image_group = displayio .Group (max_size = 77 )
@@ -254,83 +244,83 @@ def move_buttons(joystick=False): # Read position buttons and joystick
254
244
# image_group[#]=(row * 8) + column
255
245
for row in range (0 , 8 ):
256
246
for col in range (0 , 8 ):
257
- pos = element_grid (col , row )
258
- element = Rect (x = pos . x , y = pos . y ,
247
+ pos_x , pos_y = element_grid (col , row )
248
+ element = Rect (x = pos_x , y = pos_y ,
259
249
width = ELEMENT_SIZE , height = ELEMENT_SIZE ,
260
250
fill = None , outline = None , stroke = 0 )
261
251
image_group .append (element )
262
252
263
253
# Define labels and values using element grid coordinates
264
254
status_label = Label (font , text = "" , color = BLACK , max_glyphs = 6 )
265
- pos = element_grid (2.5 , 4 )
266
- status_label .x = pos . x
267
- status_label .y = pos . y
255
+ pos_x , pos_y = element_grid (2.5 , 4 )
256
+ status_label .x = pos_x
257
+ status_label .y = pos_y
268
258
image_group .append (status_label ) # image_group[65]
269
259
270
260
alarm_label = Label (font , text = "alm" , color = WHITE , max_glyphs = 3 )
271
- pos = element_grid (- 1.8 , 1.5 )
272
- alarm_label .x = pos . x
273
- alarm_label .y = pos . y
261
+ pos_x , pos_y = element_grid (- 1.8 , 1.5 )
262
+ alarm_label .x = pos_x
263
+ alarm_label .y = pos_y
274
264
image_group .append (alarm_label ) # image_group[66]
275
265
276
266
max_label = Label (font , text = "max" , color = RED , max_glyphs = 3 )
277
- pos = element_grid (- 1.8 , 3.5 )
278
- max_label .x = pos . x
279
- max_label .y = pos . y
267
+ pos_x , pos_y = element_grid (- 1.8 , 3.5 )
268
+ max_label .x = pos_x
269
+ max_label .y = pos_y
280
270
image_group .append (max_label ) # image_group[67]
281
271
282
272
min_label = Label (font , text = "min" , color = CYAN , max_glyphs = 3 )
283
- pos = element_grid (- 1.8 , 7.5 )
284
- min_label .x = pos . x
285
- min_label .y = pos . y
273
+ pos_x , pos_y = element_grid (- 1.8 , 7.5 )
274
+ min_label .x = pos_x
275
+ min_label .y = pos_y
286
276
image_group .append (min_label ) # image_group[68]
287
277
288
278
ave_label = Label (font , text = "ave" , color = YELLOW , max_glyphs = 3 )
289
- pos = element_grid (- 1.8 , 5.5 )
290
- ave_label .x = pos . x
291
- ave_label .y = pos . y
279
+ pos_x , pos_y = element_grid (- 1.8 , 5.5 )
280
+ ave_label .x = pos_x
281
+ ave_label .y = pos_y
292
282
image_group .append (ave_label ) # image_group[69]
293
283
294
284
alarm_value = Label (font , text = str (ALARM_F ), color = WHITE , max_glyphs = 5 )
295
- pos = element_grid (- 1.8 , 0.5 )
296
- alarm_value .x = pos . x
297
- alarm_value .y = pos . y
285
+ pos_x , pos_y = element_grid (- 1.8 , 0.5 )
286
+ alarm_value .x = pos_x
287
+ alarm_value .y = pos_y
298
288
image_group .append (alarm_value ) # image_group[70]
299
289
300
290
max_value = Label (font , text = str (MAX_RANGE_F ), color = RED , max_glyphs = 5 )
301
- pos = element_grid (- 1.8 , 2.5 )
302
- max_value .x = pos . x
303
- max_value .y = pos . y
291
+ pos_x , pos_y = element_grid (- 1.8 , 2.5 )
292
+ max_value .x = pos_x
293
+ max_value .y = pos_y
304
294
image_group .append (max_value ) # image_group[71]
305
295
306
296
min_value = Label (font , text = str (MIN_RANGE_F ), color = CYAN , max_glyphs = 5 )
307
- pos = element_grid (- 1.8 , 6.5 )
308
- min_value .x = pos . x
309
- min_value .y = pos . y
297
+ pos_x , pos_y = element_grid (- 1.8 , 6.5 )
298
+ min_value .x = pos_x
299
+ min_value .y = pos_y
310
300
image_group .append (min_value ) # image_group[72]
311
301
312
302
ave_value = Label (font , text = "---" , color = YELLOW , max_glyphs = 5 )
313
- pos = element_grid (- 1.8 , 4.5 )
314
- ave_value .x = pos . x
315
- ave_value .y = pos . y
303
+ pos_x , pos_y = element_grid (- 1.8 , 4.5 )
304
+ ave_value .x = pos_x
305
+ ave_value .y = pos_y
316
306
image_group .append (ave_value ) # image_group[73]
317
307
318
308
min_histo = Label (font , text = "" , color = CYAN , max_glyphs = 3 )
319
- pos = element_grid (0.5 , 7.5 )
320
- min_histo .x = pos . x
321
- min_histo .y = pos . y
309
+ pos_x , pos_y = element_grid (0.5 , 7.5 )
310
+ min_histo .x = pos_x
311
+ min_histo .y = pos_y
322
312
image_group .append (min_histo ) # image_group[74]
323
313
324
314
max_histo = Label (font , text = "" , color = RED , max_glyphs = 3 )
325
- pos = element_grid (6.5 , 7.5 )
326
- max_histo .x = pos . x
327
- max_histo .y = pos . y
315
+ pos_x , pos_y = element_grid (6.5 , 7.5 )
316
+ max_histo .x = pos_x
317
+ max_histo .y = pos_y
328
318
image_group .append (max_histo ) # image_group[75]
329
319
330
320
range_histo = Label (font , text = "" , color = BLUE , max_glyphs = 7 )
331
- pos = element_grid (2.5 , 7.5 )
332
- range_histo .x = pos . x
333
- range_histo .y = pos . y
321
+ pos_x , pos_y = element_grid (2.5 , 7.5 )
322
+ range_histo .x = pos_x
323
+ range_histo .y = pos_y
334
324
image_group .append (range_histo ) # image_group[76]
335
325
336
326
###--- PRIMARY PROCESS SETUP ---###
0 commit comments