Пример #1
0
        public MainPage()
        {
            InitializeComponent();



            OrientationSensor.Start(SensorSpeed.Game);
            OrientationSensor.ReadingChanged += Update;
        }
 public void ToggleOrientationSensor()
 {
     if (OrientationSensor.IsMonitoring)
     {
         OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged;
         OrientationSensor.Stop();
     }
     else
     {
         OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged;
         OrientationSensor.Start(speed);
     }
 }
Пример #3
0
        /// <summary>
        /// Starts sensor and registers listener to a sensor
        /// </summary>
        /// <param name="listener">Event handler to listen sensor events</param>
        public void Start(EventHandler <SensorEventArgs> listener)
        {
            handler = (sender, e) =>
            {
                listener?.Invoke(this,
                                 new SensorEventArgs(new List <float>()
                {
                    e.Azimuth, e.Pitch, e.Roll
                }));
            };

            sensor.DataUpdated += handler;
            sensor.Start();
        }
Пример #4
0
        protected override async void OnAppearing()
        {
            //خرسه
            base.OnAppearing();

            monkeyDo = await urhoSurface.Show <FaddyModels>(new ApplicationOptions(assetsFolder : "DataFaddyModels"));

            try
            {
                OrientationSensor.Start(SensorSpeed.Default);
            }
            catch
            {
                Content = new Label
                {
                    Text                    = "Sorry, the OrientationSensor is not supported on this device.",
                    VerticalOptions         = LayoutOptions.Center,
                    HorizontalTextAlignment = TextAlignment.Center,
                    Margin                  = new Thickness(50)
                };
            }
            //خرسه



            //  var amc = await App.Database.GetPeopleAsync();



            //try
            //{

            //    foreach (Person creatstack1 in amc)
            //    {


            //        stackpost2.Children.Add(stackpost);



            //    }

            //}

            //catch
            //{
            //    mozoe1.Text = string.Empty;
            //}
        }
Пример #5
0
        public override void OnAppearing()
        {
            try
            {
                OrientationSensor.ReadingChanged += OnOrientationReadingChanged;

                if (!OrientationSensor.IsMonitoring)
                {
                    OrientationSensor.Start(SensorSpeed.UI);
                }
            }
            catch (FeatureNotSupportedException ex)
            {
                Logger.Debug("Feature not supported: " + ex.Message);
            }
        }
Пример #6
0
 public void StartSensors()
 {
     try
     {
         Accelerometer.Start(SensorSpeed.Default);
         Magnetometer.Start(SensorSpeed.Default);
         Gyroscope.Start(SensorSpeed.Default);
         OrientationSensor.Start(SensorSpeed.Default);
         Accelerometer.ReadingChanged     += Accelerometer_ReadingChanged;
         Magnetometer.ReadingChanged      += Magnetometer_ReadingChanged;
         Gyroscope.ReadingChanged         += Gyrotometer_ReadingChanged;
         OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged;
     }
     catch (Exception EX)
     {
         //Log.Error(TAG, EX.GetBaseException().ToString());
     }
 }
        protected override void OnAppearing()
        {
            base.OnAppearing();

            try
            {
                OrientationSensor.Start(SensorSpeed.Normal);
            }
            catch
            {
                Content = new Label
                {
                    Text                    = "Sorry, the OrientationSensor is not supported on this device.",
                    VerticalOptions         = LayoutOptions.Center,
                    HorizontalTextAlignment = TextAlignment.Center,
                    Margin                  = new Thickness(50)
                };
            }
        }
Пример #8
0
 private void OrientationBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (OrientationSensor.IsMonitoring)
         {
             OrientationSensor.Stop();
             FindViewById <TextView>(Resource.Id.orientation).Text = "Orientation: off";
         }
         else
         {
             OrientationSensor.Start(speed);
         }
     }
     catch (Exception ex)
     {
         Toast.MakeText(ApplicationContext, ex.Message, ToastLength.Long).Show();
     }
 }
 public void Start()
 {
     try
     {
         if (!OrientationSensor.IsMonitoring)
         {
             OrientationSensor.Start(speed);
         }
         OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged;
     }
     catch (FeatureNotSupportedException fnsEx)
     {
         // Feature not supported on device
     }
     catch (System.Exception ex)
     {
         // Other error has occurred.
     }
 }
