From 9413d68976c6f076c19acdd54c505ce5ccddf452 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 2 May 2020 22:14:53 +0300 Subject: [PATCH] Add support for wired Switch Pro Controller --- JoyKit/ControllerConfiguration.inc | 40 ++++++++++++++++++++++++++++++ JoyKit/JOYAxes2D.m | 4 +-- JoyKit/JOYController.m | 4 +++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/JoyKit/ControllerConfiguration.inc b/JoyKit/ControllerConfiguration.inc index 35a6cff..b7dbfe8 100644 --- a/JoyKit/ControllerConfiguration.inc +++ b/JoyKit/ControllerConfiguration.inc @@ -367,5 +367,45 @@ hacksByName = @{ AXES2D(1): @(JOYAxes2DUsageLeftStick), AXES2D(4): @(JOYAxes2DUsageRightStick), }, + + JOYCustomReports: @{ + @(0x30): @[ + + // For USB mode, which uses the wrong report descriptor + + @{@"reportID": @(1), @"size":@1, @"offset":@16, @"usagePage":@(kHIDPage_Button), @"usage":@3}, + @{@"reportID": @(1), @"size":@1, @"offset":@17, @"usagePage":@(kHIDPage_Button), @"usage":@4}, + @{@"reportID": @(1), @"size":@1, @"offset":@18, @"usagePage":@(kHIDPage_Button), @"usage":@1}, + @{@"reportID": @(1), @"size":@1, @"offset":@19, @"usagePage":@(kHIDPage_Button), @"usage":@2}, + + // SR and SL not used on the Pro Controller + @{@"reportID": @(1), @"size":@1, @"offset":@22, @"usagePage":@(kHIDPage_Button), @"usage":@6}, + @{@"reportID": @(1), @"size":@1, @"offset":@23, @"usagePage":@(kHIDPage_Button), @"usage":@8}, + + @{@"reportID": @(1), @"size":@1, @"offset":@24, @"usagePage":@(kHIDPage_Button), @"usage":@9}, + @{@"reportID": @(1), @"size":@1, @"offset":@25, @"usagePage":@(kHIDPage_Button), @"usage":@10}, + @{@"reportID": @(1), @"size":@1, @"offset":@26, @"usagePage":@(kHIDPage_Button), @"usage":@12}, + @{@"reportID": @(1), @"size":@1, @"offset":@27, @"usagePage":@(kHIDPage_Button), @"usage":@11}, + + @{@"reportID": @(1), @"size":@1, @"offset":@28, @"usagePage":@(kHIDPage_Button), @"usage":@13}, + @{@"reportID": @(1), @"size":@1, @"offset":@29, @"usagePage":@(kHIDPage_Button), @"usage":@14}, + + @{@"reportID": @(1), @"size":@1, @"offset":@32, @"usagePage":@(kHIDPage_GenericDesktop), @"usage":@(kHIDUsage_GD_DPadDown)}, + @{@"reportID": @(1), @"size":@1, @"offset":@33, @"usagePage":@(kHIDPage_GenericDesktop), @"usage":@(kHIDUsage_GD_DPadUp)}, + @{@"reportID": @(1), @"size":@1, @"offset":@34, @"usagePage":@(kHIDPage_GenericDesktop), @"usage":@(kHIDUsage_GD_DPadRight)}, + @{@"reportID": @(1), @"size":@1, @"offset":@35, @"usagePage":@(kHIDPage_GenericDesktop), @"usage":@(kHIDUsage_GD_DPadLeft)}, + + // SR and SL not used on the Pro Controller + @{@"reportID": @(1), @"size":@1, @"offset":@38, @"usagePage":@(kHIDPage_Button), @"usage":@5}, + @{@"reportID": @(1), @"size":@1, @"offset":@39, @"usagePage":@(kHIDPage_Button), @"usage":@7}, + + /* Sticks */ + @{@"reportID": @(1), @"size":@12, @"offset":@40, @"usagePage":@(kHIDPage_GenericDesktop), @"usage":@(kHIDUsage_GD_X), @"min": @0, @"max": @0xFFF}, + @{@"reportID": @(1), @"size":@12, @"offset":@52, @"usagePage":@(kHIDPage_GenericDesktop), @"usage":@(kHIDUsage_GD_Y), @"min": @0xFFF, @"max": @0}, + + @{@"reportID": @(1), @"size":@12, @"offset":@64, @"usagePage":@(kHIDPage_GenericDesktop), @"usage":@(kHIDUsage_GD_Rx), @"min": @0, @"max": @0xFFF}, + @{@"reportID": @(1), @"size":@12, @"offset":@76, @"usagePage":@(kHIDPage_GenericDesktop), @"usage":@(kHIDUsage_GD_Ry), @"min": @0xFFF, @"max": @0}, + ], + }, }, }; diff --git a/JoyKit/JOYAxes2D.m b/JoyKit/JOYAxes2D.m index 624ccef..272d34f 100644 --- a/JoyKit/JOYAxes2D.m +++ b/JoyKit/JOYAxes2D.m @@ -57,8 +57,8 @@ uint16_t usage = element1.usage; _usage = JOYAxes2DUsageGeneric0 + usage - kHIDUsage_GD_X + 1; } - initialX = [_element1 value]; - initialY = [_element2 value]; + initialX = 0; + initialY = 0; minX = element1.max; minY = element2.max; maxX = element1.min; diff --git a/JoyKit/JOYController.m b/JoyKit/JOYController.m index 131441c..beb61a3 100644 --- a/JoyKit/JOYController.m +++ b/JoyKit/JOYController.m @@ -445,6 +445,10 @@ typedef struct __attribute__((packed)) { [self sendReport:hacks[JOYActivationReport]]; } + if (_isSwitch) { + [self sendReport:[NSData dataWithBytes:(uint8_t[]){0x80, 0x04} length:2]]; + [self sendReport:[NSData dataWithBytes:(uint8_t[]){0x80, 0x02} length:2]]; + } return self; }