Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
5428652
Added udev sensor support
oshaboy Jan 31, 2024
606742b
Fixed segfault and added hotplug support.
oshaboy Jan 31, 2024
7775239
Preliminary SDL Gyro Support
oshaboy Feb 1, 2024
ebe99ab
buncha stuff
oshaboy Feb 2, 2024
75b9de3
Comments and UDEV_TOUCH_SUPPORT flag.
oshaboy Feb 2, 2024
5fcea9b
Remove C++ style comments
oshaboy Feb 2, 2024
0277283
Update sdl_input.c
oshaboy Feb 2, 2024
5113a52
Removed silly printf hack and used proper facilities.
oshaboy Feb 2, 2024
7dc3bdb
Menu Stuff
oshaboy Feb 3, 2024
7d3fcc1
Merge branch 'libretro:master' into linux_sensor
oshaboy Feb 3, 2024
6fdfa1c
Merge branch 'linux_sensor' of https://github.com/oshaboy/RetroArch i…
oshaboy Feb 3, 2024
91613a4
I forgot a few files.
oshaboy Feb 3, 2024
ac21e7d
Moved sensitivity adjustment to some other function
oshaboy Feb 3, 2024
17a87f1
Various
oshaboy Feb 3, 2024
809d53f
Segfault fix and macro renaming
oshaboy Feb 3, 2024
1a30370
Now SDL Sensor gives names.
oshaboy Feb 5, 2024
6c7f783
Update sdl_input.c
oshaboy Feb 5, 2024
adcb02d
Update sdl_input.c
oshaboy Feb 5, 2024
cafaeff
Update sdl_input.c
oshaboy Feb 5, 2024
2ab1ef5
Mostly menu stuff for sensors
oshaboy Feb 21, 2024
c218c60
Merge branch 'master' into linux_sensor
oshaboy Feb 22, 2024
9d9e388
Messed up the merge
oshaboy Feb 22, 2024
cbb2b64
typo
oshaboy Feb 22, 2024
6a91a2c
Update configuration.c
oshaboy Apr 15, 2024
aef3009
Gave up on menu settings
oshaboy Apr 22, 2024
19f47d2
Merge branch 'master' into linux_sensor
oshaboy Apr 22, 2024
a4c6880
I commented out the wrong thing
oshaboy Apr 22, 2024
a0887a1
Merge branch 'linux_sensor' of https://github.com/oshaboy/RetroArch i…
oshaboy Apr 22, 2024
db24c1e
Made sensor remapping work for all drivers.
oshaboy May 30, 2024
0da83e8
C89 is bleh.
oshaboy May 30, 2024
9e959cb
Typo
oshaboy Aug 25, 2024
a1ebece
Merge branch 'master' into linux_sensor
oshaboy Aug 26, 2024
0a926bf
Messed Up the merge conflict
oshaboy Aug 26, 2024
034a8aa
Update net_retropad_core.c
oshaboy Aug 26, 2024
31bf40d
Merge branch 'master' into linux_sensor
oshaboy Sep 11, 2024
a34c408
I accidentally the semicolon
oshaboy Sep 11, 2024
eac2e22
Merge branch 'master' into linux_sensor
oshaboy Jan 11, 2025
585522d
More Merge Conflicts
oshaboy Jan 11, 2025
191f9a1
Update sdl_input.c
oshaboy Jan 11, 2025
09a6afa
I think it's working now but there's a bug in the light sensor code t…
oshaboy Jan 11, 2025
835974e
Whoops made a mistake.
oshaboy Jan 11, 2025
e1942e4
Merge branch 'libretro:master' into linux_sensor
oshaboy Jan 15, 2025
ed0e7f4
Code Review
oshaboy Jan 15, 2025
fc6ad33
I should probably add these comments back despite the fact that they'…
oshaboy Jan 15, 2025
c553cd1
C89 Comments
oshaboy Jan 15, 2025
ec6dc65
Moved the enums to where the define originally was
oshaboy Jan 15, 2025
ed36cb5
Uncommented Sensor Menu Code
oshaboy Jan 16, 2025
8b57051
I don't know why past me messed with code that wasn't related.
oshaboy Jan 16, 2025
e33b667
test labels
oshaboy Jan 16, 2025
5563b32
More menu stuff
oshaboy Jan 17, 2025
1c9951d
I got the menu kinda sorta working
oshaboy Jan 17, 2025
9730936
Finally got the menu remap working.
oshaboy Jan 17, 2025
6f72620
autoconfig
oshaboy Jan 19, 2025
23d7b75
removed debug stuff
oshaboy Jan 19, 2025
a65e2fc
I'm giving up on the wiimote
oshaboy Jan 19, 2025
7382561
I did not mean to remove that line
oshaboy Jan 20, 2025
20e3839
Forgot to add this check to the config file.
oshaboy Jan 20, 2025
08e8341
Update configuration.c
oshaboy Jan 20, 2025
0cac7a4
Minor changes
oshaboy Jan 20, 2025
6a361e3
Merge branch 'master' into linux_sensor
oshaboy Mar 4, 2025
5ebc362
Update menu_setting.c
oshaboy Mar 4, 2025
0f03f4e
Picking some nits
oshaboy Mar 19, 2025
a253cea
Made sure SDL only enables sensors when requested
oshaboy Mar 19, 2025
73da3df
Update sdl_input.c
oshaboy Mar 19, 2025
e01f57f
Update sdl_input.c
oshaboy Mar 19, 2025
b879025
Update sdl_input.c
oshaboy Mar 19, 2025
121f7ea
Update sdl_input.c
oshaboy Mar 19, 2025
fd000ff
asterisk
oshaboy Mar 19, 2025
b099b3c
This is why you test after a refactor.
oshaboy Apr 2, 2025
153e702
Removed buggy microoptimizations
oshaboy Apr 2, 2025
3e45a63
Update sdl_input.c
oshaboy Apr 2, 2025
77820e6
Update sdl_input.c
oshaboy Apr 2, 2025
2becb46
Update udev_input.c
oshaboy Apr 2, 2025
b800a69
More Error Handling
oshaboy Apr 2, 2025
7133929
Prevented Aux Devices being over max devices
oshaboy Apr 2, 2025
4699c3a
I found a few bugs in initialization
oshaboy Apr 2, 2025
22dfac3
Moar Error Handling
oshaboy Apr 3, 2025
6ddddae
More nits
oshaboy Apr 16, 2025
d2de297
typo
oshaboy Apr 16, 2025
9047cf5
Forgot to free on error
oshaboy Apr 16, 2025
65e035a
Easy UB fix
oshaboy May 21, 2025
16ac146
Added Guard.
oshaboy May 21, 2025
bbd25b4
Merge branch 'master' into linux_sensor
oshaboy Feb 15, 2026
414c6eb
I added back my remap code.
oshaboy Feb 15, 2026
c8fbf0c
actually it's fine, also I have no idea what that file was.
oshaboy Feb 15, 2026
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
178 changes: 170 additions & 8 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -3120,6 +3120,7 @@ void config_set_defaults(void *data)
settings->uints.input_analog_dpad_mode[i] = ANALOG_DPAD_LSTICK;
input_config_set_device((unsigned)i, RETRO_DEVICE_JOYPAD);
settings->uints.input_mouse_index[i] = (unsigned)i;
settings->uints.input_sensor_index[i] = (unsigned)i;
}

