|
1 | 1 | # Adafruit BBQ display works with ibbq protocol-based BLE temperature probes |
2 | 2 |
|
3 | | - |
4 | 3 | import time |
5 | 4 |
|
6 | 5 | import displayio |
|
18 | 17 | temperatures_screen = displayio.Group(max_size=2) |
19 | 18 |
|
20 | 19 | # define custom colors |
21 | | -GREEN = 0x00d929 |
22 | | -BLUE = 0x0000ff |
23 | | -RED = 0xff0000 |
24 | | -ORANGE = 0xff6a00 |
25 | | -YELLOW = 0xffff00 |
26 | | -PURPLE = 0xe400ff |
27 | | -BLACK = 0x000000 |
28 | | -WHITE = 0xffffff |
29 | | -BURNT = 0xbb4e00 |
| 20 | +GREEN = 0x00D929 |
| 21 | +BLUE = 0x0000FF |
| 22 | +RED = 0xFF0000 |
| 23 | +ORANGE = 0xFF6A00 |
| 24 | +YELLOW = 0xFFFF00 |
| 25 | +PURPLE = 0xE400FF |
| 26 | +BLACK = 0x000000 |
| 27 | +WHITE = 0xFFFFFF |
| 28 | +BURNT = 0xBB4E00 |
30 | 29 |
|
31 | 30 | unit_mode = False # set the temperature unit_mode. True = centigrade, False = farenheit |
32 | 31 |
|
33 | | -# background fill |
| 32 | +# Setup homescreen |
34 | 33 | color_bitmap = displayio.Bitmap(120, 120, 1) |
35 | 34 | color_palette = displayio.Palette(1) |
36 | 35 | color_palette[0] = BURNT |
|
44 | 43 |
|
45 | 44 |
|
46 | 45 | title_font = bitmap_font.load_font("/font/GothamBlack-50.bdf") |
47 | | -title_font.load_glyphs("BQLUE".encode('utf-8')) |
| 46 | +title_font.load_glyphs("BQLUE".encode("utf-8")) |
48 | 47 | title_label = label.Label(title_font, text="BBQLUE", color=clue.ORANGE, max_glyphs=15) |
49 | 48 | title_label.x = 12 |
50 | 49 | title_label.y = 120 |
51 | 50 | homescreen_screen.append(title_label) |
52 | 51 |
|
53 | 52 | clue.display.show(homescreen_screen) |
54 | 53 |
|
55 | | - |
| 54 | +# Setup temperatures screen |
56 | 55 | temp_font = bitmap_font.load_font("/font/GothamBlack-25.bdf") |
57 | | -temp_font.load_glyphs("0123456789FC.-<".encode('utf-8')) |
| 56 | +temp_font.load_glyphs("0123456789FC.-<".encode("utf-8")) |
58 | 57 |
|
59 | | -my_labels_config = [(0, "", GREEN, 2, 100), |
60 | | - (1, "", BLUE, 2, 150), |
61 | | - (2, "", RED, 2, 200), |
62 | | - (3, "", ORANGE, 135, 100), |
63 | | - (4, "", YELLOW, 135, 150), |
64 | | - (5, "", PURPLE, 135, 200) |
65 | | - ] |
| 58 | +my_labels_config = [ |
| 59 | + (0, "", GREEN, 2, 100), |
| 60 | + (1, "", BLUE, 2, 150), |
| 61 | + (2, "", RED, 2, 200), |
| 62 | + (3, "", ORANGE, 135, 100), |
| 63 | + (4, "", YELLOW, 135, 150), |
| 64 | + (5, "", PURPLE, 135, 200), |
| 65 | +] |
66 | 66 |
|
67 | 67 | my_labels = {} # dictionary of configured my_labels |
68 | 68 |
|
69 | 69 | text_group = displayio.Group(max_size=8, scale=1) |
70 | 70 |
|
71 | 71 | for label_config in my_labels_config: |
72 | 72 | (name, text, color, x, y) = label_config # unpack a tuple into five var names |
73 | | - # old way sould have been: name = label_config[0], text = label_config[1] |
74 | 73 | templabel = label.Label(temp_font, text=text, color=color, max_glyphs=15) |
75 | 74 | templabel.x = x |
76 | 75 | templabel.y = y |
|
79 | 78 |
|
80 | 79 | temperatures_screen.append(text_group) |
81 | 80 |
|
82 | | -temp_title_label = label.Label(title_font, text="BBQLUE", color=clue.ORANGE, max_glyphs=15) |
| 81 | +temp_title_label = label.Label( |
| 82 | + title_font, text="BBQLUE", color=clue.ORANGE, max_glyphs=15 |
| 83 | +) |
83 | 84 | temp_title_label.x = 12 |
84 | 85 | temp_title_label.y = 30 |
85 | 86 | temperatures_screen.append(temp_title_label) |
|
122 | 123 |
|
123 | 124 | temps = ibbq_service.temperatures |
124 | 125 | batt = ibbq_service.battery_level |
125 | | - if temps is not None: |
| 126 | + if temps != None: |
126 | 127 | probe_count = len(temps) # check how many probes there are |
127 | 128 | for i in range(probe_count): |
128 | | - if (temps[i] is not 0 and temps[i] < 1000): # unplugged probes |
| 129 | + if temps[i] is not 0 and temps[i] < 1000: # unplugged probes |
129 | 130 | if unit_mode: |
130 | 131 | clue.pixel.fill((50, 0, 0)) |
131 | 132 | temp = temps[i] |
132 | 133 | my_labels[i].text = "{} C".format(temp) |
133 | 134 | clue.pixel.fill((0, 0, 0)) |
134 | | - print("Probe", i+1, "Temperature:", temp,"C",) |
| 135 | + print("Probe", i + 1, "Temperature:", temp, "C") |
135 | 136 | else: # F |
136 | 137 | clue.pixel.fill((50, 0, 0)) |
137 | 138 | temp = temps[i] * 9 / 5 + 32 |
138 | 139 | my_labels[i].text = "{} F".format(temp) |
139 | 140 | clue.pixel.fill((0, 0, 0)) |
140 | | - print("Probe", i+1, "Temperature:", temp,"F",) |
| 141 | + print("Probe", i + 1, "Temperature:", temp, "F") |
141 | 142 | else: |
142 | | - print("Probe", i+1, "is unplugged",) |
143 | | - my_labels[i].text = (" ---") |
| 143 | + print( |
| 144 | + "Probe", i + 1, "is unplugged", |
| 145 | + ) |
| 146 | + my_labels[i].text = " ---" |
144 | 147 | clue.display.show(temperatures_screen) |
145 | 148 |
|
146 | 149 | except _bleio.ConnectionError: |
147 | | - # Redisplay splash screen here, or put it at top of while True: |
148 | 150 | continue |
0 commit comments