Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions MagTag/MagTag_Weather/openmeteo/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ def update_today(data):
today_date.text = "{} {} {}, {}".format(
DAYS[t.tm_wday].upper(), MONTHS[t.tm_mon - 1].upper(), t.tm_mday, t.tm_year
)
battery_percent = 100 * (magtag.peripherals.battery - 3.5) / (4.2 - 3.5)
battery_state.text = f'B:{battery_percent:.0f}%'
# weather icon
w = data["daily"]["weather_code"][0]
today_icon[0] = next(i for i, t in enumerate(WMO_CODE_TO_ICON) if w in t)
Expand Down Expand Up @@ -231,6 +233,10 @@ def go_to_sleep(current_time_secs):
location_name.anchor_point = (0, 0)
location_name.anchored_position = (15, 25)

battery_state = label.Label(terminalio.FONT, text="B??%", color=0x777777)
battery_state.anchor_point = (0, 0)
battery_state.anchored_position = (157, 25)

today_icon = displayio.TileGrid(
icons_large_bmp,
pixel_shader=icons_small_pal,
Expand Down Expand Up @@ -264,6 +270,7 @@ def go_to_sleep(current_time_secs):

today_banner = displayio.Group()
today_banner.append(today_date)
today_banner.append(battery_state)
today_banner.append(location_name)
today_banner.append(today_icon)
today_banner.append(today_low_temp)
Expand All @@ -287,6 +294,12 @@ def go_to_sleep(current_time_secs):
# ===========
# M A I N
# ===========

battery_percent = 100 * (magtag.peripherals.battery - 3.5) / (4.2 - 3.5)
print(f"Battery: {magtag.peripherals.battery}V, ~{battery_percent:.0f}%")
if magtag.peripherals.battery < 3.5:
print("Battery: LOW, please charge!")

print("Fetching forecast...")
resp_data = get_forecast()
forecast_data = resp_data.json()
Expand Down
Loading