Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pads: read left analog stick inputs to navigate the gui #1303

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ enum CONFIG_INDEX {
#define CONFIG_OPL_BOOT_SND_VOLUME "boot_snd_volume"
#define CONFIG_OPL_BGM_VOLUME "bgm_volume"
#define CONFIG_OPL_DEFAULT_BGM_PATH "default_bgm_path"
#define CONFIG_OPL_XSENSITIVITY "x_sensitivity"
#define CONFIG_OPL_YSENSITIVITY "y_sensitivity"

// Network config keys
#define CONFIG_NET_ETH_LINKM "eth_linkmode"
Expand Down
3 changes: 3 additions & 0 deletions include/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ enum UI_ITEMS {
CFG_BGM_VOLUME,
CFG_DEFAULT_BGM_PATH,

CFG_XSENSITIVITY,
CFG_YSENSITIVITY,

NETCFG_SHOW_ADVANCED_OPTS,
NETCFG_PS2_IP_ADDR_TYPE,
NETCFG_PS2_IP_ADDR_0,
Expand Down
3 changes: 3 additions & 0 deletions include/opl.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ extern int gBootSndVolume;
extern int gBGMVolume;
extern char gDefaultBGMPath[128];

extern int gXSensitivity;
extern int gYSensitivity;

extern int gCheatSource;
extern int gGSMSource;
extern int gPadEmuSource;
Expand Down
8 changes: 8 additions & 0 deletions lng_tmpl/_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,11 @@ gui_strings:
string: Default Theme Music
- label: DEF_BGM_PATH_HINT
string: Set path to stream music for internal theme.
- label: HIGH
string: High
- label: LOW
string: Low
- label: XSENSITIVITY
string: Analog X-Axis Sensitivity
- label: YSENSITIVITY
string: Analog Y-Axis Sensitivity
11 changes: 11 additions & 0 deletions src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,17 @@ struct UIItem diaControllerConfig[] = {
{UI_SPACER},
{UI_ENUM, CFG_SELECTBUTTON, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},

{UI_BREAK},
{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_XSENSITIVITY}}},
{UI_SPACER},
{UI_ENUM, CFG_XSENSITIVITY, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},

{UI_LABEL, 0, 1, 1, -1, -40, 0, {.label = {NULL, _STR_YSENSITIVITY}}},
{UI_SPACER},
{UI_ENUM, CFG_YSENSITIVITY, 1, 1, -1, 0, 0, {.intvalue = {0, 0}}},
{UI_BREAK},
#ifdef PADEMU
{UI_BREAK},
{UI_BUTTON, PADEMU_GLOBAL_BUTTON, 1, 1, -1, 0, 0, {.label = {NULL, _STR_PADEMUCONFIG}}},
Expand Down
7 changes: 7 additions & 0 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,16 +911,23 @@ void guiShowControllerConfig(void)
// configure the enumerations
const char *scrollSpeeds[] = {_l(_STR_SLOW), _l(_STR_MEDIUM), _l(_STR_FAST), NULL};
const char *selectButtons[] = {_l(_STR_CIRCLE), _l(_STR_CROSS), NULL};
const char *sensitivity[] = {_l(_STR_LOW), _l(_STR_MEDIUM), _l(_STR_HIGH), NULL};

diaSetEnum(diaControllerConfig, UICFG_SCROLL, scrollSpeeds);
diaSetEnum(diaControllerConfig, CFG_SELECTBUTTON, selectButtons);
diaSetEnum(diaControllerConfig, CFG_XSENSITIVITY, sensitivity);
diaSetEnum(diaControllerConfig, CFG_YSENSITIVITY, sensitivity);

diaSetInt(diaControllerConfig, UICFG_SCROLL, gScrollSpeed);
diaSetInt(diaControllerConfig, CFG_SELECTBUTTON, gSelectButton == KEY_CIRCLE ? 0 : 1);
diaSetInt(diaControllerConfig, CFG_XSENSITIVITY, gXSensitivity);
diaSetInt(diaControllerConfig, CFG_YSENSITIVITY, gYSensitivity);

int result = diaExecuteDialog(diaControllerConfig, -1, 1, NULL);
if (result) {
diaGetInt(diaControllerConfig, UICFG_SCROLL, &gScrollSpeed);
diaGetInt(diaControllerConfig, CFG_XSENSITIVITY, &gXSensitivity);
diaGetInt(diaControllerConfig, CFG_YSENSITIVITY, &gYSensitivity);

if (diaGetInt(diaControllerConfig, CFG_SELECTBUTTON, &value))
gSelectButton = value == 0 ? KEY_CIRCLE : KEY_CROSS;
Expand Down
9 changes: 9 additions & 0 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ char gOPLPart[128];
char *gHDDPrefix;
char gExportName[32];

int gXSensitivity;
int gYSensitivity;

int gOSDLanguageValue;
int gOSDTVAspectRatio;
int gOSDVideOutput;
Expand Down Expand Up @@ -908,6 +911,8 @@ static void _loadConfig()
if (configGetInt(configOPL, CONFIG_OPL_SWAP_SEL_BUTTON, &value))
gSelectButton = value == 0 ? KEY_CIRCLE : KEY_CROSS;

configGetInt(configOPL, CONFIG_OPL_XSENSITIVITY, &gXSensitivity);
configGetInt(configOPL, CONFIG_OPL_YSENSITIVITY, &gYSensitivity);
configGetInt(configOPL, CONFIG_OPL_DISABLE_DEBUG, &gEnableDebug);
configGetInt(configOPL, CONFIG_OPL_PS2LOGO, &gPS2Logo);
configGetInt(configOPL, CONFIG_OPL_HDD_GAME_LIST_CACHE, &gHDDGameListCache);
Expand Down Expand Up @@ -1093,6 +1098,8 @@ static void _saveConfig()
configSetInt(configOPL, CONFIG_OPL_BOOT_SND_VOLUME, gBootSndVolume);
configSetInt(configOPL, CONFIG_OPL_BGM_VOLUME, gBGMVolume);
configSetStr(configOPL, CONFIG_OPL_DEFAULT_BGM_PATH, gDefaultBGMPath);
configSetInt(configOPL, CONFIG_OPL_XSENSITIVITY, gXSensitivity);
configSetInt(configOPL, CONFIG_OPL_YSENSITIVITY, gYSensitivity);

configSetInt(configOPL, CONFIG_OPL_SWAP_SEL_BUTTON, gSelectButton == KEY_CIRCLE ? 0 : 1);
}
Expand Down Expand Up @@ -1709,6 +1716,8 @@ static void setDefaults(void)
gBootSndVolume = 80;
gBGMVolume = 70;
gDefaultBGMPath[0] = '\0';
gXSensitivity = 1;
gYSensitivity = 1;

gBDMStartMode = START_MODE_DISABLED;
gHDDStartMode = START_MODE_DISABLED;
Expand Down
50 changes: 50 additions & 0 deletions src/pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,54 @@ static void updatePadState(struct pad_data_t *pad, int state)
pad->state = state;
}

