wasp: clock: Add a simple battery meter
This commit is contained in:
parent
57035ce080
commit
1f2c25a7bd
4 changed files with 59 additions and 5 deletions
|
@ -9,9 +9,11 @@ freeze('../..',
|
|||
'drivers/st7789.py',
|
||||
'drivers/vibrator.py',
|
||||
'fonts.py',
|
||||
'icons.py',
|
||||
'main.py',
|
||||
'manager.py',
|
||||
'logo.py',
|
||||
'widgets.py',
|
||||
),
|
||||
opt=3
|
||||
)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import fonts
|
||||
import widgets
|
||||
|
||||
DIGITS = (
|
||||
fonts.clock_0,
|
||||
|
@ -17,6 +18,7 @@ class ClockApp(object):
|
|||
|
||||
def __init__(self):
|
||||
self.on_screen = ( -1, -1 )
|
||||
self.meter = widgets.BatteryMeter()
|
||||
|
||||
def draw(self, watch):
|
||||
display = watch.display
|
||||
|
@ -24,12 +26,13 @@ class ClockApp(object):
|
|||
display.fill(0)
|
||||
display.rleblit(fonts.clock_colon, pos=(2*48, 80), fg=0xb5b6)
|
||||
self.update(watch)
|
||||
self.meter.draw()
|
||||
|
||||
|
||||
def update(self, watch):
|
||||
now = watch.rtc.get_time()
|
||||
if now[0] == self.on_screen[0] and now[1] == self.on_screen[1]:
|
||||
# Avoid the redraw
|
||||
return False
|
||||
self.meter.update()
|
||||
|
||||
display = watch.display
|
||||
display.rleblit(DIGITS[now[1] % 10], pos=(4*48, 80))
|
||||
|
@ -38,6 +41,4 @@ class ClockApp(object):
|
|||
display.rleblit(DIGITS[now[0] // 10], pos=(0*48, 80), fg=0xc638)
|
||||
self.on_screen = now
|
||||
|
||||
return True
|
||||
|
||||
|
||||
self.meter.update()
|
||||
|
|
3
wasp/icons.py
Normal file
3
wasp/icons.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
# 1-bit RLE, generated from res/battery.png, 189 bytes
|
||||
battery = (36, 48, b'\x97\x0e\x14\x12\x11\x14\x10\x14\x0c\x08\x0c\x08\x08\x08\x0c\x08\x08\x08\x0c\x08\x08\x08\x0c\x08\x08\x04\x14\x04\x08\x04\x14\x04\x08\x04\x0c\x04\x04\x04\x08\x04\x0b\x05\x04\x04\x08\x04\n\x06\x04\x04\x08\x04\t\x07\x04\x04\x08\x04\x08\x07\x05\x04\x08\x04\x07\x07\x06\x04\x08\x04\x06\x07\x07\x04\x08\x04\x05\x07\x08\x04\x08\x04\x04\x0e\x02\x04\x08\x04\x03\x0f\x02\x04\x08\x04\x02\x10\x02\x04\x08\x04\x02\x10\x02\x04\x08\x04\x02\x0f\x03\x04\x08\x04\x02\x0e\x04\x04\x08\x04\x08\x07\x05\x04\x08\x04\x07\x07\x06\x04\x08\x04\x06\x07\x07\x04\x08\x04\x05\x07\x08\x04\x08\x04\x04\x07\t\x04\x08\x04\x04\x06\n\x04\x08\x04\x04\x05\x0b\x04\x08\x04\x04\x04\x0c\x04\x08\x04\x14\x04\x08\x04\x14\x04\x08\x04\x14\x04\x08\x04\x14\x04\x08\x1c\x08\x1c\x08\x1c\x08\x1c\x98')
|
||||
|
48
wasp/widgets.py
Normal file
48
wasp/widgets.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import icons
|
||||
import watch
|
||||
|
||||
class BatteryMeter(object):
|
||||
def __init__(self):
|
||||
self.level = None
|
||||
|
||||
def draw(self):
|
||||
display = watch.display
|
||||
icon = icons.battery
|
||||
|
||||
watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef)
|
||||
self.level = -1
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
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
|
||||
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)
|
||||
|
Loading…
Add table
Reference in a new issue