1d8b900d40
Add some extra internal padding and draw the battery in red when power is critically low.
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
import icons
|
|
import watch
|
|
|
|
class BatteryMeter(object):
|
|
def __init__(self):
|
|
self.level = -2
|
|
|
|
def draw(self):
|
|
self.level = -2
|
|
self.update()
|
|
|
|
def update(self):
|
|
icon = icons.battery
|
|
|
|
if watch.battery.charging():
|
|
if self.level != -1:
|
|
watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef)
|
|
self.level = -1
|
|
else:
|
|
level = watch.battery.level()
|
|
if level == self.level:
|
|
return
|
|
|
|
if level > 96:
|
|
h = 24
|
|
rgb = 0x07e0
|
|
else:
|
|
h = level // 4
|
|
|
|
green = level // 3
|
|
red = 31-green
|
|
rgb = (red << 11) + (green << 6)
|
|
|
|
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
|