@@ -128,6 +128,8 @@ private static int CompareRoleIdx(RoleIdx a, RoleIdx b)
128128 return a . ds . deviceIndex . CompareTo ( b . ds . deviceIndex ) ;
129129 }
130130
131+ private static string shortIdx ( uint i ) { return i == INVALID_DEVICE_INDEX ? "X" : i . ToString ( ) ; }
132+
131133 private VRModule . SubmoduleBase . Collection submodules = new VRModule . SubmoduleBase . Collection (
132134 new ViveHandTrackingSubmodule ( ) ,
133135 new WaveHandTrackingSubmodule ( ) ,
@@ -202,6 +204,7 @@ public sealed override void BeforeRenderUpdate()
202204
203205 foreach ( var device in connectedDevices )
204206 {
207+ if ( ! device . isValid ) { continue ; }
205208 if ( ! indexMap . TryGetIndex ( device , out deviceIndex ) )
206209 {
207210 string deviceName ;
@@ -220,20 +223,19 @@ public sealed override void BeforeRenderUpdate()
220223 deviceName = device . name ;
221224 }
222225
226+ // will not identify tracked hand here, currently all tracked hand should created by submodule
223227 currState . deviceClass = GetDeviceClass ( device . name , device . characteristics ) ;
224228 currState . serialNumber = deviceName + " " + device . serialNumber + " " + ( int ) device . characteristics ;
225229 currState . modelNumber = deviceName + " (" + device . characteristics + ")" ;
226230 currState . renderModelName = deviceName + " (" + device . characteristics + ")" ;
227231
228232 SetupKnownDeviceModel ( currState ) ;
229233
230- Debug . LogFormat ( "[UnityXRModule] Device connected: {0} / {1} / {2} / {3} / {4} / {5} ({6}) " ,
234+ Debug . LogFormat ( "[UnityXRModule] found new InputDevice: [ {0}] nm= \" {2} \" sn= \" {1} \" ch=( {4}) mf= \" {3} \" " ,
231235 currState . deviceIndex ,
232- currState . deviceClass ,
233- currState . deviceModel ,
234- currState . modelNumber ,
235- currState . serialNumber ,
236+ device . serialNumber ,
236237 device . name ,
238+ device . manufacturer ,
237239 device . characteristics ) ;
238240
239241 UpdateNewConnectedInputDevice ( currState , device ) ;
@@ -243,11 +245,9 @@ public sealed override void BeforeRenderUpdate()
243245 EnsureValidDeviceState ( deviceIndex , out prevState , out currState ) ;
244246 }
245247
246- currState . isConnected = true ;
247248 // update device Poses
249+ currState . isConnected = true ;
248250 currState . isPoseValid = GetDeviceFeatureValueOrDefault ( device , CommonUsages . isTracked ) ;
249- if ( ( device . characteristics & InputDeviceCharacteristics . Right ) != 0u ) { rightIndice . Add ( new RoleIdx ( currState ) ) ; }
250- else if ( ( device . characteristics & InputDeviceCharacteristics . Left ) != 0u ) { leftIndice . Add ( new RoleIdx ( currState ) ) ; }
251251
252252 if ( VIUSettings . preferUnityXRPointerPose )
253253 {
@@ -267,11 +267,17 @@ public sealed override void BeforeRenderUpdate()
267267 currDeviceConnected [ deviceIndex ] = true ;
268268 if ( currMaxConnectedIndex < ( int ) deviceIndex ) { currMaxConnectedIndex = ( int ) deviceIndex ; }
269269
270+ if ( currState . deviceClass != VRModuleDeviceClass . Invalid )
271+ {
272+ if ( ( device . characteristics & InputDeviceCharacteristics . Right ) != 0u ) { rightIndice . Add ( new RoleIdx ( currState ) ) ; }
273+ else if ( ( device . characteristics & InputDeviceCharacteristics . Left ) != 0u ) { leftIndice . Add ( new RoleIdx ( currState ) ) ; }
274+ }
275+
270276 // TODO: update hand skeleton pose
271277 }
272278
273279 // unmap index for disconnected device state
274- for ( uint i = 0u , imax = ( uint ) ( prevMaxConnectedIndex + 1 ) ; i < imax ; ++ i )
280+ for ( uint i = 0u , imax = ( uint ) prevMaxConnectedIndex ; i <= imax ; ++ i )
275281 {
276282 if ( prevDeviceConnected [ i ] && ! currDeviceConnected [ i ] )
277283 {
@@ -281,7 +287,7 @@ public sealed override void BeforeRenderUpdate()
281287 }
282288 else
283289 {
284- Debug . LogWarning ( "[UnityXRModule] Device disconnected : [" + i + "] already unmapped" ) ;
290+ Debug . LogWarning ( "[UnityXRModule] unmap failed : [" + i + "] already unmapped" ) ;
285291 }
286292
287293 if ( TryGetValidDeviceState ( i , out prevState , out currState ) && currState . isConnected )
@@ -290,19 +296,30 @@ public sealed override void BeforeRenderUpdate()
290296 }
291297 else
292298 {
293- Debug . LogWarning ( "[UnityXRModule] Device disconnected : [" + i + "] already been reset" ) ;
299+ Debug . LogWarning ( "[UnityXRModule] reset state failed : [" + i + "] already been reset" ) ;
294300 }
295-
296- Debug . LogFormat ( "[UnityXRModule] Device disconnected: {0} / {1} / {2} / {3} / {4}" ,
297- prevState . deviceIndex ,
298- prevState . deviceClass ,
299- prevState . deviceModel ,
300- prevState . modelNumber ,
301- prevState . serialNumber ) ;
302301 }
303302 }
304303
305304 submodules . UpdateModulesDeviceConnectionAndPoses ( ) ;
305+
306+ for ( uint i = 0u , imax = GetDeviceStateLength ( ) ; i < imax ; ++ i )
307+ {
308+ if ( ! TryGetValidDeviceState ( i , out prevState , out currState ) ) { continue ; }
309+ if ( prevState . isConnected != currState . isConnected )
310+ {
311+ var isDisconnect = prevState . isConnected ;
312+ var readState = isDisconnect ? prevState : ( IVRModuleDeviceState ) currState ;
313+ Debug . LogFormat ( "[UnityXRModule] device {0}connected: [{1}] sn=\" {5}\" cl={2} md={3} mn=\" {4}\" " ,
314+ isDisconnect ? "dis" : "" ,
315+ readState . deviceIndex ,
316+ readState . deviceClass ,
317+ readState . deviceModel ,
318+ readState . modelNumber ,
319+ readState . serialNumber ) ;
320+ }
321+ }
322+
306323 for ( int i = 0 , imax = submodules . ModuleCount ; i < imax ; ++ i )
307324 {
308325 if ( ! submodules [ i ] . isActivated ) { continue ; }
@@ -329,8 +346,11 @@ public sealed override void BeforeRenderUpdate()
329346 if ( leftIndice . Count != 1 ) { leftIndice . Sort ( CompareRoleIdx ) ; }
330347 newLeftIndex = leftIndice [ 0 ] . index ;
331348 }
332- if ( ChangeProp . Set ( ref moduleRightIndex , newRightIndex ) | ChangeProp . Set ( ref moduleLeftIndex , newLeftIndex ) )
349+ if ( ( moduleRightIndex != newRightIndex ) | ( moduleLeftIndex != newLeftIndex ) )
333350 {
351+ Debug . Log ( "[UnityXRModule] role changed: [" + shortIdx ( moduleLeftIndex ) + "=>" + shortIdx ( newLeftIndex ) + "]L [" + shortIdx ( moduleRightIndex ) + "=>" + shortIdx ( newRightIndex ) + "]R" ) ;
352+ moduleRightIndex = newRightIndex ;
353+ moduleLeftIndex = newLeftIndex ;
334354 InvokeControllerRoleChangedEvent ( ) ;
335355 }
336356
@@ -395,10 +415,7 @@ protected static VRModuleDeviceClass GetDeviceClass(string name, InputDeviceChar
395415 return VRModuleDeviceClass . GenericTracker ;
396416 }
397417
398- if ( ( characteristics & InputDeviceCharacteristics . HandTracking ) != 0 )
399- {
400- return VRModuleDeviceClass . TrackedHand ;
401- }
418+ // will not identify tracked hand here, currently all tracked hand should created by submodule
402419
403420 return VRModuleDeviceClass . Invalid ;
404421 }
0 commit comments