private void CrossDeviceMotion_Current_SensorValueChanged(object sender, SensorValueChangedEventArgs e)
        {
            switch(e.SensorType)
            {
                case MotionSensorType.Accelerometer:
                    System.Diagnostics.Debug.WriteLine("A: {0},{1},{2}", ((MotionVector)e.Value).X, ((MotionVector)e.Value).Y, ((MotionVector)e.Value).Z);
                    break;

                case MotionSensorType.Compass:
                    System.Diagnostics.Debug.WriteLine("C: {0}", e.Value);
                    break;

                case MotionSensorType.Gyroscope:
                    System.Diagnostics.Debug.WriteLine("G: {0},{1},{2}", ((MotionVector)e.Value).X, ((MotionVector)e.Value).Y, ((MotionVector)e.Value).Z);
                    break;
            }
        }
        public void sensorRegistration( Object s,SensorValueChangedEventArgs a)
        {
            CrossDeviceMotion.Current.Start(MotionSensorType.Accelerometer, MotionSensorDelay.Ui);
            CrossDeviceMotion.Current.Start(MotionSensorType.Magnetometer, MotionSensorDelay.Ui);
            CrossDeviceMotion.Current.Start(MotionSensorType.Gyroscope, MotionSensorDelay.Ui);

            //TODO explain each line of code here
            float[] values = new float[3];
             float[] valuesGyro = new float[3];
            switch (a.SensorType)
                {
                    case MotionSensorType.Accelerometer:

                        values[0] = (float)((MotionVector)a.Value).X;
                        values[1] = (float)((MotionVector)a.Value).Y;
                        values[2] = (float)((MotionVector)a.Value).Z;
                        filterLowPass(values, gravity, 0.98f);
                        orienGetter.setAccelerometerParam(gravity);
                        orienGetter.calculateAccMagOrientation();
                        degree = orienGetter.getFusOrientation();
                    dt = orienGetter.getDeltaT();
                    //degree = orienGetter.getOrientation(valuesGyro);
                    break;
                    case MotionSensorType.Magnetometer:
                        values[0] = (float)((MotionVector)a.Value).X;
                        values[1] = (float)((MotionVector)a.Value).Y;
                        values[2] = (float)((MotionVector)a.Value).Z;
                        orienGetter.setMagnetometerParam(values);

                   // filterLowPass(orienGetter.getOrientation(), orientation, 0.98f);

                    //for (int i = 0; i < 3; i++)
                    //    degree[i] = (float)(orientation[i] * 180 / Math.PI);

                    //give a text title to current direction.
                    //str = directionEstimate(degree[0]);

                    //Console.WriteLine(str);

                    //transfer radian to degree
                    //for (int i = 0; i < 3; i++)
                    //{
                    //    if (degree[i] < 0)
                    //        degree[i] += 360;
                    //}

                    //Debug.WriteLine("Values: {0}, {1}, {2}, {3}", orientation[0], orientation[1], orientation[2], str);

                    break;
                case MotionSensorType.Gyroscope:
                    if(!counter)
                    {
                        counter = true;
                        lastTimestamp = DateTime.Now.ToLocalTime().Ticks;
                        newTimestamp = DateTime.Now.ToLocalTime().Ticks;

                    }
                    dt = (newTimestamp-lastTimestamp)/Math.Pow(10,7);
                    lastTimestamp = newTimestamp;
                    valuesGyro[0] = (float)((MotionVector)a.Value).X;
                    valuesGyro[1] = (float)((MotionVector)a.Value).Y;
                    valuesGyro[2] = (float)((MotionVector)a.Value).Z;
                    orienGetter.gyroFunction(valuesGyro);
                    newTimestamp = DateTime.Now.ToLocalTime().Ticks;
                    degree = orienGetter.getFusOrientation();
                    break;
            };
        }