Skip to content

Commit a64f589

Browse files
committed
code update - button labels
Updating button labels to be icons rather than text
1 parent 014c913 commit a64f589

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

OctoPrint_MQTT_Controller/code.py

+33-30
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import json
88
import socketpool
99
import wifi
10-
import adafruit_requests
11-
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
1210
import board
1311
import digitalio
14-
import displayio
1512
import terminalio
13+
import adafruit_requests
14+
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
15+
import displayio
1616
from adafruit_progressbar.horizontalprogressbar import (
1717
HorizontalProgressBar,
1818
HorizontalFillDirection,
@@ -32,10 +32,12 @@
3232
splash = displayio.Group()
3333
board.DISPLAY.show(splash)
3434

35-
width = 165
35+
# set progress bar width and height relative to board's display
36+
width = 183
3637
height = 30
3738

38-
x = 70
39+
x = 50
40+
#y = board.DISPLAY.height // 3
3941
y = 100
4042

4143
# Create a new progress_bar object at (x, y)
@@ -51,23 +53,22 @@
5153
# Append progress_bar to the splash group
5254
splash.append(progress_bar)
5355

54-
rect = Rect(60, 0, 2, 135, fill=0xFFFFFF)
56+
rect = Rect(40, 0, 2, 135, fill=0xFFFFFF)
5557
splash.append(rect)
5658

5759
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")
5863

5964
tile_grid = displayio.TileGrid(bitmap=img, pixel_shader=img.pixel_shader, x = 185, y=5)
6065
splash.append(tile_grid)
6166

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)
6469

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)
7172

7273
led = digitalio.DigitalInOut(board.LED)
7374
led.direction = digitalio.Direction.OUTPUT
@@ -83,16 +84,18 @@
8384
button2 = digitalio.DigitalInOut(board.D2)
8485
button2.direction = digitalio.Direction.INPUT
8586
button2.pull = digitalio.Pull.DOWN
86-
87+
# Our array of key objects
8788
button0_state = False
8889
button1_state = False
8990
button2_state = False
9091

9192
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness = 0.6)
9293

94+
# Create a socket pool
9395
pool = socketpool.SocketPool(wifi.radio)
9496

9597
requests = adafruit_requests.Session(pool, ssl.create_default_context())
98+
# Initialize an Adafruit IO HTTP API object
9699
io = IO_HTTP(aio_username, aio_key, requests)
97100

98101
try:
@@ -127,6 +130,7 @@
127130
msg_json = [{"path": "none"}, {"state_id": "NONE"}, {"path": "none"}]
128131
print_progress = 0
129132
current_state = 0
133+
last_state = None
130134
state_value = 0
131135
current_file = None
132136
finished_file = None
@@ -185,9 +189,8 @@
185189
progress_bar.value = 100
186190
progress_bar.bar_color = colors[state_value]
187191
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
191194
button0_state = True
192195
else:
193196
led.value = True
@@ -213,47 +216,47 @@
213216
# assign value to new_msg
214217
new_feed_msg[feed] = data["value"]
215218
msg_json[feed] = json.loads(data["value"])
219+
# set servo angle
216220
print(read_feeds[feed]["key"])
217221
print()
218222
print(new_feed_msg[feed])
219223
print()
224+
#time.sleep(1)
220225
print_progress = int(msg_json[0]['progress'])
221226
current_file = str(msg_json[0]['path'])
222227
current_state = str(msg_json[1]['state_id'])
223228
finished_file = str(msg_json[2]['path'])
224229
state_value = printer_state_options.index(current_state)
225230
# log msg
226231
last_feed_msg[feed] = new_feed_msg[feed]
232+
#time.sleep(1)
227233
if current_state == "PRINTING":
234+
#print_progress = int(msg_json[0]['progress'])
228235
progress_bar.value = print_progress
229236
#octoprint green
230237
progress_bar.bar_color = 0x13c100
231238
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
235241
elif current_state in ("PAUSED", "PAUSING"):
236242
progress_bar.value = print_progress
237243
progress_bar.bar_color = colors[state_value]
238244
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
242247
# when a print is finished:
243248
elif finished_file == current_file and print_progress == 100:
244249
progress_bar.value = 100
245250
progress_bar.bar_color = purple
246251
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
250254
# when printer is idle, display status
251255
else:
252256
progress_bar.value = 100
253257
progress_bar.bar_color = colors[state_value]
254258
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
258261
# reset clock
259262
clock = time.monotonic()
4.37 KB
Binary file not shown.
4.41 KB
Binary file not shown.
4.37 KB
Binary file not shown.

0 commit comments

Comments
 (0)