Пример #10
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            monkeyDo = await urhoSurface.Show <MonkeyDo> (new ApplicationOptions(assetsFolder : "Data"));

            try
            {
                OrientationSensor.Start(SensorSpeed.Normal);
            }
            catch
            {
                Content = new Label
                {
                    Text                    = "Sorry, the OrientationSensor is not supported on this device.",
                    VerticalOptions         = LayoutOptions.Center,
                    HorizontalTextAlignment = TextAlignment.Center,
                    Margin                  = new Thickness(50)
                };
            }
        }
 private void OrientationCheckButton_Clicked(object sender, EventArgs e)
 {
     try
     {
         if (OrientationSensor.IsMonitoring)
         {
             OrientationSensor.Stop();
         }
         else
         {
             OrientationSensor.Start(SensorSpeed.Default);
         }
     }
     catch (FeatureNotSupportedException fnsEx)
     {
         DisplayAlert("Not Supported", "Error: " + fnsEx.Message, "Aceptar");
     }
     catch (Exception ex)
     {
         DisplayAlert("Exception", "Error: " + ex.Message, "Aceptar");
     }
 }
Пример #12
0
 public void ToggleOrientationSensor()
 {
     try
     {
         if (OrientationSensor.IsMonitoring)
         {
             OrientationSensor.Stop();
         }
         else
         {
             OrientationSensor.Start(speed);
         }
     }
     catch (FeatureNotSupportedException fnsEx)
     {
         // Feature not supported on device
     }
     catch (Exception ex)
     {
         // Other error has occurred.
     }
 }
        public BleServer(Context ctx)
        {
            _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService);
            _bluetoothAdapter = _bluetoothManager.Adapter;

            _bluettothServerCallback = new BleGattServerCallback();
            _bluetoothServer         = _bluetoothManager.OpenGattServer(ctx, _bluettothServerCallback);

            var service = new BluetoothGattService(UUID.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"),
                                                   GattServiceType.Primary);

            _characteristic = new BluetoothGattCharacteristic(UUID.FromString("d8de624e-140f-4a22-8594-e2216b84a5f2"), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write);

            service.AddCharacteristic(_characteristic);
            _bluetoothServer.AddService(service);

            SensorSpeed speed = SensorSpeed.UI;

            OrientationSensor.Start(speed);
            OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged;

            _bluettothServerCallback.CharacteristicReadRequest += _bluettothServerCallback_CharacteristicReadRequest;
            Console.WriteLine("Server created!");

            BluetoothLeAdvertiser myBluetoothLeAdvertiser = _bluetoothAdapter.BluetoothLeAdvertiser;

            var builder = new AdvertiseSettings.Builder();

            builder.SetAdvertiseMode(AdvertiseMode.LowLatency);
            builder.SetConnectable(true);
            builder.SetTimeout(0);
            builder.SetTxPowerLevel(AdvertiseTx.PowerHigh);
            AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
            dataBuilder.SetIncludeDeviceName(true);
            dataBuilder.SetIncludeTxPowerLevel(true);

            myBluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), new BleAdvertiseCallback());
        }
Пример #14
0
        private void MonitorOrientationChanges()
        {
            try
            {
                OrientationSensor.Start(SensorSpeed.UI);
                OrientationSensor.ReadingChanged += (object sender, OrientationSensorChangedEventArgs e) =>
                {
                    if (_orientation != DeviceDisplay.MainDisplayInfo.Orientation)
                    {
                        //orientation was changed - send event update
                        _orientation = DeviceDisplay.MainDisplayInfo.Orientation;

                        if (AppOrientationChanged != null)
                        {
                            AppOrientationChanged(_orientation);
                        }
                    }
                };
            }
            catch (Exception ex)
            {
            }
        }
Пример #15
0
 public void OrientationSensor_Stop() =>
 Assert.Throws <NotImplementedInReferenceAssemblyException>(() => OrientationSensor.Start(SensorSpeed.Default));
 /// <summary>
 /// Starts the orientation sensor.
 /// </summary>
 public void Start()
 {
     _orientationSensor?.Start();
 }
        protected override void Setup()
        {
            base.Setup();
            var bluetoothManager        = DependencyService.Get <IManagerManager>().BluetoothManager;
            var deviceInfomationService = new DeviceInfomationServiceBuilder(bluetoothManager).Build();

            SensorSpeed speed = SensorSpeed.Game;

            Gyroscope.ReadingChanged += Gyroscope_ReadingChanged;
            Gyroscope.Start(speed);
            OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged;
            OrientationSensor.Start(speed);

            bluetoothManager.GattSever.AddService(new DeviceInfomationServiceBuilder(bluetoothManager).Build());
            bluetoothManager.GattSever.AddService(new RfcommServerServiceWrapper(bluetoothManager).GattServerService);
            KeyboardServiceWrapper = new KeyboardServiceWrapper(bluetoothManager);
            bluetoothManager.GattSever.AddService(KeyboardServiceWrapper.GattServerService);
            bluetoothManager.GattSever.StartAdvertising();

            var createServiceProviderTask = bluetoothManager.CreateRfcommServiceProviderAsync(MouseServiceWrapper.ServiceId);

            createServiceProviderTask.Wait();
            var mouseServiceProvider = createServiceProviderTask.Result;

            mouseServiceProvider.OnConnectionReceived += MouseServiceProvider_OnConnectionReceived;;
            mouseServiceProvider.StartAdvertising();

            var keyManager = DependencyService.Get <IManagerManager>().KeyManager;

            keyManager.VolumnDownKeyDown += KeyManager_VolumnDownKeyDown;
            keyManager.VolumnDownKeyUp   += KeyManager_VolumnDownKeyUp;
            keyManager.VolumnUpKeyDown   += KeyManager_VolumnUpKeyDown;
            keyManager.VolumnUpKeyUp     += KeyManager_VolumnUpKeyUp;

            LeftMouseButton = Sketch.SketchEngine.Instantiate <KeyboardKeyButton>();
            LeftMouseButton.RectTransform.AnchorMax = new Vector2(0f, 1f);
            LeftMouseButton.RectTransform.AnchorMin = new Vector2(0f, 1f);
            LeftMouseButton.RectTransform.OffsetMin = new Vector2(53f, -1157f);
            LeftMouseButton.RectTransform.OffsetMax = new Vector2(403f, -807f);
            LeftMouseButton.KeyDown += LeftMouseButton_KeyDown;
            LeftMouseButton.KeyUp   += LeftMouseButton_KeyUp;

            RightMouseButton = Sketch.SketchEngine.Instantiate <KeyboardKeyButton>();
            RightMouseButton.RectTransform.AnchorMax = new Vector2(0f, 1f);
            RightMouseButton.RectTransform.AnchorMin = new Vector2(0f, 1f);
            RightMouseButton.RectTransform.OffsetMin = new Vector2(53f, -1552f);
            RightMouseButton.RectTransform.OffsetMax = new Vector2(403f, -1202f);
            RightMouseButton.KeyDown += RightMouseButton_KeyDown;
            RightMouseButton.KeyUp   += RightMouseButton_KeyUp;

            StopMouseButton = Sketch.SketchEngine.Instantiate <KeyboardKeyButton>();
            StopMouseButton.RectTransform.AnchorMax = new Vector2(0f, 1f);
            StopMouseButton.RectTransform.AnchorMin = new Vector2(0f, 1f);
            StopMouseButton.RectTransform.OffsetMin = new Vector2(53f, -778f);
            StopMouseButton.RectTransform.OffsetMax = new Vector2(214.6f, -616.4f);
            StopMouseButton.KeyDown += StopMouseButton_KeyDown;
            StopMouseButton.KeyUp   += StopMouseButton_KeyUp;

            DrawAndPressButton = Sketch.SketchEngine.Instantiate <KeyboardKeyButton>();
            DrawAndPressButton.RectTransform.AnchorMax = new Vector2(0f, 1f);
            DrawAndPressButton.RectTransform.AnchorMin = new Vector2(0f, 1f);
            DrawAndPressButton.RectTransform.OffsetMin = new Vector2(688.4f, -778f);
            DrawAndPressButton.RectTransform.OffsetMax = new Vector2(850f, -616.4f);
            DrawAndPressButton.KeyDown += DrawAndPressButton_KeyDown;
            DrawAndPressButton.KeyUp   += DrawAndPressButton_KeyUp;

            MouseStick = Sketch.SketchEngine.Instantiate <TouchpadJoystick>();
            MouseStick.RectTransform.AnchorMax = new Vector2(0f, 1f);
            MouseStick.RectTransform.AnchorMin = new Vector2(0f, 1f);
            MouseStick.RectTransform.OffsetMin = new Vector2(500f, -1359f);
            MouseStick.RectTransform.OffsetMax = new Vector2(850f, -1009f);
            MouseStick.OnMove += MouseStick_OnMove;

            OpenLazerButton = Sketch.SketchEngine.Instantiate <KeyboardKeyButton>();
            OpenLazerButton.RectTransform.AnchorMax = new Vector2(0f, 1f);
            OpenLazerButton.RectTransform.AnchorMin = new Vector2(0f, 1f);
            OpenLazerButton.RectTransform.OffsetMin = new Vector2(86f, -286.2f);
            OpenLazerButton.RectTransform.OffsetMax = new Vector2(436f, -78.00001f);
            OpenLazerButton.KeyDown += OpenLazerButton_KeyDown;
            OpenLazerButton.KeyUp   += OpenLazerButton_KeyUp;
            Sketch.SketchEngine.Instantiate <SketchBorderRenderer>();
            Sketch.SketchEngine.Instantiate <RectTransformFrameRenderer>();
            _MouseMoving = false;
        }
