/* Doubletap2wake main function */
static void detect_doubletap2wake(int x, int y, bool st)
{
        bool single_touch = st;
#if DT2W_DEBUG
        pr_info(LOGTAG"x,y(%4d,%4d) single:%s\n",
                x, y, (single_touch) ? "true" : "false");
#endif
	if ((single_touch) && (dt2w_switch > 0) && (exec_count) && (touch_cnt)) {
		touch_cnt = false;
		if (touch_nr == 0) {
			new_touch(x, y);
		} else if (touch_nr == 1) {
			if ((calc_feather(x, x_pre) < DT2W_FEATHER) &&
			    (calc_feather(y, y_pre) < DT2W_FEATHER) &&
			    ((ktime_to_ms(ktime_get())-tap_time_pre) < DT2W_TIME))
				touch_nr++;
			else {
				doubletap2wake_reset();
				new_touch(x, y);
			}
		} else {
			doubletap2wake_reset();
			new_touch(x, y);
		}
		if ((touch_nr > 1)) {
			pr_info(LOGTAG"ON\n");
			exec_count = false;
			doubletap2wake_pwrtrigger();
			doubletap2wake_reset();
		}
	}
}
/* Doubletap2wake main function */
static void detect_doubletap2wake(int x, int y, bool st)
{
        bool single_touch = st;
#if DT2W_DEBUG
        pr_info(LOGTAG"x,y(%4d,%4d) tap_time_pre:%llu\n",
                x, y, tap_time_pre);
#endif
	if (x < 100 || x > 980)
        	return;

	if (dt2w_switch < 2 && y < 1000)
        	return;

	if ((single_touch) && (dt2w_switch > 0) && (exec_count) && (touch_cnt)) {
		touch_cnt = false;
		if (touch_nr == 0) {
			new_touch(x, y);
		} else if (touch_nr == 1) {
			if ((calc_feather(x, x_pre) < DT2W_FEATHER) &&
			    (calc_feather(y, y_pre) < DT2W_FEATHER) &&
			    ((jiffies-tap_time_pre) < DT2W_TIME))
				touch_nr++;
			else {
				doubletap2wake_reset();
				new_touch(x, y);
			}
		} else {
			doubletap2wake_reset();
			new_touch(x, y);
		}
		if ((touch_nr > 1)) {
			pr_info(LOGTAG"double tap\n");
			exec_count = false;
			set_vibrate(vib_strength);
			if (gestures_switch) {
				report_gesture(5);
			} else {
				doubletap2wake_pwrtrigger();
			}
			doubletap2wake_reset();
		}
	}
}
/* Doubletap2wake main function */
static void detect_doubletap2wake(int x, int y)
{
#if DT2W_DEBUG
        pr_info(LOGTAG"x,y(%4d,%4d)\n", x, y);
#endif

	if (!scr_suspended)
		return;

	if ((!is_touching) && (!is_screen_on)) {
		is_touching = true;

		// Make enable to set touch counts (Max : 10) - by jollaman999
		if (touch_nr == 0) {
			new_touch(x, y);
			// dt2w: 'touch_nr++' when 'msm_pm_enter' called - by jollaman999
			if (dt2w_msm_pm_enter)
				touch_nr++;
		// Make enable to set touch counts (Max : 10) - by jollaman999
		} else if (touch_nr >= 1 && touch_nr <= dt2w_switch) {
			if (((calc_feather(x, x_pre) < DT2W_FEATHER) || (calc_feather(y, y_pre) < DT2W_FEATHER))
			    // Make enable to set touch counts (Max : 10) - by jollaman999
			    && ((ktime_to_ms(ktime_get()) - tap_time_pre) < (DT2W_TIME/2*(dt2w_switch+1)))) {
				touch_nr++;
			} else {
				doubletap2wake_reset();
				new_touch(x, y);
			}
		} else {
			doubletap2wake_reset();
			new_touch(x, y);
		}
		// Make enable to set touch counts (Max : 10) - by jollaman999
		if ((touch_nr > dt2w_switch)) {
			pr_info(LOGTAG"ON\n");
			is_screen_on = true;
			doubletap2wake_pwrtrigger();
			doubletap2wake_reset();
		}
	}
}