tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
elantech improvement.
Sorry once more. This's the last version for today :)
--
Xaionaro <xaionaro%ultanet.org@localhost>
UltaNetwork, EraTelecom, Rosnet.
+7 (906) 734 41 55
*** sys/dev/pckbport/elantech.c 2008-12-30 10:44:30.000000000 +0000
--- sys/dev/pckbport/elantech.c 2009-06-23 01:15:30.000000000 +0000
*************** __KERNEL_RCSID(0, "$NetBSD: elantech.c,v
*** 37,42 ****
--- 37,43 ----
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/bus.h>
+ #include <sys/time.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsmousevar.h>
*************** __KERNEL_RCSID(0, "$NetBSD: elantech.c,v
*** 51,59 ****
--- 52,66 ----
static int elantech_xy_unprecision_nodenum;
static int elantech_z_unprecision_nodenum;
+ static int elantech_1f_nodenum;
+ static int elantech_2f_nodenum;
+ static int elantech_double_timeout_nodenum;
static int elantech_xy_unprecision = 2;
static int elantech_z_unprecision = 3;
+ static int elantech_1f = 1;
+ static int elantech_2f = 3;
+ static int elantech_double_timeout = 200;
struct elantech_packet {
int16_t ep_x, ep_y, ep_z;
*************** pms_sysctl_elantech_verify(SYSCTLFN_ARGS
*** 75,84 ****
return error;
if (node.sysctl_num == elantech_xy_unprecision_nodenum ||
! node.sysctl_num == elantech_z_unprecision_nodenum) {
if (t < 0 || t > 7)
return EINVAL;
} else
return EINVAL;
*(int *)rnode->sysctl_data = t;
--- 82,97 ----
return error;
if (node.sysctl_num == elantech_xy_unprecision_nodenum ||
! node.sysctl_num == elantech_z_unprecision_nodenum ||
! node.sysctl_num == elantech_1f_nodenum ||
! node.sysctl_num == elantech_2f_nodenum) {
if (t < 0 || t > 7)
return EINVAL;
} else
+ if (node.sysctl_num == elantech_double_timeout_nodenum) {
+ if (t < 1 || t > 120000)
+ return EINVAL;
+ } else
return EINVAL;
*(int *)rnode->sysctl_data = t;
*************** pms_sysctl_elantech(struct sysctllog **c
*** 128,133 ****
--- 141,183 ----
goto err;
elantech_z_unprecision_nodenum = node->sysctl_num;
+
+ if ((rc = sysctl_createv(clog, 0, NULL, &node,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "finger1",
+ SYSCTL_DESCR("Mouse button number to emulate when 1 finger"),
+ pms_sysctl_elantech_verify, 0,
+ &elantech_1f,
+ 0, CTL_HW, root_num, CTL_CREATE,
+ CTL_EOL)) != 0)
+ goto err;
+
+ elantech_1f_nodenum = node->sysctl_num;
+
+ if ((rc = sysctl_createv(clog, 0, NULL, &node,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "finger2",
+ SYSCTL_DESCR("Mouse button number to emulate when 2 fingers"),
+ pms_sysctl_elantech_verify, 0,
+ &elantech_2f,
+ 0, CTL_HW, root_num, CTL_CREATE,
+ CTL_EOL)) != 0)
+ goto err;
+
+ elantech_2f_nodenum = node->sysctl_num;
+
+ if ((rc = sysctl_createv(clog, 0, NULL, &node,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "double_timeout",
+ SYSCTL_DESCR("Timeout for double-click (ms)"),
+ pms_sysctl_elantech_verify, 0,
+ &elantech_double_timeout,
+ 0, CTL_HW, root_num, CTL_CREATE,
+ CTL_EOL)) != 0)
+ goto err;
+
+ elantech_double_timeout_nodenum = node->sysctl_num;
+
return;
err:
*************** pms_elantech_init(struct pms_softc *psc)
*** 248,257 ****
static void
pms_elantech_input(void *opaque, int data)
{
struct pms_softc *psc = opaque;
struct elantech_softc *sc = &psc->u.elantech;
struct elantech_packet ep;
! int s;
if (!psc->sc_enabled)
return;
--- 298,310 ----
static void
pms_elantech_input(void *opaque, int data)
{
+ static int moved=0, lf=0, fp=0, dbl=0;
+ static struct timeval otv;
struct pms_softc *psc = opaque;
struct elantech_softc *sc = &psc->u.elantech;
struct elantech_packet ep;
! struct timeval tv;
! int s, dx, dy, dz;
if (!psc->sc_enabled)
return;
*************** pms_elantech_input(void *opaque, int dat
*** 268,281 ****
return;
psc->inputstate = 0;
ep.ep_nfingers = (psc->packet[0] & 0xc0) >> 6;
! ep.ep_buttons = 0;
! ep.ep_buttons = psc->packet[0] & 1; /* left button */
ep.ep_buttons |= (psc->packet[0] & 2) << 1; /* right button */
if (ep.ep_nfingers == 0 || ep.ep_nfingers != sc->last_nfingers)
sc->initializing = true;
switch (ep.ep_nfingers) {
case 0:
--- 321,386 ----
return;
psc->inputstate = 0;
+ dx=dy=dz=0;
ep.ep_nfingers = (psc->packet[0] & 0xc0) >> 6;
! ep.ep_buttons = psc->packet[0] & 1; /* left button */
ep.ep_buttons |= (psc->packet[0] & 2) << 1; /* right button */
if (ep.ep_nfingers == 0 || ep.ep_nfingers != sc->last_nfingers)
sc->initializing = true;
+
+ if((!ep.ep_nfingers) && sc->last_nfingers) {
+ lf=0;
+ if(!moved) {
+ fp=0;
+ switch(sc->last_nfingers) {
+ case 1:
+ fp=elantech_1f;
+ break;
+ case 2:
+ fp=elantech_2f;
+ break;
+ default:
+ fp=0;
+ }
+ switch(fp) {
+ case 1:
+ ep.ep_buttons |= 1;
+ break;
+ case 2:
+ ep.ep_buttons |= 4;
+ break;
+ case 3:
+ ep.ep_buttons |= 2;
+ break;
+ }
+ lf=sc->last_nfingers;
+ getmicrouptime(&otv);
+ }
+ moved=0;
+ dbl=0;
+ } else
+ if(lf)
+ if(!sc->initializing) {
+ getmicrouptime(&tv);
+ if(!((tv.tv_sec - otv.tv_sec) * 1000 + (tv.tv_usec -
otv.tv_usec) % 1000 >= elantech_double_timeout))
+ if(lf == ep.ep_nfingers)
+ switch(fp) {
+ case 1:
+ dbl |= 1;
+ break;
+ case 2:
+ dbl |= 4;
+ break;
+ case 3:
+ dbl |= 2;
+ break;
+ }
+ lf=0;
+ }
+
+ ep.ep_buttons |= dbl;
switch (ep.ep_nfingers) {
case 0:
*************** pms_elantech_input(void *opaque, int dat
*** 283,288 ****
--- 388,395 ----
case 1:
ep.ep_x = ((int16_t)psc->packet[1] << 8) | psc->packet[2];
ep.ep_y = ((int16_t)psc->packet[4] << 8) | psc->packet[5];
+ dx = (ep.ep_x - sc->last_x) >> elantech_xy_unprecision;
+ dy = (ep.ep_y - sc->last_y) >> elantech_xy_unprecision;
aprint_debug_dev(psc->sc_dev,
"%d finger detected in elantech mode:\n", ep.ep_nfingers);
*************** pms_elantech_input(void *opaque, int dat
*** 295,318 ****
s = spltty();
wsmouse_input(psc->sc_wsmousedev, ep.ep_buttons,
! sc->initializing ?
! 0 : (ep.ep_x - sc->last_x) >> elantech_xy_unprecision,
! sc->initializing ?
! 0 : (ep.ep_y - sc->last_y) >> elantech_xy_unprecision,
! 0, 0,
WSMOUSE_INPUT_DELTA);
splx(s);
! if (sc->initializing == true ||
! ((ep.ep_x - sc->last_x) >> elantech_xy_unprecision) != 0)
sc->last_x = ep.ep_x;
- if (sc->initializing == true ||
- ((ep.ep_y - sc->last_y) >> elantech_xy_unprecision) != 0)
sc->last_y = ep.ep_y;
break;
case 2:
/* emulate z axis */
ep.ep_z = psc->packet[2];
aprint_debug_dev(psc->sc_dev,
"2 fingers detected in elantech mode:\n");
aprint_debug_dev(psc->sc_dev,
--- 402,428 ----
s = spltty();
wsmouse_input(psc->sc_wsmousedev, ep.ep_buttons,
! sc->initializing ? 0 : dx,
! sc->initializing ? 0 : dy,
! 0,
! 0,
WSMOUSE_INPUT_DELTA);
splx(s);
! if (sc->initializing == true) {
sc->last_x = ep.ep_x;
sc->last_y = ep.ep_y;
+ } else {
+ if(dx)
+ sc->last_x = ep.ep_x;
+ if(dy)
+ sc->last_y = ep.ep_y;
+ }
break;
case 2:
/* emulate z axis */
ep.ep_z = psc->packet[2];
+ dz = (sc->last_z - ep.ep_z) >> elantech_z_unprecision;
aprint_debug_dev(psc->sc_dev,
"2 fingers detected in elantech mode:\n");
aprint_debug_dev(psc->sc_dev,
*************** pms_elantech_input(void *opaque, int dat
*** 321,336 ****
psc->packet[3], psc->packet[4], psc->packet[5]);
s = spltty();
! wsmouse_input(psc->sc_wsmousedev, 0,
! 0, 0,
! sc->initializing ?
! 0 : (sc->last_z - ep.ep_z) >> elantech_z_unprecision,
0,
WSMOUSE_INPUT_DELTA);
splx(s);
! if (sc->initializing == true ||
! ((sc->last_z - ep.ep_z) >> elantech_z_unprecision) != 0)
sc->last_z = ep.ep_z;
break;
default:
--- 431,445 ----
psc->packet[3], psc->packet[4], psc->packet[5]);
s = spltty();
! wsmouse_input(psc->sc_wsmousedev, ep.ep_buttons,
! 0,
! 0,
! sc->initializing ? 0 : dz,
0,
WSMOUSE_INPUT_DELTA);
splx(s);
! if (sc->initializing == true || dz)
sc->last_z = ep.ep_z;
break;
default:
*************** pms_elantech_input(void *opaque, int dat
*** 338,345 ****
--- 447,459 ----
return;
}
+ if(!sc->initializing)
+ if(dx || dy || dz)
+ moved=1;
+
if (ep.ep_nfingers > 0)
sc->initializing = false;
+
sc->last_nfingers = ep.ep_nfingers;
}
Home |
Main Index |
Thread Index |
Old Index