Skip to content

Commit

Permalink
Finally got the menu remap working.
Browse files Browse the repository at this point in the history
  • Loading branch information
oshaboy committed Jan 17, 2025
1 parent 1c9951d commit 9730936
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 32 deletions.
26 changes: 2 additions & 24 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -6010,21 +6010,13 @@ bool input_remapping_load_file(void *data, const char *path)
"accel_x","accel_y", "accel_z",
"gyro_x","gyro_y","gyro_z"
};
static const char * sensor_strings_flip[RETROPAD_RETRO_SENSOR_LAST] =
{
"accel_x_flip","accel_y_flip", "accel_z_flip",
"gyro_x_flip","gyro_y_flip","gyro_z_flip"
};
for (j = 0; j < RETROPAD_RETRO_SENSOR_LAST; j++){

int sensor_remap = -1;
bool sensor_flip_remap = false;
char sensor_ident[128];
char sensor_flip_ident[128];
fill_pathname_join_delim(sensor_ident, s1,
sensor_strings[j], '_', sizeof(sensor_ident));
fill_pathname_join_delim(sensor_flip_ident, s1,
sensor_strings_flip[j], '_', sizeof(sensor_flip_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;

Expand Down Expand Up @@ -6072,11 +6064,6 @@ bool input_remapping_save_file(const char *path)
"accel_x","accel_y", "accel_z",
"gyro_x","gyro_y","gyro_z"
};
static const char * sensor_strings_flip[RETROPAD_RETRO_SENSOR_LAST] =
{
"accel_x_flip","accel_y_flip", "accel_z_flip",
"gyro_x_flip","gyro_y_flip","gyro_z_flip"
};
config_file_t *conf = NULL;
runloop_state_t *runloop_st = runloop_state_get_ptr();
settings_t *settings = config_st;
Expand Down Expand Up @@ -6220,14 +6207,11 @@ bool input_remapping_save_file(const char *path)
config_set_int(conf, s1, settings->uints.input_remap_ports[i]);
for (j = 0; j < RETROPAD_RETRO_SENSOR_LAST; j++){
char sensor_ident[128];
char sensor_ident_flip[128];
unsigned sensor_remap = settings->uints.input_sensor_ids[i][j];

fill_pathname_join_delim(sensor_ident, s1,
sensor_strings[j], '_', sizeof(sensor_ident));
fill_pathname_join_delim(sensor_ident_flip, s1,
sensor_strings_flip[j], '_', sizeof(sensor_ident_flip));

RARCH_DBG("sensor ident2: %s %d\n",sensor_ident,sensor_remap);
if (sensor_remap == j)
config_unset(conf, sensor_ident);
else
Expand All @@ -6238,12 +6222,6 @@ bool input_remapping_save_file(const char *path)
config_set_int(conf, sensor_ident,
settings->uints.input_sensor_ids[i][j]);
}
/*
configuration_set_bool(conf,
settings->bools.input_sensor_flip_axis[i][j],
settings->bools.input_sensor_flip_axis[i][j]
);
*/
}
}

Expand Down
3 changes: 2 additions & 1 deletion input/drivers/udev_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -4380,7 +4380,7 @@ static float udev_input_get_sensor_input(void *data, unsigned port, unsigned id)

if (id == RETRO_SENSOR_ILLUMINANCE && udev->illuminance_sensor)
return linux_get_illuminance_reading(udev->illuminance_sensor);
/*
RARCH_DBG(
"[udev] sensor:\n"
"\t%d\n"
Expand All @@ -4394,6 +4394,7 @@ static float udev_input_get_sensor_input(void *data, unsigned port, unsigned id)
limits.max,
(((sensor_value-limits.min)/(limits.max-limits.min))-0.5f)*2.f
);
*/
return (
/*clamp it to the 0 to 1 range*/
((sensor_value-limits.min)/(limits.max-limits.min))
Expand Down
8 changes: 7 additions & 1 deletion input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -4407,14 +4407,20 @@ float input_get_sensor_state(unsigned port, unsigned id)
bool input_sensors_enable = settings->bools.input_sensors_enable;
float sensitivity;
int remapped_port=settings->uints.input_sensor_index[port];
int invert = (settings->uints.input_sensor_ids[port][id]%2)?-1:1;
unsigned remapped_input_sensor_id = settings->uints.input_sensor_ids[port][id]/2;

if (id >= RETRO_SENSOR_ACCELEROMETER_X && id <= RETRO_SENSOR_ACCELEROMETER_Z)
sensitivity=settings->floats.input_sensor_accelerometer_sensitivity;
else if (id >= RETRO_SENSOR_GYROSCOPE_X && id <= RETRO_SENSOR_GYROSCOPE_Z)
sensitivity=settings->floats.input_sensor_gyroscope_sensitivity;
else
sensitivity=1.f;
return input_driver_get_sensor(remapped_port, input_sensors_enable, id)*((float)pow(2,sensitivity));
return input_driver_get_sensor(
remapped_port,
input_sensors_enable,
remapped_input_sensor_id)
*invert*((float)pow(2,sensitivity));
}

