OpenDingux: Optimise rumble interface

This commit is contained in:
jdgleaver 2020-11-18 17:21:38 +00:00
parent c8f92d2247
commit de146545af
2 changed files with 16 additions and 16 deletions

View File

@ -70,9 +70,9 @@ typedef struct
#if defined(HAVE_LIBSHAKE) #if defined(HAVE_LIBSHAKE)
dingux_joypad_rumble_t rumble; dingux_joypad_rumble_t rumble;
#endif #endif
unsigned num_axes;
uint16_t pad_state; uint16_t pad_state;
int16_t analog_state[2][2]; int16_t analog_state[2][2];
unsigned num_axes;
bool connected; bool connected;
bool menu_toggle; bool menu_toggle;
} dingux_joypad_t; } dingux_joypad_t;
@ -171,8 +171,6 @@ static bool sdl_dingux_rumble_update(Shake_Device *device,
dingux_joypad_rumble_effect_t *effect, dingux_joypad_rumble_effect_t *effect,
uint16_t strength, uint16_t max_strength) uint16_t strength, uint16_t max_strength)
{ {
int id;
/* If strength is zero, halt rumble effect */ /* If strength is zero, halt rumble effect */
if (strength == 0) if (strength == 0)
{ {
@ -180,8 +178,7 @@ static bool sdl_dingux_rumble_update(Shake_Device *device,
{ {
if (Shake_Stop(device, effect->id) == SHAKE_OK) if (Shake_Stop(device, effect->id) == SHAKE_OK)
{ {
effect->active = false; effect->active = false;
effect->strength = 0;
return true; return true;
} }
else else
@ -191,20 +188,23 @@ static bool sdl_dingux_rumble_update(Shake_Device *device,
return true; return true;
} }
/* If strength is unchanged, do nothing */ /* If strength has changed, update effect */
if (strength == effect->strength) if (strength != effect->strength)
return true; {
int id;
/* Strength has changed - update effect */ effect->effect.id = effect->id;
effect->effect.id = effect->id; effect->effect.u.periodic.magnitude = (max_strength * strength) / 0xFFFF;
effect->effect.u.periodic.magnitude = (max_strength * strength) / 0xFFFF; id = Shake_UploadEffect(device, &effect->effect);
id = Shake_UploadEffect(device, &effect->effect);
if (id == SHAKE_ERROR) if (id == SHAKE_ERROR)
return false; return false;
effect->id = id; effect->id = id;
effect->strength = strength;
}
/* If effect is currently idle, activate it */
if (!effect->active) if (!effect->active)
{ {
if (Shake_Play(device, effect->id) == SHAKE_OK) if (Shake_Play(device, effect->id) == SHAKE_OK)

View File

@ -11807,7 +11807,7 @@ static bool setting_append_list(
general_write_handler, general_write_handler,
general_read_handler); general_read_handler);
(*list)[list_info->index - 1].ui_type = ST_UI_TYPE_UINT_COMBOBOX; (*list)[list_info->index - 1].ui_type = ST_UI_TYPE_UINT_COMBOBOX;
(*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint_special;
menu_settings_list_current_add_range(list, list_info, 0, 100, 5, true, true); menu_settings_list_current_add_range(list, list_info, 0, 100, 5, true, true);
#endif #endif
CONFIG_UINT( CONFIG_UINT(