📄 touch_panel.c
字号:
touhc_push_data_to_buffer(x, event);
touhc_push_data_to_buffer(y>>8, event);
touhc_push_data_to_buffer(y, event);
}
}
}
/*************************************************************************
* FUNCTION
* touch_panel_check_cali
*
* DESCRIPTION
* This function is to check calibration result.
*
* PARAMETERS
* x: x coord.
* y: y coord.
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool touch_panel_check_cali_stage3(void)
{
kal_int16 x, y, x_diff, y_diff;
double x_slope, y_slope, x_offset, y_offset;
touch_panel_tuning(cali_point[0].x, cali_point_adc[0].x,
cali_point[1].x, cali_point_adc[1].x,
&x_slope, &x_offset);
touch_panel_tuning(cali_point[0].y, cali_point_adc[0].y,
cali_point[1].y, cali_point_adc[1].y,
&y_slope, &y_offset);
x=(kal_int16)(x_slope*(double)(cali_point_adc[2].x)+x_offset);
y=(kal_int16)(y_slope*(double)(cali_point_adc[2].y)+y_offset);
x_diff=cali_point[2].x-x;
y_diff=cali_point[2].y-y;
if(x_diff>TOUCH_PANEL_CALI_CHECK_OFFSET||x_diff<-TOUCH_PANEL_CALI_CHECK_OFFSET||
y_diff>TOUCH_PANEL_CALI_CHECK_OFFSET||y_diff<-TOUCH_PANEL_CALI_CHECK_OFFSET)
return KAL_FALSE;
return KAL_TRUE;
}
kal_bool touch_panel_check_cali_stage1(void)
{
kal_int32 x_adc_range, x_coord_range, x_adc_high, x_adc_low;
kal_int32 y_adc_range, y_coord_range, y_adc_high, y_adc_low;
/*use the relative ADC difference*/
/*X ADC Diff*/
if(cali_point_adc[1].x>=cali_point_adc[0].x)
x_adc_range=cali_point_adc[1].x-cali_point_adc[0].x;
else
x_adc_range=cali_point_adc[0].x-cali_point_adc[1].x;
/*Y ADC Diff*/
if(cali_point_adc[1].y>=cali_point_adc[0].y)
y_adc_range=cali_point_adc[1].y-cali_point_adc[0].y;
else
y_adc_range=cali_point_adc[0].y-cali_point_adc[1].y;
/*0(24,32),1(216,288),2(132,176)*/
/*X Coord Diff*/
if(cali_point[1].x>=cali_point[0].x)
x_coord_range=cali_point[1].x-cali_point[0].x; //192
else
x_coord_range=cali_point[0].x-cali_point[1].x;
/*Y Coord Diff*/
if(cali_point[1].y>=cali_point[0].y)
y_coord_range=cali_point[1].y-cali_point[0].y; //256
else
y_coord_range=cali_point[0].y-cali_point[1].y;
x_adc_high=x_coord_range*(ADC_X_END-ADC_X_START)*150/(SCREEN_X_END-SCREEN_X_START)/100; //4761.6//4382
x_adc_low=x_coord_range*(ADC_X_END-ADC_X_START)*50/(SCREEN_X_END-SCREEN_X_START)/100;//1587.2//1460
y_adc_high=y_coord_range*(ADC_Y_END-ADC_Y_START)*150/(SCREEN_Y_END-SCREEN_Y_START)/100; //6316.8
y_adc_low=y_coord_range*(ADC_Y_END-ADC_Y_START)*50/(SCREEN_Y_END-SCREEN_Y_START)/100;//2105.6
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("x adc diff=%d high=%d low=%d\r\n",x_adc_range,x_adc_high,x_adc_low );
dbg_printWithTime("y adc diff=%d high=%d low=%d\r\n",y_adc_range,y_adc_high,y_adc_low );
#endif
if((x_adc_range<x_adc_low) || (x_adc_range>x_adc_high))
return KAL_FALSE;
if((y_adc_range<y_adc_low) || (y_adc_range>y_adc_high))
return KAL_FALSE;
return KAL_TRUE;
}
kal_bool touch_panel_check_cali_stage2(void)
{
kal_int32 x02_diff, y02_diff, x12_diff, y12_diff;
/*use the point 3 to check if the previous 2 two points are opposite*/
if(cali_point_adc[1].x>=cali_point_adc[0].x)/*1>2>0*/
{
x12_diff=cali_point_adc[1].x-cali_point_adc[2].x;
x02_diff=cali_point_adc[2].x-cali_point_adc[0].x;
}
else/*0>2>1*/
{
x12_diff=cali_point_adc[2].x-cali_point_adc[1].x;
x02_diff=cali_point_adc[0].x-cali_point_adc[2].x;
}
if(cali_point_adc[1].y>=cali_point_adc[0].y)/*1>2>0*/
{
y12_diff=cali_point_adc[1].y-cali_point_adc[2].y;
y02_diff=cali_point_adc[2].y-cali_point_adc[0].y;
}
else/*0>2>1*/
{
y12_diff=cali_point_adc[2].y-cali_point_adc[1].y;
y02_diff=cali_point_adc[0].y-cali_point_adc[2].y;
}
if(y12_diff>y02_diff||x12_diff>x02_diff)
return KAL_FALSE;
return KAL_TRUE;
}
kal_bool touch_panel_check_cali(void)
{
kal_bool result1, result2, result3;
result1=touch_panel_check_cali_stage1();
result2=touch_panel_check_cali_stage2();
result3=touch_panel_check_cali_stage3();
//kal_prompt_trace(MOD_TP_TASK, "touch_panel_check_cali: %d,%d,%d", result1,result2,result3);
//QSH
/*
if(result1==KAL_TRUE&&result2==KAL_TRUE&&result3==KAL_TRUE)
return KAL_TRUE;
else
return KAL_FALSE;
*/
return KAL_TRUE;
}
/*************************************************************************
* FUNCTION
* touch_excute_cali
*
* DESCRIPTION
* This function is to excute calibration.
*
* PARAMETERS
* x: x coord.
* y: y coord.
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_excute_cali(kal_int16 x_adc, kal_int16 y_adc)
{
ilm_struct *tp_ilm;
tp_cali_done_struct *local_para;
kal_bool cali_result;
module_type owner=0;
if(tp_cali_mode==KAL_FALSE)
{
// kal_print("touch_excute_cali return");
return;
}
//kal_prompt_trace(MOD_TP_TASK, "touch_excute_cali(),mode:%d,cnt:%d", tp_cali_mode,tp_cali_cnt);
if(tp_cali_cnt==0)
{
kal_print("touch_excute_cali 11");
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("1st Cali %d,%d\r\n",x_adc,y_adc);
#endif
//touch_panel_read_adc(&(cali_point_adc[0].x),&(cali_point_adc[0].y));
tp_cali_cnt++;
cali_point_adc[0].x=x_adc;
cali_point_adc[0].y=y_adc;
}
else if(tp_cali_cnt==1)
{
kal_print("touch_excute_cali 22");
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("2nd Cali %d,%d\r\n",x_adc,y_adc);
#endif
tp_cali_cnt++;
cali_point_adc[1].x=x_adc;
cali_point_adc[1].y=y_adc;
}
else if(tp_cali_cnt==2)
{
cali_point_adc[2].x=x_adc;
cali_point_adc[2].y=y_adc;
tp_cali_mode=KAL_FALSE;
tp_cali_cnt=0;
cali_result=touch_panel_check_cali();
//kal_prompt_trace(MOD_TP_TASK, "touch_panel_check_cali return: %d", cali_result);
if(cali_result==KAL_TRUE)
{
//kal_print("touch_excute_cali 33");
// touch_panel_tuning(coord1,adc1,coord2,adc2,*slope, offset);
touch_panel_tuning(SCREEN_X_END, ADC_X_START, SCREEN_X_START, ADC_X_END, &TPCali.x_slope, &TPCali.x_offset);
touch_panel_tuning(SCREEN_Y_START, ADC_Y_START, SCREEN_Y_END, ADC_Y_END, &TPCali.y_slope, &TPCali.y_offset);
///*QSH
//touch_panel_tuning(cali_point[0].x, cali_point_adc[0].x, cali_point[1].x, cali_point_adc[1].x,&TPCali.x_slope, &TPCali.x_offset);
//touch_panel_tuning(cali_point[0].y, cali_point_adc[0].y, cali_point[1].y, cali_point_adc[1].y,&TPCali.y_slope, &TPCali.y_offset);
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("x slope=%f off=%f\r\n",TPCali.x_slope,TPCali.x_offset);
dbg_printWithTime("y slope=%f off=%f\r\n",TPCali.y_slope,TPCali.y_offset);
#endif
}
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("cali result=%d\r\n",cali_result);
#endif
local_para = (tp_cali_done_struct *)
construct_local_para(sizeof(tp_cali_done_struct),TD_UL);
local_para->result=cali_result;
#ifdef TOUCH_PANEL_DEBUG
owner=MOD_SSDBG1;
#else
owner=MOD_MMI;
#endif
DRV_BuildPrimitive(tp_ilm,
MOD_TP_TASK,
owner,
MSG_ID_TP_CALI_DONE,
local_para);
msg_send_ext_queue(tp_ilm);
}
}
/*************************************************************************
* FUNCTION
* touch_panel_longtap_cb
*
* DESCRIPTION
* This function is long tap timer callback function.
*
* PARAMETERS
* Parameter
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_longtap_cb(void *parameter) //启动stroke_longtat EPN_LONGTAP定时器
{
i2c_tp_ReadAllData(); //qsh 04-17
//kal_print("touch_panel_longtap_cb");
//if(!(finger_num)) //qsh 04-17
if((!(finger_num))&&(!(tp_tapcode))) //qsh 04-15
//if(!(finger_num)) //qsh 04-15
touch_panel_up_hdr();////qsh 04-17
else
{
if(TP.state==DOWN)
{
if(TP.area==HAND_WRITING)
{
// kal_print("SEND STROKE_LONGTAP EVENT");
tp_data_pop(STROKE_LONGTAP, TP.pre.x, TP.pre.y);
}
else
{
// kal_print("SEND PEN_LONGTAP EVENT");
tp_data_pop(PEN_LONGTAP, TP.pre.x, TP.pre.y);
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("PEN LONGTAP x=%d y=%d\r\n",TP.pre.x,TP.pre.y);
#endif
if(TP.repeat_cnt!=0)
{
GPTI_StartItem(touch_panel_repeat_handle,
TP.repeat_cnt,
touch_panel_repeat_cb,
NULL);
}
}
}
}
}
/*************************************************************************
* FUNCTION
* touch_panel_repeat_cb
*
* DESCRIPTION
* This function is repeat timer callback function.
*
* PARAMETERS
* Parameter
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_repeat_cb(void *parameter)
{
i2c_tp_ReadAllData(); //qsh 04-17
//kal_print("touch_panel_repeat_cb");
//x = TP_I2C_X;//qsh
//y = TP_I2C_Y;//qsh
//if(!(finger_num)) //qsh 04-17
if((!(finger_num))&&(!(tp_tapcode))) //qsh 04-15
touch_panel_up_hdr();////qsh 04-17
else
{
if(TP.state==DOWN)
{
// kal_print("SEND PEN_REPEAT EVENT");
tp_data_pop(PEN_REPEAT, TP.pre.x, TP.pre.y);
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("PEN REPEAT x=%d y=%d\r\n",TP.pre.x,TP.pre.y);
#endif
if(TP.repeat_cnt!=0)
{
GPTI_StartItem(touch_panel_repeat_handle,
TP.repeat_cnt,
touch_panel_repeat_cb,
NULL);
}
}
}
}
/*************************************************************************
* FUNCTION
* touch_panel_stroke_cb
*
* DESCRIPTION
* This function is polling timer callback function in handwriting area.
*
* PARAMETERS
* Parameter
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_stroke_cb(void *parameter)//启动STROKE_MOVE定时器
{
kal_int16 x, y;
kal_bool valid=KAL_FALSE;
char str[100];
// i2c_tp_ReadAllData();//qsh 04-15;
//x = TP_I2C_X;//qsh
//y = TP_I2C_Y;//qsh
touch_panel_read_adc(&x, &y); //qsh 04-15
//kal_print("touch_panel_stroke_cb");
//if((!(finger_num))
if((!(finger_num))&&(!(tp_tapcode))) //qsh 04-15
//if(!(finger_num)) //qsh 04-15
touch_panel_up_hdr();////qsh 04-15
else
{
if(TP.state==DOWN)
{
#ifdef TOUCH_PANEL_PRESSURE
if (KAL_TRUE == tp_fun_ptr->tp_pressure_check())
{
#endif
//kal_print("touch_panel_stroke_cb11");
// touch_panel_read_adc(&x, &y); //qsh
// sprintf(str,"touch_panel_stroke_cb x=%d,y=%d,slope=%f,offset=%f",x,y,TPCali.y_slope,TPCali.y_offset);
// kal_print(str);
valid=touch_panel_adc_to_coordinate(&x,&y);/*translate*/
if(valid==KAL_TRUE)
{
// kal_print("valid is true");
touch_panel_stroke_filter(x, y);
}
else
{
kal_print("valid is false");
// touch_panel_state =0; //qsh
// EINT_Set_Polarity(TP.eint_chan,touch_panel_state);//qsh
// touch_panel_up_hdr();////qsh 04-15
// tp_data_pop(STROKE_UP, TP.pre.x, TP.pre.y);
}
#ifdef TOUCH_PANEL_PRESSURE
}
#endif
/*start polling again*/
touch_panel_stroke_hdr();//启动定时器
}
}
}
/*************************************************************************
* FUNCTION
* touch_panel_event_cb
*
* DESCRIPTION
* This function is polling timer callback function in non-handwriting.
*
* PARAMETERS
* Parameter
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*Event timer callback function*/
void touch_panel_event_cb(void *parameter)
{
kal_int16 x=0, y=0;
kal_bool valid=KAL_FALSE;
char str[100];
touch_panel_read_adc(&x, &y);
//x = TP_I2C_X;//qsh
//y = TP_I2C_Y;//qsh
//if(!(finger_num))
if((!(finger_num))&&(!(tp_tapcode))) //qsh 04-15
//if(!(finger_num)) //qsh 04-15
touch_panel_up_hdr();//qsh
else
{
//kal_print("qsh test touch_panel_event_cb PEN_MOVE");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -