Skip to content

Commit bd7a995

Browse files
committed
Add x and y axis to reflow graph
1 parent f7538e6 commit bd7a995

1 file changed

Lines changed: 60 additions & 34 deletions

File tree

PyPortal_EZ_Make_Oven/code.py

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,31 @@
2020
display_group = displayio.Group(max_size=20)
2121
board.DISPLAY.show(display_group)
2222

23-
PLOT_SIZE = 2 # plot thickness
24-
PLOT_COLOR = 0x00FF55 # plot color
23+
PROFILE_SIZE = 2 # plot thickness
24+
PROFILE_COLOR = 0x00FF55 # plot color
2525
GRID_SIZE = 2
2626
GRID_COLOR = 0x2020FF
2727
GRID_STYLE = 3
2828
TEMP_SIZE = 2
29-
TEMP_COLOR = 0xFFFF00
29+
TEMP_COLOR = 0xFF0000
3030
LABEL_COLOR = 0x8080FF
31+
AXIS_SIZE = 2
32+
AXIS_COLOR = 0xFFFF00
3133

3234
WIDTH = board.DISPLAY.width
3335
HEIGHT = board.DISPLAY.height
3436

3537
pyportal = PyPortal()
3638

37-
palette = displayio.Palette(4)
39+
palette = displayio.Palette(5)
3840
palette[0] = 0x0
39-
palette[1] = PLOT_COLOR
41+
palette[1] = PROFILE_COLOR
4042
palette[2] = GRID_COLOR
4143
palette[3] = TEMP_COLOR
44+
palette[4] = AXIS_COLOR
4245
palette.make_transparent(0)
4346

44-
plot = displayio.Bitmap(WIDTH, HEIGHT, 3)
47+
plot = displayio.Bitmap(WIDTH, HEIGHT, 8)
4548
pyportal.splash.append(displayio.TileGrid(plot, pixel_shader=palette))
4649

4750
ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
@@ -77,7 +80,6 @@ def play(self, duration=0.1):
7780
# otherwise, use refresh() in loop to turn off long beep
7881
time.sleep(duration)
7982
self.stop()
80-
print("play", duration, self.start)
8183

8284
def stop(self):
8385
if pyportal._speaker_enable.value:
@@ -101,7 +103,7 @@ def __init__(self, pin):
101103
with open("/profiles/" + self.config["profile"] + ".json", mode="r") as fpr:
102104
self.sprofile = json.load(fpr)
103105
fpr.close()
104-
i2c = busio.I2C(board.SCL, board. SDA, frequency=200000)
106+
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
105107
try:
106108
self.sensor = MCP9600(i2c, self.config["sensor_address"], "K")
107109
except ValueError:
@@ -230,7 +232,7 @@ def __init__(self):
230232
self.height = HEIGHT
231233