Пример #18
0
        /// <summary>
        /// Start the specified sensorType and interval.
        /// </summary>
        /// <param name="sensorType">Sensor type.</param>
        /// <param name="interval">Interval.</param>
        public void Start(MotionSensorType sensorType, MotionSensorDelay interval = MotionSensorDelay.Default)
        {
            uint delay = (uint)((double)Convert.ToInt32(interval) / ms);

            switch (sensorType)
            {
            case MotionSensorType.Accelerometer:
                if (accelerometer != null)
                {
                    accelerometer.Interval     = delay;
                    accelerometer.DataUpdated += AccelerometerDataUpdated;
                    accelerometer.Start();
                    sensorStatus[sensorType] = true;
                }
                else
                {
                    Debug.WriteLine("Accelerometer not available");
                }
                break;

            case MotionSensorType.Gyroscope:
                if (gyroscope != null)
                {
                    gyroscope.Interval     = delay;
                    gyroscope.DataUpdated += GyroscopeDataUpdated;
                    gyroscope.Start();
                    sensorStatus[sensorType] = true;
                }
                else
                {
                    Debug.WriteLine("Gyroscope not available");
                }
                break;

            case MotionSensorType.Magnetometer:
                if (magnetometer != null)
                {
                    magnetometer.Interval     = delay;
                    magnetometer.DataUpdated += MagnetometerDataUpdated;
                    magnetometer.Start();
                    sensorStatus[sensorType] = true;
                }
                else
                {
                    Debug.WriteLine("Magnetometer not available");
                }
                break;

            case MotionSensorType.Compass:

                if (orientation != null)
                {
                    orientation.Interval     = delay;
                    orientation.DataUpdated += OrientationDataUpdated;
                    orientation.Start();
                    sensorStatus[sensorType] = true;
                }
                else
                {
                    Debug.WriteLine("OrientationSensor not available");
                }
                break;
            }
        }
 void StartButton_Clicked(object sender, EventArgs e)
 {
     OrientationSensor.Start((SensorSpeed)speedPicker.SelectedIndex);
 }
