From 133c62941e1c2fdce6a783bee2c805248d7d716c Mon Sep 17 00:00:00 2001 From: tritegeist <55514816+tritegeist@users.noreply.github.com> Date: Sat, 2 Oct 2021 03:23:32 -0700 Subject: [PATCH] Input: Determine tipswitch value from pressure input for Magic Trackpad 2 (#436) * Determine tipswitch value from pressure input * Fix invalid references to pressure value Co-authored-by: Jordan Craven --- src/AmtPtpDeviceUsbKm/Interrupt.c | 2 +- src/AmtPtpDeviceUsbUm/InputInterrupt.c | 4 ++-- src/AmtPtpHidFilter/Input.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AmtPtpDeviceUsbKm/Interrupt.c b/src/AmtPtpDeviceUsbKm/Interrupt.c index 95407bb..27ae01d 100644 --- a/src/AmtPtpDeviceUsbKm/Interrupt.c +++ b/src/AmtPtpDeviceUsbKm/Interrupt.c @@ -209,7 +209,7 @@ AmtPtpEvtUsbInterruptPipeReadComplete( PtpReport.Contacts[i].ContactID = (UCHAR) i; PtpReport.Contacts[i].X = x; PtpReport.Contacts[i].Y = y; - PtpReport.Contacts[i].TipSwitch = (AmtRawToInteger(f->touch_major) << 1) >= 200 || (AmtRawToInteger(f->touch_minor) << 1) >= 150; + PtpReport.Contacts[i].TipSwitch = f->pressure != 0; PtpReport.Contacts[i].Confidence = (AmtRawToInteger(f->touch_minor) << 1) > 0; } } diff --git a/src/AmtPtpDeviceUsbUm/InputInterrupt.c b/src/AmtPtpDeviceUsbUm/InputInterrupt.c index 3ece692..24d1df9 100644 --- a/src/AmtPtpDeviceUsbUm/InputInterrupt.c +++ b/src/AmtPtpDeviceUsbUm/InputInterrupt.c @@ -335,7 +335,7 @@ AmtPtpServiceTouchInputInterrupt( PtpReport.Contacts[i].ContactID = (UCHAR) i; PtpReport.Contacts[i].X = x; PtpReport.Contacts[i].Y = y; - PtpReport.Contacts[i].TipSwitch = (AmtRawToInteger(f->touch_major) << 1) >= 200; + PtpReport.Contacts[i].TipSwitch = f->pressure != 0; PtpReport.Contacts[i].Confidence = (AmtRawToInteger(f->touch_minor) << 1) > 0; #ifdef INPUT_CONTENT_TRACE @@ -515,7 +515,7 @@ AmtPtpServiceTouchInputInterruptType5( PtpReport.Contacts[i].ContactID = f_type5->ContactIdentifier.Id; PtpReport.Contacts[i].X = (USHORT) x; PtpReport.Contacts[i].Y = (USHORT) y; - PtpReport.Contacts[i].TipSwitch = (AmtRawToInteger(f_type5->TouchMajor) << 1) > 0; + PtpReport.Contacts[i].TipSwitch = f_type5->Pressure != 0; // The Microsoft spec says reject any input larger than 25mm. This is not ideal // for Magic Trackpad 2 - so we raised the threshold a bit higher. diff --git a/src/AmtPtpHidFilter/Input.c b/src/AmtPtpHidFilter/Input.c index 1d5265e..9cbc4c0 100644 --- a/src/AmtPtpHidFilter/Input.c +++ b/src/AmtPtpHidFilter/Input.c @@ -210,7 +210,7 @@ PtpFilterInputRequestCompletionCallback( ptpOutputReport.Contacts[i].ContactID = f_type5->OrientationAndOrigin.ContactIdentifier.Id; ptpOutputReport.Contacts[i].X = (USHORT)x; ptpOutputReport.Contacts[i].Y = (USHORT)y; - ptpOutputReport.Contacts[i].TipSwitch = ((signed short) (f_type5->TouchMajor) << 1) > 0; + ptpOutputReport.Contacts[i].TipSwitch = f_type5->Pressure != 0; // The Microsoft spec says reject any input larger than 25mm. This is not ideal // for Magic Trackpad 2 - so we raised the threshold a bit higher. // Or maybe I used the wrong unit? IDK