⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 af_alg_2.c

📁 dm270 source code
💻 C
字号:
// NOT SUPPORTED
/* Hardware auto-focus control algorithm 2 - Rule based */

#include <system/intc270.h>
#include <system/uart270.h>
#include <system/h3a270.h>

#include <user/af_ctrl.h>

#include <demo/mem_alloc.h>

#include <h3a/af_alg_externs.h>


STATUS AFAlg2_FocusCtrlReset();
STATUS AFAlg2_FocusCtrl(int focus_value, int *motor_value);

AF_ConfigData	af_config;
AF_CTRL af_ctrl_2;
AF_ALG  af_alg_2;

int AFAlg2Init() {

	af_ctrl_2.afConfig	= &af_config;

	af_ctrl_2.afConfig->sdramAddress = AF_DATA_ADDR;

	af_ctrl_2.afConfig->numWinH		= 9;            
	af_ctrl_2.afConfig->numWinV		= 4;            
	af_ctrl_2.afConfig->winWidth	= 120;            
	af_ctrl_2.afConfig->winHeight	= 24;           
	af_ctrl_2.afConfig->winStartH	= 358;                
	af_ctrl_2.afConfig->winStartV	= 34;                
	af_ctrl_2.afConfig->iirStartH	= 330;            
	af_ctrl_2.afConfig->winLineIncrement = 2;       
	
	af_ctrl_2.afConfig->greenPixel[0][0]=AF_NON_GREEN;
	af_ctrl_2.afConfig->greenPixel[0][1]=AF_GREEN;
	af_ctrl_2.afConfig->greenPixel[1][0]=AF_GREEN;
	af_ctrl_2.afConfig->greenPixel[1][1]=AF_NON_GREEN;

	AFAlgSetFilter( &af_ctrl_2, IIR_FILTER_BUTTER_MED, IIR_FILTER_NONE);
	
	af_ctrl_2.afConfig->fvAccMode		= AF_FV_SUM;         

	af_ctrl_2.af_alg			= &af_alg_2;				

	af_alg_2.sharp_calc.reset	= AFAlgSharpCalcReset;
	af_alg_2.sharp_calc.execute = AFAlgSharpCalc;

	af_alg_2.focus_ctrl.reset	= AFAlg2_FocusCtrlReset;
	af_alg_2.focus_ctrl.execute = AFAlg2_FocusCtrl;

	af_alg_2.motor_ctrl.reset	= CCDM_MotorCtrlReset;
	af_alg_2.motor_ctrl.execute = CCDM_MotorCtrl;

	af_ctrl_2.vdIntID	= INT_VD0;

	return E_PASS;
}

int fcur, fprev, fmax, count, motor_value_max;
static int cdown;

static int AF2_OPT_1;

STATUS AFAlg2_FocusCtrlReset() {
	fcur=0;
	fprev=0;
	fmax=0;
	count=0;
	cdown=0;
	motor_value_max=0;
	return E_PASS;
}

STATUS AFAlg2_FocusCtrl(int focus_value, int *motor_value) {
	if(count==0) {
		fmax=focus_value;
		motor_value_max=cur_motor_value;
	}

	count++;
	if(focus_value>fmax) {
		fmax=focus_value;
		motor_value_max=cur_motor_value;
	}

	if(cur_motor_value<MIN_MOTOR_VALUE) {
		*motor_value=0;
		if( (motor_value_max-cur_motor_value) > 0) {
			CCDM_MotorCtrl((motor_value_max-cur_motor_value+16));
			CCDM_MotorCtrl(-16);
			cur_motor_value=motor_value_max;
		}
		#if AF_DEBUG
		sprintf( out_buff, "\r\n Max FV Motor Value = %ld, (FV calc = %ld)\r\n", motor_value_max, fmax);
		UART_sendString( UART0, out_buff);
		#endif
		#if AF_OUT_DATA
		if(dump_data)
			DumpDataToFile();
		#endif
		return E_PASS;
	} else {
		cur_motor_value-=fine_step_size;
		*motor_value=-fine_step_size;
		return E_DEVICE;
	}
}


