Skip to content

Commit

Permalink
Take into account min/max range when getting hat offset
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored and SiegeLord committed Aug 15, 2023
1 parent 75d0b67 commit 02382ed
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/macosx/hidjoy.m
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,19 @@ static void value_callback(
}

int int_value = IOHIDValueGetIntegerValue(value);
int min = joy->min[joy->dpad_stick][1];
int max = joy->max[joy->dpad_stick][1];

if (joy->dpad == elem){
if (joy->min[joy->dpad_stick][1] > int_value || joy->max[joy->dpad_stick][1] < int_value) {
if (int_value >= min && int_value <= max) {
int index = int_value - min;
if (index < MAX_HAT_DIRECTIONS) {
osx_joy_generate_axis_event(joy, joy->dpad_stick, joy->dpad_axis_vert, (float)hat_mapping[index].axisV);
osx_joy_generate_axis_event(joy, joy->dpad_stick, joy->dpad_axis_horiz, (float)hat_mapping[index].axisH);
}
} else {
osx_joy_generate_axis_event(joy, joy->dpad_stick, joy->dpad_axis_vert, 0);
osx_joy_generate_axis_event(joy, joy->dpad_stick, joy->dpad_axis_horiz, 0);
} else if (int_value > 0 && int_value <= MAX_HAT_DIRECTIONS) {
osx_joy_generate_axis_event(joy, joy->dpad_stick, joy->dpad_axis_vert, (float)hat_mapping[int_value-1].axisV);
osx_joy_generate_axis_event(joy, joy->dpad_stick, joy->dpad_axis_horiz, (float)hat_mapping[int_value-1].axisH);
}
goto done;
}
Expand Down

0 comments on commit 02382ed

Please sign in to comment.