private void accelerometer_ReadingChanged(object sender, Windows.Devices.Sensors.AccelerometerReadingChangedEventArgs e)
 {
     System.Windows.Application.Current.Dispatcher.BeginInvoke((Action) delegate
     {
         AccelerometerReading = e.Reading;
     });
 }
        private async void SendDeviceToCloudMessagesAsync()
        {
            byte[]  byteData;
            string  JSONString = "";
            Message EventToSend;

            count++;
            if (chkGoSlow.IsChecked == true)
            {
                if (count % 10 != 0)
                {
                    return;
                }
            }
            // Calculate Accelleration and Position
            Accelerometer        accelerometer = Accelerometer.GetDefault();
            AccelerometerReading r             = accelerometer.GetCurrentReading();
            double G = Math.Sqrt((r.AccelerationX * r.AccelerationX) + (r.AccelerationY * r.AccelerationY) + (r.AccelerationZ * r.AccelerationZ));

            // Create JSON String
            JSONString = "{\"DataTypeKey\": \"ACC\", \"Count\": " + count + ", \"X\": " + Math.Round(r.AccelerationX, 2) + ", \"Y\": " + Math.Round(r.AccelerationY, 2) + ", \"Z\": " + Math.Round(r.AccelerationZ, 2) + ", \"G\": " + Math.Round(G, 2) + "}";

            Label1.Text = JSONString;
            byteData    = Encoding.UTF8.GetBytes(JSONString);
            EventToSend = new Message(byteData);

            if (sending == 1)
            {
                await deviceClient.SendEventAsync(EventToSend);
            }
        }
Exemplo n.º 3
0
        private void OnGetAccelerometer(object sender, RoutedEventArgs e)
        {
            Accelerometer        accelerometer = Accelerometer.GetDefault();
            AccelerometerReading reading       = accelerometer.GetCurrentReading();

            this.DefaultViewModel["AccelerometerResult"] = GetAccelerometerResult(reading);
        }
Exemplo n.º 4
0
        private void ReadingChangedforVibrator(object sender, AccelerometerReadingChangedEventArgs e)
        {
            AccelerometerReading reading = e.Reading;

            string sMessage = "";


            if (Math.Abs(reading.AccelerationX - 0.09) > 0.07 || Math.Abs(reading.AccelerationY - 0.01) > 0.05 || Math.Abs(Math.Abs(reading.AccelerationZ) - 0.96) > 0.4)
            {
                sMessage  = "";
                sMessage += "Round" + TestRound + "->" + TestCount + ":VibrationDevice Success.";
                sMessage += "\r\n";
                Vlog.WriteText(sMessage);
            }
            else
            {
                sMessage  = "";
                sMessage += "Round" + TestRound + "->" + TestCount + ":VibrationDevice Failed.";
                sMessage += "\r\n";
                Vlog.WriteText(sMessage);
            }


            _accelerometer.ReportInterval  = 0;
            _accelerometer.ReadingChanged -= new Windows.Foundation.TypedEventHandler <Windows.Devices.Sensors.Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChangedforVibrator);



            if (TestCount >= TestMaxCount)
            {
                Vtimer.Cancel();
                TestCount = 0;
                Gtimer    = ThreadPoolTimer.CreatePeriodicTimer(Gyrometer_Timer_Tick, TimeSpan.FromMilliseconds(2000));
            }
        }
Exemplo n.º 5
0
        // Using the packet format
        private byte[] ConvertAccelerometerForMioty(AccelerometerReading reading)
        {
            double[] arr = { reading.AccelerationX, reading.AccelerationY, reading.AccelerationZ };
            double   max = arr.Max();
            double   min = arr.Min();
            double   precision;

            if (Math.Abs(max) > Math.Abs(min))
            {
                precision = Math.Ceiling(max);
            }
            else
            {
                precision = Math.Ceiling(Math.Abs(min));
            }

            var   AccelerometerHex = new byte[8];
            sbyte SBytePreceision  = Convert.ToSByte(precision);
            var   ret = SByteIntoHexForMioty(SBytePreceision);

            AccelerometerHex[0] = ret[0];
            AccelerometerHex[1] = ret[1];
            for (int i = 0; i < 3; i++)
            {
                var temp   = arr[i];
                int factor = 127;

                sbyte SByteAccelerometer = Convert.ToSByte(factor * temp / precision);
                ret = SByteIntoHexForMioty(SByteAccelerometer);
                AccelerometerHex[2 + i * 2] = ret[0];
                AccelerometerHex[3 + i * 2] = ret[1];
            }
            return(AccelerometerHex);
        }
