@@ -176,8 +176,9 @@ def stop_cam(self):
176176 i2c .writeto (camera_addr , bytes ([reg_high , reg_low , power_off_command ]))
177177 except Exception as e :
178178 print (f"Warning: powering off camera got exception: { e } " )
179- print ("emptying self.current_cam_buffer..." )
180- self .image_dsc .data = None # it's important to delete the image when stopping the camera, otherwise LVGL might try to display it and crash
179+ if self .image_dsc : # it's important to delete the image when stopping the camera, otherwise LVGL might try to display it and crash
180+ print ("emptying self.current_cam_buffer..." )
181+ self .image_dsc .data = None
181182
182183 def load_settings_cached (self ):
183184 from mpos .config import SharedPreferences
@@ -453,7 +454,7 @@ def remove_bom(self, buffer):
453454 return buffer
454455
455456
456- def apply_camera_settings (self , cam , use_webcam ):
457+ def apply_camera_settings (self , prefs , cam , use_webcam ):
457458 """Apply all saved camera settings to the camera.
458459
459460 Only applies settings when use_webcam is False (ESP32 camera).
@@ -469,101 +470,101 @@ def apply_camera_settings(self, cam, use_webcam):
469470
470471 try :
471472 # Basic image adjustments
472- brightness = self . prefs .get_int ("brightness" , 0 )
473+ brightness = prefs .get_int ("brightness" , 0 )
473474 cam .set_brightness (brightness )
474475
475- contrast = self . prefs .get_int ("contrast" , 0 )
476+ contrast = prefs .get_int ("contrast" , 0 )
476477 cam .set_contrast (contrast )
477478
478- saturation = self . prefs .get_int ("saturation" , 0 )
479+ saturation = prefs .get_int ("saturation" , 0 )
479480 cam .set_saturation (saturation )
480481
481482 # Orientation
482- hmirror = self . prefs .get_bool ("hmirror" , False )
483+ hmirror = prefs .get_bool ("hmirror" , False )
483484 cam .set_hmirror (hmirror )
484485
485- vflip = self . prefs .get_bool ("vflip" , True )
486+ vflip = prefs .get_bool ("vflip" , True )
486487 cam .set_vflip (vflip )
487488
488489 # Special effect
489- special_effect = self . prefs .get_int ("special_effect" , 0 )
490+ special_effect = prefs .get_int ("special_effect" , 0 )
490491 cam .set_special_effect (special_effect )
491492
492493 # Exposure control (apply master switch first, then manual value)
493- exposure_ctrl = self . prefs .get_bool ("exposure_ctrl" , True )
494+ exposure_ctrl = prefs .get_bool ("exposure_ctrl" , True )
494495 cam .set_exposure_ctrl (exposure_ctrl )
495496
496497 if not exposure_ctrl :
497- aec_value = self . prefs .get_int ("aec_value" , 300 )
498+ aec_value = prefs .get_int ("aec_value" , 300 )
498499 cam .set_aec_value (aec_value )
499500
500- ae_level = self . prefs .get_int ("ae_level" , 2 if self .scanqr_mode else 0 )
501+ ae_level = prefs .get_int ("ae_level" , 2 if self .scanqr_mode else 0 )
501502 cam .set_ae_level (ae_level )
502503
503- aec2 = self . prefs .get_bool ("aec2" , False )
504+ aec2 = prefs .get_bool ("aec2" , False )
504505 cam .set_aec2 (aec2 )
505506
506507 # Gain control (apply master switch first, then manual value)
507- gain_ctrl = self . prefs .get_bool ("gain_ctrl" , True )
508+ gain_ctrl = prefs .get_bool ("gain_ctrl" , True )
508509 cam .set_gain_ctrl (gain_ctrl )
509510
510511 if not gain_ctrl :
511- agc_gain = self . prefs .get_int ("agc_gain" , 0 )
512+ agc_gain = prefs .get_int ("agc_gain" , 0 )
512513 cam .set_agc_gain (agc_gain )
513514
514- gainceiling = self . prefs .get_int ("gainceiling" , 0 )
515+ gainceiling = prefs .get_int ("gainceiling" , 0 )
515516 cam .set_gainceiling (gainceiling )
516517
517518 # White balance (apply master switch first, then mode)
518- whitebal = self . prefs .get_bool ("whitebal" , True )
519+ whitebal = prefs .get_bool ("whitebal" , True )
519520 cam .set_whitebal (whitebal )
520521
521522 if not whitebal :
522- wb_mode = self . prefs .get_int ("wb_mode" , 0 )
523+ wb_mode = prefs .get_int ("wb_mode" , 0 )
523524 cam .set_wb_mode (wb_mode )
524525
525- awb_gain = self . prefs .get_bool ("awb_gain" , True )
526+ awb_gain = prefs .get_bool ("awb_gain" , True )
526527 cam .set_awb_gain (awb_gain )
527528
528529 # Sensor-specific settings (try/except for unsupported sensors)
529530 try :
530- sharpness = self . prefs .get_int ("sharpness" , 0 )
531+ sharpness = prefs .get_int ("sharpness" , 0 )
531532 cam .set_sharpness (sharpness )
532533 except :
533534 pass # Not supported on OV2640?
534535
535536 try :
536- denoise = self . prefs .get_int ("denoise" , 0 )
537+ denoise = prefs .get_int ("denoise" , 0 )
537538 cam .set_denoise (denoise )
538539 except :
539540 pass # Not supported on OV2640?
540541
541542 # Advanced corrections
542- colorbar = self . prefs .get_bool ("colorbar" , False )
543+ colorbar = prefs .get_bool ("colorbar" , False )
543544 cam .set_colorbar (colorbar )
544545
545- dcw = self . prefs .get_bool ("dcw" , True )
546+ dcw = prefs .get_bool ("dcw" , True )
546547 cam .set_dcw (dcw )
547548
548- bpc = self . prefs .get_bool ("bpc" , False )
549+ bpc = prefs .get_bool ("bpc" , False )
549550 cam .set_bpc (bpc )
550551
551- wpc = self . prefs .get_bool ("wpc" , True )
552+ wpc = prefs .get_bool ("wpc" , True )
552553 cam .set_wpc (wpc )
553554
554- raw_gma = self . prefs .get_bool ("raw_gma" , False if self .scanqr_mode else True )
555+ raw_gma = prefs .get_bool ("raw_gma" , False if self .scanqr_mode else True )
555556 print (f"applying raw_gma: { raw_gma } " )
556557 cam .set_raw_gma (raw_gma )
557558
558- lenc = self . prefs .get_bool ("lenc" , True )
559+ lenc = prefs .get_bool ("lenc" , True )
559560 cam .set_lenc (lenc )
560561
561562 # JPEG quality (only relevant for JPEG format)
562- try :
563- quality = self . prefs .get_int ("quality" , 85 )
564- cam .set_quality (quality )
565- except :
566- pass # Not in JPEG mode
563+ # try:
564+ # quality = prefs.get_int("quality", 85)
565+ # cam.set_quality(quality)
566+ # except:
567+ # pass # Not in JPEG mode
567568
568569 print ("Camera settings applied successfully" )
569570
0 commit comments