コード例 #1
0
    private double Accelerometer_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandAccelerometerReading> e)
    {
        IBandAccelerometerReading accel = e.SensorReading;
        //Read in accelerometer data from sensor
        string text = string.Format("Accelerometer X = {0:G4}, Y = {1:G4}, Z = {2:G4}", accel.AccelerationX, accel.AccelerationY, accel.AccelerationZ);

        System.Diagnostics.Debug.WriteLine(text);
        return(Math.Abs(Math.Max(accel.AccelerationX, Math.Max(accel.AccelerationY, accel.AccelerationZ))));
    }
コード例 #2
0
 public static AccelerometerReading FromBandSensor(IBandAccelerometerReading reading)
 {
     return new AccelerometerReading
     {
         AccelerationX = reading.AccelerationX,
         AccelerationY = reading.AccelerationY,
         AccelerationZ = reading.AccelerationZ,
         Timestamp = reading.Timestamp
     };
 }
コード例 #3
0
        private void Accelerometer_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandAccelerometerReading> e)
        {
            IBandAccelerometerReading accelerometerRead = e.SensorReading;

            data.accelerometer = new VectorData3D <double>()
            {
                X = accelerometerRead.AccelerationX,
                Y = accelerometerRead.AccelerationY,
                Z = accelerometerRead.AccelerationZ
            };
        }
コード例 #4
0
        private async void Accelerometer_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandAccelerometerReading> e)
        {
            IBandAccelerometerReading accel = e.SensorReading;

            string text = string.Format("X = {0}\nY = {1}\nZ = {2}", accel.AccelerationX, accel.AccelerationY, accel.AccelerationZ);

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                this.accelerometerBlock.Text = text;
            }).AsTask();
        }
コード例 #5
0
        public void AddMeasurement(IBandAccelerometerReading reading)
        {
            _numMeasPoints++;
            var acc = new Vector(reading.AccelerationX, reading.AccelerationY, reading.AccelerationZ);
            if (_numMeasPoints < 10)
            {
                _calibrationValues.Add(acc);
                return;
            }
            if (_numMeasPoints == 10)
            {
                _calibrationValue = 1.0 / _calibrationValues.AverageValue;
                _calibrationValues = null;

                Debug.WriteLine($"Calibrated to {_calibrationValue}");
            }

            _lastAccValue = acc.Multiply(9.81 * _calibrationValue);
            //Debug.WriteLine($"Acc: {acc}, value: {acc.Value}");
        }
コード例 #6
0
        public void AddMeasurement(IBandAccelerometerReading reading)
        {
            _numMeasPoints++;
            var acc = new Vector(reading.AccelerationX, reading.AccelerationY, reading.AccelerationZ);

            if (_numMeasPoints < 10)
            {
                _calibrationValues.Add(acc);
                return;
            }
            if (_numMeasPoints == 10)
            {
                _calibrationValue  = 1.0 / _calibrationValues.AverageValue;
                _calibrationValues = null;

                Debug.WriteLine($"Calibrated to {_calibrationValue}");
            }

            _lastAccValue = acc.Multiply(9.81 * _calibrationValue);
            //Debug.WriteLine($"Acc: {acc}, value: {acc.Value}");
        }
コード例 #7
0
        private async void Accelerometer_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandAccelerometerReading> e)
        {
            IBandAccelerometerReading accel = e.SensorReading;

            accelData = string.Format("X = {0:G4}\nY = {1:G4}\nZ = {2:G4}", accel.AccelerationX, accel.AccelerationY, accel.AccelerationZ);
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                listView.Items.Add(accelData);
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    isoStore.CreateDirectory("Accelerometer");
                    IsolatedStorageFileStream fileStream = isoStore.OpenFile("Accelerometer\\myFile.txt", FileMode.Append, FileAccess.Write);
                    using (StreamWriter writeFile = new StreamWriter(fileStream))
                    {
                        writeFile.WriteLine(accelData.ToString());
                        writeFile.Dispose();
                    }
                }

                //using (IsolatedStorageFile Loisf = IsolatedStorageFile.GetUserStoreForApplication())
                //{
                //    if (Loisf.FileExists("myData.store"))
                //    {
                //        using (IsolatedStorageFileStream fstream = Loisf.OpenFile("myData.store", FileMode.Open))
                //        {
                //            IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
                //            IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("Accelerometer\\myFile.txt", FileMode.Open, FileAccess.Read);
                //            fileStream.Position = 0;
                //            using (StreamReader reader = new StreamReader(fileStream))
                //            {
                //                tbResult.Text += "\n" + reader.ReadToEnd();
                //            }
                //        }
                //    }

                //}
            }).AsTask();
        }
