コード例 #1
0
        void FindControllersWorker()
        {
            while (true)
            {
                var foundUnpairedControllerAddresses = FindUnpairedControllersAddresses();
                foreach (var nameAddressTuple in foundUnpairedControllerAddresses)
                {
                    var deviceName       = nameAddressTuple.Item1;
                    var bluetoothAddress = nameAddressTuple.Item2;

                    if (_discoveredControllers.Any(c => c.BluetoothAddress == nameAddressTuple.Item2))
                    {
                        // we already know about this controller
                        //logger.Info($"Found {deviceName} - Already added before");
                        continue;
                    }

                    logger.Info($"Found {deviceName} - NEW");

                    if (deviceName.Contains("Gear VR Controller"))
                    {
                        // create and add new gear vr controller
                        var gearVRController = new GearVRController(bluetoothAddress);
                        gearVRController.Initialize();

                        _discoveredControllers.Add(gearVRController);

                        OnNewControllerAdded(gearVRController);
                    }
                    // TODO: elseif Daydream
                }
            }
        }
コード例 #2
0
        private void TransmitDataForController(GearVRController controller)
        {
            if ((DateTime.Now - _lastTimeSent).TotalMilliseconds > 0)
            {
                try {
                    var trackingData = controller.LatestTrackingData;

                    var serializedStr = JsonConvert.SerializeObject(trackingData, Formatting.None);

                    _oscClient.Send(new OscMessage($"/{controller.Name}",
                                                   serializedStr,
                                                   DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                                                   ));
                }
                catch (Exception ex) {
                    logger.Info($"Failed to send OSC: {ex.Message}");
                }

                _lastTimeSent = DateTime.Now;
            }
        }