ui: code style, make header icon optional

pull/25/head
Jan Pochyla 8 years ago
parent b60206d588
commit ad2955aaab

@ -72,23 +72,23 @@ def blend(ca: int, cb: int, t: float) -> int:
async def alert(count=3): async def alert(count=3):
current = display.backlight() current = display.backlight()
for i in range(count*2): for i in range(count * 2):
if i % 2 == 0: if i % 2 == 0:
display.backlight(BACKLIGHT_MAX) display.backlight(BACKLIGHT_MAX)
yield loop.Sleep(20000) yield loop.Sleep(20000)
else: else:
display.backlight(BACKLIGHT_NORMAL) display.backlight(BACKLIGHT_NORMAL)
yield loop.Sleep(80000) yield loop.Sleep(80000)
display.backlight(current) display.backlight(current)
async def backlight_slide(val, speed=20000): async def backlight_slide(val, speed=20000):
current = display.backlight() current = display.backlight()
for i in range(current, val, -1 if current > val else 1): for i in range(current, val, -1 if current > val else 1):
display.backlight(i) display.backlight(i)
await loop.Sleep(speed) await loop.Sleep(speed)
def animate_pulse(func, ca, cb, speed=200000, delay=30000): def animate_pulse(func, ca, cb, speed=200000, delay=30000):
while True: while True:
# normalize sin from interval -1:1 to 0:1 # normalize sin from interval -1:1 to 0:1
@ -97,12 +97,15 @@ def animate_pulse(func, ca, cb, speed=200000, delay=30000):
func(c) func(c)
yield loop.Sleep(delay) yield loop.Sleep(delay)
def header(title, icon=ICON_RESET, fg=BLACK, bg=PM_DARK_BLUE): def header(title, icon=ICON_RESET, fg=BLACK, bg=PM_DARK_BLUE):
display.bar(0, 0, 240, 32, bg) display.bar(0, 0, 240, 32, bg)
image = res.load(icon) if icon is not None:
display.icon(8, 4, image, fg, bg) image = res.load(icon)
display.icon(8, 4, image, fg, bg)
display.text(8 + 24 + 8, 23, title, BOLD, fg, bg) display.text(8 + 24 + 8, 23, title, BOLD, fg, bg)
def rotate_coords(pos: tuple) -> tuple: def rotate_coords(pos: tuple) -> tuple:
r = display.orientation() r = display.orientation()
if r == 0: if r == 0:

Loading…
Cancel
Save