16
16
from adafruit_mcp9600 import MCP9600
17
17
18
18
TITLE = "EZ Make Oven Controller"
19
- VERSION = "1.1 .0"
19
+ VERSION = "1.2 .0"
20
20
21
21
print (TITLE , "version " , VERSION )
22
22
time .sleep (2 )
25
25
board .DISPLAY .show (display_group )
26
26
27
27
PROFILE_SIZE = 2 # plot thickness
28
- PROFILE_COLOR = 0x00FF55 # plot color
29
28
GRID_SIZE = 2
30
- GRID_COLOR = 0x2020FF
31
29
GRID_STYLE = 3
32
30
TEMP_SIZE = 2
33
- TEMP_COLOR = 0xFF0000
34
- LABEL_COLOR = 0x8080FF
35
31
AXIS_SIZE = 2
36
- AXIS_COLOR = 0xFFFF00
32
+
33
+ BLACK = 0x0
34
+ BLUE = 0x2020FF
35
+ GREEN = 0x00FF55
36
+ RED = 0xFF0000
37
+ YELLOW = 0xFFFF00
37
38
38
39
WIDTH = board .DISPLAY .width
39
40
HEIGHT = board .DISPLAY .height
40
41
41
42
pyportal = PyPortal ()
42
43
43
44
palette = 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
+
49
51
palette .make_transparent (0 )
50
52
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 ))
53
66
54
67
ts = adafruit_touchscreen .Touchscreen (board .TOUCH_XL , board .TOUCH_XR ,
55
68
board .TOUCH_YD , board .TOUCH_YU ,
@@ -253,8 +266,8 @@ def __init__(self):
253
266
self .ymax = 240
254
267
self .xstart = 0
255
268
self .ystart = 0
256
- self .width = WIDTH
257
- self .height = HEIGHT
269
+ self .width = GWIDTH
270
+ self .height = GHEIGHT
258
271
259
272
# pylint: disable=too-many-branches
260
273
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):
323
336
for yy in range (y - offset , y + offset + 1 ):
324
337
if yy in range (self .ystart , self .ystart + self .height ):
325
338
try :
326
- yy = HEIGHT - yy
339
+ yy = GHEIGHT - yy
327
340
plot [xx , yy ] = color
328
341
except IndexError :
329
342
pass
330
343
331
344
def draw_profile (graph , profile ):
332
345
"""Update the display with current info."""
333
- for i in range (WIDTH * HEIGHT ):
346
+ for i in range (GWIDTH * GHEIGHT ):
334
347
plot [i ] = 0
335
348
336
349
# draw stage lines
337
350
# preheat
338
351
graph .draw_line (profile ["stages" ]["preheat" ][0 ], profile ["temp_range" ][0 ],
339
352
profile ["stages" ]["preheat" ][0 ], profile ["temp_range" ][1 ]
340
353
* 1.1 ,
341
- GRID_SIZE , 2 , GRID_STYLE )
354
+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
342
355
graph .draw_line (profile ["time_range" ][0 ], profile ["stages" ]["preheat" ][1 ],
343
356
profile ["time_range" ][1 ], profile ["stages" ]["preheat" ][1 ],
344
- GRID_SIZE , 2 , GRID_STYLE )
357
+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
345
358
# soak
346
359
graph .draw_line (profile ["stages" ]["soak" ][0 ], profile ["temp_range" ][0 ],
347
360
profile ["stages" ]["soak" ][0 ], profile ["temp_range" ][1 ]* 1.1 ,
348
- GRID_SIZE , 2 , GRID_STYLE )
361
+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
349
362
graph .draw_line (profile ["time_range" ][0 ], profile ["stages" ]["soak" ][1 ],
350
363
profile ["time_range" ][1 ], profile ["stages" ]["soak" ][1 ],
351
- GRID_SIZE , 2 , GRID_STYLE )
364
+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
352
365
# reflow
353
366
graph .draw_line (profile ["stages" ]["reflow" ][0 ], profile ["temp_range" ][0 ],
354
367
profile ["stages" ]["reflow" ][0 ], profile ["temp_range" ][1 ]
355
368
* 1.1 ,
356
- GRID_SIZE , 2 , GRID_STYLE )
369
+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
357
370
graph .draw_line (profile ["time_range" ][0 ], profile ["stages" ]["reflow" ][1 ],
358
371
profile ["time_range" ][1 ], profile ["stages" ]["reflow" ][1 ],
359
- GRID_SIZE , 2 , GRID_STYLE )
372
+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
360
373
# cool
361
374
graph .draw_line (profile ["stages" ]["cool" ][0 ], profile ["temp_range" ][0 ],
362
375
profile ["stages" ]["cool" ][0 ], profile ["temp_range" ][1 ]* 1.1 ,
363
- GRID_SIZE , 2 , GRID_STYLE )
376
+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
364
377
graph .draw_line (profile ["time_range" ][0 ], profile ["stages" ]["cool" ][1 ],
365
378
profile ["time_range" ][1 ], profile ["stages" ]["cool" ][1 ],
366
- GRID_SIZE , 2 , GRID_STYLE )
379
+ GRID_SIZE , GRID_COLOR , GRID_STYLE )
367
380
368
381
# draw labels
369
382
x = profile ["time_range" ][0 ]
370
383
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 ))
375
388
376
389
label_reflow .x = xp + 10
377
390
label_reflow .y = HEIGHT - yp
378
391
label_reflow .text = str (profile ["stages" ]["reflow" ][1 ])
379
392
print ("reflow temp:" , str (profile ["stages" ]["reflow" ][1 ]))
380
393
print ("graph point: " , x , y , "->" , xp , yp )
381
394
395
+ x = profile ["stages" ]["reflow" ][0 ]
396
+ y = profile ["stages" ]["reflow" ][1 ]
397
+
382
398
# 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 )
386
403
# draw time ticks
387
404
tick = graph .xmin
388
405
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 )
391
410
tick += 60
392
411
393
412
# 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 )
397
418
# draw temperature ticks
398
419
tick = graph .ymin
399
420
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 )
402
425
tick += 50
403
426
404
427
# draw profile
@@ -407,7 +430,7 @@ def draw_profile(graph, profile):
407
430
for point in profile ["profile" ]:
408
431
x2 = point [0 ]
409
432
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 )
411
434
# print(point)
412
435
x1 = x2
413
436
y1 = y2
@@ -429,7 +452,7 @@ def format_time(seconds):
429
452
430
453
431
454
label_reflow = label .Label (font1 , text = "" , max_glyphs = 10 ,
432
- color = LABEL_COLOR , line_spacing = 0 )
455
+ color = 0xFFFFFF , line_spacing = 0 )
433
456
label_reflow .x = 0
434
457
label_reflow .y = - 20
435
458
pyportal .splash .append (label_reflow )
@@ -445,7 +468,7 @@ def format_time(seconds):
445
468
message .x = 100
446
469
message .y = 40
447
470
pyportal .splash .append (message )
448
- alloy_label = label .Label (font1 , text = "Alloy: " , color = 0xAAAAAA )
471
+ alloy_label = label .Label (font1 , text = "Alloy:" , color = 0xAAAAAA )
449
472
alloy_label .x = 5
450
473
alloy_label .y = 40
451
474
pyportal .splash .append (alloy_label )
@@ -482,10 +505,14 @@ def format_time(seconds):
482
505
483
506
sgraph = Graph ()
484
507
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
489
516
sgraph .xmin = oven .sprofile ["time_range" ][0 ]
490
517
sgraph .xmax = oven .sprofile ["time_range" ][1 ]
491
518
sgraph .ymin = oven .sprofile ["temp_range" ][0 ]
@@ -535,7 +562,7 @@ def format_time(seconds):
535
562
last_status = ""
536
563
537
564
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 :
539
566
print ("touch!" )
540
567
if oven .state == "ready" :
541
568
button .label = "Stop"
@@ -587,6 +614,6 @@ def format_time(seconds):
587
614
print (oven .state )
588
615
if oven_temp >= 50 :
589
616
sgraph .draw_graph_point (int (timediff ), oven_temp ,
590
- size = TEMP_SIZE , color = 3 )
617
+ size = TEMP_SIZE , color = TEMP_COLOR )
591
618
592
619
last_state = oven .state
0 commit comments