EMF_Camp_Badge/beer/main.py

42 lines
1.2 KiB
Python
Raw Normal View History

2018-09-01 09:53:14 -04:00
"""What's on tap?!
"""
___name___ = "beer"
___license___ = "MIT"
___dependencies___ = ["app", "sleep", "wifi", "http", "ugfx_helper"]
___categories___ = ["EMF"]
2018-09-01 11:53:59 -04:00
import wifi, ugfx, http, ujson, app, sleep
from tilda import Buttons, LED
2018-09-01 09:53:14 -04:00
2018-09-01 11:53:59 -04:00
def get_beer():
global bar
2018-09-01 09:53:14 -04:00
2018-09-01 11:53:59 -04:00
LED(LED.RED).on()
2018-09-01 09:53:14 -04:00
bar_json = http.get("https://bar.emf.camp/location/Bar.json").raise_for_status().content
bar = ujson.loads(bar_json)
2018-09-01 11:53:59 -04:00
LED(LED.RED).off()
2018-09-01 09:53:14 -04:00
2018-09-01 11:53:59 -04:00
def draw_screen():
get_beer()
ugfx.clear(ugfx.BLACK)
ugfx.text(60, 5, "what's on tap?", ugfx.RED)
ugfx.line(5, 20, ugfx.width(), 20, ugfx.GREY)
2018-09-01 09:53:14 -04:00
for idx, beer in enumerate(bar['location']):
2018-09-01 11:53:59 -04:00
ugfx.text(5, 22 + idx*15, beer['description'], ugfx.WHITE)
ugfx.init()
ugfx.clear()
Buttons.enable_interrupt(Buttons.BTN_A, lambda button_id:draw_screen(), on_press=True, on_release=False)
Buttons.enable_interrupt(Buttons.BTN_B, lambda button_id:app.restart_to_default(), on_press=True, on_release=False)
ugfx.text(5, 30, "Press the A button to refresh", ugfx.BLACK)
ugfx.text(5, 45, "Press the B button to exit", ugfx.BLACK)
2018-09-01 09:53:14 -04:00
2018-09-01 11:53:59 -04:00
draw_screen()
2018-09-01 09:53:14 -04:00
2018-09-01 11:53:59 -04:00
while True:
sleep.wfi()
ugfx.clear()
2018-09-01 09:53:14 -04:00
app.restart_to_default()