diff --git a/src/joystick.c b/src/joystick.c index 3a516d1f..c7a09a91 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -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) { diff --git a/src/joystick.h b/src/joystick.h index d069f527..92a4913b 100644 --- a/src/joystick.h +++ b/src/joystick.h @@ -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; diff --git a/src/prefs.h b/src/prefs.h index 40d428a3..ddf71f62 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -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"