waps: widgets: Improve the battery meter athtetics

Add some extra internal padding and draw the battery in red when
power is critically low.
This commit is contained in:
Daniel Thompson 2020-02-04 08:43:49 +00:00
parent 3e0cb4eed5
commit 1d8b900d40

View file

@ -3,46 +3,46 @@ import watch
class BatteryMeter(object):
def __init__(self):
self.level = None
self.level = -2
def draw(self):
display = watch.display
icon = icons.battery
watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef)
self.level = -1
self.level = -2
self.update()
def update(self):
icon = icons.battery
if watch.battery.charging():
if self.level != -1:
icon = icons.battery
watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef)
self.level = -1
else:
level = watch.battery.level()
if level == self.level:
return
self.level = level
x = 239 - 31
w = 18
# Use the level to work out the correct height
if level == 100:
h = 26
if level > 96:
h = 24
rgb = 0x07e0
else:
h = level // 4
# Use the level to figure out the right color
if level > 96:
rgb = 0x07e0
else:
green = level // 3
red = 31-green
rgb = (red << 11) + (green << 6)
if 26 - h:
watch.display.fill(0, x, 13, 18, 26 - h)
if h:
watch.display.fill(rgb, x, 39 - h, 18, h)
if (level > 5) ^ (self.level > 5):
if level > 5:
watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef)
else:
rgb = 0xf800
watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0xf800)
x = 239 - 30
w = 16
if 24 - h:
watch.display.fill(0, x, 14, w, 24 - h)
if h:
watch.display.fill(rgb, x, 38 - h, w, h)
self.level = level