Пример #20
0
 protected override void OnAppearing()
 {
     base.OnAppearing();
     OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged;
     OrientationSensor.Start(SensorSpeed.UI);
 }
 /// <inheritdoc />
 public void Start(SensorSpeed sensorSpeed = SensorSpeed.Default) => OrientationSensor.Start(sensorSpeed);
        private void FabOnClick(object sender, EventArgs eventArgs)
        {
            AppCompatButton view = (AppCompatButton)sender;

            try
            {
                TextView          status = FindViewById <TextView>(Resource.Id.status);
                AppCompatEditText ipaddr = FindViewById <AppCompatEditText>(Resource.Id.textInputEditText1);

                if (!OrientationSensor.IsMonitoring)
                {
                    IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(ipaddr.Text), 9050);
                    udpClient = new UdpClient(9050);
                    udpClient.Connect(ipep);

                    var msg = Encoding.ASCII.GetBytes($"connected");
                    udpClient.Send(msg, msg.Length);

                    IPEndPoint udpsender = new IPEndPoint(IPAddress.Any, 0);

                    status.Text = "Status: Connecting...";

                    udpThread = new Thread(() =>
                    {
                        while (true)
                        {
                            var data = udpClient.Receive(ref udpsender);
                            var msg  = Encoding.ASCII.GetString(data, 0, data.Length);

                            if (msg == "connected" || msg == "pong")
                            {
                                if (msg == "connected")
                                {
                                    RunOnUiThread(() =>
                                    {
                                        status.Text = "Status: Connected";
                                    });

                                    var battmsg = Encoding.ASCII.GetBytes($"{(int)(Battery.ChargeLevel * 1000)}");
                                    udpClient.Send(battmsg, battmsg.Length);
                                }

                                Running  = true;
                                lastPing = DateTime.Now;
                            }
                            //Try/catch haptics in case something goes wrong
                            //Haptic format is "H{0} {1} {2}"
                            //Haptic stop is "H C {1} {2}"
                            //Haptic without stop is "H {1} {2}"
                            //H C 1 1
                            //H 1 1
                            int spacesOffset = 0;
                            try
                            {
                                if (msg[0] == 'H')
                                {
                                    if (msg[2] == 'C')
                                    {
                                        //stop haptics
                                        Vibration.Cancel();
                                        spacesOffset = 1;
                                    }
                                    int effect = int.Parse(msg.Split(' ')[2 + spacesOffset]);
                                    int reps   = int.Parse(msg.Split(' ')[1 + spacesOffset]);
                                    switch (effect)
                                    {
                                    case 1:
                                        //single click
                                        Vibration.Vibrate(250);
                                        break;

                                    case 10:
                                        //double click
                                        Vibration.Vibrate(250);
                                        Thread.Sleep(500);
                                        Vibration.Vibrate(250);
                                        break;

                                    case 24:
                                        //calibration?
                                        Vibration.Vibrate(1000);
                                        break;

                                    case 14:
                                        //buzz
                                        for (int i = 0; i < 10; i++)
                                        {
                                            Vibration.Vibrate(25);
                                            Thread.Sleep(50);
                                        }
                                        break;

                                    default:
                                        //uh oh, we have no clue what this should be doing? Maybe a new version of DecaHub?
                                        Console.Error.WriteLine("Haptic error: Unknown haptic effect {}", effect);
                                        break;
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Console.Error.WriteLine("Haptic error: {}", e.StackTrace);
                            }
                        }
                    });
                    udpThread.Start();

                    lastPing = DateTime.Now;

                    Timer connCheckTimer = new Timer(connectionCheck);
                    connCheckTimer.Change(0, 5000);

                    DeviceDisplay.KeepScreenOn = true;

                    OrientationSensor.Start(SensorSpeed.Fastest);
                    view.Text = "Stop";
                }
                else
                {
                    DeviceDisplay.KeepScreenOn = false;

                    Running = false;
                    OrientationSensor.Stop();
                    view.Text   = "Start";
                    status.Text = "Status: Not Running";

                    var msg = Encoding.ASCII.GetBytes("stop");
                    udpClient.Send(msg, msg.Length);
                }
            }
            catch (Exception e)
            {
                Snackbar.Make(view, e.Message, Snackbar.LengthLong).SetAction("Action", (View.IOnClickListener)null).Show();
            }
        }