static u32 readLeftJoy(struct pad_data_t *pad, u32 pdata)
{
u32 padData = pdata;
int xDeadzone, yDeadzone;

if ((pad->buttons.mode >> 4) == 0x07) {
switch (gXSensitivity) {
case 0:
xDeadzone = 100;
break;
case 1:
xDeadzone = 80;
break;
case 2:
xDeadzone = 60;
break;
default:
xDeadzone = 80;
}

switch (gYSensitivity) {
case 0:
yDeadzone = 100;
break;
case 1:
yDeadzone = 80;
break;
case 2:
yDeadzone = 60;
break;
default:
yDeadzone = 80;
}

if (pad->buttons.ljoy_h < 127 - xDeadzone)
padData |= PAD_LEFT;
else if (pad->buttons.ljoy_h > 127 + xDeadzone)
padData |= PAD_RIGHT;

if (pad->buttons.ljoy_v < 127 - yDeadzone)
padData |= PAD_UP;
else if (pad->buttons.ljoy_v > 127 + yDeadzone)
padData |= PAD_DOWN;
}

return padData;
}

static int readPad(struct pad_data_t *pad)
{
int rcode = 0, oldState, newState, ret, padsRead;
Expand Down Expand Up @@ -247,6 +295,8 @@ static int readPad(struct pad_data_t *pad)
else
rcode = 0;

newpdata |= readLeftJoy(pad, newpdata);

pad->oldpaddata = pad->paddata;
pad->paddata = newpdata;

Expand Down
Loading