Skip to content

Commit a59bccf

Browse files
Show Fonts: add FPS logging
1 parent 61186f0 commit a59bccf

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

  • internal_filesystem/apps/com.micropythonos.showfonts/assets

internal_filesystem/apps/com.micropythonos.showfonts/assets/showfonts.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def onCreate(self):
2020

2121
self.setContentView(screen)
2222

23+
def onResume(self, screen):
24+
lv.log_register_print_cb(ShowFonts.log_callback)
25+
26+
def onPause(self, screen): # Activity goes background
27+
lv.log_register_print_cb(None)
28+
2329
def addAllFontsTitles(self, screen):
2430
fonts = FontManager.listFonts()
2531
fonts.append((self._ttf_font, "TTF Rancourt 42"))
@@ -106,3 +112,19 @@ def _focus_obj(event):
106112
def _defocus_obj(event):
107113
target = event.get_target_obj()
108114
target.set_style_border_width(0, lv.PART.MAIN)
115+
116+
@staticmethod
117+
# Custom log callback to capture FPS
118+
def log_callback(level, log_str):
119+
# Convert log_str to string if it's a bytes object
120+
log_str = log_str.decode() if isinstance(log_str, bytes) else log_str
121+
# Optional: Print for debugging
122+
# print(f"Level: {level}, Log: {log_str}")
123+
# Log message format: "sysmon: 25 FPS (refr_cnt: 8 | redraw_cnt: 1), ..."
124+
if "sysmon:" in log_str and "FPS" in log_str:
125+
try:
126+
# Extract FPS value (e.g., "25" from "sysmon: 25 FPS ...")
127+
fps_part = log_str.split("FPS")[0].split("sysmon:")[1].strip()
128+
print(f"Current FPS: {fps_part}")
129+
except (IndexError, ValueError):
130+
pass

0 commit comments

Comments
 (0)