コード例 #8
0
 public BandAccelerometerSensorReadingEventArgs(IBandAccelerometerReading sensorReading)
 {
     this.SensorReading = sensorReading;
 }
コード例 #9
0
        private async void Accelerometer_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandAccelerometerReading> e)
        {
            IBandAccelerometerReading accel = e.SensorReading;
            string text = string.Format("X = {0}\nY = {1}\nZ = {2}", accel.AccelerationX, accel.AccelerationY, accel.AccelerationZ);
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.textBlock.Text = text; }).AsTask();

            //multiply MET value by weight in kilograms and by 3.5
            Product_MET_kilo = MET_Value * 3.5 * Weight_kgs;

            // Get calories per minute
            CaloriesPerMinute = Product_MET_kilo / 200;

            var settings = Windows.Storage.ApplicationData.Current.RoamingSettings;
            //read secs value from settings storage
            Object secs = settings.Values["secs"];

            if (stoptrig == true)
            {
                string timeout_enabled = settings.Values["timeout-checked"].ToString();
                if (timeout_enabled == "true")
                {
                    dispatcherTimer_trig.Start();
                }
            }
            if (Secs <= 58)
            {
                PartOfMinute = Secs * 0.01666667;
            }
            else
            {
                PartOfMinute = 0;
            }

            if (ThresholdTarget == ThresholdDetectEnum.THRESHOLD_1)
            {
                /******************************************************************
                * Determine if we hit Threshold 1 based off of vector acceleration
                * ****************************************************************/

                if (
                    // X range set
                    EvalLambda(accel.AccelerationX, XVectorThreshold1_1, CompareLambdaExpx1_1) &&
                    EvalLambda(accel.AccelerationX, XVectorThreshold1_2, CompareLambdaExpx1_2)
                    // Y Range set
                    && EvalLambda(accel.AccelerationY, YVectorThreshold1_1, CompareLambdaExpy1_1) &&
                    EvalLambda(accel.AccelerationY, YVectorThreshold1_2, CompareLambdaExpy1_2)
                    // Z Range set
                    && EvalLambda(accel.AccelerationZ, ZVectorThreshold1_1, CompareLambdaExpz1_1) &&
                    EvalLambda(accel.AccelerationZ, ZVectorThreshold1_2, CompareLambdaExpz1_2)
                    )
                {
                    // Set new threshold target to THRESHOLD_2
                    ThresholdTarget = ThresholdDetectEnum.THRESHOLD_2;
                    //stoptrig = true;
                    //reset pause trigger counter and hide paused screen
                    Object time_checked    = settings.Values["timeout-checked"];
                    string timeout_checked = time_checked.ToString();

                    if (timeout_checked != null)
                    {
                        timeout_enabled = settings.Values["timeout-checked"].ToString();

                        if (timeout_enabled == "true")
                        {
                            dispatcherTimer_trig.Stop();
                            dispatcherTimer_trig.Start();
                        }
                    }
                    else
                    {
                        if (timeout_enabled == "false")
                        {
                        }
                        else
                        {
                            dispatcherTimer_trig.Stop();
                            dispatcherTimer_trig.Start();
                        }
                    }
                    btn_pause.Visibility   = Windows.UI.Xaml.Visibility.Visible;
                    pause_layer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    Status_Text.Text       = "Active";
                    if (lockedflag == true)
                    {
                        btn_reset.IsEnabled = false;
                        btn_stop.IsEnabled  = false;
                    }
                }
                else
                {
                    //do nothing or pause logic here
                }
            }

            else
            {
                if (ThresholdTarget == ThresholdDetectEnum.THRESHOLD_2)
                {
                    /******************************************************************
                    * Determine if we hit threshold 2 based off of vector acceleration
                    * ****************************************************************/
                    if (
                        // X range set
                        EvalLambda(accel.AccelerationX, XVectorThreshold2_1, CompareLambdaExpx2_1) &&
                        EvalLambda(accel.AccelerationX, XVectorThreshold2_2, CompareLambdaExpx2_2)
                        // Y range set
                        && EvalLambda(accel.AccelerationY, YVectorThreshold2_1, CompareLambdaExpy2_1) &&
                        EvalLambda(accel.AccelerationY, YVectorThreshold2_2, CompareLambdaExpy2_2)
                        //z range set
                        && EvalLambda(accel.AccelerationZ, ZVectorThreshold2_1, CompareLambdaExpz2_1) &&
                        EvalLambda(accel.AccelerationZ, ZVectorThreshold2_2, CompareLambdaExpz2_2)
                        )
                    {
                        // Increment Rep count only on second threshold!!!
                        RepCounterHelper.GlobalCount++;

                        // Update Rep count display
                        Count_Number.Text = RepCounterHelper.GlobalCount.ToString("");
                        //stop if no movement
                        if (!dispatcherTimer.IsEnabled)
                        {
                            dispatcherTimer.Start();
                        }
                        // Set new threshold target to THRESHOLD_1
                        ThresholdTarget = ThresholdDetectEnum.THRESHOLD_1;
                        //reset pause trigger counter
                        dispatcherTimer_trig.Stop();
                        dispatcherTimer_trig.Start();
                        btn_pause.Visibility   = Windows.UI.Xaml.Visibility.Visible;
                        pause_layer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                        Status_Text.Text       = "Active";
                        if (lockedflag == true)
                        {
                            btn_reset.IsEnabled = false;
                            btn_stop.IsEnabled  = false;
                        }
                    }
                    else
                    {
                        //do nothing or pause logic here
                    }
                    Magnitude = Math.Sqrt(Math.Pow(accel.AccelerationX, 2) + Math.Pow(accel.AccelerationY, 2) + Math.Pow(accel.AccelerationZ, 2));
                    // Show the values graphically.
                    //this.chart.Series[0].ItemsSource = Magnitude;
                }
            }
        }
