|
7 | 7 | import json |
8 | 8 | import socketpool |
9 | 9 | import wifi |
10 | | -import adafruit_requests |
11 | | -from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError |
12 | 10 | import board |
13 | 11 | import digitalio |
14 | | -import displayio |
15 | 12 | import terminalio |
| 13 | +import adafruit_requests |
| 14 | +from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError |
| 15 | +import displayio |
16 | 16 | from adafruit_progressbar.horizontalprogressbar import ( |
17 | 17 | HorizontalProgressBar, |
18 | 18 | HorizontalFillDirection, |
|
32 | 32 | splash = displayio.Group() |
33 | 33 | board.DISPLAY.show(splash) |
34 | 34 |
|
35 | | -width = 165 |
| 35 | +# set progress bar width and height relative to board's display |
| 36 | +width = 183 |
36 | 37 | height = 30 |
37 | 38 |
|
38 | | -x = 70 |
| 39 | +x = 50 |
| 40 | +#y = board.DISPLAY.height // 3 |
39 | 41 | y = 100 |
40 | 42 |
|
41 | 43 | # Create a new progress_bar object at (x, y) |
|
51 | 53 | # Append progress_bar to the splash group |
52 | 54 | splash.append(progress_bar) |
53 | 55 |
|
54 | | -rect = Rect(60, 0, 2, 135, fill=0xFFFFFF) |
| 56 | +rect = Rect(40, 0, 2, 135, fill=0xFFFFFF) |
55 | 57 | splash.append(rect) |
56 | 58 |
|
57 | 59 | img = displayio.OnDiskBitmap("octoprint_logo.bmp") |
| 60 | +idle_icons = displayio.OnDiskBitmap("idle_icons.bmp") |
| 61 | +printing_icons = displayio.OnDiskBitmap("printing_icons.bmp") |
| 62 | +finished_icon = displayio.OnDiskBitmap("finished_icon.bmp") |
58 | 63 |
|
59 | 64 | tile_grid = displayio.TileGrid(bitmap=img, pixel_shader=img.pixel_shader, x = 185, y=5) |
60 | 65 | splash.append(tile_grid) |
61 | 66 |
|
62 | | -text = bitmap_label.Label(terminalio.FONT, text="Connecting", scale=2, x=75, y=45) |
63 | | -splash.append(text) |
| 67 | +icon_grid = displayio.TileGrid(bitmap=idle_icons, pixel_shader=idle_icons.pixel_shader, x = 0, y=0) |
| 68 | +splash.append(icon_grid) |
64 | 69 |
|
65 | | -d0_text = bitmap_label.Label(terminalio.FONT, text="Cooldown", scale=1, x=5, y=10) |
66 | | -splash.append(d0_text) |
67 | | -d1_text = bitmap_label.Label(terminalio.FONT, text="Heat up", scale=1, x=5, y=65) |
68 | | -splash.append(d1_text) |
69 | | -d2_text = bitmap_label.Label(terminalio.FONT, text="Reboot", scale=1, x=5, y=125) |
70 | | -splash.append(d2_text) |
| 70 | +text = bitmap_label.Label(terminalio.FONT, text="Connecting", scale=2, x=55, y=45) |
| 71 | +splash.append(text) |
71 | 72 |
|
72 | 73 | led = digitalio.DigitalInOut(board.LED) |
73 | 74 | led.direction = digitalio.Direction.OUTPUT |
|
83 | 84 | button2 = digitalio.DigitalInOut(board.D2) |
84 | 85 | button2.direction = digitalio.Direction.INPUT |
85 | 86 | button2.pull = digitalio.Pull.DOWN |
86 | | - |
| 87 | +# Our array of key objects |
87 | 88 | button0_state = False |
88 | 89 | button1_state = False |
89 | 90 | button2_state = False |
90 | 91 |
|
91 | 92 | pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness = 0.6) |
92 | 93 |
|
| 94 | +# Create a socket pool |
93 | 95 | pool = socketpool.SocketPool(wifi.radio) |
94 | 96 |
|
95 | 97 | requests = adafruit_requests.Session(pool, ssl.create_default_context()) |
| 98 | +# Initialize an Adafruit IO HTTP API object |
96 | 99 | io = IO_HTTP(aio_username, aio_key, requests) |
97 | 100 |
|
98 | 101 | try: |
|
127 | 130 | msg_json = [{"path": "none"}, {"state_id": "NONE"}, {"path": "none"}] |
128 | 131 | print_progress = 0 |
129 | 132 | current_state = 0 |
| 133 | +last_state = None |
130 | 134 | state_value = 0 |
131 | 135 | current_file = None |
132 | 136 | finished_file = None |
|
185 | 189 | progress_bar.value = 100 |
186 | 190 | progress_bar.bar_color = colors[state_value] |
187 | 191 | text.text = "\n".join(wrap_text_to_lines("Status: %s" % current_state, 11)) |
188 | | - d0_text.text = "Cooldown" |
189 | | - d1_text.text = "Heat up" |
190 | | - d2_text.text = "Reboot" |
| 192 | + icon_grid.bitmap = idle_icons |
| 193 | + icon_grid.pixel_shader = idle_icons.pixel_shader |
191 | 194 | button0_state = True |
192 | 195 | else: |
193 | 196 | led.value = True |
|
213 | 216 | # assign value to new_msg |
214 | 217 | new_feed_msg[feed] = data["value"] |
215 | 218 | msg_json[feed] = json.loads(data["value"]) |
| 219 | + # set servo angle |
216 | 220 | print(read_feeds[feed]["key"]) |
217 | 221 | print() |
218 | 222 | print(new_feed_msg[feed]) |
219 | 223 | print() |
| 224 | + #time.sleep(1) |
220 | 225 | print_progress = int(msg_json[0]['progress']) |
221 | 226 | current_file = str(msg_json[0]['path']) |
222 | 227 | current_state = str(msg_json[1]['state_id']) |
223 | 228 | finished_file = str(msg_json[2]['path']) |
224 | 229 | state_value = printer_state_options.index(current_state) |
225 | 230 | # log msg |
226 | 231 | last_feed_msg[feed] = new_feed_msg[feed] |
| 232 | + #time.sleep(1) |
227 | 233 | if current_state == "PRINTING": |
| 234 | + #print_progress = int(msg_json[0]['progress']) |
228 | 235 | progress_bar.value = print_progress |
229 | 236 | #octoprint green |
230 | 237 | progress_bar.bar_color = 0x13c100 |
231 | 238 | text.text = "\n".join(wrap_text_to_lines("%d%% Printed" % print_progress, 7)) |
232 | | - d0_text.text = "Pause" |
233 | | - d1_text.text = "Resume" |
234 | | - d2_text.text = "Cancel" |
| 239 | + icon_grid.bitmap = printing_icons |
| 240 | + icon_grid.pixel_shader = printing_icons.pixel_shader |
235 | 241 | elif current_state in ("PAUSED", "PAUSING"): |
236 | 242 | progress_bar.value = print_progress |
237 | 243 | progress_bar.bar_color = colors[state_value] |
238 | 244 | text.text = "\n".join(wrap_text_to_lines("Status: %s" % current_state, 11)) |
239 | | - d0_text.text = "Pause" |
240 | | - d1_text.text = "Resume" |
241 | | - d2_text.text = "Cancel" |
| 245 | + icon_grid.bitmap = printing_icons |
| 246 | + icon_grid.pixel_shader = printing_icons.pixel_shader |
242 | 247 | # when a print is finished: |
243 | 248 | elif finished_file == current_file and print_progress == 100: |
244 | 249 | progress_bar.value = 100 |
245 | 250 | progress_bar.bar_color = purple |
246 | 251 | text.text = "\n".join(wrap_text_to_lines("Print Finished!", 11)) |
247 | | - d0_text.text = "Confirm" |
248 | | - d1_text.text = " " |
249 | | - d2_text.text = " " |
| 252 | + icon_grid.bitmap = finished_icon |
| 253 | + icon_grid.pixel_shader = finished_icon.pixel_shader |
250 | 254 | # when printer is idle, display status |
251 | 255 | else: |
252 | 256 | progress_bar.value = 100 |
253 | 257 | progress_bar.bar_color = colors[state_value] |
254 | 258 | text.text = "\n".join(wrap_text_to_lines("Status: %s" % current_state, 11)) |
255 | | - d0_text.text = "Cooldown" |
256 | | - d1_text.text = "Heat up" |
257 | | - d2_text.text = "Reboot" |
| 259 | + icon_grid.bitmap = idle_icons |
| 260 | + icon_grid.pixel_shader = idle_icons.pixel_shader |
258 | 261 | # reset clock |
259 | 262 | clock = time.monotonic() |
0 commit comments