Skip to content

Commit 4706701

Browse files
committed
cli: Fix flickering when profile data is rendered.
Signed-off-by: iabdalkader <[email protected]>
1 parent 959660d commit 4706701

File tree

2 files changed

+28
-33
lines changed

2 files changed

+28
-33
lines changed

src/openmv/cli.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,20 @@ def main():
249249
for event in pygame.event.get():
250250
if event.type == pygame.QUIT:
251251
raise KeyboardInterrupt
252-
elif event.type == pygame.KEYDOWN:
253-
if event.key == pygame.K_ESCAPE:
254-
raise KeyboardInterrupt
255-
elif profile_enabled and event.key == pygame.K_p:
256-
profile_view = (profile_view + 1) % 3 # Cycle views
257-
logging.info(f"Profile view: {profile_view}")
258-
elif profile_enabled and event.key == pygame.K_m:
259-
profile_mode = not profile_mode
260-
camera.profiler_mode(exclusive=profile_mode)
261-
logging.info(f"Profile mode: {'Exclusive' if profile_mode else 'Inclusive'}")
262-
elif profile_enabled and event.key == pygame.K_r:
263-
camera.profiler_reset()
264-
logging.info("Profiler reset")
252+
if event.type != pygame.KEYDOWN:
253+
continue
254+
if event.key == pygame.K_ESCAPE:
255+
raise KeyboardInterrupt
256+
elif event.key == pygame.K_p and profile_enabled:
257+
profile_view = (profile_view + 1) % 3 # Cycle views
258+
logging.info(f"Profile view: {profile_view}")
259+
elif event.key == pygame.K_r and profile_enabled:
260+
camera.profiler_reset()
261+
logging.info("Profiler reset")
262+
elif event.key == pygame.K_m and profile_enabled:
263+
profile_mode = not profile_mode
264+
camera.profiler_mode(exclusive=profile_mode)
265+
logging.info(f"Profile mode: {'Exclusive' if profile_mode else 'Inclusive'}")
265266

266267
# Read camera status
267268
status = camera.read_status()
@@ -278,6 +279,13 @@ def main():
278279
preview = data[:10] if len(data) > 10 else data
279280
logging.info(f"[{args.channel}] ({size} bytes) {preview}")
280281

282+
# Read profiler data if enabled (max 10Hz)
283+
if profile_enabled and profile_view and screen is not None:
284+
current_time = time.time()
285+
if current_time - profile_update_ms >= 0.1: # 10Hz
286+
if profile_data := camera.read_profile():
287+
profile_update_ms = current_time
288+
281289
# Read frame data
282290
if frame := camera.read_frame():
283291
fps = fps_clock.get_fps()
@@ -304,27 +312,17 @@ def main():
304312
rate_text = f"{current_mbps * 1024:.2f} KB/s"
305313
else:
306314
rate_text = f"{current_mbps:.2f} MB/s"
315+
307316
fps_text = f"{fps:.2f} FPS {rate_text} {w}x{h} RGB888"
308317
screen.blit(font.render(fps_text, True, (255, 0, 0)), (0, 0))
309318

310-
fps_clock.tick()
311-
312-
# Read profiler data if enabled (max 10Hz)
313-
if profile_enabled and profile_view and screen is not None:
314-
current_time = time.time()
315-
if current_time - profile_update_ms >= 0.1: # 10Hz
316-
if profile_data := camera.read_profile():
317-
profile_update_ms = current_time
318-
319319
# Draw profiler overlay if enabled and data available
320320
if profile_data is not None:
321-
screen_width, screen_height = screen.get_size()
322-
draw_profile_overlay(screen, screen_width, screen_height,
323-
profile_data, profile_mode, profile_view, 1, symbols)
321+
draw_profile_overlay(screen, profile_data, profile_mode,
322+
profile_view, 1, symbols, alpha=200)
324323

325-
# Update display once at the end
326-
if frame:
327324
pygame.display.flip()
325+
fps_clock.tick()
328326

329327
# Control main loop timing
330328
clock.tick(1000 // args.poll)

src/openmv/profiler.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,11 @@ def draw_profile_table(overlay_surface, config, profile_data, profile_mode, symb
371371
overlay_surface.blit(instruction_text, (0, summary_y + int(20 * config['scale_factor'])))
372372

373373

374-
def draw_profile_overlay(screen, screen_width, screen_height, profile_data,
375-
profile_mode, profile_view, scale, symbols, alpha=250):
374+
def draw_profile_overlay(screen, profile_data, profile_mode, profile_view, scale, symbols, alpha=250):
376375
"""Main entry point for drawing the profile overlay.
377376
378377
Args:
379378
screen: pygame surface to draw on
380-
screen_width: Screen width in pixels
381-
screen_height: Screen height in pixels
382379
profile_data: List of profile records from camera
383380
profile_mode: Boolean, True=exclusive, False=inclusive
384381
profile_view: 1=performance, 2=events
@@ -388,8 +385,8 @@ def draw_profile_overlay(screen, screen_width, screen_height, profile_data,
388385
"""
389386
# Calculate dimensions and create surface
390387
base_width, base_height = 800, 800
391-
screen_width *= scale
392-
screen_height *= scale
388+
screen_width = screen.get_size()[0] * scale
389+
screen_height = screen.get_size()[1] * scale
393390
scale_factor = min(screen_width / base_width, screen_height / base_height)
394391

395392
overlay_surface = pygame.Surface((screen_width, screen_height), pygame.SRCALPHA)

0 commit comments

Comments
 (0)