1- # Thermal_Cam_v31 .py
2- # 2020-01-28 v3.1
1+ # Thermal_Cam_v32 .py
2+ # 2020-01-29 v3.2
33# (c) 2020 Jan Goolsbey for Adafruit Industries
44
55import time
6- from collections import namedtuple
76import board
87import displayio
98from simpleio import map_range
7776param_list = [("ALARM" , WHITE ), ("RANGE" , RED ), ("RANGE" , CYAN )]
7877
7978### Helpers ###
80- Coords = namedtuple ("Point" , "x y" ) # Used by element_grid()
81-
8279def 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
8483
8584def flash_status (text = "" , duration = 0.05 ): # Flash status message once
8685 status_label .color = WHITE
@@ -160,7 +159,7 @@ def setup_mode(): # Set alarm threshold and minimum/maximum range values
160159 # Select parameter to set
161160 while not panel .button .start :
162161 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 )
164163 if up :
165164 param_index = param_index - 1
166165 if down :
@@ -182,7 +181,7 @@ def setup_mode(): # Set alarm threshold and minimum/maximum range values
182181 # Adjust parameter value
183182 param_value = int (image_group [param_index + 70 ].text )
184183 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 )
186185 if up :
187186 param_value = param_value + 1
188187 if down :
@@ -217,27 +216,18 @@ def setup_mode(): # Set alarm threshold and minimum/maximum range values
217216 return int (alarm_value .text ), int (max_value .text ), int (min_value .text )
218217
219218def move_buttons (joystick = False ): # Read position buttons and joystick
220- move_r = move_l = False
221219 move_u = move_d = False
222220 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
227221 if panel .joystick [1 ] < 20000 :
228222 move_u = True
229223 elif panel .joystick [1 ] > 44000 :
230224 move_d = True
231225 else : # For PyBadge read the buttons
232- if panel .button .right :
233- move_r = True
234- if panel .button .left :
235- move_l = True
236226 if panel .button .up :
237227 move_u = True
238228 if panel .button .down :
239229 move_d = True
240- return move_r , move_l , move_u , move_d
230+ return move_u , move_d
241231
242232### Define the display group ###
243233image_group = displayio .Group (max_size = 77 )
@@ -254,83 +244,83 @@ def move_buttons(joystick=False): # Read position buttons and joystick
254244# image_group[#]=(row * 8) + column
255245for row in range (0 , 8 ):
256246 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 ,
259249 width = ELEMENT_SIZE , height = ELEMENT_SIZE ,
260250 fill = None , outline = None , stroke = 0 )
261251 image_group .append (element )
262252
263253# Define labels and values using element grid coordinates
264254status_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
268258image_group .append (status_label ) # image_group[65]
269259
270260alarm_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
274264image_group .append (alarm_label ) # image_group[66]
275265
276266max_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
280270image_group .append (max_label ) # image_group[67]
281271
282272min_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
286276image_group .append (min_label ) # image_group[68]
287277
288278ave_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
292282image_group .append (ave_label ) # image_group[69]
293283
294284alarm_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
298288image_group .append (alarm_value ) # image_group[70]
299289
300290max_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
304294image_group .append (max_value ) # image_group[71]
305295
306296min_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
310300image_group .append (min_value ) # image_group[72]
311301
312302ave_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
316306image_group .append (ave_value ) # image_group[73]
317307
318308min_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
322312image_group .append (min_histo ) # image_group[74]
323313
324314max_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
328318image_group .append (max_histo ) # image_group[75]
329319
330320range_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
334324image_group .append (range_histo ) # image_group[76]
335325
336326###--- PRIMARY PROCESS SETUP ---###
0 commit comments