Exemplo n.º 6
0
        void updateMyScreen(AccelerometerReading e)
        {
            // updates the textblocks
            xreadout.Text = e.Acceleration.X.ToString("0.00");
            yreadout.Text = e.Acceleration.Y.ToString("0.00");
            zreadout.Text = e.Acceleration.Z.ToString("0.00");

            //draws on the canvas:

            double currentXOnGraph = Math.Abs((e.Acceleration.X * 200) - 200);
            double currentYOnGraph = Math.Abs((e.Acceleration.Y * 200) - 200);
            double currentZOnGraph = Math.Abs((e.Acceleration.Z * 200) - 200);

            Rectangle xPoint = new Rectangle();
            Rectangle yPoint = new Rectangle();
            Rectangle zPoint = new Rectangle();

            xPoint.Fill = new SolidColorBrush(Colors.Red);
            yPoint.Fill = new SolidColorBrush(Colors.Blue);
            zPoint.Fill = new SolidColorBrush(Colors.Green);

            // these pixels will be "pasted into" the canvas by setting their position according
            // to the currentX/Y/Z-on-graph values. To set their position relative to the canvas,
            // pass the canvas properties on to the pixels via the SetValue method.
            // use a generic iterator to determine the distance the pixel should be from the left
            // side of the canvas.

            xPoint.SetValue(Canvas.LeftProperty, iterator);
            xPoint.SetValue(Canvas.TopProperty, currentXOnGraph);

            yPoint.SetValue(Canvas.LeftProperty, iterator);
            yPoint.SetValue(Canvas.TopProperty, currentYOnGraph);

            zPoint.SetValue(Canvas.LeftProperty, iterator);
            zPoint.SetValue(Canvas.TopProperty, currentZOnGraph);

            // set the pixel size
            xPoint.Width  = 1;
            xPoint.Height = 2;
            yPoint.Width  = 1;
            yPoint.Height = 2;
            zPoint.Width  = 1;
            zPoint.Height = 2;

            // finally, associate pixels with the canvas.

            Log.Children.Add(xPoint);
            Log.Children.Add(yPoint);
            Log.Children.Add(zPoint);

            if (iterator == 399)
            {
                Log.Children.Clear();
                iterator = 0;
            }
            else
            {
                iterator++;
            }
        }
        private void MoveCar(AccelerometerReading r)
        {
            Vector3 acceleration = r.Acceleration;
            double  z_limit = -0.4;
            double  y_limit = -0.4;
            double  leftAccel, rightAccel, leftTurn, rightTurn;

            leftAccel  = (acceleration.Z - z_threshold) / (z_limit) * (150);
            rightAccel = (acceleration.Z - z_threshold) / (z_limit) * (150);

            leftTurn  = (acceleration.Y - y_threshold) / (y_limit) * (100);
            rightTurn = (acceleration.Y - y_threshold) / (y_limit) * (-100);


            _cc.LeftSpeed  = 1 * (int)(2 * leftAccel + leftTurn) / 3;
            _cc.RightSpeed = 1 * (int)(2 * rightAccel + rightTurn) / 3;
            _cc.MoveCar();


            LeftAccel.Text         = "Left Acceleration" + leftAccel.ToString();
            RightAccel.Text        = "Right Acceleration" + rightAccel.ToString();
            LeftTurn.Text          = "Left Turn" + leftTurn.ToString();
            RightTurn.Text         = "Right Turn" + rightTurn.ToString();
            AccelerometerData.Text = "X:" + acceleration.X.ToString("0.00") + " Y:" + acceleration.Y.ToString("0.00") + " Z:" + acceleration.Z.ToString("0.00");
        }
Exemplo n.º 8
0
 //Изменение местоположения робота
 private void OnAccelerometerUpdated(object sender, AccelerometerReading reading)
 {
     if (m_gameIsStarted)
     {
         MoveRobot(reading.X, reading.Y);
     }
 }
Exemplo n.º 9
0
        private void UpdateUI(AccelerometerReading accelerometerReading)
        {
            Vector3 acceleration = accelerometerReading.Acceleration;

            Debug.writeToIO("Acceleration x value" + acceleration.X);
            if (acceleration.X > 0.5)
            {
                // button1.Click;

                try
                {
                    accelerometer.Stop();


                    PhoneCallTask MyPCT = new PhoneCallTask();

                    MyPCT.DisplayName = nametextBox.Text;   // "Amit Maheshwari";

                    MyPCT.PhoneNumber = numbertextBox.Text; //"9412331585";

                    MyPCT.Show();
                    // phoneNumberChooserTask = new PhoneNumberChooserTask();
                    //phoneNumberChooserTask.Completed += new EventHandler<PhoneNumberResult>(phoneNumberChooserTask_Completed);
                    //     phoneTask.DisplayName = nametextBox.Text;
                    //   phoneTask.PhoneNumber = numbertextBox.Text;



                    // phoneTask.Show();
                }
                catch (Exception ex)
                {
                }
            }
        }
