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,85 @@ 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 )
384
+ xp = (GXSTART + graph .width * (x - graph .xmin )
372
385
// (graph .xmax - graph .xmin ))
373
- yp = ( graph . ystart + int (graph . height * (y - graph .ymin )
374
- / (graph .ymax - graph .ymin ) ))
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 , graph .ymin + 1 , AXIS_SIZE , AXIS_COLOR , 1 )
400
+ graph .draw_line (graph .xmin , graph .ymax , graph .xmax , graph .ymax ,
401
+ AXIS_SIZE , AXIS_COLOR , 1 )
386
402
# draw time ticks
387
403
tick = graph .xmin
388
404
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 )
405
+ graph .draw_line (tick , graph .ymin , tick , graph .ymin + 10 , AXIS_SIZE , AXIS_COLOR , 1 )
406
+ graph .draw_line (tick , graph .ymax , tick , graph .ymax - 10 - AXIS_SIZE , AXIS_SIZE , AXIS_COLOR , 1 )
391
407
tick += 60
392
408
393
409
# 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 )
410
+ graph .draw_line (graph .xmin , graph .ymin , graph .xmin , graph .ymax , AXIS_SIZE , AXIS_COLOR , 1 )
411
+ graph .draw_line (graph .xmax - AXIS_SIZE + 1 , graph .ymin , graph .xmax - AXIS_SIZE + 1 ,
412
+ graph .ymax , AXIS_SIZE , AXIS_COLOR , 1 )
397
413
# draw temperature ticks
398
414
tick = graph .ymin
399
415
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 )
416
+ graph .draw_line (graph .xmin , tick , graph .xmin + 10 , tick , AXIS_SIZE , AXIS_COLOR , 1 )
417
+ graph .draw_line (graph .xmax , tick , graph .xmax - 10 - AXIS_SIZE , tick , AXIS_SIZE , AXIS_COLOR , 1 )
402
418
tick += 50
403
419
404
420
# draw profile
@@ -407,7 +423,7 @@ def draw_profile(graph, profile):
407
423
for point in profile ["profile" ]:
408
424
x2 = point [0 ]
409
425
y2 = point [1 ]
410
- graph .draw_line (x1 , y1 , x2 , y2 , PROFILE_SIZE , 1 , 1 )
426
+ graph .draw_line (x1 , y1 , x2 , y2 , PROFILE_SIZE , PROFILE_COLOR , 1 )
411
427
# print(point)
412
428
x1 = x2
413
429
y1 = y2
@@ -429,7 +445,7 @@ def format_time(seconds):
429
445
430
446
431
447
label_reflow = label .Label (font1 , text = "" , max_glyphs = 10 ,
432
- color = LABEL_COLOR , line_spacing = 0 )
448
+ color = 0xFFFFFF , line_spacing = 0 )
433
449
label_reflow .x = 0
434
450
label_reflow .y = - 20
435
451
pyportal .splash .append (label_reflow )
@@ -445,7 +461,7 @@ def format_time(seconds):
445
461
message .x = 100
446
462
message .y = 40
447
463
pyportal .splash .append (message )
448
- alloy_label = label .Label (font1 , text = "Alloy: " , color = 0xAAAAAA )
464
+ alloy_label = label .Label (font1 , text = "Alloy:" , color = 0xAAAAAA )
449
465
alloy_label .x = 5
450
466
alloy_label .y = 40
451
467
pyportal .splash .append (alloy_label )
@@ -482,10 +498,14 @@ def format_time(seconds):
482
498
483
499
sgraph = Graph ()
484
500
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
501
+ #sgraph.xstart = 100
502
+ #sgraph.ystart = 4
503
+ sgraph .xstart = 0
504
+ sgraph .ystart = 0
505
+ #sgraph.width = WIDTH - sgraph.xstart - 4 # 216 for standard PyPortal
506
+ #sgraph.height = HEIGHT - 80 # 160 for standard PyPortal
507
+ sgraph .width = GWIDTH # 216 for standard PyPortal
508
+ sgraph .height = GHEIGHT # 160 for standard PyPortal
489
509
sgraph .xmin = oven .sprofile ["time_range" ][0 ]
490
510
sgraph .xmax = oven .sprofile ["time_range" ][1 ]
491
511
sgraph .ymin = oven .sprofile ["temp_range" ][0 ]
@@ -535,7 +555,7 @@ def format_time(seconds):
535
555
last_status = ""
536
556
537
557
if p :
538
- if p [0 ] >= 0 and p [0 ] <= 80 and p [1 ] >= 200 and p [1 ] <= 240 :
558
+ if p [0 ] >= 0 and p [0 ] <= 80 and p [1 ] >= HEIGHT - 40 and p [1 ] <= HEIGHT :
539
559
print ("touch!" )
540
560
if oven .state == "ready" :
541
561
button .label = "Stop"
@@ -587,6 +607,6 @@ def format_time(seconds):
587
607
print (oven .state )
588
608
if oven_temp >= 50 :
589
609
sgraph .draw_graph_point (int (timediff ), oven_temp ,
590
- size = TEMP_SIZE , color = 3 )
610
+ size = TEMP_SIZE , color = TEMP_COLOR )
591
611
592
612
last_state = oven .state
0 commit comments