232234
# pylint: disable=too-many-branches
233-
def draw_line(self, x1, y1, x2, y2, size=PLOT_SIZE, color=1, style=1):
235+
def draw_line(self, x1, y1, x2, y2, size=PROFILE_SIZE, color=1, style=1):
234236
# print("draw_line:", x1, y1, x2, y2)
235237
# convert graph coords to screen coords
236238
x1p = (self.xstart + self.width * (x1 - self.xmin)
@@ -274,7 +276,7 @@ def draw_line(self, x1, y1, x2, y2, size=PLOT_SIZE, color=1, style=1):
274276
else:
275277
self.draw_point(xx, yy, size, color)
276278

277-
def draw_graph_point(self, x, y, size=PLOT_SIZE, color=1):
279+
def draw_graph_point(self, x, y, size=PROFILE_SIZE, color=1):
278280
""" draw point using graph coordinates """
279281
xx = (self.xstart + self.width * (x - self.xmin)
280282
// (self.xmax - self.xmin))
@@ -283,7 +285,7 @@ def draw_graph_point(self, x, y, size=PLOT_SIZE, color=1):
283285
print("graph point:", x, y, xx, yy)
284286
self.draw_point(xx, max(0 + size, yy), size, color)
285287

286-
def draw_point(self, x, y, size=PLOT_SIZE, color=1):
288+
def draw_point(self, x, y, size=PROFILE_SIZE, color=1):
287289
"""Draw data point on to the plot bitmap at (x,y)."""
288290
if y is None:
289291
return
@@ -343,17 +345,41 @@ def draw_profile(graph, profile):
343345
yp = (graph.ystart + int(graph.height * (y - graph.ymin)
344346
/ (graph.ymax - graph.ymin)))
345347

346-
label_reflow.x = xp
347-
label_reflow.y = yp + 16 # fudge factor here to get close to line
348+
label_reflow.x = xp + 10
349+
label_reflow.y = HEIGHT - yp
348350
label_reflow.text = str(profile["stages"]["reflow"][1])
349351
print("reflow temp:", str(profile["stages"]["reflow"][1]))
352+
print("graph point: ", x, y, "->", xp, yp)
353+
354+
# draw time line (horizontal)
355+
graph.draw_line(graph.xmin, graph.ymin, graph.xmax, graph.ymin, AXIS_SIZE, 4, 1)
356+
graph.draw_line(graph.xmin, graph.ymax - AXIS_SIZE, graph.xmax, graph.ymax
357+
- AXIS_SIZE, AXIS_SIZE, 4, 1)
358+
# draw time ticks
359+
tick = graph.xmin
360+
while tick < (graph.xmax - graph.xmin):
361+
graph.draw_line(tick, graph.ymin, tick, graph.ymin + 10, AXIS_SIZE, 4, 1)
362+
graph.draw_line(tick, graph.ymax, tick, graph.ymax - 10 - AXIS_SIZE, AXIS_SIZE, 4, 1)
363+
tick += 60
364+
365+
# draw temperature line (vertical)
366+
graph.draw_line(graph.xmin, graph.ymin, graph.xmin, graph.ymax, AXIS_SIZE, 4, 1)
367+
graph.draw_line(graph.xmax - AXIS_SIZE, graph.ymin, graph.xmax - AXIS_SIZE,
368+
graph.ymax, AXIS_SIZE, 4, 1)
369+
# draw temperature ticks
370+
tick = graph.ymin
371+
while tick < (graph.ymax - graph.ymin)*1.1:
372+
graph.draw_line(graph.xmin, tick, graph.xmin + 10, tick, AXIS_SIZE, 4, 1)
373+
graph.draw_line(graph.xmax, tick, graph.xmax - 10 - AXIS_SIZE, tick, AXIS_SIZE, 4, 1)
374+
tick += 50
375+
350376
# draw profile
351377
x1 = profile["profile"][0][0]
352378
y1 = profile["profile"][0][1]
353379
for point in profile["profile"]:
354380
x2 = point[0]
355381
y2 = point[1]
356-
graph.draw_line(x1, y1, x2, y2)
382+
graph.draw_line(x1, y1, x2, y2, PROFILE_SIZE, 1, 1)
357383
# print(point)
358384
x1 = x2
359385
y1 = y2
@@ -376,7 +402,7 @@ def format_time(seconds):
376402
label_reflow.y = -20
377403
pyportal.splash.append(label_reflow)
378404
title_label = label.Label(font3, text="EZ Make Oven Controller")
379-
title_label.x = 10
405+
title_label.x = 5
380406
title_label.y = 14
381407
pyportal.splash.append(title_label)
382408
# version_label = label.Label(font1, text=VERSION, color=0xAAAAAA)
@@ -385,38 +411,38 @@ def format_time(seconds):
385411
# pyportal.splash.append(version_label)
386412
message = label.Label(font2, text="Wait", max_glyphs=20)
387413
message.x = 100
388-
message.y = 50
414+
message.y = 40
389415
pyportal.splash.append(message)
390-
profile_label = label.Label(font1, text="Profile:", color=0xAAAAAA)
391-
profile_label.x = 10
392-
profile_label.y = 40
393-
pyportal.splash.append(profile_label)
394-
profile_data = label.Label(font1, text=oven.sprofile["title"])
395-
profile_data.x = 20
396-
profile_data.y = 60
397-
pyportal.splash.append(profile_data)
398416
alloy_label = label.Label(font1, text="Alloy: ", color=0xAAAAAA)
399-
alloy_label.x = 10
400-
alloy_label.y = 80
417+
alloy_label.x = 5
418+
alloy_label.y = 40
401419
pyportal.splash.append(alloy_label)
402420
alloy_data = label.Label(font1, text=str(oven.sprofile["alloy"]))
403-
alloy_data.x = 20
404-
alloy_data.y = 100
421+
alloy_data.x = 10
422+
alloy_data.y = 60
405423
pyportal.splash.append(alloy_data)
424+
profile_label = label.Label(font1, text="Profile:", color=0xAAAAAA)
425+
profile_label.x = 5
426+
profile_label.y = 80
427+
pyportal.splash.append(profile_label)
428+
profile_data = label.Label(font1, text=oven.sprofile["title"])
429+
profile_data.x = 10
430+
profile_data.y = 100
431+
pyportal.splash.append(profile_data)
406432
timer_label = label.Label(font1, text="Time:", color=0xAAAAAA)
407-
timer_label.x = 10
433+
timer_label.x = 5
408434
timer_label.y = 120
409435
pyportal.splash.append(timer_label)
410436
timer_data = label.Label(font3, text=format_time(timediff), max_glyphs=10)
411-
timer_data.x = 20
437+
timer_data.x = 10
412438
timer_data.y = 140
413439
pyportal.splash.append(timer_data)
414440
temp_label = label.Label(font1, text="Temp(C):", color=0xAAAAAA)
415-
temp_label.x = 10
441+
temp_label.x = 5
416442
temp_label.y = 160
417443
pyportal.splash.append(temp_label)
418444
temp_data = label.Label(font3, text="--", max_glyphs=10)
419-
temp_data.x = 20
445+
temp_data.x = 10
420446
temp_data.y = 180
421447
pyportal.splash.append(temp_data)
422448
circle = Circle(308, 12, 8, fill=0)
@@ -425,8 +451,8 @@ def format_time(seconds):
425451
sgraph = Graph()
426452

427453
sgraph.xstart = 100
428-
sgraph.ystart = 0
429-
sgraph.width = 220
454+
sgraph.ystart = 4
455+
sgraph.width = 216
430456
sgraph.height = 160
431457
sgraph.xmin = oven.sprofile["time_range"][0]
432458
sgraph.xmax = oven.sprofile["time_range"][1]

0 commit comments

Comments
 (0)