custom_vp->width = 0;
Expand Down Expand Up @@ -4034,9 +4035,13 @@ static bool config_load_file(global_t *global,
_len = old_len;
_len += snprintf(prefix + _len, sizeof(prefix) - _len, "%u", i + 1);

strlcpy(prefix + _len, "_sensor_index", sizeof(prefix) - _len);
CONFIG_GET_INT_BASE(conf, settings, uints.input_sensor_index[i], prefix);

strlcpy(prefix + _len, "_mouse_index", sizeof(prefix) - _len);
CONFIG_GET_INT_BASE(conf, settings, uints.input_mouse_index[i], prefix);


strlcpy(prefix + _len, "_joypad_index", sizeof(prefix) - _len);
CONFIG_GET_INT_BASE(conf, settings, uints.input_joypad_index[i], prefix);

Expand Down Expand Up @@ -5159,7 +5164,6 @@ static void save_keybind_axis(config_file_t *conf,
}
config_set_string(conf, key, config);
}

static void save_keybind_mbutton(config_file_t *conf,
const char *prefix,
const char *base,
Expand Down Expand Up @@ -5235,7 +5239,18 @@ const char *input_config_get_prefix(unsigned user, bool meta)
}
return bind_user_prefix[user];
}
static bool get_config_name_for_sensor(char * buf,size_t buf_len, unsigned sensor){
const char * sensor_str;
char direction;

if (sensor >= 6)
return false;
sensor_str = sensor>=3?"gyroscope":"accelerometer";
direction = "xyzxyz"[sensor];
snprintf(buf, buf_len,"input_sensor_%s_%c",
sensor_str, direction);
return true;
}
/**
* input_config_save_keybinds_user:
* @conf : pointer to config file object
Expand Down Expand Up @@ -5467,8 +5482,24 @@ bool config_save_autoconf_profile(const char *device_name, unsigned user)
input_config_bind_map_get_base(i), bind, false);
}
}

RARCH_LOG("[Autoconf] Writing autoconf file for device \"%s\" to \"%s\".\n", device_name, autoconf_file);
for (i = 0; i<RETROPAD_RETRO_SENSOR_LAST; i++){
char new_bind_str[16];
char sensor_str[256];
unsigned new_bind;

new_bind=config_get_ptr()->uints.input_sensor_ids[user][i];
snprintf(new_bind_str,16,
"%u%s",
new_bind/2,
(new_bind%2)?"inv":""
);
get_config_name_for_sensor(sensor_str, sizeof(sensor_str),i);
config_set_string(conf,
sensor_str,
new_bind_str
);
}
RARCH_LOG("[Autoconf]: Writing autoconf file for device \"%s\" to \"%s\".\n", device_name, autoconf_file);
ret = config_file_write(conf, autoconf_file, false);
if (conf)
config_file_free(conf);
Expand Down Expand Up @@ -5629,6 +5660,9 @@ bool config_save_file(const char *path)

_len = strlcpy(cfg, "input_player", sizeof(cfg));
_len += strlcpy(cfg + _len, formatted_number, sizeof(cfg) - _len);

strlcpy(cfg + _len, "_sensor_index", sizeof(cfg) - _len);
config_set_int(conf, cfg, settings->uints.input_sensor_index[i]);

strlcpy(cfg + _len, "_mouse_index", sizeof(cfg) - _len);
config_set_int(conf, cfg, settings->uints.input_mouse_index[i]);
Expand Down Expand Up @@ -5979,6 +6013,14 @@ int8_t config_save_overrides(enum override_type type,
_len = strlcpy(cfg, "input_player", sizeof(cfg));
_len += strlcpy(cfg + _len, formatted_number, sizeof(cfg) - _len);

if (settings->uints.input_sensor_index[i]
!= overrides->uints.input_sensor_index[i])
{
strlcpy(cfg + _len, "_sensor_index", sizeof(cfg) - _len);
config_set_int(conf, cfg, overrides->uints.input_sensor_index[i]);
RARCH_DBG("[Overrides]: %s = \"%u\"\n", cfg, overrides->uints.input_sensor_index[i]);
}

if (settings->uints.input_mouse_index[i]
!= overrides->uints.input_mouse_index[i])
{
Expand Down Expand Up @@ -6177,7 +6219,7 @@ bool input_remapping_load_file(void *data, const char *path)
config_file_t *conf = (config_file_t*)data;
settings_t *settings = config_st;
runloop_state_t *runloop_st = runloop_state_get_ptr();
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][8] =
static const char * key_strings[RARCH_FIRST_CUSTOM_BIND + 8] =
{
"b", "y", "select", "start",
"up", "down", "left", "right",
Expand All @@ -6186,7 +6228,11 @@ bool input_remapping_load_file(void *data, const char *path)
"l_x+", "l_x-", "l_y+", "l_y-",
"r_x+", "r_x-", "r_y+", "r_y-"
};

static const char * sensor_strings[RETROPAD_RETRO_SENSOR_LAST] =
{
"accel_x","accel_y", "accel_z",
"gyro_x","gyro_y","gyro_z"
};
if ( !conf
|| string_is_empty(path))
return false;
Expand Down Expand Up @@ -6287,6 +6333,42 @@ bool input_remapping_load_file(void *data, const char *path)
_len = strlcpy(s1, "input_remap_port_p", sizeof(s1));
strlcpy(s1 + _len, formatted_number, sizeof(s1) - _len);
CONFIG_GET_INT_BASE(conf, settings, uints.input_remap_ports[i], s1);
for (j = 0; j < RETROPAD_RETRO_SENSOR_LAST; j++){

int sensor_remap = -1;
char sensor_ident[128];
fill_pathname_join_delim(sensor_ident, s1,
sensor_strings[j], '_', sizeof(sensor_ident));
RARCH_DBG("Sensor Ident: %s %d\n", sensor_ident,sensor_remap);
if(!config_get_int(conf, sensor_ident, &sensor_remap))
sensor_remap=RETROK_UNKNOWN;

configuration_set_uint(settings,
settings->uints.input_sensor_ids[i][j], sensor_remap);

}

/* Turbo fire settings */
_len = strlcpy(s1, "input_turbo_enable", sizeof(s1));
CONFIG_GET_BOOL_BASE(conf, settings, bools.input_turbo_enable, s1);

