[转载] [TouchPanel]TouchPanel的虚拟按键没有震感

[FAQ06834] [TouchPanel]TouchPanel的虚拟按键没有震感
Branch: ICSICS2JBJB2

FAQ Content

【问题描述】
 Setting->情景模式->使能振动选项,TP虚拟按键无振动效果
 
【问题原因】
 在TouchPanel的driver中,如果虚拟按键是以 input_report_key(tpd->kpd, key_code, key_val);方式上报key值,是不会有触感的。
 如果虚拟按键是以坐标形式上报,如下所示:
   input_report_abs(tpd->dev, ABS_MT_POSITION_X, x);
   input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y);
 上报的,就会有触感。
 
【解决方法】
 把虚拟按键以坐标的形式上报。
1,TPD_HAVE_BUTTON宏要打开:#define TPD_HAVE_BUTTON
 
2,定义按键的坐标位置(具体定义,可以参考  FAQ03862  --电容屏客制化文件vitual key的配置
#define TPD_BUTTON_HEIGH   100
#define TPD_KEY_COUNT           3
#define TPD_KEYS                { KEY_MENU, KEY_HOME,KEY_BACK}
#define TPD_KEYS_DIM            {{80,850,160,TPD_BUTTON_HEIGH},{240,850,160,TPD_BUTTON_HEIGH},{400,850,160,TPD_BUTTON_HEIGH}}
 
3, 从TouchPanel中读到的虚拟按键数据有两种,一种是key值(1,2,3),另一种是报的坐标值((x,y));
如果读出的虚拟按键值为坐标,那直接按TouchPanel报坐标点的方式上报就OK了。
如果是key值,那就需要把key人为的转为坐标,然后在上报。
 
【例子】
 以msg2133为列,它的虚拟按键读取的为key值,需要转成坐标上报,code如下:
 static void tpd_down(int x, int y, int p, int id) {
   input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 100);
   input_report_abs(tpd->dev, ABS_PRESSURE, 100);
   input_report_key(tpd->dev, BTN_TOUCH, 1);
   input_report_abs(tpd->dev, ABS_MT_POSITION_X, x);
   input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y);
   /* track id Start 0 */
  //input_report_abs(tpd->dev, ABS_MT_TRACKING_ID, p);  
   input_mt_sync(tpd->dev);
   if (FACTORY_BOOT == get_boot_mode()|| RECOVERY_BOOT == get_boot_mode())
   {    
  tpd_button(x, y, 1);   
   }
   if(y > TPD_RES_Y) //virtual key debounce to avoid android ANR issue
   {
    msleep(50);
    TPD_DEBUG("D virtual key \n");
   }
   TPD_EM_PRINT(x, y, x, y, id, 1);
  }
   
 static void tpd_up(int x, int y,int *count) {
   input_report_key(tpd->dev, BTN_TOUCH, 0);
   input_mt_sync(tpd->dev);
   TPD_EM_PRINT(x, y, x, y, 0, 0);
     
   if(FACTORY_BOOT == get_boot_mode()|| RECOVERY_BOOT == get_boot_mode())
   {    
     TPD_DEBUG(KERN_ERR "[msg2133a]--tpd_up-BOOT MODE--X:%d, Y:%d; \n", x, y);
   tpd_button(x, y, 0);  
   }      
 
  }
  static void tpd_key(int key_code, int key_val)
 {
   input_report_key(tpd->kpd, key_code, key_val);
 TPD_DEBUG(KERN_ERR "[msg2133a] key_code = %d(%d)\n", key_code, key_val);
 }
 
 static void tpd_check_key(int *key, int *is_down)
 {
  static int pre_key = 0;
 int cur_key;
   
  if (*key == 1) cur_key = KEY_MENU;
  else if (*key == 2) cur_key = KEY_HOME;
  else if (*key == 4) cur_key = KEY_BACK;
  else cur_key = 0;
   
  if ((pre_key != 0) && (cur_key != pre_key))
  {
   // current key is different from previous key, then need to send key up
   cur_key = pre_key;
  pre_key = 0;
  *is_down = 0;
  }
  else  
  {
   pre_key = cur_key;
   *is_down = 1;
  }
   
  *key = cur_key;
 }
 static int touch_event_handler(void *unused)
 {
   
    TouchScreenInfo_t touchData;
 u8 touchkeycode = 0;
 static u32 preKeyStatus = 0;
 int i=0;
 
    TPD_DEBUG(KERN_ERR "[msg2133a]touch_event_handler() do while \n");
 touchData.nFingerNum = 0;
 TPD_DEBUG(KERN_ERR "[msg2133a]touch_event_handler() do while \n");
   
 if (tpd_touchinfo(&touchData))  
 {
   
  TPD_DEBUG(KERN_ERR "[msg2133a]--KeyMode:%d, KeyCode:%d, FingerNum =%d \n", touchData.nTouchKeyMode, touchData.nTouchKeyCode, touchData.nFingerNum );
   
  //key event
  if( touchData.nTouchKeyMode )
  {
   //report key    以报key的方式上报数据,虚拟按键不会有触感
   #if 0
   int key_code = touchData.nTouchKeyCode;  
   int key_val;
   tpd_check_key(&key_code, &key_val);
   
      tpd_key(key_code, key_val);
   input_sync(tpd->kpd);
   goto TPD_EVENT_END;
   #else
   //report coordinate     把key值转变为坐标值,然后在上报数据,此时就会有震感。
   touchData.nFingerNum = 1;
   if( touchData.nTouchKeyCode == 1 )
   {
    //touchkeycode = KEY_MENU;
    touchData.Point[0].X = 80;
    touchData.Point[0].Y = 850;
   }
   if( touchData.nTouchKeyCode == 2 )
   {
    //touchkeycode = KEY_HOMEPAGE ;
    touchData.Point[0].X = 240;
    touchData.Point[0].Y = 850;
   }
   if( touchData.nTouchKeyCode == 4 )
   {
    //touchkeycode = KEY_BACK;
    touchData.Point[0].X = 400;
    touchData.Point[0].Y = 850;
   }
   if( touchData.nTouchKeyCode == 8 )
   {
    //touchkeycode = KEY_SEARCH;
    //touchData.Point[0].X = 560;
    //touchData.Point[0].Y = 850;
   }
   #endif
   
  }
  //Touch event
  if( ( touchData.nFingerNum ) == 0 ) //touch end
  {
   TPD_DEBUG("------UP------ \n");
   TPD_DEBUG(KERN_ERR "[msg2133a]---X:%d, Y:%d; \n", touchData.Point[0].X, touchData.Point[0].Y);
   tpd_up(touchData.Point[0].X, touchData.Point[0].Y, 0);
   input_sync( tpd->dev );
  }
  else //touch on screen
  {
   TPD_DEBUG("------DOWN------ \n");
   for( i = 0; i < ( (int)touchData.nFingerNum ); i++ )
   {
       tpd_down(touchData.Point[i].X, touchData.Point[i].Y, 1, i);
    TPD_DEBUG(KERN_ERR "[msg2133a]---X:%d, Y:%d; i=%d \n", touchData.Point[i].X, touchData.Point[i].Y, i);
   }
   input_sync( tpd->dev );
  }
 }
TPD_EVENT_END:
    mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);  
 return 0;
 }

猜你喜欢

转载自duanyu010.iteye.com/blog/1946377