コード例 #10
0
 public void AddAccelerometerReading(IBandAccelerometerReading accelerometerReading)
 {
     rx.OnNext(accelerometerReading);
 }
コード例 #11
0
ファイル: MainPage.xaml.cs プロジェクト: sindab/ContextShow
 string FormatAccelerometer(IBandAccelerometerReading reading) =>
 $"X:{reading.AccelerationX:F2},Y:{reading.AccelerationY:F2},Z:{reading.AccelerationZ:F2}";
コード例 #12
0
        private async void Start_Click(object sender, RoutedEventArgs e)
        {
            this.Stop.IsEnabled  = true;
            this.Start.IsEnabled = false;
            StatusMessage.Text   = "";
            // load list point stored in previous collections
            //ListPoint = store.LoadDataPoint(FileName);
            unknown.Clear();
            try
            {
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();

                if (pairedBands.Length < 1)
                {
                    this.StatusMessage.Text = "This app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                    return;
                }

                // Connect to Microsoft Band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {
                    int       samplesReceivedAcc  = 0; // the number of Accelerometer samples received
                    int       samplesReceivedGyro = 0; // the number of Gyroscope samples received
                    Stopwatch myWatch             = Stopwatch.StartNew();
                    // Subscribe to Accelerometer data.
                    bandClient.SensorManager.Accelerometer.ReadingChanged += (s, args) =>
                                                                             bandClient.SensorManager.Gyroscope.ReadingChanged += (s1, args1) =>
                    {
                        Point point = new Point();
                        samplesReceivedAcc++;
                        if ((samplesReceivedAcc % 50) == 0)
                        {
                            // Only report occasional Accelerometer data
                            IBandAccelerometerReading readings = args.SensorReading;
                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                this.Accx.Text = readings.AccelerationX.ToString();
                                this.Accy.Text = readings.AccelerationY.ToString();
                                this.Accz.Text = readings.AccelerationZ.ToString();

                                point.setAccelerometter(readings.AccelerationX, readings.AccelerationY, readings.AccelerationZ);
                            });
                        }
                        samplesReceivedGyro++;
                        if ((samplesReceivedGyro % 50) == 0)
                        {
                            // Only report occasional Gyroscope data
                            IBandGyroscopeReading readings = args1.SensorReading;
                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                this.Gyx.Text = readings.AccelerationX.ToString();
                                this.Gyy.Text = readings.AccelerationY.ToString();
                                this.Gyz.Text = readings.AccelerationZ.ToString();
                                Clock.Text    = myWatch.Elapsed.ToString();
                                point.setGyroscope(readings.AccelerationX, readings.AccelerationY, readings.AccelerationZ);
                                // point.SampleName = samplename;
                                unknown.Add(point);
                            });
                        }
                    };
                    await bandClient.SensorManager.Accelerometer.StartReadingsAsync();

                    await bandClient.SensorManager.Gyroscope.StartReadingsAsync();

                    // Receive sensor data for a while
                    await Task.Delay(TimeSpan.FromSeconds(2));

                    // Stop the sensor subscriptions

                    await bandClient.SensorManager.Accelerometer.StopReadingsAsync();

                    await bandClient.SensorManager.Gyroscope.StopReadingsAsync();
                }
            }
            catch (Exception ex)
            {
                this.StatusMessage.Text = ex.ToString();
            }
        }
コード例 #13
0
 public ChangeInMotion(double ChangeVsLastReading, IBandAccelerometerReading Reading)
 {
     this.ChangeVsLastReading = ChangeVsLastReading;
     this.Reading             = Reading;
 }