Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Xbox controllers in Bluetooth mode on macOS (3.x) #51117

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions platform/osx/joypad_osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ void joypad::add_hid_element(IOHIDElementRef p_element) {
switch (usage) {
case kHIDUsage_Sim_Rudder:
case kHIDUsage_Sim_Throttle:
case kHIDUsage_Sim_Accelerator:
case kHIDUsage_Sim_Brake:
if (!has_element(cookie, &axis_elements)) {
list = &axis_elements;
}
Expand Down Expand Up @@ -339,6 +341,13 @@ bool JoypadOSX::configure_joypad(IOHIDDeviceRef p_device_ref, joypad *p_joy) {
p_joy->add_hid_elements(array);
CFRelease(array);
}
// Xbox controller hat values start at 1 rather than 0.
p_joy->offset_hat = vendor == 0x45e &&
(product_id == 0x0b05 ||
product_id == 0x02e0 ||
product_id == 0x02fd ||
product_id == 0x0b13);

return true;
}

Expand Down Expand Up @@ -395,13 +404,16 @@ bool joypad::check_ff_features() {
return false;
}

static int process_hat_value(int p_min, int p_max, int p_value) {
static int process_hat_value(int p_min, int p_max, int p_value, bool p_offset_hat) {
int range = (p_max - p_min + 1);
int value = p_value - p_min;
int hat_value = InputDefault::HAT_MASK_CENTER;
if (range == 4) {
value *= 2;
}
if (p_offset_hat) {
value -= 1;
}

switch (value) {
case 0:
Expand Down Expand Up @@ -475,7 +487,7 @@ void JoypadOSX::process_joypads() {
for (int j = 0; j < joy.hat_elements.size(); j++) {
rec_element &elem = joy.hat_elements.write[j];
int value = joy.get_hid_element_state(&elem);
int hat_value = process_hat_value(elem.min, elem.max, value);
int hat_value = process_hat_value(elem.min, elem.max, value, joy.offset_hat);
input->joy_hat(joy.id, hat_value);
}

Expand Down
3 changes: 2 additions & 1 deletion platform/osx/joypad_osx.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ struct joypad {
Vector<rec_element> button_elements;
Vector<rec_element> hat_elements;

int id;
int id = 0;
bool offset_hat = false;

io_service_t ffservice; /* Interface for force feedback, 0 = no ff */
FFCONSTANTFORCE ff_constant_force;
Expand Down