|
|
@@ -106,12 +106,20 @@ void IZ_JoystickHandleHatEvents(IZ_Action* action, SDL_Event e) { |
|
|
|
void IZ_JoystickHandleButtonEvents(IZ_JoystickState* state, IZ_Action* action, SDL_Event e) { |
|
|
|
u8 control_index; |
|
|
|
|
|
|
|
|
|
|
|
SDL_JoystickGUID joystick_guid = SDL_JoystickGetGUID(SDL_JoystickFromInstanceID(e.jbutton.which)); |
|
|
|
bool is_valid_event = false; |
|
|
|
for (u8 zz = 0; zz < 16; zz += 1) { |
|
|
|
printf("%02x", joystick_guid.data[zz]); |
|
|
|
is_valid_event |= joystick_guid.data[zz] != 0; |
|
|
|
} |
|
|
|
if (!is_valid_event) { |
|
|
|
return; |
|
|
|
} |
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
// printf("button event from guid: "); |
|
|
|
// for (u8 zz = 0; zz < 16; zz += 1) { |
|
|
|
// printf("%02x", joystick_guid.data[zz]); |
|
|
|
// } |
|
|
|
// printf("\n"); |
|
|
|
|
|
|
|
for (control_index = 4; control_index < IZ_CONTROLS; control_index += 1) { |
|
|
|
u8 normalized_button = e.jbutton.button; |
|
|
@@ -218,8 +226,8 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) { |
|
|
|
}; |
|
|
|
|
|
|
|
config_items[base_index + 2] = (IZ_ConfigItem) { |
|
|
|
IZ_CONFIG_TYPE_STRING, |
|
|
|
sizeof(u16), |
|
|
|
IZ_CONFIG_TYPE_GUID, |
|
|
|
sizeof(SDL_GUID), |
|
|
|
main_section_name, |
|
|
|
"GUID", |
|
|
|
NULL, |
|
|
@@ -269,18 +277,43 @@ IZ_ProcedureResult IZ_JoystickInitializeConfig(IZ_JoystickState(* state)[IZ_PLAY |
|
|
|
|
|
|
|
IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) { |
|
|
|
SDL_memcpy(state, &IZ_JOYSTICK_DEFAULT_STATE, sizeof(IZ_JoystickState) * IZ_PLAYERS); |
|
|
|
|
|
|
|
// TODO query this file from the internet? |
|
|
|
SDL_GameControllerAddMappingsFromFile("assets/gamecontrollerdb.txt"); |
|
|
|
u8 player_index; |
|
|
|
|
|
|
|
if (IZ_JoystickInitializeConfig(state, config_path, argc, argv) < 0) { |
|
|
|
return -2; |
|
|
|
} |
|
|
|
|
|
|
|
SDL_GameControllerAddMappingsFromFile("assets/gamecontrollerdb.txt"); |
|
|
|
u8 player_index; |
|
|
|
u8 joysticks_count = SDL_NumJoysticks(); |
|
|
|
for (player_index = 0; player_index < joysticks_count; player_index += 1) { |
|
|
|
if (player_index >= IZ_PLAYERS) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
(*state)[player_index].device = SDL_JoystickOpen(state[player_index]->config.device_id); |
|
|
|
if (!(*state)[player_index].device) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
(*state)[player_index].config.device_id = SDL_JoystickInstanceID((*state)[player_index].device); |
|
|
|
SDL_GUID joystick_guid = SDL_JoystickGetGUID((*state)[player_index].device); |
|
|
|
memcpy(&(*state)[player_index].config.guid, &joystick_guid, sizeof(SDL_GUID)); |
|
|
|
//(*state)[player_index].config.guid = joystick_guid; |
|
|
|
|
|
|
|
printf("initialize event from guid: "); |
|
|
|
for (u8 zz = 0; zz < 16; zz += 1) { |
|
|
|
printf("%02x", (*state)[player_index].config.guid.data[zz]); |
|
|
|
} |
|
|
|
printf("\n"); |
|
|
|
} |
|
|
|
|
|
|
|
// Post config (after joystick GUIDs have been queried), this is unique to joysticks since they can be plugged in any |
|
|
|
// time. |
|
|
|
IZ_ConfigSaveResult post_config_save_result = IZ_ConfigSave(joystick_config_items, config_path); |
|
|
|
if (post_config_save_result < 0) { |
|
|
|
return -3; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|