USB: introduce back linux support

This commit is contained in:
GovanifY 2020-11-04 13:43:32 +01:00 committed by refractionpcsx2
parent 30235f49db
commit 92be17986f
9 changed files with 82 additions and 2 deletions

View File

@ -136,15 +136,24 @@ void SaveConfig()
SaveSetting("MAIN", "log", conf.Log); SaveSetting("MAIN", "log", conf.Log);
#endif #endif
#ifdef _WIN32
SaveSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, str_to_wstr(conf.Port[0])); SaveSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, str_to_wstr(conf.Port[0]));
SaveSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, str_to_wstr(conf.Port[1])); SaveSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, str_to_wstr(conf.Port[1]));
#else
SaveSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, conf.Port[0]);
SaveSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, conf.Port[1]);
#endif
SaveSetting(nullptr, 0, N_DEVICE_PORT, N_WHEEL_TYPE, conf.WheelType[0]); SaveSetting(nullptr, 0, N_DEVICE_PORT, N_WHEEL_TYPE, conf.WheelType[0]);
SaveSetting(nullptr, 1, N_DEVICE_PORT, N_WHEEL_TYPE, conf.WheelType[1]); SaveSetting(nullptr, 1, N_DEVICE_PORT, N_WHEEL_TYPE, conf.WheelType[1]);
for (auto& k : changedAPIs) for (auto& k : changedAPIs)
{ {
#ifdef _WIN32
SaveSetting(nullptr, k.first.first, k.first.second, N_DEVICE_API, str_to_wstr(k.second)); SaveSetting(nullptr, k.first.first, k.first.second, N_DEVICE_API, str_to_wstr(k.second));
#else
SaveSetting(nullptr, k.first.first, k.first.second, N_DEVICE_API, k.second);
#endif
} }
#ifdef _WIN32 #ifdef _WIN32
@ -169,8 +178,13 @@ void LoadConfig()
LoadSetting("MAIN", "log", conf.Log); LoadSetting("MAIN", "log", conf.Log);
#endif #endif
#ifdef _WIN32
LoadSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, str_to_wstr(conf.Port[0])); LoadSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, str_to_wstr(conf.Port[0]));
LoadSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, str_to_wstr(conf.Port[1])); LoadSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, str_to_wstr(conf.Port[1]));
#else
LoadSetting(nullptr, 0, N_DEVICE_PORT, N_DEVICE, conf.Port[0]);
LoadSetting(nullptr, 1, N_DEVICE_PORT, N_DEVICE, conf.Port[1]);
#endif
LoadSetting(nullptr, 0, N_DEVICE_PORT, N_WHEEL_TYPE, conf.WheelType[0]); LoadSetting(nullptr, 0, N_DEVICE_PORT, N_WHEEL_TYPE, conf.WheelType[0]);
LoadSetting(nullptr, 1, N_DEVICE_PORT, N_WHEEL_TYPE, conf.WheelType[1]); LoadSetting(nullptr, 1, N_DEVICE_PORT, N_WHEEL_TYPE, conf.WheelType[1]);
@ -180,7 +194,11 @@ void LoadConfig()
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
std::string api; std::string api;
#ifdef _WIN32
LoadSetting(nullptr, i, conf.Port[i], N_DEVICE_API, str_to_wstr(api)); LoadSetting(nullptr, i, conf.Port[i], N_DEVICE_API, str_to_wstr(api));
#else
LoadSetting(nullptr, i, conf.Port[i], N_DEVICE_API, api);
#endif
auto dev = instance.Device(conf.Port[i]); auto dev = instance.Device(conf.Port[i]);
if (dev) if (dev)

View File

@ -516,7 +516,11 @@ namespace usb_eyetoy
{ {
VideoDevice* videodev = nullptr; VideoDevice* videodev = nullptr;
std::string varApi; std::string varApi;
#ifdef _WIN32
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi)); LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi));
#else
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, varApi);
#endif
VideoDeviceProxyBase* proxy = RegisterVideoDevice::instance().Proxy(varApi); VideoDeviceProxyBase* proxy = RegisterVideoDevice::instance().Proxy(varApi);
if (!proxy) if (!proxy)
{ {

View File

@ -730,7 +730,11 @@ namespace usb_hid
UsbHIDState* s; UsbHIDState* s;
std::string varApi; std::string varApi;
#ifdef _WIN32
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi)); LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi));
#else
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, varApi);
#endif
UsbHIDProxyBase* proxy = RegisterUsbHID::instance().Proxy(varApi); UsbHIDProxyBase* proxy = RegisterUsbHID::instance().Proxy(varApi);
if (!proxy) if (!proxy)
{ {
@ -821,7 +825,11 @@ namespace usb_hid
UsbHIDState* s; UsbHIDState* s;
std::string varApi; std::string varApi;
#ifdef _WIN32
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi)); LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi));
#else
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, varApi);
#endif
UsbHIDProxyBase* proxy = RegisterUsbHID::instance().Proxy(varApi); UsbHIDProxyBase* proxy = RegisterUsbHID::instance().Proxy(varApi);
if (!proxy) if (!proxy)
{ {
@ -893,7 +901,11 @@ namespace usb_hid
UsbHIDState* s; UsbHIDState* s;
std::string varApi; std::string varApi;
#ifdef _WIN32
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi)); LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi));
#else
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, varApi);
#endif
UsbHIDProxyBase* proxy = RegisterUsbHID::instance().Proxy(varApi); UsbHIDProxyBase* proxy = RegisterUsbHID::instance().Proxy(varApi);
if (!proxy) if (!proxy)
{ {

View File

@ -986,7 +986,11 @@ namespace usb_mic
USBDevice* HeadsetDevice::CreateDevice(int port) USBDevice* HeadsetDevice::CreateDevice(int port)
{ {
std::string api; std::string api;
#ifdef _WIN32
if (!LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(api))) if (!LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(api)))
#else
if (!LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, api))
#endif
return nullptr; return nullptr;
return HeadsetDevice::CreateDevice(port, api); return HeadsetDevice::CreateDevice(port, api);
} }

View File

@ -243,7 +243,11 @@ namespace usb_mic
USBDevice* LogitechMicDevice::CreateDevice(int port) USBDevice* LogitechMicDevice::CreateDevice(int port)
{ {
std::string api; std::string api;
#ifdef _WIN32
if (!LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(api))) if (!LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(api)))
#else
if (!LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, api))
#endif
return nullptr; return nullptr;
USBDevice* dev = SingstarDevice::CreateDevice(port, api); USBDevice* dev = SingstarDevice::CreateDevice(port, api);

View File

@ -778,7 +778,11 @@ namespace usb_mic
USBDevice* SingstarDevice::CreateDevice(int port) USBDevice* SingstarDevice::CreateDevice(int port)
{ {
std::string api; std::string api;
#ifdef _WIN32
LoadSetting(nullptr, port, SingstarDevice::TypeName(), N_DEVICE_API, str_to_wstr(api)); LoadSetting(nullptr, port, SingstarDevice::TypeName(), N_DEVICE_API, str_to_wstr(api));
#else
LoadSetting(nullptr, port, SingstarDevice::TypeName(), N_DEVICE_API, api);
#endif
return SingstarDevice::CreateDevice(port, api); return SingstarDevice::CreateDevice(port, api);
} }
USBDevice* SingstarDevice::CreateDevice(int port, const std::string& api) USBDevice* SingstarDevice::CreateDevice(int port, const std::string& api)

View File

@ -1228,7 +1228,11 @@ namespace usb_pad
ClearSection(section); ClearSection(section);
SaveSetting(section, _T("INVERTFORCES"), INVERTFORCES[port]); SaveSetting(section, _T("INVERTFORCES"), INVERTFORCES[port]);
#ifdef _WIN32
SaveSetting(section, _T("# CONTROL n"), str_to_wstr("GUID,MAPPING TYPE,MAPPED TO,INVERTED,HALF,LINEAR,OFFSET,DEADZONE")); SaveSetting(section, _T("# CONTROL n"), str_to_wstr("GUID,MAPPING TYPE,MAPPED TO,INVERTED,HALF,LINEAR,OFFSET,DEADZONE"));
#else
SaveSetting(section, _T("# CONTROL n"), "GUID,MAPPING TYPE,MAPPED TO,INVERTED,HALF,LINEAR,OFFSET,DEADZONE");
#endif
for (auto& control : g_Controls[port]) for (auto& control : g_Controls[port])
{ {
@ -1250,7 +1254,11 @@ namespace usb_pad
} }
swprintf_s(text, _T("CONTROL %i"), cid); swprintf_s(text, _T("CONTROL %i"), cid);
#ifdef _WIN32
SaveSetting(section, text, str_to_wstr(ss.str())); SaveSetting(section, text, str_to_wstr(ss.str()));
#else
SaveSetting(section, text, ss.str());
#endif
} }
SaveSetting(section, _T("GAINZ"), GAINZ[port][0]); SaveSetting(section, _T("GAINZ"), GAINZ[port][0]);
@ -1285,7 +1293,11 @@ namespace usb_pad
std::stringstream ss; std::stringstream ss;
swprintf_s(text, _T("CONTROL %i"), cid); swprintf_s(text, _T("CONTROL %i"), cid);
#ifdef _WIN32
if (!LoadSetting(section, text, str_to_wstr(control))) if (!LoadSetting(section, text, str_to_wstr(control)))
#else
if (!LoadSetting(section, text, control))
#endif
continue; continue;
ss << control; ss << control;

View File

@ -539,7 +539,11 @@ namespace usb_pad
USBDevice* PadDevice::CreateDevice(int port) USBDevice* PadDevice::CreateDevice(int port)
{ {
std::string varApi; std::string varApi;
#ifdef _WIN32
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi)); LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi));
#else
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, varApi);
#endif
PadProxyBase* proxy = RegisterPad::instance().Proxy(varApi); PadProxyBase* proxy = RegisterPad::instance().Proxy(varApi);
if (!proxy) if (!proxy)
{ {
@ -663,7 +667,11 @@ namespace usb_pad
USBDevice* RBDrumKitDevice::CreateDevice(int port) USBDevice* RBDrumKitDevice::CreateDevice(int port)
{ {
std::string varApi; std::string varApi;
#ifdef _WIN32
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi)); LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi));
#else
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, varApi);
#endif
PadProxyBase* proxy = RegisterPad::instance().Proxy(varApi); PadProxyBase* proxy = RegisterPad::instance().Proxy(varApi);
if (!proxy) if (!proxy)
{ {
@ -732,7 +740,11 @@ namespace usb_pad
USBDevice* BuzzDevice::CreateDevice(int port) USBDevice* BuzzDevice::CreateDevice(int port)
{ {
std::string varApi; std::string varApi;
#ifdef _WIN32
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi)); LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi));
#else
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, varApi);
#endif
PadProxyBase* proxy = RegisterPad::instance().Proxy(varApi); PadProxyBase* proxy = RegisterPad::instance().Proxy(varApi);
if (!proxy) if (!proxy)
{ {

View File

@ -392,7 +392,11 @@ namespace usb_pad
USBDevice* SeamicDevice::CreateDevice(int port) USBDevice* SeamicDevice::CreateDevice(int port)
{ {
std::string varApi; std::string varApi;
#ifdef _WIN32
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi)); LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, str_to_wstr(varApi));
#else
LoadSetting(nullptr, port, TypeName(), N_DEVICE_API, varApi);
#endif
PadProxyBase* proxy = RegisterPad::instance().Proxy(varApi); PadProxyBase* proxy = RegisterPad::instance().Proxy(varApi);
if (!proxy) if (!proxy)
{ {
@ -401,10 +405,16 @@ namespace usb_pad
return NULL; return NULL;
} }
USB_LOG("usb-pad: creating device '%s' on port %d with %s\n", TypeName(), port, str_to_wstr(varApi));
std::string api; std::string api;
#ifdef _WIN32
USB_LOG("usb-pad: creating device '%s' on port %d with %s\n", TypeName(), port, str_to_wstr(varApi));
if (!LoadSetting(nullptr, port, usb_mic::SingstarDevice::TypeName(), N_DEVICE_API, str_to_wstr(api))) if (!LoadSetting(nullptr, port, usb_mic::SingstarDevice::TypeName(), N_DEVICE_API, str_to_wstr(api)))
#else
USB_LOG("usb-pad: creating device '%s' on port %d with %s\n", TypeName(), port, varApi.c_str());
if (!LoadSetting(nullptr, port, usb_mic::SingstarDevice::TypeName(), N_DEVICE_API, api))
#endif
return nullptr; return nullptr;
USBDevice* mic = usb_mic::SingstarDevice::CreateDevice(port, api); USBDevice* mic = usb_mic::SingstarDevice::CreateDevice(port, api);