private void BLEConnecter()
        {
            while (!(deviceConnected[0] == 2 && deviceConnected[1] == 2) && isScanning == true)
            {
                if (connectableDevice.Count > 0)
                {
                    if (deviceConnected[0] != 1 && deviceConnected[1] != 1)
                    {
                        if (deviceConnected[connectableDevice.ElementAt(0).Key] != 2)
                        {
                            ConnectBLEDevice(connectableDevice.ElementAt(0).Value, connectableDevice.ElementAt(0).Key);
                        }
                        connectableDevice.RemoveAt(0);
                    }
                }
                else
                {
                    if (currentTimeMillis() - scanTime > 10000)
                    {
                        if (deviceConnected[0] == 0 && deviceConnected[1] == 0)
                        {
                            ToastHelper.ShowToast("센서를 찾을 수 없습니다. 다시 연결해주세요");
                            watcher.Stop();
                            return;
                        }
                        else if (deviceConnected[0] == 0)
                        {
                            ToastHelper.ShowToast("왼쪽센서를 찾을 수 없습니다. 센서를 확인해주세요");
                            watcher.Stop();
                            return;
                        }
                        else if (deviceConnected[0] == 0)
                        {
                            ToastHelper.ShowToast("오른쪽센서를 찾을 수 없습니다. 센서를 확인해주세요");
                            watcher.Stop();
                            return;
                        }
                    }
                }
                Task.Delay(100);
            }
            isScanning = false;
            watcher.Stop();
            if (deviceConnected[0] == 2 && deviceConnected[1] == 2)
            {
                characteristics[1].ValueChanged += ValueChangeHandlerR;
                characteristics[0].ValueChanged += ValueChangeHandlerL;

                ToastHelper.ShowToast("모듈 연결 완료");

                Task t = Task.Factory.StartNew(() => {
                    Touch.GetInstance().ConsumeTouch(ref leftData, ref rightData, ref isScanning);
                });
            }
            while (true)
            {
                long current = currentTimeMillis();
                if (current - leftTime > 1000 && deviceConnected[0] != 1)
                {
                    ConnectBLEDevice(connectedDeviceInfo[0], 0);
                    ToastHelper.ShowToast("왼쪽센서와 연결이 끊겼습니다. 재연결을 시도합니다.");
                }
                if (current - rightTime > 1000 && deviceConnected[1] != 1)
                {
                    ConnectBLEDevice(connectedDeviceInfo[1], 1);
                    ToastHelper.ShowToast("오른쪽센서와 연결이 끊겼습니다. 재연결을 시도합니다.");
                }
                if (current - leftTime > 5000)
                {
                    ToastHelper.ShowToast("왼쪽센서와 연결되지 않습니다. 센서를 확인해주세요");
                    return;
                }
                if (current - rightTime > 5000)
                {
                    ToastHelper.ShowToast("오른쪽센서와 연결되지 않습니다. 센서를 확인해주세요");
                    return;
                }
            }
        }
Exemplo n.º 2
0
        private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            if (args.Request.Message.ContainsKey("content"))
            {
                object message = null;
                args.Request.Message.TryGetValue("content", out message);
                if (App.IsForeground)
                {
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(async() =>
                    {
                        MessageDialog dialog = new MessageDialog(message.ToString());
                        await dialog.ShowAsync();
                    }));
                }
                else
                {
                    ToastHelper.ShowToast(message.ToString());
                }
            }

            if (args.Request.Message.ContainsKey("resolutionchaged"))
            {
                object message = null;
                args.Request.Message.TryGetValue("resolutionchaged", out message);
                int a = Convert.ToInt32(message);
                SettingValue.GetInstance().ResolutionChanged(a / 10000, a % 10000);
                System.Diagnostics.Debug.WriteLine("resolutionchaged");

                ToastHelper.ShowToast("해상도 변경 : " + a / 10000 + " X " + a % 10000);
            }

            if (args.Request.Message.ContainsKey("autoSetting"))
            {
                object message = null;
                args.Request.Message.TryGetValue("autoSetting", out message);
                int    a                  = Convert.ToInt32(message);
                int[]  resolution         = SettingValue.GetInstance().ResolutionChanged(a / 10000, a % 10000);
                double actualSizeInInches = Double.MaxValue;
                if (DisplayInformation.GetForCurrentView().DiagonalSizeInInches.HasValue)
                {
                    actualSizeInInches = DisplayInformation.GetForCurrentView().DiagonalSizeInInches.Value;
                }
                double d = resolution[0] ^ 2 + resolution[1] ^ 2;
                d = actualSizeInInches / Math.Sqrt(d);
                int[] size = { (int)(d * resolution[0]), (int)(d * resolution[1]) };
                SettingValue.GetInstance().SetScreenSize(size);

                Scenario3_bluetoothAdvertisement.Current.reSetting();
            }

            if (args.Request.Message.ContainsKey("openSetting"))
            {
                if (App.IsForeground)
                {
                    MainPage.Current.ScenarioControl_Settting();
                }
            }

            if (args.Request.Message.ContainsKey("battery"))
            {
                object message = null;
                args.Request.Message.TryGetValue("battery", out message);
                int a = Convert.ToInt32(message);

                ToastHelper.ShowToast("왼쪽 모듈 배터리    : " + a / 10000 + "%\n오른쪽 모듈 배터리 : " + a % 10000 + "%");
            }

            if (args.Request.Message.ContainsKey("exit"))
            {
                App.Current.Exit();
            }
        }
Exemplo n.º 3
0
        public void ConsumeTouch(ref List <JsonArray> leftData, ref List <JsonArray> rightData, ref bool isScanning)
        {
            while (true)
            {
                if (isScanning)
                {
                    return;
                }
                if (currentTimeMillis() - preInputTime > 400 && autoDetached == false)
                {
                    autoDetached = true;
                    inRange      = false;
                    TouchInput(2, prePoint.X, prePoint.Y);
                }

                if (leftData.Count > 0)
                {
                    if (rightData.Count > 0)
                    {
                        try
                        {
                            JsonArray left = leftData.First();
                            leftData.RemoveAt(0);
                            JsonArray right = rightData.First();
                            rightData.RemoveAt(0);
                            double leftDistance  = Calib(left, 0);
                            double rightDistance = Calib(right, 1);
                            if (leftDistance + rightDistance < instance.screenW)
                            {
                                ToastHelper.ShowToast("비정상적인 입력 감지");
                                continue;
                            }
                            Point point;
                            if (leftDistance >= 0 && rightDistance >= 0)
                            {
                                point = CalcXY(leftDistance, rightDistance);
                            }
                            else
                            {
                                continue;
                            }
                            //Debug.WriteLine(point);
                            if (point.X >= 0 && point.X <= w && point.Y > 0 && point.Y <= h)
                            {
                                if (inRange)
                                {
                                    TouchInput(1, point.X, point.Y);
                                }
                                else
                                {
                                    inRange = true;
                                    TouchInput(0, point.X, point.Y);
                                }
                                prePoint     = point;
                                preInputTime = currentTimeMillis();
                                autoDetached = false;
                            }
                            else if (inRange)
                            {
                                autoDetached = false;
                                inRange      = false;
                                TouchInput(2, prePoint.X, prePoint.Y);
                            }
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        leftData.Clear();
                        Task.Delay(300);
                    }
                }
                else
                {
                    rightData.Clear();
                    Task.Delay(300);
                }
            }
        }