Commit 815d8552 authored by Niek Blankers's avatar Niek Blankers
Browse files

16px high battery icon

parent 1f87386b
Pipeline #2960 failed with stages
in 1 minute
......@@ -15,6 +15,7 @@ import buttons
import light_sensor
import ujson
import os
import math
FILENAME = 'nickname.txt'
FILENAME_ADV = 'nickname.json'
......@@ -43,6 +44,20 @@ def get_time():
timestamp = timestamp + str(utime.localtime()[5])
return timestamp
# Sigmoidial approx. from https://github.com/rlogiacco/BatterySense
# Returns 0-100 in percent
def sigmoidial(volt, v_min, v_max):
result = 105.0 - (105.0 / (1.0 + math.pow(1.724 * (volt - v_min)/(v_max - v_min), 5.5)))
if result > 100:
return 100
else:
return result
def batt_percent():
v_max = 4.2
v_min = 3.3 # Actually cuts off around 3.4
return sigmoidial(os.read_battery(), v_min, v_max)
def toggle_rockets(state):
brightness = 15
......@@ -124,6 +139,10 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg):
toggle_rockets(False)
with display.open() as disp:
disp.rect(0, 0, 160, 80, col=r_bg, filled=True)
disp.rect(160 - 32, 0, 157, 14, col=r_fg_color, filled=False)
disp.rect(158, 4, 160, 11, col=r_fg_color, filled=True)
width = round(batt_percent() * 26.0 / 100.0)
disp.rect(130, 2, 130 + width, 13, col=r_fg_color, filled=True)
disp.print(title, fg=r_fg_color, bg=r_bg_color, posx=80 - round(len(title) / 2 * 14), posy=posy)
if r_sub != '':
disp.print(r_sub, fg=r_fg_sub_color, bg=r_bg_sub_color, posx=80 - round(len(r_sub) / 2 * 14), posy=42)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment