|
18 | 18 |
|
19 | 19 | LOG_CHANNEL(hid_log, "HID"); |
20 | 20 |
|
| 21 | +#ifdef ANDROID |
| 22 | +std::vector<int> g_android_usb_devices; |
| 23 | +std::mutex g_android_usb_devices_mutex; |
| 24 | +#endif |
| 25 | + |
21 | 26 | struct hid_instance |
22 | 27 | { |
23 | 28 | public: |
@@ -56,9 +61,9 @@ struct hid_instance |
56 | 61 |
|
57 | 62 | hid_log.notice("Initializing HIDAPI ..."); |
58 | 63 |
|
59 | | - if (hid_init() != 0) |
| 64 | + if (int errorCode = hid_init(); errorCode != 0) |
60 | 65 | { |
61 | | - hid_log.fatal("hid_init error"); |
| 66 | + hid_log.fatal("hid_init error %d", errorCode); |
62 | 67 | return false; |
63 | 68 | } |
64 | 69 |
|
@@ -179,9 +184,18 @@ template <class Device> |
179 | 184 | void hid_pad_handler<Device>::enumerate_devices() |
180 | 185 | { |
181 | 186 | Timer timer; |
182 | | - std::set<std::string> device_paths; |
183 | | - std::map<std::string, std::wstring> serials; |
| 187 | + std::set<hid_enumerated_device_type> device_paths; |
| 188 | + std::map<hid_enumerated_device_type, std::wstring> serials; |
184 | 189 |
|
| 190 | +#ifdef ANDROID |
| 191 | + { |
| 192 | + std::lock_guard lock(g_android_usb_devices_mutex); |
| 193 | + for (auto device : g_android_usb_devices) |
| 194 | + { |
| 195 | + device_paths.insert(device); |
| 196 | + } |
| 197 | + } |
| 198 | +#else |
185 | 199 | for (const auto& [vid, pid] : m_ids) |
186 | 200 | { |
187 | 201 | hid_device_info* dev_info = hid_enumerate(vid, pid); |
@@ -209,6 +223,7 @@ void hid_pad_handler<Device>::enumerate_devices() |
209 | 223 | } |
210 | 224 | hid_free_enumeration(head); |
211 | 225 | } |
| 226 | +#endif |
212 | 227 | hid_log.notice("%s enumeration found %d devices (%f ms)", m_type, device_paths.size(), timer.GetElapsedTimeInMilliSec()); |
213 | 228 |
|
214 | 229 | std::lock_guard lock(m_enumeration_mutex); |
@@ -254,7 +269,7 @@ void hid_pad_handler<Device>::update_devices() |
254 | 269 | // Scrap devices that are not in the new list |
255 | 270 | for (auto& controller : m_controllers) |
256 | 271 | { |
257 | | - if (controller.second && !controller.second->path.empty() && !m_new_enumerated_devices.contains(controller.second->path)) |
| 272 | + if (controller.second && controller.second->path != hid_enumerated_device_default && !m_new_enumerated_devices.contains(controller.second->path)) |
258 | 273 | { |
259 | 274 | controller.second->close(); |
260 | 275 | cfg_pad* config = controller.second->config; |
@@ -284,7 +299,11 @@ void hid_pad_handler<Device>::update_devices() |
284 | 299 | } |
285 | 300 | #endif |
286 | 301 |
|
287 | | - if (hid_device* dev = hid_open_path(path.c_str())) |
| 302 | +#ifdef ANDROID |
| 303 | + if (hid_device* dev = hid_libusb_wrap_sys_device(path, -1)) |
| 304 | +#else |
| 305 | + if (hid_device* dev = hid_open_path(path)) |
| 306 | +#endif |
288 | 307 | { |
289 | 308 | if (const hid_device_info* info = hid_get_device_info(dev)) |
290 | 309 | { |
|
0 commit comments