From 3130116fb540dcfff82c7a1c426b58fb3b1b600b Mon Sep 17 00:00:00 2001 From: Justin White Date: Fri, 20 Mar 2026 23:54:18 -0400 Subject: [PATCH 1/3] MagTag Daily Weather: Add battery state display Curious as to how long it's lasting, figured daily updates on battery state would be good. Also print battery state on the console. --- MagTag/MagTag_Weather/openmeteo/code.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MagTag/MagTag_Weather/openmeteo/code.py b/MagTag/MagTag_Weather/openmeteo/code.py index fc4d41f64..25ffb6bf7 100644 --- a/MagTag/MagTag_Weather/openmeteo/code.py +++ b/MagTag/MagTag_Weather/openmeteo/code.py @@ -9,6 +9,7 @@ import adafruit_imageload from adafruit_display_text import label from adafruit_magtag.magtag import MagTag +import analogio # --| USER CONFIG |-------------------------- LAT = 47.6 # latitude @@ -168,6 +169,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:{batt_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) @@ -231,6 +234,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, @@ -264,6 +271,7 @@ def go_to_sleep(current_time_secs): today_banner = displayio.Group() today_banner.append(today_date) +today_banner.append(batt_volt) today_banner.append(location_name) today_banner.append(today_icon) today_banner.append(today_low_temp) @@ -287,6 +295,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() From 4ba2551404aa793931883754f94880b9a3900b7c Mon Sep 17 00:00:00 2001 From: Justin White Date: Sat, 21 Mar 2026 00:13:57 -0400 Subject: [PATCH 2/3] Fix missed renaming --- MagTag/MagTag_Weather/openmeteo/code.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MagTag/MagTag_Weather/openmeteo/code.py b/MagTag/MagTag_Weather/openmeteo/code.py index 25ffb6bf7..3c9819b7b 100644 --- a/MagTag/MagTag_Weather/openmeteo/code.py +++ b/MagTag/MagTag_Weather/openmeteo/code.py @@ -170,7 +170,7 @@ def update_today(data): 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:{batt_percent:.0f}%' + 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) @@ -271,7 +271,7 @@ def go_to_sleep(current_time_secs): today_banner = displayio.Group() today_banner.append(today_date) -today_banner.append(batt_volt) +today_banner.append(battery_state) today_banner.append(location_name) today_banner.append(today_icon) today_banner.append(today_low_temp) From a04e74c23ff5a3a5bbacabdd60d0e1065b5b9fb2 Mon Sep 17 00:00:00 2001 From: Justin White Date: Sat, 21 Mar 2026 00:18:49 -0400 Subject: [PATCH 3/3] Fix extraneous import --- MagTag/MagTag_Weather/openmeteo/code.py | 1 - 1 file changed, 1 deletion(-) diff --git a/MagTag/MagTag_Weather/openmeteo/code.py b/MagTag/MagTag_Weather/openmeteo/code.py index 3c9819b7b..5fcf598f9 100644 --- a/MagTag/MagTag_Weather/openmeteo/code.py +++ b/MagTag/MagTag_Weather/openmeteo/code.py @@ -9,7 +9,6 @@ import adafruit_imageload from adafruit_display_text import label from adafruit_magtag.magtag import MagTag -import analogio # --| USER CONFIG |-------------------------- LAT = 47.6 # latitude