_len = strlcpy(s1, "input_turbo_allow_dpad", sizeof(s1));
CONFIG_GET_BOOL_BASE(conf, settings, bools.input_turbo_allow_dpad, s1);

_len = strlcpy(s1, "input_turbo_mode", sizeof(s1));
CONFIG_GET_INT_BASE(conf, settings, uints.input_turbo_mode, s1);

_len = strlcpy(s1, "input_turbo_bind", sizeof(s1));
CONFIG_GET_INT_BASE(conf, settings, ints.input_turbo_bind, s1);

_len = strlcpy(s1, "input_turbo_button", sizeof(s1));
CONFIG_GET_INT_BASE(conf, settings, uints.input_turbo_button, s1);

_len = strlcpy(s1, "input_turbo_period", sizeof(s1));
CONFIG_GET_INT_BASE(conf, settings, uints.input_turbo_period, s1);

_len = strlcpy(s1, "input_turbo_duty_cycle", sizeof(s1));
CONFIG_GET_INT_BASE(conf, settings, uints.input_turbo_duty_cycle, s1);
}

/* Turbo fire settings */
Expand Down Expand Up @@ -6321,7 +6403,7 @@ bool input_remapping_save_file(const char *path)
bool ret;
unsigned i, j;
char remap_file_dir[DIR_MAX_LENGTH];
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][8] =
static const char * key_strings[RARCH_FIRST_CUSTOM_BIND + 8] =
{
"b", "y", "select", "start",
"up", "down", "left", "right",
Expand All @@ -6330,14 +6412,19 @@ bool input_remapping_save_file(const char *path)
"l_x+", "l_x-", "l_y+", "l_y-",
"r_x+", "r_x-", "r_y+", "r_y-"
};
static const char * sensor_strings[RETROPAD_RETRO_SENSOR_LAST] =
{
"accel_x","accel_y", "accel_z",
"gyro_x","gyro_y","gyro_z"
};
config_file_t *conf = NULL;
runloop_state_t *runloop_st = runloop_state_get_ptr();
settings_t *settings = config_st;
unsigned max_users = settings->uints.input_max_users;


