Skip to content
Snippets Groups Projects
Unverified Commit d7d028c3 authored by Valtteri Koskivuori's avatar Valtteri Koskivuori
Browse files

trackpad-fw: Eliminate need to ditch initial 4 readings of each touch event

Instead of skipping first 4 readings, which incurs a slight latency
penalty at the start of a touch event, we clear lastx/lasty values as
touch events end, and check them before computing deltas. This way, at
the start of every touch event, we only lose one potential delta, and
then start tracking right away after that.
It should be noted, that manual delta computation is only used for
multi-finger gesture tracking at the moment, as the Azoteq sensor
provides smooth relative delta values for us in the case that only one
finger is active.
parent e272f0c1
No related branches found
No related tags found
No related merge requests found
......@@ -136,7 +136,6 @@ int16_t lastx2 = 0, lasty2 = 0;
unsigned int cycle = 0;
int wheeling = 0;
int touched_time = 0;
int touched_time2 = 0;
int last_num_fingers = 0;
int start_num_fingers = 0;
int report_lift = 0;
......@@ -211,11 +210,13 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
// touched?
if (sensor.num_fingers) {
touched_time++;
touched_time2++;
wheeling = 0;
if (sensor.num_fingers != last_num_fingers) {
touched_time2 = 0;
lastx2 = 0;
lasty2 = 0;
lastx = 0;
lasty = 0;
}
if (start_num_fingers < sensor.num_fingers) {
......@@ -232,30 +233,26 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
//MouseReport->Button |= 2;
}
// skip the first motion reading(s) immediately after
// touchdown because they often have skips
if (touched_time2 > 4) {
if (sensor.num_fingers >= 2) {
dx = ((float)sensor.fingers[1].abs_x + (float)sensor.fingers[0].abs_x) / 2.0f - ((float)lastx2 + (float)lastx) / 2.0f;
dy = ((float)sensor.fingers[1].abs_y + (float)sensor.fingers[0].abs_y) / 2.0f - ((float)lasty2 + (float)lasty) / 2.0f;
} else {
dx = (float)sensor.relative_x;
dy = (float)sensor.relative_y;
}
if (wheeling) {
// horizontal and vertical scrolling
MouseReport->Pan = dx;
MouseReport->Wheel = -dy;
} else {
// normal movement
MouseReport->X = dx;
MouseReport->Y = dy;
}
if (sensor.num_fingers >= 2) {
dx = lastx && lastx2 ? ((float)sensor.fingers[1].abs_x + (float)sensor.fingers[0].abs_x) / 2.0f - ((float)lastx2 + (float)lastx) / 2.0f : 0.0f;
dy = lasty && lasty2 ? ((float)sensor.fingers[1].abs_y + (float)sensor.fingers[0].abs_y) / 2.0f - ((float)lasty2 + (float)lasty) / 2.0f : 0.0f;
} else {
dx = (float)sensor.relative_x;
dy = (float)sensor.relative_y;
}
if (wheeling) {
// horizontal and vertical scrolling
MouseReport->Pan = dx / 4.0f;
MouseReport->Wheel = -dy / 4.0f;
} else {
// normal movement
MouseReport->X = dx;
MouseReport->Y = dy;
}
lastx = sensor.fingers[0].abs_x; lasty = sensor.fingers[0].abs_y;
lastx2 = sensor.fingers[1].abs_x; lasty2 = sensor.fingers[1].abs_y;
if (sensor.num_fingers > 1) lastx2 = sensor.fingers[1].abs_x; lasty2 = sensor.fingers[1].abs_y;
} else {
// no (more) touches
......@@ -274,6 +271,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
report_lift = 1;
dx = 0;
dy = 0;
lastx = 0;
lasty = 0;
lastx2 = 0;
lasty2 = 0;
}
last_num_fingers = sensor.num_fingers;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment