Skip to content

Commit 08d74d3

Browse files
authored
Merge pull request #797 from cmitu/sdl-vendored-input
input: export additional info for joysticks inputs
2 parents 9afa234 + 9473f19 commit 08d74d3

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

es-core/src/InputConfig.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "InputConfig.h"
22

33
#include "Log.h"
4+
#include "utils/StringUtil.h"
45
#include <pugixml/src/pugixml.hpp>
56

67
//some util functions
@@ -39,19 +40,10 @@ InputType stringToInputType(const std::string& type)
3940
}
4041

4142

42-
std::string toLower(std::string str)
43-
{
44-
for(unsigned int i = 0; i < str.length(); i++)
45-
{
46-
str[i] = (char)tolower(str[i]);
47-
}
48-
49-
return str;
50-
}
51-
//end util functions
52-
5343
InputConfig::InputConfig(int deviceId, const std::string& deviceName, const std::string& deviceGUID) : mDeviceId(deviceId), mDeviceName(deviceName), mDeviceGUID(deviceGUID)
5444
{
45+
mVendorId = 0;
46+
mProductId = 0;
5547
}
5648

5749
void InputConfig::clear()
@@ -66,19 +58,19 @@ bool InputConfig::isConfigured()
6658

6759
void InputConfig::mapInput(const std::string& name, Input input)
6860
{
69-
mNameMap[toLower(name)] = input;
61+
mNameMap[Utils::String::toLower(name)] = input;
7062
}
7163

7264
void InputConfig::unmapInput(const std::string& name)
7365
{
74-
auto it = mNameMap.find(toLower(name));
66+
auto it = mNameMap.find(Utils::String::toLower(name));
7567
if(it != mNameMap.cend())
7668
mNameMap.erase(it);
7769
}
7870

7971
bool InputConfig::getInputByName(const std::string& name, Input* result)
8072
{
81-
auto it = mNameMap.find(toLower(name));
73+
auto it = mNameMap.find(Utils::String::toLower(name));
8274
if(it != mNameMap.cend())
8375
{
8476
*result = it->second;
@@ -188,7 +180,7 @@ void InputConfig::loadFromXML(pugi::xml_node& node)
188180
if(value == 0)
189181
LOG(LogWarning) << "WARNING: InputConfig value is 0 for " << type << " " << id << "!\n";
190182

191-
mNameMap[toLower(name)] = Input(mDeviceId, typeEnum, id, value, true);
183+
mNameMap[Utils::String::toLower(name)] = Input(mDeviceId, typeEnum, id, value, true);
192184
}
193185
}
194186

@@ -210,6 +202,11 @@ void InputConfig::writeToXML(pugi::xml_node& parent)
210202
{
211203
cfg.append_attribute("type") = "joystick";
212204
cfg.append_attribute("deviceName") = mDeviceName.c_str();
205+
if(mVendorId && mProductId)
206+
{
207+
cfg.append_attribute("vendorId") = mVendorId;
208+
cfg.append_attribute("productId") = mProductId;
209+
}
213210
}
214211

215212
cfg.append_attribute("deviceGUID") = mDeviceGUID.c_str();

es-core/src/InputConfig.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,14 @@ class InputConfig
102102
void mapInput(const std::string& name, Input input);
103103
void unmapInput(const std::string& name); // unmap all Inputs mapped to this name
104104

105-
inline int getDeviceId() const { return mDeviceId; };
105+
inline int getDeviceId() const { return mDeviceId; }
106106
inline const std::string& getDeviceName() { return mDeviceName; }
107107
inline const std::string& getDeviceGUIDString() { return mDeviceGUID; }
108+
inline const unsigned short getVendorId() { return mVendorId; }
109+
inline const unsigned short getProductId() { return mProductId; }
110+
111+
inline void setVendorId(unsigned short vendorID) { mVendorId = vendorID; }
112+
inline void setProductId(unsigned short productID) { mProductId = productID; }
108113

109114
//Returns true if Input is mapped to this name, false otherwise.
110115
bool isMappedTo(const std::string& name, Input input);
@@ -127,6 +132,9 @@ class InputConfig
127132
const int mDeviceId;
128133
const std::string mDeviceName;
129134
const std::string mDeviceGUID;
135+
136+
unsigned short mVendorId;
137+
unsigned short mProductId;
130138
};
131139

132140
#endif // ES_CORE_INPUT_CONFIG_H

es-core/src/InputManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ void InputManager::addJoystickByDeviceIndex(int id)
100100

101101
// create the InputConfig
102102
mInputConfigs[joyId] = new InputConfig(joyId, SDL_JoystickName(joy), guid);
103+
104+
// add Vendor and Product IDs
105+
mInputConfigs[joyId]->setVendorId(SDL_JoystickGetVendor(joy));
106+
mInputConfigs[joyId]->setProductId(SDL_JoystickGetProduct(joy));
107+
103108
if(!loadInputConfig(mInputConfigs[joyId]))
104109
{
105110
LOG(LogInfo) << "Added unconfigured joystick '" << SDL_JoystickName(joy) << "' (GUID: " << guid << ", instance ID: " << joyId << ", device index: " << id << ").";

0 commit comments

Comments
 (0)