MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / findAndAttachDevice_

Method findAndAttachDevice_

source/MRViewer/MRSpaceMouseHandlerHidapi.cpp:57–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57bool HandlerHidapi::findAndAttachDevice_( bool verbose )
58{
59 const static int HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER = 8; //Multi-axis Controller
60 const static int HID_USAGE_PAGE_GENERIC = 1; //Generic Desktop Controls
61 assert( !device_ );
62 for ( const auto& [vendorId, supportedDevicesId] : cVendor2Device )
63 {
64 // search through supported vendors
65 hid_device_info* localDevicesIt = hid_enumerate( vendorId, 0x0 ); // hid_enumerate( 0x0, 0x0 ) to enumerate all devices of all vendors
66 while ( localDevicesIt && ( !device_ || verbose ) )
67 {
68 if ( verbose )
69 {
70 spdlog::info( "HID API device found: {:04x}:{:04x}, path={}, usage={}, usage_page={}, name={}:{}",
71 vendorId, localDevicesIt->product_id, localDevicesIt->path, localDevicesIt->usage, localDevicesIt->usage_page,
72 wideToUtf8( localDevicesIt->manufacturer_string ), wideToUtf8( localDevicesIt->product_string ) );
73 if ( localDevicesIt->usage == HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER && localDevicesIt->usage_page == HID_USAGE_PAGE_GENERIC )
74 TelemetrySignal( fmt::format( "HID API device {:04x}:{:04x} found: {}:{}", vendorId, localDevicesIt->product_id,
75 wideToUtf8( localDevicesIt->manufacturer_string ), wideToUtf8( localDevicesIt->product_string ) ) );
76 }
77 for ( ProductId deviceId : supportedDevicesId )
78 {
79 if ( !device_ && deviceId == localDevicesIt->product_id && localDevicesIt->usage == HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER && localDevicesIt->usage_page == HID_USAGE_PAGE_GENERIC )
80 {
81 device_ = hid_open_path( localDevicesIt->path );
82 if ( device_ )
83 {
84 numMsg_ = 0;
85 spdlog::info( "SpaceMouse connected: {:04x}:{:04x}, path={}", vendorId, deviceId, localDevicesIt->path );
86 TelemetrySignal( fmt::format( "HID API device {:04x}:{:04x} opened", vendorId, localDevicesIt->product_id ) );
87 smDevice_.resetDevice( vendorId, deviceId );
88 if ( !verbose )
89 break;
90 }
91 else if ( verbose )
92 {
93 spdlog::error( "HID API device ({:04x}:{:04x}, path={}) open error: {}",
94 vendorId, deviceId, localDevicesIt->path, wideToUtf8( hid_error( nullptr ) ) );
95 TelemetrySignal( fmt::format( "HID API device {:04x}:{:04x} open failed", vendorId, localDevicesIt->product_id ) );
96 }
97 }
98 }
99 localDevicesIt = localDevicesIt->next;
100 }
101 hid_free_enumeration( localDevicesIt );
102 }
103 return (bool)device_;
104}
105
106void HandlerHidapi::handle()
107{

Callers

nothing calls this directly

Calls 2

wideToUtf8Function · 0.85
resetDeviceMethod · 0.45

Tested by

no test coverage detected