@@ -61,7 +61,6 @@ def load_resolution_preference(self):
6161 self .height = self .DEFAULT_HEIGHT
6262
6363 def onCreate (self ):
64- self .load_resolution_preference ()
6564 self .scanqr_mode = self .getIntent ().extras .get ("scanqr_mode" )
6665 self .main_screen = lv .obj ()
6766 self .main_screen .set_style_pad_all (1 , 0 )
@@ -127,11 +126,12 @@ def onCreate(self):
127126 self .setContentView (self .main_screen )
128127
129128 def onResume (self , screen ):
129+ self .load_resolution_preference () # needs to be done BEFORE the camera is initialized
130130 self .cam = init_internal_cam (self .width , self .height )
131131 if self .cam :
132132 self .image .set_rotation (900 ) # internal camera is rotated 90 degrees
133133 # Apply saved camera settings, only for internal camera for now:
134- apply_camera_settings (self .cam , self .use_webcam )
134+ apply_camera_settings (self .cam , self .use_webcam ) # needs to be done AFTER the camera is initialized
135135 else :
136136 print ("camera app: no internal camera found, trying webcam on /dev/video0" )
137137 try :
@@ -296,70 +296,14 @@ def zoom_button_click(self, e):
296296 outputY = prefs .get_int ("startX" , CameraSettingsActivity .outputY_default )
297297 scale = prefs .get_bool ("scale" , CameraSettingsActivity .scale_default )
298298 binning = prefs .get_bool ("binning" , CameraSettingsActivity .binning_default )
299- # This works as it's what works in the C code:
300299 result = self .cam .set_res_raw (startX ,startY ,endX ,endY ,offsetX ,offsetY ,totalX ,totalY ,outputX ,outputY ,scale ,binning )
301300 print (f"self.cam.set_res_raw returned { result } " )
302301
303302 def open_settings (self ):
304303 self .image_dsc .data = None
305304 self .current_cam_buffer = None
306- """Launch the camera settings activity."""
307305 intent = Intent (activity_class = CameraSettingsActivity )
308- self .startActivityForResult (intent , self .handle_settings_result )
309-
310- def handle_settings_result (self , result ):
311- print (f"handle_settings_result: { result } " )
312- """Handle result from settings activity."""
313- if result .get ("result_code" ) == True :
314- print ("Settings changed, reloading resolution..." )
315- # Reload resolution preference
316- self .load_resolution_preference ()
317-
318- # CRITICAL: Pause capture timer to prevent race conditions during reconfiguration
319- if self .capture_timer :
320- self .capture_timer .delete ()
321- self .capture_timer = None
322- print ("Capture timer paused" )
323-
324- # Clear stale data pointer to prevent segfault during LVGL rendering
325- self .image_dsc .data = None
326- self .current_cam_buffer = None
327- print ("Image data cleared" )
328-
329- # Update image descriptor with new dimensions
330- # Note: image_dsc is an LVGL struct, use attribute access not dictionary access
331- self .image_dsc .header .w = self .width
332- self .image_dsc .header .h = self .height
333- self .image_dsc .header .stride = self .width * (2 if self .colormode else 1 )
334- self .image_dsc .data_size = self .width * self .height * (2 if self .colormode else 1 )
335- print (f"Image descriptor updated to { self .width } x{ self .height } " )
336-
337- # Reconfigure camera if active
338- if self .cam :
339- if self .use_webcam :
340- print (f"Reconfiguring webcam to { self .width } x{ self .height } " )
341- # Reconfigure webcam resolution (input and output are the same)
342- webcam .reconfigure (self .cam , width = self .width , height = self .height )
343- # Resume capture timer for webcam
344- self .capture_timer = lv .timer_create (self .try_capture , 100 , None )
345- print ("Webcam reconfigured, capture timer resumed" )
346- else :
347- # For internal camera, need to reinitialize
348- print (f"Reinitializing internal camera to { self .width } x{ self .height } " )
349- self .cam .deinit ()
350- self .cam = init_internal_cam (self .width , self .height )
351- if self .cam :
352- # Apply all camera settings
353- apply_camera_settings (self .cam , self .use_webcam )
354- self .capture_timer = lv .timer_create (self .try_capture , 100 , None )
355- print ("Internal camera reinitialized, capture timer resumed" )
356- else :
357- print ("ERROR: Failed to reinitialize camera after resolution change" )
358- self .status_label .set_text ("Failed to reinitialize camera.\n Please restart the app." )
359- self .status_label_cont .remove_flag (lv .obj .FLAG .HIDDEN )
360- return # Don't continue if camera failed
361-
362- self .update_preview_image ()
306+ self .startActivity (intent )
363307
364308 def try_capture (self , event ):
365309 #print("capturing camera frame")
0 commit comments