Skip to content

Commit

Permalink
Fixed #542: Don't try to get joystick Axis if it has none
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Dec 7, 2019
1 parent 6e91bfa commit 4768f8e
Showing 1 changed file with 56 additions and 54 deletions.
110 changes: 56 additions & 54 deletions src/osdep/amiberry_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,70 +1135,72 @@ static void read_joystick()
held_offset = 0;
}

auto val = 0;

// this should allow use to change the tolerance
auto lower_bound = -32767;
auto upper_bound = 32767;

// left stick
if (!currprefs.input_analog_remap)
if (SDL_JoystickNumAxes(joysticktable[hostjoyid]) > 0)
{
// handle the X axis (left stick)
val = SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x);
if (current_controller_map.lstick_axis_x_invert != 0)
val = val * -1;
int val;

setjoystickstate(hostjoyid + 1, 0, val, upper_bound);
// this should allow use to change the tolerance
const auto lower_bound = -32767;
const auto upper_bound = 32767;

// handle the Y axis
val = SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y);
if (current_controller_map.lstick_axis_y_invert != 0)
val = val * -1;
// left stick
if (!currprefs.input_analog_remap)
{
// handle the X axis (left stick)
val = SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x);
if (current_controller_map.lstick_axis_x_invert != 0)
val = val * -1;

setjoystickstate(hostjoyid + 1, 1, val, upper_bound);
}
setjoystickstate(hostjoyid + 1, 0, val, upper_bound);

else
{
// alternative code for custom remapping the left stick
// handle the Y axis (left stick)
setjoybuttonstate(hostjoyid + 1, 7 + held_offset,
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y) <=
lower_bound
? 1
: 0);
setjoybuttonstate(hostjoyid + 1, 8 + held_offset,
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y) >=
upper_bound
? 1
: 0);
// handle the X axis
setjoybuttonstate(hostjoyid + 1, 9 + held_offset,
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x) <=
lower_bound
? 1
: 0);
setjoybuttonstate(hostjoyid + 1, 10 + held_offset,
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x) >=
upper_bound
? 1
: 0);
}
// handle the Y axis
val = SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y);
if (current_controller_map.lstick_axis_y_invert != 0)
val = val * -1;

// right stick
val = SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.rstick_axis_x);
if (current_controller_map.rstick_axis_x_invert != 0)
val = val * -1;
setjoystickstate(hostjoyid + 1, 1, val, upper_bound);
}

setjoystickstate(hostjoyid + 1, 2, val, upper_bound);
else
{
// alternative code for custom remapping the left stick
// handle the Y axis (left stick)
setjoybuttonstate(hostjoyid + 1, 7 + held_offset,
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y) <=
lower_bound
? 1
: 0);
setjoybuttonstate(hostjoyid + 1, 8 + held_offset,
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y) >=
upper_bound
? 1
: 0);
// handle the X axis
setjoybuttonstate(hostjoyid + 1, 9 + held_offset,
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x) <=
lower_bound
? 1
: 0);
setjoybuttonstate(hostjoyid + 1, 10 + held_offset,
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x) >=
upper_bound
? 1
: 0);
}

val = SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.rstick_axis_y);
if (current_controller_map.rstick_axis_y_invert != 0)
val = val * -1;
// right stick
val = SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.rstick_axis_x);
if (current_controller_map.rstick_axis_x_invert != 0)
val = val * -1;

setjoystickstate(hostjoyid + 1, 2, val, upper_bound);

setjoystickstate(hostjoyid + 1, 3, val, upper_bound);
val = SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.rstick_axis_y);
if (current_controller_map.rstick_axis_y_invert != 0)
val = val * -1;

setjoystickstate(hostjoyid + 1, 3, val, upper_bound);
}
// cd32 red, blue, green, yellow
// south
setjoybuttonstate(hostjoyid + 1, 0 + held_offset,
Expand Down

0 comments on commit 4768f8e

Please sign in to comment.