Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
drivers/input: oplus-ts-v2: simplify gesture detection sequence
Browse files Browse the repository at this point in the history
Use a switch case, instead of massive if-else ladder

Change-Id: I39ea087049b5eb96408e1225afafbac9875c9f7f
Signed-off-by: Vaisakh Murali <[email protected]>
  • Loading branch information
mvaisakh committed Mar 17, 2023
1 parent 6b8028b commit 3e18c65
Showing 1 changed file with 115 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ static void tp_geture_info_transform(struct gesture_info *gesture,
static void tp_gesture_handle(struct touchpanel_data *ts)
{
struct gesture_info gesture_info_temp;
unsigned int gesture_code;

if (((!ts->ts_ops->get_gesture_info) && (!ts->enable_point_auto_change))
|| ((!ts->ts_ops->get_gesture_info_auto) && ts->enable_point_auto_change)) {
Expand Down Expand Up @@ -466,40 +467,126 @@ static void tp_gesture_handle(struct touchpanel_data *ts)

#endif /* end of CONFIG_OPLUS_TP_APK*/

if (gesture_info_temp.gesture_type == DOU_TAP
&& CHK_BIT(ts->gesture_enable_indep, (1 << gesture_info_temp.gesture_type))) {
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
switch(gesture_info_temp.gesture_type) {
case DOU_TAP:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
input_report_key(ts->input_dev, KEY_WAKEUP, 1);
input_sync(ts->input_dev);
input_report_key(ts->input_dev, KEY_WAKEUP, 0);
input_sync(ts->input_dev);

} else if (gesture_info_temp.gesture_type != UNKOWN_GESTURE
&& gesture_info_temp.gesture_type != FINGER_PRINTDOWN
&& gesture_info_temp.gesture_type != FRINGER_PRINTUP
&& CHK_BIT(ts->gesture_enable_indep, (1 << gesture_info_temp.gesture_type))) {
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
gesture_code = KEY_WAKEUP;
break;
case FINGER_PRINTDOWN:
ts->fp_info.touch_state = 1;
ts->fp_info.x = gesture_info_temp.Point_start.x;
ts->fp_info.y = gesture_info_temp.Point_start.y;
TP_INFO(ts->tp_index, "screen off down : (%d, %d)\n", ts->fp_info.x, ts->fp_info.y);
touch_call_notifier_fp(&ts->fp_info);
break;
case FRINGER_PRINTUP:
ts->fp_info.touch_state = 0;
ts->fp_info.x = gesture_info_temp.Point_start.x;
ts->fp_info.y = gesture_info_temp.Point_start.y;
TP_INFO(ts->tp_index, "screen off up : (%d, %d)\n", ts->fp_info.x, ts->fp_info.y);
touch_call_notifier_fp(&ts->fp_info);
break;
case UP_VEE:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case DOWN_VEE:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case LEFT_VEE:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case RIGHT_VEE:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case CIRCLE_GESTURE:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case DOU_SWIP:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case LEFT2RIGHT_SWIP:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case RIGHT2LEFT_SWIP:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case UP2DOWN_SWIP:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case DOWN2UP_SWIP:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case M_GESTRUE:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case W_GESTURE:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case SINGLE_TAP:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
input_report_key(ts->input_dev, KEY_GESTURE_START + gesture_info_temp.gesture_type, 1);
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case HEART:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
case S_GESTURE:
tp_memcpy(&ts->gesture, sizeof(ts->gesture), \
&gesture_info_temp, sizeof(struct gesture_info), \
sizeof(struct gesture_info));
gesture_code = KEY_GESTURE_START + gesture_info_temp.gesture_type;
break;
default:
gesture_code = KEY_UNKNOWN;
break;
}
if (gesture_code != KEY_UNKNOWN) {
input_report_key(ts->input_dev, gesture_code, 1);
input_sync(ts->input_dev);
input_report_key(ts->input_dev, KEY_GESTURE_START + gesture_info_temp.gesture_type, 0);
input_report_key(ts->input_dev, gesture_code, 0);
input_sync(ts->input_dev);

} else if (gesture_info_temp.gesture_type == FINGER_PRINTDOWN) {
ts->fp_info.touch_state = 1;
ts->fp_info.x = gesture_info_temp.Point_start.x;
ts->fp_info.y = gesture_info_temp.Point_start.y;
TP_INFO(ts->tp_index, "screen off down : (%d, %d)\n", ts->fp_info.x, ts->fp_info.y);
touch_call_notifier_fp(&ts->fp_info);
} else if (gesture_info_temp.gesture_type == FRINGER_PRINTUP) {
ts->fp_info.touch_state = 0;
ts->fp_info.x = gesture_info_temp.Point_start.x;
ts->fp_info.y = gesture_info_temp.Point_start.y;
TP_INFO(ts->tp_index, "screen off up : (%d, %d)\n", ts->fp_info.x, ts->fp_info.y);
touch_call_notifier_fp(&ts->fp_info);
}
}

Expand Down

0 comments on commit 3e18c65

Please sign in to comment.