Exemplo n.º 10
0
        private void UpdateUI(AccelerometerReading accreading)
        {
            Vector3 acc = accreading.Acceleration;

            X.Text = acc.X.ToString("0.00");
            Y.Text = acc.Y.ToString("0.00");
            Z.Text = acc.Z.ToString("0.00");
//send w,a,s or d according to accelerometer readings to server
            if (acc.Z < -0.55)
            {
                websoc.Send("w");
            }
            else if (acc.Z > 0.25)
            {
                websoc.Send("s");
            }
            else if (acc.Y > 0.30)
            {
                websoc.Send("a");
            }
            else if (acc.Y < -0.30)
            {
                websoc.Send("d");
            }
            else
            {
                websoc.Send("p");
            }
        }
        private async void MyAccelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
        {
            AccelerometerReading reading = args.Reading;
            var    xsq         = reading.AccelerationX * reading.AccelerationX;
            var    ysq         = reading.AccelerationY * reading.AccelerationY;
            var    zsq         = reading.AccelerationZ * reading.AccelerationZ;
            var    readprod    = xsq + ysq + zsq;
            string Resultaccel = "Panic";

            if (readprod > 1.5 & msgsent == false) //use this to only send once, dont know if you wanna do this multiple messages could be handy
            {
                try
                {
                    msgsent = true;
                    // dlg = new Windows.UI.Popups.MessageDialog(Resultaccel);
                    // await dlg.ShowAsync();
                    myAccelerometer = null;

                    LatLng latlng = await mycoordinatesGPS();

                    string message = latlng.lat + latlng.lng + "_Test_Panic_Distress_Call";
                    await sendSMS(message);
                    await Send_Email(message);

                    CloseApp(); //close the app leave no trace you had this set
                }
                catch (Exception ex) { CloseApp(); } //if an exception occurs you still want to close app as to leave no trace what you did
            }
        }
Exemplo n.º 12
0
 async void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         accelerometerReading = args.Reading;
         AcceShowData();
     });
 }
Exemplo n.º 13
0
 private async void OnReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         AccelerometerReading reading = args.Reading;
         //tbAccelX.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
     });
 }
Exemplo n.º 14
0
 /// <summary>
 /// 读取传感器变化
 /// </summary>
 private async void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         AccelerometerReading reading = e.Reading;
         sensorX = reading.AccelerationX;
     });
 }
Exemplo n.º 15
0
        private void AccelChanged(object sender, AccelerometerReadingChangedEventArgs e)
        {
            AccelerometerReading reading = e.Reading;

            unchainedAccel((float)reading.AccelerationX * Constant.ACCEL_FACTOR,
                           (float)reading.AccelerationY * Constant.ACCEL_FACTOR,
                           (float)reading.AccelerationZ * Constant.ACCEL_FACTOR);
        }
Exemplo n.º 16
0
 private async void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
         AccelerometerReading reading = e.Reading;
         //render.pointer.pitch = (float)reading.AccelerationY;
         render.roll = (float)reading.AccelerationX;
     });
 }
Exemplo n.º 17
0
 static Vector ConvertToVector(AccelerometerReading reading)
 {
     return(new Vector
     {
         X = reading.AccelerationX,
         Y = reading.AccelerationY,
         Z = reading.AccelerationZ
     });
 }
Exemplo n.º 18
0
        /// <summary>
        /// This is the dispatcher callback.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void DisplayCurrentReading(object sender, object args)
        {
            AccelerometerReading reading = _accelerometer.GetCurrentReading();

            if (reading != null)
            {
                MainPage.SetReadingText(ScenarioOutput, reading);
            }
        }
Exemplo n.º 19
0
 async private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
         AccelerometerReading reading = e.Reading;
         ScenarioOutput_X.Text        = String.Format("{0,5:0.00}", reading.AccelerationX);
         ScenarioOutput_Y.Text        = String.Format("{0,5:0.00}", reading.AccelerationY);
         ScenarioOutput_Z.Text        = String.Format("{0,5:0.00}", reading.AccelerationZ);
     });
 }
Exemplo n.º 20
0
        private string GetAccelerometerResult(AccelerometerReading reading)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("x: {0}\n", reading.AccelerationX);
            sb.AppendFormat("y: {0}\n", reading.AccelerationY);
            sb.AppendFormat("z: {0}\n", reading.AccelerationZ);
            return(sb.ToString());
        }
