1616from adafruit_mcp9600 import MCP9600
1717
1818TITLE = "EZ Make Oven Controller"
19- VERSION = "1.1 .0"
19+ VERSION = "1.2 .0"
2020
2121print (TITLE , "version " , VERSION )
2222time .sleep (2 )
2525board .DISPLAY .show (display_group )
2626
2727PROFILE_SIZE = 2 # plot thickness
28- PROFILE_COLOR = 0x00FF55 # plot color
2928GRID_SIZE = 2
30- GRID_COLOR = 0x2020FF
3129GRID_STYLE = 3
3230TEMP_SIZE = 2
33- TEMP_COLOR = 0xFF0000
34- LABEL_COLOR = 0x8080FF
3531AXIS_SIZE = 2
36- AXIS_COLOR = 0xFFFF00
32+
33+ BLACK = 0x0
34+ BLUE = 0x2020FF
35+ GREEN = 0x00FF55
36+ RED = 0xFF0000
37+ YELLOW = 0xFFFF00
3738
3839WIDTH = board .DISPLAY .width
3940HEIGHT = board .DISPLAY .height
4041
4142pyportal = PyPortal ()
4243
4344palette = displayio .Palette (5 )
44- palette [0 ] = 0x0
45- palette [1 ] = PROFILE_COLOR
46- palette [2 ] = GRID_COLOR
47- palette [3 ] = TEMP_COLOR
48- palette [4 ] = AXIS_COLOR
45+ palette [0 ] = BLACK
46+ palette [1 ] = GREEN
47+ palette [2 ] = BLUE
48+ palette [3 ] = RED
49+ palette [4 ] = YELLOW
50+
4951palette .make_transparent (0 )
5052
51- plot = displayio .Bitmap (WIDTH , HEIGHT , 8 )
52- pyportal .splash .append (displayio .TileGrid (plot , pixel_shader = palette ))
53+ BACKGROUND_COLOR = 0
54+ PROFILE_COLOR = 1
55+ GRID_COLOR = 2
56+ TEMP_COLOR = 3
57+ AXIS_COLOR = 2
58+
59+ GXSTART = 100
60+ GYSTART = 80
61+ GWIDTH = WIDTH - GXSTART
62+ GHEIGHT = HEIGHT - GYSTART
63+ plot = displayio .Bitmap (GWIDTH , GHEIGHT , 4 )
64+
65+ pyportal .splash .append (displayio .TileGrid (plot , pixel_shader = palette , x = GXSTART , y = GYSTART ))
5366
5467ts = adafruit_touchscreen .Touchscreen (board .TOUCH_XL , board .TOUCH_XR ,
5568 board .TOUCH_YD , board .TOUCH_YU ,
@@ -253,8 +266,8 @@ def __init__(self):
253266 self .ymax = 240
254267 self .xstart = 0
255268 self .ystart = 0
256- self .width = WIDTH
257- self .height = HEIGHT
269+ self .width = GWIDTH
270+ self .height = GHEIGHT
258271
259272 # pylint: disable=too-many-branches
260273 def draw_line (self , x1 , y1 , x2 , y2 , size = PROFILE_SIZE , color = 1 , style = 1 ):
@@ -323,82 +336,92 @@ def draw_point(self, x, y, size=PROFILE_SIZE, color=1):
323336 for yy in range (y - offset , y + offset + 1 ):
324337 if yy in range (self .ystart , self .ystart + self .height ):
325338 try :
326- yy = HEIGHT - yy
339+ yy = GHEIGHT - yy
327340 plot [xx , yy ] = color
328341 except IndexError :
329342 pass
330343
331344def draw_profile (graph , profile ):
332345 """Update the display with current info."""
333- for i in range (WIDTH * HEIGHT ):
346+ for i in range (GWIDTH * GHEIGHT ):
334347 plot [i ] = 0
335348
336349 # draw stage lines
337350 # preheat
338351 graph .draw_line (profile ["stages" ]["preheat" ][0 ], profile ["temp_range" ][0 ],
339352 profile ["stages" ]["preheat" ][0 ], profile ["temp_range" ][1 ]
340353 * 1.1 ,
341- GRID_SIZE , 2 , GRID_STYLE )
354+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
342355 graph .draw_line (profile ["time_range" ][0 ], profile ["stages" ]["preheat" ][1 ],
343356 profile ["time_range" ][1 ], profile ["stages" ]["preheat" ][1 ],
344- GRID_SIZE , 2 , GRID_STYLE )
357+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
345358 # soak
346359 graph .draw_line (profile ["stages" ]["soak" ][0 ], profile ["temp_range" ][0 ],
347360 profile ["stages" ]["soak" ][0 ], profile ["temp_range" ][1 ]* 1.1 ,
348- GRID_SIZE , 2 , GRID_STYLE )
361+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
349362 graph .draw_line (profile ["time_range" ][0 ], profile ["stages" ]["soak" ][1 ],
350363 profile ["time_range" ][1 ], profile ["stages" ]["soak" ][1 ],
351- GRID_SIZE , 2 , GRID_STYLE )
364+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
352365 # reflow
353366 graph .draw_line (profile ["stages" ]["reflow" ][0 ], profile ["temp_range" ][0 ],
354367 profile ["stages" ]["reflow" ][0 ], profile ["temp_range" ][1 ]
355368 * 1.1 ,
356- GRID_SIZE , 2 , GRID_STYLE )
369+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
357370 graph .draw_line (profile ["time_range" ][0 ], profile ["stages" ]["reflow" ][1 ],
358371 profile ["time_range" ][1 ], profile ["stages" ]["reflow" ][1 ],
359- GRID_SIZE , 2 , GRID_STYLE )
372+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
360373 # cool
361374 graph .draw_line (profile ["stages" ]["cool" ][0 ], profile ["temp_range" ][0 ],
362375 profile ["stages" ]["cool" ][0 ], profile ["temp_range" ][1 ]* 1.1 ,
363- GRID_SIZE , 2 , GRID_STYLE )
376+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
364377 graph .draw_line (profile ["time_range" ][0 ], profile ["stages" ]["cool" ][1 ],
365378 profile ["time_range" ][1 ], profile ["stages" ]["cool" ][1 ],
366- GRID_SIZE , 2 , GRID_STYLE )
379+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
367380
368381 # draw labels
369382 x = profile ["time_range" ][0 ]
370383 y = profile ["stages" ]["reflow" ][1 ]
371- xp = ( graph . xstart + graph .width * (x - graph .xmin )
372- // (graph .xmax - graph .xmin ))
373- yp = ( graph . ystart + int (graph . height * (y - graph .ymin )
374- / (graph .ymax - graph .ymin ) ))
384+ xp = int ( GXSTART + graph .width * (x - graph .xmin )
385+ // (graph .xmax - graph .xmin ))
386+ yp = int (GHEIGHT * (y - graph .ymin )
387+ // (graph .ymax - graph .ymin ))
375388
376389 label_reflow .x = xp + 10
377390 label_reflow .y = HEIGHT - yp
378391 label_reflow .text = str (profile ["stages" ]["reflow" ][1 ])
379392 print ("reflow temp:" , str (profile ["stages" ]["reflow" ][1 ]))
380393 print ("graph point: " , x , y , "->" , xp , yp )
381394
395+ x = profile ["stages" ]["reflow" ][0 ]
396+ y = profile ["stages" ]["reflow" ][1 ]
397+
382398 # draw time line (horizontal)
383- graph .draw_line (graph .xmin , graph .ymin , graph .xmax , graph .ymin , AXIS_SIZE , 4 , 1 )
384- graph .draw_line (graph .xmin , graph .ymax - AXIS_SIZE , graph .xmax , graph .ymax
385- - AXIS_SIZE , AXIS_SIZE , 4 , 1 )
399+ graph .draw_line (graph .xmin , graph .ymin + 1 , graph .xmax ,
400+ graph .ymin + 1 , AXIS_SIZE , AXIS_COLOR , 1 )
401+ graph .draw_line (graph .xmin , graph .ymax , graph .xmax , graph .ymax ,
402+ AXIS_SIZE , AXIS_COLOR , 1 )
386403 # draw time ticks
387404 tick = graph .xmin
388405 while tick < (graph .xmax - graph .xmin ):
389- graph .draw_line (tick , graph .ymin , tick , graph .ymin + 10 , AXIS_SIZE , 4 , 1 )
390- graph .draw_line (tick , graph .ymax , tick , graph .ymax - 10 - AXIS_SIZE , AXIS_SIZE , 4 , 1 )
406+ graph .draw_line (tick , graph .ymin , tick , graph .ymin + 10 ,
407+ AXIS_SIZE , AXIS_COLOR , 1 )
408+ graph .draw_line (tick , graph .ymax , tick , graph .ymax - 10 - AXIS_SIZE ,
409+ AXIS_SIZE , AXIS_COLOR , 1 )
391410 tick += 60
392411
393412 # draw temperature line (vertical)
394- graph .draw_line (graph .xmin , graph .ymin , graph .xmin , graph .ymax , AXIS_SIZE , 4 , 1 )
395- graph .draw_line (graph .xmax - AXIS_SIZE , graph .ymin , graph .xmax - AXIS_SIZE ,
396- graph .ymax , AXIS_SIZE , 4 , 1 )
413+ graph .draw_line (graph .xmin , graph .ymin , graph .xmin ,
414+ graph .ymax , AXIS_SIZE , AXIS_COLOR , 1 )
415+ graph .draw_line (graph .xmax - AXIS_SIZE + 1 , graph .ymin ,
416+ graph .xmax - AXIS_SIZE + 1 ,
417+ graph .ymax , AXIS_SIZE , AXIS_COLOR , 1 )
397418 # draw temperature ticks
398419 tick = graph .ymin
399420 while tick < (graph .ymax - graph .ymin )* 1.1 :
400- graph .draw_line (graph .xmin , tick , graph .xmin + 10 , tick , AXIS_SIZE , 4 , 1 )
401- graph .draw_line (graph .xmax , tick , graph .xmax - 10 - AXIS_SIZE , tick , AXIS_SIZE , 4 , 1 )
421+ graph .draw_line (graph .xmin , tick , graph .xmin + 10 , tick ,
422+ AXIS_SIZE , AXIS_COLOR , 1 )
423+ graph .draw_line (graph .xmax , tick , graph .xmax - 10 - AXIS_SIZE ,
424+ tick , AXIS_SIZE , AXIS_COLOR , 1 )
402425 tick += 50
403426
404427 # draw profile
@@ -407,7 +430,7 @@ def draw_profile(graph, profile):
407430 for point in profile ["profile" ]:
408431 x2 = point [0 ]
409432 y2 = point [1 ]
410- graph .draw_line (x1 , y1 , x2 , y2 , PROFILE_SIZE , 1 , 1 )
433+ graph .draw_line (x1 , y1 , x2 , y2 , PROFILE_SIZE , PROFILE_COLOR , 1 )
411434 # print(point)
412435 x1 = x2
413436 y1 = y2
@@ -429,7 +452,7 @@ def format_time(seconds):
429452
430453
431454label_reflow = label .Label (font1 , text = "" , max_glyphs = 10 ,
432- color = LABEL_COLOR , line_spacing = 0 )
455+ color = 0xFFFFFF , line_spacing = 0 )
433456label_reflow .x = 0
434457label_reflow .y = - 20
435458pyportal .splash .append (label_reflow )
@@ -445,7 +468,7 @@ def format_time(seconds):
445468message .x = 100
446469message .y = 40
447470pyportal .splash .append (message )
448- alloy_label = label .Label (font1 , text = "Alloy: " , color = 0xAAAAAA )
471+ alloy_label = label .Label (font1 , text = "Alloy:" , color = 0xAAAAAA )
449472alloy_label .x = 5
450473alloy_label .y = 40
451474pyportal .splash .append (alloy_label )
@@ -482,10 +505,14 @@ def format_time(seconds):
482505
483506sgraph = Graph ()
484507
485- sgraph .xstart = 100
486- sgraph .ystart = 4
487- sgraph .width = WIDTH - sgraph .xstart - 4 # 216 for standard PyPortal
488- sgraph .height = HEIGHT - 80 # 160 for standard PyPortal
508+ #sgraph.xstart = 100
509+ #sgraph.ystart = 4
510+ sgraph .xstart = 0
511+ sgraph .ystart = 0
512+ #sgraph.width = WIDTH - sgraph.xstart - 4 # 216 for standard PyPortal
513+ #sgraph.height = HEIGHT - 80 # 160 for standard PyPortal
514+ sgraph .width = GWIDTH # 216 for standard PyPortal
515+ sgraph .height = GHEIGHT # 160 for standard PyPortal
489516sgraph .xmin = oven .sprofile ["time_range" ][0 ]
490517sgraph .xmax = oven .sprofile ["time_range" ][1 ]
491518sgraph .ymin = oven .sprofile ["temp_range" ][0 ]
@@ -535,7 +562,7 @@ def format_time(seconds):
535562 last_status = ""
536563
537564 if p :
538- if p [0 ] >= 0 and p [0 ] <= 80 and p [1 ] >= 200 and p [1 ] <= 240 :
565+ if p [0 ] >= 0 and p [0 ] <= 80 and p [1 ] >= HEIGHT - 40 and p [1 ] <= HEIGHT :
539566 print ("touch!" )
540567 if oven .state == "ready" :
541568 button .label = "Stop"
@@ -587,6 +614,6 @@ def format_time(seconds):
587614 print (oven .state )
588615 if oven_temp >= 50 :
589616 sgraph .draw_graph_point (int (timediff ), oven_temp ,
590- size = TEMP_SIZE , color = 3 )
617+ size = TEMP_SIZE , color = TEMP_COLOR )
591618
592619 last_state = oven .state
0 commit comments