Skip to content

Commit

Permalink
Test multiple multitouch IDs to support MacBook Pro 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
niw committed Jul 27, 2018
1 parent 6f96a27 commit 500ecdf
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions HapticKey/Classes/HTKMultitouchActuator.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

@interface HTKMultitouchActuator ()

@property (nonatomic) UInt64 lastKnownMultitouchDeviceMultitouchID;

@end

@implementation HTKMultitouchActuator
Expand Down Expand Up @@ -62,25 +64,49 @@ - (BOOL)actuateActuationID:(SInt32)actuationID unknown1:(UInt32)unknown1 unknown
return result;
}

// By using IORegistoryExploere, which is in Additional Tools for Xcode,
// By using IORegistryExplorer, which is in Additional Tools for Xcode,
// Find `AppleMultitouchDevice` which has `Multitouch ID`.
// Probably this is a fixed value.
static const UInt64 kAppleMultitouchDeviceMultitouchID = 0x200000001000000;
// Probably these are fixed value.
static const UInt64 kKnownAppleMultitouchDeviceMultitouchIDs[] = {
// For MacBook Pro 2016, 2017
0x200000001000000,
// For MacBook Pro 2018
0x300000080500000
};

- (void)_htk_main_openActuator
{
if (_actuatorRef) {
return;
}

const CFTypeRef actuatorRef = MTActuatorCreateFromDeviceID(kAppleMultitouchDeviceMultitouchID);
if (!actuatorRef) {
os_log_error(OS_LOG_DEFAULT, "Fail to MTActuatorCreateFromDeviceID");
return;
if (self.lastKnownMultitouchDeviceMultitouchID) {
const CFTypeRef actuatorRef = MTActuatorCreateFromDeviceID(self.lastKnownMultitouchDeviceMultitouchID);
if (!actuatorRef) {
os_log_error(OS_LOG_DEFAULT, "Fail to MTActuatorCreateFromDeviceID: 0x%llx", self.lastKnownMultitouchDeviceMultitouchID);
return;
}
_actuatorRef = actuatorRef;
} else {
const size_t count = sizeof(kKnownAppleMultitouchDeviceMultitouchIDs) / sizeof(UInt64);
for (size_t index = 0; index < count; index++) {
const UInt64 multitouchDeviceMultitouchID = kKnownAppleMultitouchDeviceMultitouchIDs[index];
const CFTypeRef actuatorRef = MTActuatorCreateFromDeviceID(multitouchDeviceMultitouchID);
if (actuatorRef) {
os_log_info(OS_LOG_DEFAULT, "Use MTActuatorCreateFromDeviceID: 0x%llx", multitouchDeviceMultitouchID);
_actuatorRef = actuatorRef;
self.lastKnownMultitouchDeviceMultitouchID = multitouchDeviceMultitouchID;
break;
}
os_log_info(OS_LOG_DEFAULT, "Fail to test MTActuatorCreateFromDeviceID: 0x%llx", multitouchDeviceMultitouchID);
}
if (!_actuatorRef) {
os_log_info(OS_LOG_DEFAULT, "Fail to MTActuatorCreateFromDeviceID");
return;
}
}
_actuatorRef = actuatorRef;

const IOReturn error = MTActuatorOpen(actuatorRef);
const IOReturn error = MTActuatorOpen(_actuatorRef);
if (error != kIOReturnSuccess) {
os_log_error(OS_LOG_DEFAULT, "Fail to MTActuatorOpen: %p error: 0x%x", _actuatorRef, error);
CFRelease(_actuatorRef);
Expand Down

0 comments on commit 500ecdf

Please sign in to comment.