Improved clamping of Mac joystick/gamepad axes

This commit is contained in:
Aaron Culliney 2016-04-23 14:56:05 -07:00
parent 747a469241
commit e5b3099b04

View File

@ -132,8 +132,14 @@
}
#endif
uint8_t x = (uint8_t)((value+DDHID_JOYSTICK_VALUE_MAX) * DDHID_JOYSTICK_NORMALIZER);
joydriver_setAxisValue(x, joydriver_getAxisY());
int x = (int)((value+DDHID_JOYSTICK_VALUE_MAX) * DDHID_JOYSTICK_NORMALIZER);
if (x < 0) {
x = 0;
}
if (x >= JOY_RANGE) {
x = JOY_RANGE-1;
}
joydriver_setAxisValue((uint8_t)x, joydriver_getAxisY());
}
- (void)ddhidJoystick:(DDHidJoystick *)joystick stick:(unsigned int)stick yChanged:(int)value
@ -144,8 +150,14 @@
}
#endif
uint8_t y = (uint8_t)((value+DDHID_JOYSTICK_VALUE_MAX) * DDHID_JOYSTICK_NORMALIZER);
joydriver_setAxisValue(joydriver_getAxisX(), y);
int y = (int)((value+DDHID_JOYSTICK_VALUE_MAX) * DDHID_JOYSTICK_NORMALIZER);
if (y < 0) {
y = 0;
}
if (y >= JOY_RANGE) {
y = JOY_RANGE-1;
}
joydriver_setAxisValue(joydriver_getAxisX(), (uint8_t)y);
}
- (void)ddhidJoystick:(DDHidJoystick *)joystick stick:(unsigned int)stick otherAxis:(unsigned)otherAxis valueChanged:(int)value