@ -107,8 +107,6 @@ static void camera_release_buffer(void* cookie, int buf_idx) { 
			
		
	
		
			
				
					static  void  camera_init ( CameraState  * s ,  int  camera_id ,  int  camera_num ,  
			
		
	
		
			
				
					                        uint32_t  pixel_clock ,  uint32_t  line_length_pclk ,   
			
		
	
		
			
				
					                        unsigned  int  max_gain ,  unsigned  int  fps )  {   
			
		
	
		
			
				
					  memset ( s ,  0 ,  sizeof ( * s ) ) ;   
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					  s - > camera_num  =  camera_num ;   
			
		
	
		
			
				
					  s - > camera_id  =  camera_id ;   
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -261,8 +259,6 @@ static int imx179_s5k3p8sp_apply_exposure(CameraState *s, int gain, int integ_li 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					void  cameras_init ( DualCameraState  * s )  {  
			
		
	
		
			
				
					  memset ( s ,  0 ,  sizeof ( * s ) ) ;   
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					  char  project_name [ 1024 ]  =  { 0 } ;   
			
		
	
		
			
				
					  property_get ( " ro.boot.project_name " ,  project_name ,  " " ) ;   
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -396,7 +392,9 @@ static void set_exposure(CameraState *s, float exposure_frac, float gain_frac) { 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					  if  ( err  = =  0 )  {   
			
		
	
		
			
				
					    s - > cur_exposure_frac  =  exposure_frac ;   
			
		
	
		
			
				
					    pthread_mutex_lock ( & s - > frame_info_lock ) ;   
			
		
	
		
			
				
					    s - > cur_gain_frac  =  gain_frac ;   
			
		
	
		
			
				
					    pthread_mutex_unlock ( & s - > frame_info_lock ) ;   
			
		
	
		
			
				
					  }   
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					  //LOGD("set exposure: %f %f - %d", exposure_frac, gain_frac, err);
   
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -413,16 +411,20 @@ static void do_autoexposure(CameraState *s, float grey_frac) { 
			
		
	
		
			
				
					    const  unsigned  int  exposure_time_min  =  16 ;   
			
		
	
		
			
				
					    const  unsigned  int  exposure_time_max  =  frame_length  -  11 ;  // copied from set_exposure()
   
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    float  cur_gain_frac  =  s - > cur_gain_frac ;   
			
		
	
		
			
				
					    float  exposure_factor  =  pow ( 1.05 ,  ( target_grey  -  grey_frac )  /  0.05 ) ;   
			
		
	
		
			
				
					    if  ( s - > cur_gain_frac  >  0.125  & &  exposure_factor  <  1 )  {   
			
		
	
		
			
				
					      s - > cur_gain_frac  * =  exposure_factor ;   
			
		
	
		
			
				
					    if  ( cur_gain_frac  >  0.125  & &  exposure_factor  <  1 )  {   
			
		
	
		
			
				
					      cur_gain_frac  * =  exposure_factor ;   
			
		
	
		
			
				
					    }  else  if  ( s - > cur_integ_lines  *  exposure_factor  < =  exposure_time_max  & &  s - > cur_integ_lines  *  exposure_factor  > =  exposure_time_min )  {  // adjust exposure time first
   
			
		
	
		
			
				
					      s - > cur_exposure_frac  * =  exposure_factor ;   
			
		
	
		
			
				
					    }  else  if  ( s - > cur_gain_frac  *  exposure_factor  < =  gain_frac_max  & &  s - > cur_gain_frac  *  exposure_factor  > =  gain_frac_min )  {   
			
		
	
		
			
				
					      s - > cur_gain_frac  * =  exposure_factor ;   
			
		
	
		
			
				
					    }  else  if  ( cur_gain_frac  *  exposure_factor  < =  gain_frac_max  & &  cur_gain_frac  *  exposure_factor  > =  gain_frac_min )  {   
			
		
	
		
			
				
					      cur_gain_frac  * =  exposure_factor ;   
			
		
	
		
			
				
					    }   
			
		
	
		
			
				
					    pthread_mutex_lock ( & s - > frame_info_lock ) ;   
			
		
	
		
			
				
					    s - > cur_gain_frac  =  cur_gain_frac ;   
			
		
	
		
			
				
					    pthread_mutex_unlock ( & s - > frame_info_lock ) ;   
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    set_exposure ( s ,  s - > cur_exposure_frac ,  s - > cur_gain_frac ) ;   
			
		
	
		
			
				
					    set_exposure ( s ,  s - > cur_exposure_frac ,  cur_gain_frac ) ;   
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					  }  else  {  // keep the old for others
   
			
		
	
		
			
				
					    float  new_exposure  =  s - > cur_exposure_frac ;   
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -1794,15 +1796,16 @@ static void do_autofocus(CameraState *s) { 
			
		
	
		
			
				
					  const  int  dac_up  =  s - > device  = =  DEVICE_LP3 ?  LP3_AF_DAC_UP : OP3T_AF_DAC_UP ;   
			
		
	
		
			
				
					  const  int  dac_down  =  s - > device  = =  DEVICE_LP3 ?  LP3_AF_DAC_DOWN : OP3T_AF_DAC_DOWN ;   
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					  float  lens_true_pos  =  s - > lens_true_pos ;   
			
		
	
		
			
				
					  if  ( ! isnan ( err ) )   {   
			
		
	
		
			
				
					    // learn lens_true_pos
   
			
		
	
		
			
				
					    s - > lens_true_pos  - =  err * focus_kp ;   
			
		
	
		
			
				
					    lens_true_pos  - =  err * focus_kp ;   
			
		
	
		
			
				
					  }   
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					  // stay off the walls
   
			
		
	
		
			
				
					  s - > lens_true_pos  =  clamp ( s - > lens_true_pos ,  dac_down ,  dac_up ) ;   
			
		
	
		
			
				
					
  
			
		
	
		
			
				
					  int  target  =  clamp ( s - > lens_true_pos  -  sag ,  dac_down ,  dac_up ) ;   
			
		
	
		
			
				
					  lens_true_pos  =  clamp ( lens_true_pos ,  dac_down ,  dac_up ) ;   
			
		
	
		
			
				
					  int  target  =  clamp ( lens_true_pos  -  sag ,  dac_down ,  dac_up ) ;   
			
		
	
		
			
				
					  s - > lens_true_pos  =  lens_true_pos ;   
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					  /*char debug[4096];
   
			
		
	
		
			
				
					  char  * pdebug  =  debug ;