Refresh the device list.
Re-enumerates available devices. May trigger device callbacks for newly connected or disconnected devices.
132{
134 return 0;
135 }
136
138
139 std::unordered_set<std::string> previous_paths;
141 previous_paths.insert(info.path);
142 }
143
144 std::unordered_set<std::string> current_paths;
145
146 hid_device_info* devs = hid_enumerate(0x0, 0x0);
147 hid_device_info* cur = devs;
148
149 while (cur) {
152 cur->usage_page, cur->usage)) {
153 cur = cur->next;
154 continue;
155 }
156 }
157
158 std::string path(cur->path);
159 current_paths.insert(path);
160
161 bool is_new = (previous_paths.find(path) == previous_paths.end());
162
164
165 HIDDeviceInfoExt info;
166 info.id = dev_id;
168 info.vendor_id = cur->vendor_id;
169 info.product_id = cur->product_id;
170 info.usage_page = cur->usage_page;
171 info.usage = cur->usage;
172 info.release_number = cur->release_number;
173 info.interface_number = cur->interface_number;
174 info.path = path;
175 info.is_connected = true;
176
177 if (cur->manufacturer_string) {
178 std::wstring ws(cur->manufacturer_string);
179 info.manufacturer.resize(ws.length());
180 std::ranges::transform(ws, info.manufacturer.begin(), [](wchar_t c) { return static_cast<char>(c); });
181 }
182 if (cur->product_string) {
183 std::wstring ws(cur->product_string);
184 info.name.resize(ws.length());
185 std::ranges::transform(ws, info.name.begin(), [](wchar_t c) { return static_cast<char>(c); });
186 } else {
187 info.name = "HID Device " + std::to_string(cur->vendor_id) + ":" + std::to_string(cur->product_id);
188 }
189 if (cur->serial_number) {
190 std::wstring ws(cur->serial_number);
191 info.serial_number.resize(ws.length());
192 std::ranges::transform(ws, info.serial_number.begin(), [](wchar_t c) { return static_cast<char>(c); });
193 }
194
196
197 if (is_new) {
199 "HID device found: {} (VID:{:04X} PID:{:04X})",
200 info.name, info.vendor_id, info.product_id);
202 }
203
204 cur = cur->next;
205 }
206
207 hid_free_enumeration(devs);
208
210 if (current_paths.find(it->second.path) == current_paths.end()) {
212 "HID device disconnected: {}", it->second.name);
213
216 if (open_it->second->handle) {
217 hid_close(open_it->second->handle);
218 }
220 }
221
224 } else {
225 ++it;
226 }
227 }
228
230}
#define MF_INFO(comp, ctx,...)
bool matches_any_filter(uint16_t vid, uint16_t pid, uint16_t usage_page, uint16_t usage) const
std::atomic< bool > m_initialized
std::mutex m_devices_mutex
uint32_t find_or_assign_device_id(const std::string &path)
std::unordered_map< uint32_t, HIDDeviceInfoExt > m_enumerated_devices
void notify_device_change(const InputDeviceInfo &info, bool connected)
std::unordered_map< uint32_t, std::shared_ptr< HIDDeviceState > > m_open_devices
@ HID
Generic HID devices (game controllers, custom hardware)
@ InputBackend
Input device backend (HID, MIDI, OSC)
@ Core
Core engine, backend, subsystems.
std::vector< HIDDeviceFilter > filters
Device filters (empty = all devices)