示例#1
0
        private async void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            var cursor = Window.Current.CoreWindow.PointerCursor;

            Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Wait, cursor.Id);
            try
            {
                if (lstDeviceIdList.SelectedIndex < 0)
                {
                    return;
                }

                _OrpheShoe = new OrpheShoe();
                _OrpheShoe.ValueChanged += OrpheShoe_ValueChanged;
                if (!await _OrpheShoe.Connect((string)lstDeviceIdList.SelectedItem))
                {
                    _OrpheShoe = null;
                    await new MessageDialog("Orpheとの接続確立に失敗しました。\nOrpheをペアリングモードに変更して再接続してください。").ShowAsync();
                    return;
                }

                _DeviceWatcher.Stop();

                lstDeviceIdList.IsEnabled = false;
                btnConnect.IsEnabled      = false;
                btnScene.IsEnabled        = true;
                btnLightTrigger.IsEnabled = true;
                btnLightOn.IsEnabled      = true;
                btnLightOff.IsEnabled     = true;
            }
            finally
            {
                Window.Current.CoreWindow.PointerCursor = cursor;
            }
        }
示例#2
0
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     _DeviceWatcher          = DeviceInformation.CreateWatcher(OrpheShoe.GetDeviceSelector(), new string[] { "System.Devices.Aep.IsConnected", "System.Devices.Aep.SignalStrength", }, DeviceInformationKind.AssociationEndpoint);
     _DeviceWatcher.Added   += DeviceWatcher_Added;
     _DeviceWatcher.Updated += DeviceWatcher_Updated;
     _DeviceWatcher.Removed += DeviceWatcher_Removed;
     _DeviceWatcher.Start();
 }
 // Use this for initialization
 public void Init(string deviceName = "orphe")
 {
     Debug.Log("init");
     isConnected    = false;
     _DeviceWatcher = DeviceInformation.CreateWatcher(OrpheShoe.GetDeviceSelector(deviceName), new string[] { "System.Devices.Aep.IsConnected", "System.Devices.Aep.SignalStrength", }, DeviceInformationKind.AssociationEndpoint);
     //_DeviceWatcher = DeviceInformation.CreateWatcher("System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\"", null, DeviceInformationKind.AssociationEndpoint);
     _DeviceWatcher.Added   += DeviceWatcher_Added;
     _DeviceWatcher.Updated += DeviceWatcher_Updated;
     _DeviceWatcher.Removed += DeviceWatcher_Removed;
     _DeviceWatcher.Start();
 }
        public async void btnConnect_Click(string deviceID)
        {
            if (isConnected)
            {
                Debug.Log("すでに接続済み");
                Task.Run(async() =>
                {
                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        OnConnectFailed(deviceID);
                    }, true);
                });
                return;
            }


            _OrpheShoe = new OrpheShoe();
            _OrpheShoe.ValueChanged += OrpheShoe_ValueChanged;

            if (!await _OrpheShoe.Connect(deviceID))
            {
                _OrpheShoe = null;


                Debug.Log("Orpheとの接続確立に失敗しました。\nOrpheをペアリングモードに変更して再接続してください。");
                Task.Run(async() =>
                {
                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        OnConnectFailed(deviceID);
                    }, true);
                });
                /// await new MessageDialog("Orpheとの接続確立に失敗しました。\nOrpheをペアリングモードに変更して再接続してください。").ShowAsync();
                return;
            }

            _DeviceWatcher.Stop();

            Debug.Log("Connected!");
            isConnected = true;
            Task.Run(async() =>
            {
                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    OnConnected(deviceID);
                }, true);
            });
        }