reform

MNT Reform: Open Source Portable Computer
Log (Feed) | Files | Refs (Tags) | README

commit d7d028c37bfd4a49f104dfcd2b6e0d8c47922e7d
parent e272f0c18e2e17568174dcea4f64bebad0e66b2f
Author: Valtteri Koskivuori <vkoskiv@gmail.com>
Date:   Wed, 18 Oct 2023 00:51:54 +0300

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.

Diffstat:
Mreform2-trackpad-fw/Mouse.c | 49+++++++++++++++++++++++++------------------------
1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/reform2-trackpad-fw/Mouse.c b/reform2-trackpad-fw/Mouse.c @@ -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;