Exemplo n.º 21
0
        private void OnTick(object sender, object e)
        {
            Initialize();

            if (accelerometer != null)
            {
                AccelerometerReading reading = accelerometer.GetCurrentReading();

                if (reading != null)
                {
                    //Debug.WriteLine(reading.AccelerationX + ", " + reading.AccelerationY);

                    const double multiplier = 15;

                    // Increment speed and move object.
                    speedX    += reading.AccelerationX;
                    positionX += speedX;

                    if (positionX < 0)
                    {
                        positionX = 0;

                        // Invert direction.
                        speedX *= -1;
                    }
                    else if (positionX > myCanvas.ActualWidth - rectangle.Width)
                    {
                        positionX = myCanvas.ActualWidth - rectangle.Width;

                        // Invert direction.
                        speedX *= -1;
                    }

                    // Increment speed and move object.
                    speedY    += reading.AccelerationY;
                    positionY -= speedY;

                    if (positionY < 0)
                    {
                        positionY = 0;

                        // Invert direction.
                        speedY *= -1;
                    }
                    else if (positionY > myCanvas.ActualHeight - rectangle.Height)
                    {
                        positionY = myCanvas.ActualHeight - rectangle.Height;

                        // Invert direction.
                        speedY *= -1;
                    }

                    rectangle.SetValue(Canvas.LeftProperty, positionX);
                    rectangle.SetValue(Canvas.TopProperty, positionY);
                }
            }
        }
Exemplo n.º 22
0
        void _myDispatcherTimer_Tick(object sender, object e)
        {
            AccelerometerReading reading = _accelerometer.GetCurrentReading();

            if (reading != null)
            {
                ValuesHandler(reading);
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// This is the event handler for ReadingChanged event of the 'accelerometerReadingTransform' and should
 /// notify of the accelerometer reading changes.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args">
 /// Event data represents the accelerometer reading in its original reference frame.
 /// </param>
 async void _accelerometerReadingTransform_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         AccelerometerReading reading           = args.Reading;
         ScenarioOutput_X_ReadingTransform.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
         ScenarioOutput_Y_ReadingTransform.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
         ScenarioOutput_Z_ReadingTransform.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
     });
 }
Exemplo n.º 24
0
 private void A_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         AccelerometerReading reading = args.Reading;
         ScenarioOutput_X.Text        = String.Format("{0,5:0.00}", reading.AccelerationX);
         ScenarioOutput_Y.Text        = String.Format("{0,5:0.00}", reading.AccelerationY);
         ScenarioOutput_Z.Text        = String.Format("{0,5:0.00}", reading.AccelerationZ);
     });
 }
Exemplo n.º 25
0
        private static void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
        {
            AccelerometerReading reading = e.Reading;
            Vector3 newAcceration        = new Vector3();

            newAcceration.X            = (float)(reading.AccelerationX * AccelerometerAlpha + reading.AccelerationX * (1.0f - AccelerometerAlpha)) + 0.25f;
            newAcceration.Y            = (float)(reading.AccelerationY * AccelerometerAlpha + reading.AccelerationY * (1.0f - AccelerometerAlpha));
            newAcceration.Z            = (float)(reading.AccelerationZ * AccelerometerAlpha + reading.AccelerationZ * (1.0f - AccelerometerAlpha));
            CurrentAccelerometerValues = newAcceration;
        }
Exemplo n.º 26
0
 private void ForceReadingUpdated(AccelerometerReading reading)
 {
     _forceReading = reading;
     if (_state == GenerationState.Gathering)
     {
         ForceX.Value = reading.AccelerationX;
         ForceY.Value = reading.AccelerationY;
         ForceZ.Value = reading.AccelerationZ;
     }
 }
Exemplo n.º 27
0
 private async void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
 {
     await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         AccelerometerReading reading = e.Reading;
         txtXAxis = String.Format("{0,5:0.00}", reading.AccelerationX);
         txtYAxis = String.Format("{0,5:0.00}", reading.AccelerationY);
         txtZAxis = String.Format("{0,5:0.00}", reading.AccelerationZ);
     });
 }
Exemplo n.º 28
0
 private async void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
 {
     AccelerometerReading reading = args.Reading;
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         accelerometerX.Text = string.Format("{0,5:0.00}", reading.AccelerationX);
         accelerometerY.Text = string.Format("{0,5:0.00}", reading.AccelerationY);
         accelerometerZ.Text = string.Format("{0,5:0.00}", reading.AccelerationZ);
     });
 }
Exemplo n.º 29
0
 private async void MyAccel_ReadingChanged(Accelerometer sender,
                                           AccelerometerReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         AccelerometerReading reading = args.Reading; // gets the reading
         updateUI(reading);                           // update the UI with that reading
     }
                               );
 }
Exemplo n.º 30
0
 void accelerometer_CurrentValueChanged(object sender, SensorReadingEventArgs <AccelerometerReading> e)
 {
     if (Math.Abs(lastReading.Acceleration.X - e.SensorReading.Acceleration.X) > ReadingThreshold)
     {
         if (Shook != null)
         {
             Shook(this, e); // Call shook event every time we shake
         }
     }
     lastReading = e.SensorReading;
 }