public override void OnConnectedDeviceChanged(uint deviceIndex, ETrackedDeviceClass deviceClass, string deviceSN, bool connected)
        {
            if (RoleMap.IsDeviceBound(deviceSN))
            {
                return;
            }

            if (connected)
            {
                if (deviceClass != ETrackedDeviceClass.GenericTracker)
                {
                    return;
                }

                // find unmapped role
                var role = RoleMap.RoleInfo.MinValidRole;
                while (!RoleMap.RoleInfo.IsValidRole(role) || RoleMap.IsRoleMapped(role))
                {
                    if (++role > RoleMap.RoleInfo.MaxValidRole)
                    {
                        return;
                    }
                }

                MappingRole(role, deviceIndex);
            }
            else
            {
                UnmappingDevice(deviceIndex);
            }
        }
Example #2
0
 public override void OnConnectedDeviceChanged(uint deviceIndex, VRModuleDeviceClass deviceClass, string deviceSN, bool connected)
 {
     if (!RoleMap.IsDeviceBound(deviceSN) && deviceClass != VRModuleDeviceClass.TrackedHand)
     {
         return;
     }
     Refresh();
 }
        public override void OnConnectedDeviceChanged(uint deviceIndex, VRModuleDeviceClass deviceClass, string deviceSN, bool connected)
        {
            if (!RoleMap.IsDeviceBound(deviceSN) && !IsController(deviceClass) && !IsTracker(deviceClass))
            {
                return;
            }

            Refresh();
        }
        public override void OnConnectedDeviceChanged(uint deviceIndex, VRModuleDeviceClass deviceClass, string deviceSN, bool connected)
        {
            if (connected)
            {
                if (RoleMap.IsDeviceBound(deviceSN))
                {
                    return;
                }
            }
            else
            {
                return;
            }

            Refresh();
        }
Example #5
0
        public override void OnConnectedDeviceChanged(uint deviceIndex, ETrackedDeviceClass deviceClass, string deviceSN, bool connected)
        {
            if (RoleMap.IsDeviceBound(deviceSN) || deviceClass != ETrackedDeviceClass.Controller)
            {
                return;
            }

            if (!connected)
            {
                UnmappingDevice(deviceIndex);
            }

            if (handsAreMappedOrBound)
            {
                MappingOthers();
            }
            else
            {
                MappingHandsAndOthers();
            }
        }
        public void Refresh()
        {
            // find right/left controller index
            var rightIndex = VRModule.INVALID_DEVICE_INDEX;
            var leftIndex  = VRModule.INVALID_DEVICE_INDEX;

            if (RoleMap.IsRoleValueBound((int)ControllerRole.RightHand))
            {
                rightIndex = RoleMap.GetMappedDeviceByRoleValue((int)ControllerRole.RightHand);
            }
            else
            {
                var index = VRModule.GetRightControllerDeviceIndex();
                if (VRModule.GetDeviceState(index).deviceClass == VRModuleDeviceClass.Controller)
                {
                    rightIndex = index;
                }
            }
            if (RoleMap.IsRoleValueBound((int)ControllerRole.LeftHand))
            {
                leftIndex = RoleMap.GetMappedDeviceByRoleValue((int)ControllerRole.LeftHand);
            }
            else
            {
                var index = VRModule.GetRightControllerDeviceIndex();
                if (VRModule.GetDeviceState(index).deviceClass == VRModuleDeviceClass.Controller)
                {
                    leftIndex = index;
                }
            }
            if (leftIndex == rightIndex)
            {
                leftIndex = VRModule.INVALID_DEVICE_INDEX;
            }

            // find all other unbound controller class devices
            for (uint i = 0u, imax = VRModule.GetDeviceStateCount(); i < imax; ++i)
            {
                if (i == rightIndex)
                {
                    continue;
                }
                if (i == leftIndex)
                {
                    continue;
                }

                var device = VRModule.GetDeviceState(i);
                if (!device.isConnected)
                {
                    continue;
                }
                if (device.deviceClass != VRModuleDeviceClass.Controller)
                {
                    continue;
                }
                if (RoleMap.IsDeviceBound(device.serialNumber))
                {
                    continue;
                }

                m_sortedDeviceList.Add(i);
            }

            // if module didn't hint left/right controllers
            // find left/right most device in m_sortedDeviceList and assigned to leftIndex/rightIndex
            if (m_sortedDeviceList.Count > 0)
            {
                HandRoleHandler.SortDeviceIndicesByDirection(m_sortedDeviceList, VRModule.GetCurrentDeviceState(VRModule.HMD_DEVICE_INDEX).pose);

                if (rightIndex == VRModule.INVALID_DEVICE_INDEX && !RoleMap.IsRoleBound(ControllerRole.RightHand))
                {
                    rightIndex = m_sortedDeviceList[0];
                    m_sortedDeviceList.RemoveAt(0);
                }

                if (m_sortedDeviceList.Count > 0 && leftIndex == VRModule.INVALID_DEVICE_INDEX && !RoleMap.IsRoleBound(ControllerRole.RightHand))
                {
                    leftIndex = m_sortedDeviceList[m_sortedDeviceList.Count - 1];
                    m_sortedDeviceList.RemoveAt(m_sortedDeviceList.Count - 1);
                }
            }

            if (rightIndex != VRModule.INVALID_DEVICE_INDEX)
            {
                MappingRoleIfUnbound(ControllerRole.RightHand, rightIndex);
            }

            if (leftIndex != VRModule.INVALID_DEVICE_INDEX)
            {
                MappingRoleIfUnbound(ControllerRole.LeftHand, leftIndex);
            }

            if (m_sortedDeviceList.Count > 0)
            {
                var otherCtrlIndex = -1;
                var otherRole      = ControllerRole.Controller3 - 1;
                while (NextUnmappedSortedDevice(ref otherCtrlIndex) && NextUnmappedRole(ref otherRole))
                {
                    MappingRole(otherRole, m_sortedDeviceList[otherCtrlIndex]);
                }

                m_sortedDeviceList.Clear();
            }
        }