Display measure battery level in the header. Erratic for now.

This commit is contained in:
Gabriel Augendre 2023-03-21 16:13:32 +01:00
parent 4a92abed38
commit f5d856f6ff
2 changed files with 9 additions and 3 deletions

View file

@ -9,6 +9,7 @@ from badger2040w import (
UPDATE_MEDIUM, UPDATE_MEDIUM,
UPDATE_FAST, UPDATE_FAST,
) )
from badger_os import get_battery_level
import secrets import secrets
from secrets import HA_BASE_URL, HA_ACCESS_TOKEN from secrets import HA_BASE_URL, HA_ACCESS_TOKEN
@ -253,8 +254,14 @@ def display_header(text):
_, _, _, hour, minute, _, _ = display.rtc.datetime() _, _, _, hour, minute, _, _ = display.rtc.datetime()
hour = (hour + 1) % 24 hour = (hour + 1) % 24
time = f"{hour:02d}:{minute:02d}" time = f"{hour:02d}:{minute:02d}"
time_offset = display.measure_text(time) time_offset = display.measure_text(time) + 3
display.text(time, WIDTH - time_offset - 3, 4) display.text(time, WIDTH - time_offset, 4)
# display battery level
battery_level = get_battery_level()
battery = f"{battery_level}%"
battery_offset = display.measure_text(battery) + 15
display.text(battery, WIDTH - time_offset - battery_offset, 4)
main() main()

View file

@ -9,7 +9,6 @@ import badger2040w as badger2040
def get_battery_level(): def get_battery_level():
return 0
# Battery measurement # Battery measurement
vbat_adc = machine.ADC(badger2040.PIN_BATTERY) vbat_adc = machine.ADC(badger2040.PIN_BATTERY)
vref_adc = machine.ADC(badger2040.PIN_1V2_REF) vref_adc = machine.ADC(badger2040.PIN_1V2_REF)