@@ -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 )
0 commit comments