Skip to content

Commit

Permalink
bug(switch): corrects unresponsive down/left analog to dpad translations
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertDaleSmith committed May 6, 2024
1 parent f08bc21 commit c00b353
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions src/devices/switch_pro.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef struct TU_ATTR_PACKED
switch_instance_t instances[CFG_TUH_HID];
uint8_t instance_count;
uint8_t instance_root;
bool is_pro;
} switch_device_t;

static switch_device_t switch_devices[MAX_DEVICES] = { 0 };
Expand Down Expand Up @@ -85,6 +86,7 @@ void unmount_switch_pro(uint8_t dev_addr, uint8_t instance)
switch_devices[dev_addr].instances[instance].imu_enabled = false;
switch_devices[dev_addr].instances[instance].rumble = 0;
switch_devices[dev_addr].instances[instance].player_led_set = 0xff;
switch_devices[dev_addr].is_pro = false;

if (switch_devices[dev_addr].instance_count > 1) {
switch_devices[dev_addr].instance_count--;
Expand Down Expand Up @@ -180,36 +182,36 @@ void input_report_switch_pro(uint8_t dev_addr, uint8_t instance, uint8_t const*
uint8_t rightX = 0;
uint8_t rightY = 0;

bool is_left_joycon = (!update_report.right_x && !update_report.right_y);
bool is_right_joycon = (!update_report.left_x && !update_report.left_y);
if (is_left_joycon) {
dpad_up = update_report.up;
dpad_right = update_report.right;
dpad_down = update_report.down;
dpad_left = update_report.left;
bttn_l1 = update_report.l;
bttn_s2 = false;

leftX = scale_analog_switch_pro(update_report.left_x + 127);
leftY = scale_analog_switch_pro(update_report.left_y - 127);
}
else if (is_right_joycon)
{
dpad_up = false; // (right_stick_y > (2048 + threshold));
dpad_right = false; // (right_stick_x > (2048 + threshold));
dpad_down = false; // (right_stick_y < (2048 - threshold));
dpad_left = false; // (right_stick_x < (2048 - threshold));
bttn_a1 = false;

rightX = scale_analog_switch_pro(update_report.right_x);
rightY = scale_analog_switch_pro(update_report.right_y + 127);
}
else
{
if (switch_devices[dev_addr].is_pro) {
leftX = scale_analog_switch_pro(update_report.left_x);
leftY = scale_analog_switch_pro(update_report.left_y);
rightX = scale_analog_switch_pro(update_report.right_x);
rightY = scale_analog_switch_pro(update_report.right_y);
} else {
bool is_left_joycon = (!update_report.right_x && !update_report.right_y);
bool is_right_joycon = (!update_report.left_x && !update_report.left_y);
if (is_left_joycon) {
dpad_up = update_report.up;
dpad_right = update_report.right;
dpad_down = update_report.down;
dpad_left = update_report.left;
bttn_l1 = update_report.l;
bttn_s2 = false;

leftX = scale_analog_switch_pro(update_report.left_x + 127);
leftY = scale_analog_switch_pro(update_report.left_y - 127);
}
else if (is_right_joycon)
{
dpad_up = false; // (right_stick_y > (2048 + threshold));
dpad_right = false; // (right_stick_x > (2048 + threshold));
dpad_down = false; // (right_stick_y < (2048 - threshold));
dpad_left = false; // (right_stick_x < (2048 - threshold));
bttn_a1 = false;

rightX = scale_analog_switch_pro(update_report.right_x);
rightY = scale_analog_switch_pro(update_report.right_y + 127);
}
}

buttons = (((dpad_up) ? 0x00 : USBR_BUTTON_DU) |
Expand Down Expand Up @@ -491,6 +493,10 @@ static inline bool init_switch_pro(uint8_t dev_addr, uint8_t instance)
if ((++switch_devices[dev_addr].instance_count) == 1) {
switch_devices[dev_addr].instance_root = instance; // save initial root instance to merge extras into
}

uint16_t vid, pid;
tuh_vid_pid_get(dev_addr, &vid, &pid);
if (pid == 0x2009) switch_devices[dev_addr].is_pro = true;
}

DeviceInterface switch_pro_interface = {
Expand Down

0 comments on commit c00b353

Please sign in to comment.