Skip to content

Instantly share code, notes, and snippets.

@jdc-cunningham
Last active March 9, 2023 22:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdc-cunningham/78978029f2aeef4ca27db6aa68aaf68c to your computer and use it in GitHub Desktop.
Save jdc-cunningham/78978029f2aeef4ca27db6aa68aaf68c to your computer and use it in GitHub Desktop.
Brilliant Labs Monocle AR - different scenes
import time
import device
import display
def draw_welcome(placeholder_arg):
display.text("Welcome, <name>", 150, 175, 0xffffff)
def weather_report(placeholder):
display.text("Weather in <Location>", 100, 125, 0xffffff)
display.text("43F Cloudy", 100, 175, 0xffffff)
def draw_batt_indicator(placeholder_arg):
batt_level = device.battery_level()
display.text("batt: ", 0, 12, 0xffffff)
display.hline(110, 12, 100, 0xffffff)
display.vline(110, 12, 50, 0xffffff)
display.hline(110, 32, batt_level, 0xffa500)
display.hline(110, 34, batt_level, 0xffa500)
display.hline(110, 36, batt_level, 0xffa500)
display.hline(110, 38, batt_level, 0xffa500)
display.hline(110, 40, batt_level, 0xffa500)
display.hline(110, 60, 100, 0xffffff)
display.vline(210, 12, 50, 0xffffff)
display.text(str(batt_level) + "%", 230, 12, 0xffffff)
def draw_borders(placeholder_arg):
display.hline(0, 0, 600, 0xffa500)
display.hline(0, 380, 600, 0xffa500)
def render():
display.show()
def draw_menu(active = "none"):
hn_color = 0xffa500 if (active == "hn") else 0xffffff
rn_color = 0xffa500 if (active == "rn") else 0xffffff
display.text("HN", 250, 325, hn_color)
display.vline(308, 322, 50, 0xffa500)
display.text("RN", 325, 325, rn_color)
def draw_loading_msg(str = ""):
display.text("Loading " + str + "...", 100, 175, 0xffffff)
hacker_news = [
[
"Show HN: BBC In Our Time, categorised by Dewey Decimal, heavy lifting by GPT",
"Finally, my interest in LLMs is piqued! Seems like everyone has been getting excited around the search or code-generation use cases ..."
],
]
# for remaining 350px height
# based on 21 char horizontal length
def str_chunker(str):
words = str.split()
lines = ["", "", "", "", "", "", ""]
line = 0
max_lines = 6
max_chars = 21
for word in words:
cur_line = lines[line]
if (line > max_lines):
break
if (cur_line == ""):
lines[line] = word
else:
if (
(len(lines[line]) + len(word)) < max_chars
):
lines[line] = lines[line] + " " + word
else:
if (line < max_lines):
print(line)
line += 1
lines[line] = lines[line] + word
return lines
def read_hn(hn_arr):
display.text(hn_arr[0][0][:21], 0, 0, 0xffa500)
lines = str_chunker(hn_arr[0][1])
line_y = 50
for line in lines:
display.text(line, 0, line_y, 0xffffff)
line_y += 50
hn_arr.pop(0)
scenes = [
[
[draw_welcome, None]
],
[
[weather_report, None]
],
[
[draw_borders, None],
[draw_batt_indicator, None],
[draw_menu, None]
],
[
[draw_borders, None],
[draw_batt_indicator, None],
[draw_menu, "hn"],
[draw_loading_msg, "hn articles"]
],
[
[read_hn, hacker_news]
]
]
for scene_cmds in scenes:
render()
for cmd in scene_cmds:
cmd[0](cmd[1])
render()
time.sleep(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment