nusb/kb: revert multitouch, breaks some mice...

This commit is contained in:
cinap_lenrek 2018-11-13 03:34:19 +01:00
parent b5ea1cc4be
commit 8a7f897b30

View file

@ -46,16 +46,8 @@ struct Hiddev
}; };
typedef struct Hidreport Hidreport; typedef struct Hidreport Hidreport;
typedef struct Hidslot Hidslot; struct Hidreport
struct Hidslot
{ {
int valid;
int usage;
int oor;
int id;
int abs; /* for xyz */
int x; int x;
int y; int y;
int z; int z;
@ -63,14 +55,8 @@ struct Hidslot
int b; int b;
int m; int m;
int w; int absz;
int h; u8int abs;
};
struct Hidreport
{
int ns;
Hidslot s[16];
int nk; int nk;
uchar k[64]; uchar k[64];
@ -236,14 +222,7 @@ repparse1(uchar *d, uchar *e, int g[], int l[], int c,
switch(t){ switch(t){
case Collection: case Collection:
memset(l, 0, Nl*sizeof(l[0])); memset(l, 0, Nl*sizeof(l[0]));
i = l[Nu] | g[UsagPg]<<16;
l[Usage] = i;
(*f)(t, v, g, l, c, a);
d = repparse1(d, e, g, l, v, f, a); d = repparse1(d, e, g, l, v, f, a);
l[Usage] = i;
(*f)(CollectionEnd, v, g, l, c, a);
continue; continue;
case CollectionEnd: case CollectionEnd:
return d; return d;
@ -516,42 +495,17 @@ static void
hidparse(int t, int f, int g[], int l[], int, void *a) hidparse(int t, int f, int g[], int l[], int, void *a)
{ {
Hidreport *p = a; Hidreport *p = a;
Hidslot *s = &p->s[p->ns];
int v, m; int v, m;
switch(t){ if(t != Input)
case Input: return;
if(g[RepId] != 0){ if(g[RepId] != 0){
if(p->p[0] != g[RepId]){ if(p->p[0] != g[RepId]){
p->o = 0; p->o = 0;
return; return;
}
if(p->o < 8)
p->o = 8; /* skip report id byte */
} }
break; if(p->o < 8)
case Collection: p->o = 8; /* skip report id byte */
if(g[RepId] != 0 && p->p[0] != g[RepId])
return;
memset(s, 0, sizeof(*s));
s->usage = l[Usage];
s->id = p->ns+1;
return;
case CollectionEnd:
if(g[RepId] != 0 && p->p[0] != g[RepId])
return;
if(l[Usage] != s->usage || !s->valid)
return;
/* if out of range or touchscreen finger not touching, ignore the slot */
if(s->oor || s->usage == 0x0D0022 && s->b == 0)
return;
if(p->ns < nelem(p->s))
p->ns++;
return;
default:
return;
} }
v = getbits(p->p, p->e, g[RepSize], p->o); v = getbits(p->p, p->e, g[RepSize], p->o);
p->o += g[RepSize]; p->o += g[RepSize];
@ -586,9 +540,6 @@ hidparse(int t, int f, int g[], int l[], int, void *a)
v -= (g[PhysMax] * (g[LogiMax] - g[LogiMin])) / (g[PhysMax] - g[PhysMin]); v -= (g[PhysMax] * (g[LogiMax] - g[LogiMin])) / (g[PhysMax] - g[PhysMin]);
switch(l[Usage]){ switch(l[Usage]){
default:
return;
case 0x090001: case 0x090001:
case 0x090002: case 0x090002:
case 0x090003: case 0x090003:
@ -598,59 +549,35 @@ hidparse(int t, int f, int g[], int l[], int, void *a)
case 0x090007: case 0x090007:
case 0x090008: case 0x090008:
m = 1<<(l[Usage] - 0x090001); m = 1<<(l[Usage] - 0x090001);
Button: p->m |= m;
s->m |= m; p->b &= ~m;
s->b &= ~m;
if(v != 0) if(v != 0)
s->b |= m; p->b |= m;
break; break;
case 0x0D0032: /* In Range */
s->oor = !v;
break;
case 0x0D0042: /* Tip Switch */
m = 1;
goto Button;
case 0x0D0044: /* Barrel Switch */
m = 2;
goto Button;
case 0x0D0045: /* Eraser */
m = 4;
goto Button;
case 0x0D0048: /* Contact width */
s->w = v;
break;
case 0x0D0049: /* Contact height */
s->h = v;
break;
case 0x0D0051: /* Conteact identifier */
s->id = v;
break;
case 0x010030: case 0x010030:
if((f & (Fabs|Frel)) == Fabs){ if((f & (Fabs|Frel)) == Fabs){
v = ((vlong)(v - g[LogiMin]) << 31) / (g[LogiMax] - g[LogiMin]); v = ((vlong)(v - g[LogiMin]) << 31) / (g[LogiMax] - g[LogiMin]);
s->abs |= 1; p->abs = 1;
} }
s->x = v; p->x = v;
break; break;
case 0x010031: case 0x010031:
if((f & (Fabs|Frel)) == Fabs){ if((f & (Fabs|Frel)) == Fabs){
v = ((vlong)(v - g[LogiMin]) << 31) / (g[LogiMax] - g[LogiMin]); v = ((vlong)(v - g[LogiMin]) << 31) / (g[LogiMax] - g[LogiMin]);
s->abs |= 2; p->abs = 1;
} }
s->y = v; p->y = v;
break; break;
case 0x010038: case 0x010038:
if((f & (Fabs|Frel)) == Fabs) if((f & (Fabs|Frel)) == Fabs){
s->abs |= 4; p->z = v - p->absz;
s->z = v; p->absz = v;
} else {
p->z = v;
p->absz += v;
}
break; break;
} }
s->valid = 1;
} }
} }
@ -673,10 +600,8 @@ readerproc(void* a)
{ {
char err[ERRMAX], mbuf[80]; char err[ERRMAX], mbuf[80];
uchar lastk[64], uk, dk; uchar lastk[64], uk, dk;
int i, c, nerrs, lastb, nlastk; int i, c, b, nerrs, lastb, nlastk;
int abs, x, y, z, b;
Hidreport p; Hidreport p;
Hidslot lasts[nelem(p.s)], *s, *l;
Hiddev* f = a; Hiddev* f = a;
threadsetname("readerproc %s", f->ep->dir); threadsetname("readerproc %s", f->ep->dir);
@ -709,10 +634,9 @@ readerproc(void* a)
p.o = 0; p.o = 0;
p.e = p.p + c; p.e = p.p + c;
p.ns = 0; p.abs = 0;
repparse(f->rep, f->rep+f->nrep, hidparse, &p); repparse(f->rep, f->rep+f->nrep, hidparse, &p);
/* handle keyboard report */
if(p.nk != 0 || nlastk != 0){ if(p.nk != 0 || nlastk != 0){
if(debug){ if(debug){
fprint(2, "kbd: "); fprint(2, "kbd: ");
@ -754,79 +678,32 @@ readerproc(void* a)
p.nk = 0; p.nk = 0;
} }
/* handle mouse/touchpad */ /* map mouse buttons */
if(p.ns == 0) b = p.b & 1;
continue; if(p.b & (4|8))
b |= 2;
if(p.b & 2)
b |= 4;
if(p.z != 0)
b |= (p.z > 0) ? 8 : 16;
/* combine all the slots */ if(p.abs || p.x != 0 || p.y != 0 || p.z != 0 || b != lastb){
abs = x = y = b = 0; if(debug)
for(i=0; i<p.ns; i++){ if(p.abs)
s = &p.s[i]; fprint(2, "ptr: b=%x m=%x x=%f y=%f z=%d\n", p.b, p.m, (uint)p.x / 2147483648.0, (uint)p.y / 2147483648.0, p.z);
/* find the previous slot corresponding to same id */
for(l = lasts; l < &lasts[nelem(p.s)]; l++){
if(l->valid && l->usage == s->usage && l->id == s->id){
l->valid = 0; /* no duplicates */
break;
}
}
if(l == &lasts[nelem(p.s)])
l = s;
/* convet absolute z to relative */
z = s->z;
if(s->abs & 4)
z -= l->z;
if(debug) {
if((s->abs & 3) == 3)
fprint(2, "ptr[%d]: id=%d b=%x m=%x x=%f y=%f z=%d\n",
i, s->id, s->b, s->m,
(uint)s->x / 2147483648.0, (uint)s->y / 2147483648.0, z);
else else
fprint(2, "ptr[%d]: id=%d b=%x m=%x x=%d y=%d z=%d\n", fprint(2, "ptr: b=%x m=%x x=%d y=%d z=%d\n", p.b, p.m, p.x, p.y, p.z);
i, s->id, s->b, s->m,
s->x, s->y, z);
}
/* map to mouse buttons */
b |= s->b & 1;
if(s->b & (4|8))
b |= 2;
if(s->b & 2)
b |= 4;
if(z != 0)
b |= z > 0 ? 8 : 16;
/* X/Y are absolute? */
if((s->abs & 3) == 3){
/* ignore absolute position when nothing changed */
if(s->abs == l->abs && s->x == l->x && s->y == l->y && s->b == l->b)
continue;
abs = 1;
} else {
/* both X/Y have to be relative then */
if((s->abs & 3) != 0)
continue;
/* ignore relative position when we have absolute one */
if(abs)
continue;
}
x = s->x;
y = s->y;
}
memmove(lasts, p.s, sizeof(p.s));
if(abs || x != 0 || y != 0 || b != lastb){
lastb = b;
if(f->minfd < 0){ if(f->minfd < 0){
f->minfd = open("/dev/mousein", OWRITE); f->minfd = open("/dev/mousein", OWRITE);
if(f->minfd < 0) if(f->minfd < 0)
hdfatal(f, "open /dev/mousein"); hdfatal(f, "open /dev/mousein");
} }
seprint(mbuf, mbuf+sizeof(mbuf), "%c%11d %11d %11d", "ma"[abs], x, y, b);
seprint(mbuf, mbuf+sizeof(mbuf), "%c%11d %11d %11d", "ma"[p.abs], p.x, p.y, b);
write(f->minfd, mbuf, strlen(mbuf)); write(f->minfd, mbuf, strlen(mbuf));
lastb = b;
} }
} }
} }