/**
Expand Down
6 changes: 5 additions & 1 deletion intl/msg_hash_us.h
Original file line number Diff line number Diff line change
Expand Up @@ -4397,13 +4397,17 @@ MSG_HASH(
"Gyroscope Z Binding"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_ABS_SOURCE_VALUE,
MENU_ENUM_LABEL_INPUT_ABS_SOURCE_AUTO,
"ABS Source %u Value"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_ABS_SOURCE,
"ABS Source %u"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_ABS_SOURCE_INVERTED,
"ABS Source %u Inverted"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_MOUSE_INDEX,
"The physical mouse as recognized by RetroArch."
Expand Down
21 changes: 17 additions & 4 deletions menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -8441,8 +8441,21 @@ static void get_string_representation_of_abs_device(
rarch_setting_t *setting, char *s, size_t len)
{
settings_t *settings = config_get_ptr();
unsigned index=settings->uints.input_sensor_ids[setting->index_offset][setting->retropad_sensor_index];
snprintf(s, len, msg_hash_to_str(MENU_ENUM_LABEL_INPUT_ABS_SOURCE),index);
unsigned index=settings->uints.input_sensor_ids
[setting->index_offset]
[setting->retropad_sensor_index];


snprintf(
s,len,
msg_hash_to_str(
(index%2)?MENU_ENUM_LABEL_INPUT_ABS_SOURCE_INVERTED:MENU_ENUM_LABEL_INPUT_ABS_SOURCE
),
index/2
);



}
static void read_handler_audio_rate_control_delta(rarch_setting_t *setting)
{
Expand Down Expand Up @@ -10109,7 +10122,7 @@ static bool setting_append_list_input_player_options(
(*list)[list_info->index - 1].action_select = &setting_action_right_input_mouse_index;
(*list)[list_info->index - 1].action_ok = &setting_action_ok_uint;
(*list)[list_info->index - 1].get_string_representation = &get_string_representation_of_abs_device;
menu_settings_list_current_add_range(list, list_info, 0, RETROPAD_RETRO_SENSOR_LAST - 1, 1, true, true);
menu_settings_list_current_add_range(list, list_info, 0, (RETROPAD_RETRO_SENSOR_LAST*2) - 1, 1, true, true);
MENU_SETTINGS_LIST_CURRENT_ADD_ENUM_IDX_PTR(list, list_info,
(enum msg_hash_enums)(MENU_ENUM_LABEL_INPUT_SENSOR_MAPPING + j));
}
Expand All @@ -10121,7 +10134,7 @@ static bool setting_append_list_input_player_options(
snprintf(
label,
NAME_MAX_LENGTH,
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_ABS_SOURCE_VALUE),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_ABS_SOURCE_AUTO),
j
);
snprintf(name,NAME_MAX_LENGTH, "tmp name sensor poll %d", j);
Expand Down
3 changes: 2 additions & 1 deletion msg_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,8 @@ enum msg_hash_enums
MENU_ENUM_LABEL_INPUT_SENSOR_ACCELEROMETER_X=
MENU_ENUM_LABEL_INPUT_SENSOR_FIRST,
MENU_ENUM_LABEL_INPUT_ABS_SOURCE,
MENU_ENUM_LABEL_INPUT_ABS_SOURCE_VALUE,
MENU_ENUM_LABEL_INPUT_ABS_SOURCE_INVERTED,
MENU_ENUM_LABEL_INPUT_ABS_SOURCE_AUTO,
MENU_ENUM_LABEL_INPUT_SENSOR_ACCELEROMETER_Y,
MENU_ENUM_LABEL_INPUT_SENSOR_ACCELEROMETER_Z,
MENU_ENUM_LABEL_INPUT_SENSOR_GYROSCOPE_X,
Expand Down

0 comments on commit 9730936

Please sign in to comment.