EMF_Camp_Badge/home_ham/main.py

91 lines
2.2 KiB
Python
Raw Normal View History

2018-09-01 19:04:22 -04:00
"""Amateur Radio homescreen
2018-09-01 17:37:27 -04:00
2018-09-01 19:04:22 -04:00
This is a modified version of the default homescreen that allows you to set a callsign
2018-09-01 17:37:27 -04:00
"""
2018-09-03 09:59:37 -04:00
___title___ = "Amateur Radio Homescreen"
2018-09-01 17:37:27 -04:00
___license___ = "MIT"
___categories___ = ["Homescreens"]
2018-09-01 19:11:33 -04:00
___dependencies___ = ["homescreen"]
2018-09-01 17:37:27 -04:00
import ugfx
from homescreen import *
import time
from tilda import Buttons
init()
# Padding for name
intro_height = 30
name_height = 60
status_height = 20
callsign_height = 50
info_height = 30
2018-09-01 18:47:52 -04:00
logo_path = "home_ham/emf_ham.png"
2018-09-01 17:37:27 -04:00
logo_width = 200
# Maximum length of name before downscaling
max_name = 8
# Background stuff
ugfx.clear(ugfx.html_color(0xffffff))
# Colour stuff
style = ugfx.Style()
style.set_enabled([ugfx.BLACK, ugfx.html_color(0xffffff), ugfx.html_color(0xffffff), ugfx.html_color(0xffffff)])
style.set_background(ugfx.html_color(0xffffff))
ugfx.set_default_style(style)
ugfx.orientation(90)
# Logo stuff
ugfx.display_image(
int((ugfx.width() - logo_width) / 2),
30,
logo_path
)
# Draw for people to see
# Draw introduction
ugfx.set_default_font(ugfx.FONT_TITLE)
# Process name
name_setting = name("Set your name in the settings app")
callsign_setting = callsign("Set your callsign in the settings app")
if len(name_setting) <= max_name:
ugfx.set_default_font(ugfx.FONT_NAME)
else:
ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
# Draw name
2018-09-01 18:10:51 -04:00
ugfx.Label(0, 220 ,ugfx.width(), name_height, name_setting, justification=ugfx.Label.CENTER)
2018-09-01 17:37:27 -04:00
# Title
2018-09-01 18:10:51 -04:00
if len(callsign_setting) <= max_name:
ugfx.set_default_font(ugfx.FONT_NAME)
else:
ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
# Draw callsign
ugfx.Label(0, 270, ugfx.width(), callsign_height, callsign_setting, justification=ugfx.Label.CENTER)
2018-09-01 17:37:27 -04:00
ugfx.set_default_font(ugfx.FONT_SMALL)
# Draw for wearer to see
ugfx.orientation(270)
status = ugfx.Label(0, 300, ugfx.width(), status_height, "", justification=ugfx.Label.CENTER)
# update loop
while True:
text = "";
value_wifi_strength = wifi_strength()
value_battery = battery()
if value_wifi_strength:
text += "Wi-Fi: %s%%, " % int(value_wifi_strength)
if value_battery:
text += "Battery: %s%%" % int(value_battery)
status.text(text)
sleep_or_exit(0.5)
2018-09-01 18:48:08 -04:00
app.restart_to_default()