int AFAlgSetArea(Uint16 hstart, Uint16 hend, Uint16 vstart, Uint16 vend) {
	
	if( hend>8 || hstart>hend || vstart>vend || vend>3 )
		return E_INVALID_INPUT;

	af_hstart=hstart;
	af_hend=hend;
	af_vstart=vstart;
	af_vend=vend;
	return E_PASS;
}

int AFAlgConfig() {
	char choice;
	char szBuf[80];

	UART_sendString( UART0, "******************\r\n");
	UART_sendString( UART0, " AF ALG 1/2 Config \r\n");
	UART_sendString( UART0, "******************\r\n");
	#if AF_OUT_DATA
	UART_sendString( UART0, "0: Do NOT Dump data to file\r\n");
	UART_sendString( UART0, "1: Dump data to file\r\n");
	#endif
	UART_sendString( UART0, "2: 9x4 - complete area	\r\n");
	UART_sendString( UART0, "3: 5x2 - center horizontal\r\n");
	UART_sendString( UART0, "4: 3x4 - center vertical\r\n");
	UART_sendString( UART0, "5: Set maximum motor position value (0..280)\r\n"
					"    must be set greater than minimum motor position value\r\n");
	UART_sendString( UART0, "6: Set minimum motor position value (0..280)\r\n"
					"    small value = focus range near to lens but greater AF time\r\n");
	if(AF2_OPT_1==0) 
		UART_sendString( UART0, "7: ENABLE Stop after peak is found (ALGO 2 only)\r\n");
	else
		UART_sendString( UART0, "7: DISABLE Stop after peak is found (ALGO 2 only)\r\n");
	UART_sendString( UART0, "\r\n");
	UART_sendString( UART0, "9: Previous Menu\r\n");
	UART_sendString( UART0, "\r\n");
	UART_sendString( UART0, "Select No. : ");
	UART_recv( UART0, &choice, 1);

	UART_sendString( UART0, "\r\n");
	switch(choice) {
		#if AF_OUT_DATA
		case '0': 
			dump_data=FALSE;
			break;
		case '1': 
			dump_data=TRUE;
			break;
		#endif
		case '5':
			sprintf(out_buff,"\r\nOLD MAX MOTOR VALUE = %d", MAX_MOTOR_VALUE);
			UART_sendString( UART0, out_buff);

			UART_sendString( UART0, "\r\nENTER MAX MOTOR VALUE : ");
			UART_recvString( UART0, szBuf, 80);
			{
				int i=atoi(szBuf);

				if(i>10)
					MAX_MOTOR_VALUE = i;
			}

			sprintf(out_buff,"\r\nNEW MAX MOTOR VALUE = %d\r\n", MAX_MOTOR_VALUE);
			UART_sendString( UART0, out_buff);
			break;
		case '6':
			sprintf(out_buff,"\r\nOLD MIN MOTOR VALUE = %d", MIN_MOTOR_VALUE);
			UART_sendString( UART0, out_buff);

			UART_sendString( UART0, "\r\nENTER MIN MOTOR VALUE : ");
			UART_recvString( UART0, szBuf, 80);
			{
				int i=atoi(szBuf);

				if(i>10 && i<MAX_MOTOR_VALUE)
					MIN_MOTOR_VALUE = i;
			}

			sprintf(out_buff,"\r\nNEW MIN MOTOR VALUE = %d\r\n", MIN_MOTOR_VALUE);
			UART_sendString( UART0, out_buff);
			break;
		case '7':
			AF2_OPT_1^=1;
			break;
		case '2':
			AFAlgSetArea(0, 8, 0, 3);
			break;
		case '3':
			AFAlgSetArea(2, 6, 1, 2);
			break;
		case '4':
			AFAlgSetArea(3, 5, 0, 3);
			break;
		case '9':
			break;
		default: 
			break;
	}
	return E_PASS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -