controller vendor/product/version IDs

This commit is contained in:
Noel Berry 2020-12-23 16:58:04 -08:00
parent eda7cc8398
commit e6f27857b4
4 changed files with 24 additions and 6 deletions

View File

@ -37,7 +37,7 @@ namespace Blah
// Call this when a Controller is connected. Note that the Name parameter must be kept valid
// until on_controller_disconnect is called with the same index.
void on_controller_connect(int index, const char* name, int isGamepad, int buttonCount, int axisCount);
void on_controller_connect(int index, const char* name, int isGamepad, int buttonCount, int axisCount, uint16_t vendor, uint16_t product, uint16_t version);
// Call this when a controller is disconnected
void on_controller_disconnect(int index);

View File

@ -30,9 +30,9 @@ using namespace Blah;
namespace
{
SDL_Window* window = nullptr;
SDL_Window* window = nullptr;
SDL_Joystick* joysticks[Blah::Input::max_controllers];
SDL_GameController* gamepads[Blah::Input::max_controllers];
SDL_GameController* gamepads[Blah::Input::max_controllers];
char* basePath = nullptr;
char* userPath = nullptr;
bool displayed = false;
@ -235,8 +235,11 @@ void PlatformBackend::frame()
const char* name = SDL_JoystickName(ptr);
int button_count = SDL_JoystickNumButtons(ptr);
int axis_count = SDL_JoystickNumAxes(ptr);
uint16_t vendor = SDL_JoystickGetVendor(ptr);
uint16_t product = SDL_JoystickGetProduct(ptr);
uint16_t version = SDL_JoystickGetProductVersion(ptr);
InputBackend::on_controller_connect(index, name, 0, button_count, axis_count);
InputBackend::on_controller_connect(index, name, 0, button_count, axis_count, vendor, product, version);
}
}
else if (event.type == SDL_JOYDEVICEREMOVED)
@ -280,7 +283,11 @@ void PlatformBackend::frame()
Sint32 index = event.cdevice.which;
SDL_GameController* ptr = gamepads[index] = SDL_GameControllerOpen(index);
const char* name = SDL_GameControllerName(ptr);
InputBackend::on_controller_connect(index, name, 1, 15, 6);
uint16_t vendor = SDL_GameControllerGetVendor(ptr);
uint16_t product = SDL_GameControllerGetProduct(ptr);
uint16_t version = SDL_GameControllerGetProductVersion(ptr);
InputBackend::on_controller_connect(index, name, 1, 15, 6, vendor, product, version);
}
else if (event.type == SDL_CONTROLLERDEVICEREMOVED)
{

View File

@ -138,7 +138,7 @@ void InputBackend::on_text_utf8(const char* text)
strncat(g_next_state.keyboard.text, text, Blah::Input::max_text_input);
}
void InputBackend::on_controller_connect(int index, const char* name, int is_gamepad, int button_count, int axis_count)
void InputBackend::on_controller_connect(int index, const char* name, int is_gamepad, int button_count, int axis_count, uint16_t vendor, uint16_t product, uint16_t version)
{
if (index < Blah::Input::max_controllers)
{
@ -149,6 +149,9 @@ void InputBackend::on_controller_connect(int index, const char* name, int is_gam
controller->is_gamepad = is_gamepad;
controller->button_count = button_count;
controller->axis_count = axis_count;
controller->vendor = vendor;
controller->product = product;
controller->version = version;
}
}

View File

@ -298,6 +298,14 @@ namespace Blah
// Timestamp, in milliseconds, since each axis last had a value set
uint64_t axis_timestamp[Input::max_controller_axis];
// The USB Vendor ID
uint16_t vendor;
// The USB Product ID
uint16_t product;
// the Product Version
uint16_t version;
};
struct KeyboardState