Minor refactor joystick prefs

This commit is contained in:
Aaron Culliney 2018-11-04 14:06:38 -08:00
parent d443f01af3
commit 2a7e375f26
3 changed files with 18 additions and 2 deletions

View File

@ -20,7 +20,7 @@
extern void copy_and_pad_string(char *dest, const char* src, const char c, const int len, const char cap);
#endif
joystick_mode_t joy_mode = JOY_PCJOY;
joystick_mode_t joy_mode = JOY_MODE_DEFAULT;
/* parameters for generic and keyboard-simulated joysticks */
uint16_t joy_x = HALF_JOY_RANGE;
@ -37,8 +37,15 @@ void (*joydriver_resetJoystick)(void) = NULL;
static void joystick_prefsChanged(const char *domain) {
assert(strcmp(domain, PREF_DOMAIN_JOYSTICK) == 0);
#ifdef KEYPAD_JOYSTICK
long lVal = 0;
if (prefs_parseLongValue(domain, PREF_JOYSTICK_MODE, &lVal, /*base:*/10)) {
joy_mode = getJoyMode(lVal);
}
prefs_parseBoolValue(domain, PREF_JOYSTICK_CLIP_TO_RADIUS, &joy_clip_to_radius);
#ifdef KEYPAD_JOYSTICK
prefs_parseLongValue(domain, PREF_JOYSTICK_KPAD_STEP, &lVal, /*base:*/10);
joy_step = (short)lVal;
if (joy_step < 1) {

View File

@ -24,6 +24,14 @@ typedef enum joystick_mode_t {
NUM_JOYOPTS
} joystick_mode_t;
#define JOY_MODE_DEFAULT JOY_PCJOY
static inline joystick_mode_t getJoyMode(long lVal) {
if (lVal < 0 || lVal >= NUM_JOYOPTS) {
lVal = JOY_MODE_DEFAULT;
}
return (joystick_mode_t)lVal;
}
extern joystick_mode_t joy_mode;
extern uint16_t joy_x;

View File

@ -45,6 +45,7 @@
#define PREF_JOYSTICK_KPAD_AUTO_RECENTER "kpAutoRecenter"
#define PREF_JOYSTICK_KPAD_STEP "kpStep"
#define PREF_JOYSTICK_MODE "joystickMode"
#define PREF_JOYSTICK_CLIP_TO_RADIUS "clipToRadius"
// joystick (touchscreen)
#define PREF_AXIS_ON_LEFT "axisIsOnLeft"
#define PREF_AXIS_SENSITIVITY "axisSensitivity"