if (string_is_empty(path))
return false;

/* Create output directory, if required */
fill_pathname_parent_dir(remap_file_dir, path,
sizeof(remap_file_dir));
Expand Down Expand Up @@ -6485,6 +6572,46 @@ bool input_remapping_save_file(const char *path)
_len = strlcpy(s1, "input_remap_port_p", sizeof(s1));
strlcpy(s1 + _len, formatted_number, sizeof(s1) - _len);
config_set_int(conf, s1, settings->uints.input_remap_ports[i]);

for (j = 0; j < RETROPAD_RETRO_SENSOR_LAST; j++){
char sensor_ident[128];
unsigned sensor_remap = settings->uints.input_sensor_ids[i][j];

fill_pathname_join_delim(sensor_ident, s1,
sensor_strings[j], '_', sizeof(sensor_ident));
if (sensor_remap == j)
config_unset(conf, sensor_ident);
else
{
if (sensor_remap == RARCH_UNMAPPED)
config_set_int(conf, sensor_ident, -1);
else
config_set_int(conf, sensor_ident,
settings->uints.input_sensor_ids[i][j]);
}
}

/* Turbo fire settings */
_len = strlcpy(s1, "input_turbo_enable", sizeof(s1));
config_set_string(conf, s1, settings->bools.input_turbo_enable ? "true" : "false");

_len = strlcpy(s1, "input_turbo_allow_dpad", sizeof(s1));
config_set_string(conf, s1, settings->bools.input_turbo_allow_dpad ? "true" : "false");

_len = strlcpy(s1, "input_turbo_mode", sizeof(s1));
config_set_int(conf, s1, settings->uints.input_turbo_mode);

_len = strlcpy(s1, "input_turbo_bind", sizeof(s1));
config_set_int(conf, s1, settings->ints.input_turbo_bind);

_len = strlcpy(s1, "input_turbo_button", sizeof(s1));
config_set_int(conf, s1, settings->uints.input_turbo_button);

_len = strlcpy(s1, "input_turbo_period", sizeof(s1));
config_set_int(conf, s1, settings->uints.input_turbo_period);

_len = strlcpy(s1, "input_turbo_duty_cycle", sizeof(s1));
config_set_int(conf, s1, settings->uints.input_turbo_duty_cycle);
}

/* Turbo fire settings */
Expand Down Expand Up @@ -6653,6 +6780,7 @@ uint8_t input_config_bind_map_get_retro_key(unsigned bind_index)
return keybind->retro_key;
}


void input_config_reset_autoconfig_binds(unsigned port)
{
size_t i;
Expand Down Expand Up @@ -6690,7 +6818,6 @@ void input_config_set_autoconfig_binds(unsigned port, void *data)
return;

binds = input_autoconf_binds[port];

for (i = 0; i < RARCH_BIND_LIST_END; i++)
{
const struct input_bind_map *keybind =
Expand All @@ -6705,6 +6832,14 @@ void input_config_set_autoconfig_binds(unsigned port, void *data)
input_config_parse_joy_axis (str, config, "input", base, &binds[i]);
}
}
for (i = 0; i < RETROPAD_RETRO_SENSOR_LAST; i++){
/* I am the implementor I get to choose the implementation details */
char str[256];

get_config_name_for_sensor(str, sizeof(str), i);
config_get_ptr()->uints.input_sensor_ids[port][i]=
input_config_parse_sensor (i,str, config);
}
}

void input_config_parse_mouse_button(char *s,
Expand Down Expand Up @@ -6919,7 +7054,34 @@ void input_config_parse_joy_button(
bind->joykey_label = strdup(tmp_a->value);
}
}
unsigned input_config_parse_sensor(
unsigned id,
char *s,
void *conf_data)
{
char tmp[64];
char sensor_label[64];
config_file_t *conf = (config_file_t*)conf_data;
struct config_entry_list *tmp_a = NULL;

tmp[0] = '\0';

fill_pathname_join_delim(sensor_label, s,
"label", '_', sizeof(sensor_label));
if (config_get_array(conf, s, tmp, sizeof(tmp)))
{
if (strcmp(tmp, "nul") != 0){
RARCH_DBG("tmp: %s\n", tmp);
if ((*tmp>='0') && (*tmp<='5')){
if (strcmp(tmp+1,"inv") == 0)
return (((*tmp)-'0')*2)+1;
else if (tmp[1] == '\0')
return ((*tmp)-'0')*2;
}
}
}
return id*2;
}
void retroarch_config_deinit(void)
{
if (config_st)
Expand Down
8 changes: 8 additions & 0 deletions configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ typedef struct settings
unsigned input_joypad_index[MAX_USERS];
unsigned input_device[MAX_USERS];
unsigned input_mouse_index[MAX_USERS];
unsigned input_sensor_index[MAX_USERS];

unsigned input_libretro_device[MAX_USERS];
unsigned input_analog_dpad_mode[MAX_USERS];
Expand All @@ -173,6 +174,7 @@ typedef struct settings
unsigned input_remap_ports[MAX_USERS];
unsigned input_remap_ids[MAX_USERS][RARCH_CUSTOM_BIND_LIST_END];
unsigned input_keymapper_ids[MAX_USERS][RARCH_CUSTOM_BIND_LIST_END];
unsigned input_sensor_ids[MAX_USERS][RETROPAD_RETRO_SENSOR_LAST];
unsigned input_remap_port_map[MAX_USERS][MAX_USERS + 1];

unsigned led_map[MAX_LEDS];
Expand Down Expand Up @@ -1424,6 +1426,12 @@ void input_config_parse_mouse_button(
void *conf_data, const char *prefix,
const char *btn, void *bind_data);

/* Parse Accelerometer and Gyroscope Bindings
* from the controller configuration file */
unsigned input_config_parse_sensor(
unsigned id,
char *s,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this parameter const to clarify your intent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be const it uses char * s as a buffer. I might rename it to buffer instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s is only used with functions that take it as const. Is it possible you made a subtle mistake or typo somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're right. But all other functions such as fill_pathname_join_delim take a non const s. So I can't do it without discarding the qualifier.

void *conf_data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this parameter is a void* despite not being used for any kind of polymorphism?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's necessary for the API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? I'm searching for uses of it but I don't see any that would need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK all other functions that take a config_file_t pass it as a void *. If you want to refactor that that's on you. I am just following Chesterton's Fence principle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

const char *input_config_get_prefix(unsigned user, bool meta);

RETRO_END_DECLS
Expand Down
Loading
Loading