コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: simple0812/IoT
 private void _mpu6050_SensorInterruptEvent(object sender, MpuSensorEventArgs e)
 {
     var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         _interruptCount         += e.Values.Length;
         float samples_per_second = (float)_interruptCount / (float)((DateTime.Now - _startTime).Seconds);
         textBoxStatus.Text       = String.Format("{0} {1} {2}", e.Status, e.SamplePeriod, samples_per_second);
         textBoxAccel.Text        = String.Format("{0}, {1}, {2}", e.Values[0].AccelerationX, e.Values[0].AccelerationY, e.Values[0].AccelerationZ);
         textBoxGyro.Text         = String.Format("{0}, {1}, {2}", e.Values[0].GyroX, e.Values[0].GyroY, e.Values[0].GyroZ);
     });
 }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: erickbp/IoT
 private void _mpu6050_SensorInterruptEvent(object sender, MpuSensorEventArgs e)
 {
     var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         _interruptCount += e.Values.Length;
         float samples_per_second = (float)_interruptCount / (float)((DateTime.Now - _startTime).Seconds);
         textBoxStatus.Text = String.Format("{0} {1} {2}", e.Status, e.SamplePeriod, samples_per_second);
         textBoxAccel.Text = String.Format("{0}, {1}, {2}", e.Values[0].AccelerationX, e.Values[0].AccelerationY, e.Values[0].AccelerationZ);
         textBoxGyro.Text = String.Format("{0}, {1}, {2}", e.Values[0].GyroX, e.Values[0].GyroY, e.Values[0].GyroZ);
     });
 }
コード例 #3
0
ファイル: Class1.cs プロジェクト: simple0812/IoT
        private void Interrupt(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            if (_mpu6050Device != null)
            {
                int interrupt_status = ReadByte(INT_STATUS);
                if ((interrupt_status & 0x10) != 0)
                {
                    WriteByte(USER_CTRL, 0x44); // reset and enable fifo
                }
                if ((interrupt_status & 0x1) != 0)
                {
                    MpuSensorEventArgs ea = new MpuSensorEventArgs();
                    ea.Status       = (byte)interrupt_status;
                    ea.SamplePeriod = 0.02f;
                    List <MpuSensorValue> l = new List <MpuSensorValue>();

                    int count = ReadWord(FIFO_COUNT);

                    while (count >= SensorBytes)
                    {
                        byte[] data = ReadBytes(FIFO_R_W, (byte)SensorBytes);
                        count -= SensorBytes;

                        short xa = (short)((int)data[0] << 8 | (int)data[1]);
                        short ya = (short)((int)data[2] << 8 | (int)data[3]);
                        short za = (short)((int)data[4] << 8 | (int)data[5]);

                        short xg = (short)((int)data[6] << 8 | (int)data[7]);
                        short yg = (short)((int)data[8] << 8 | (int)data[9]);
                        short zg = (short)((int)data[10] << 8 | (int)data[11]);

                        MpuSensorValue sv = new MpuSensorValue();
                        sv.AccelerationX = (float)xa / (float)16384;
                        sv.AccelerationY = (float)ya / (float)16384;
                        sv.AccelerationZ = (float)za / (float)16384;
                        sv.GyroX         = (float)xg / (float)131;
                        sv.GyroY         = (float)yg / (float)131;
                        sv.GyroZ         = (float)zg / (float)131;
                        l.Add(sv);
                    }
                    ea.Values = l.ToArray();

                    if (SensorInterruptEvent != null)
                    {
                        if (ea.Values.Length > 0)
                        {
                            SensorInterruptEvent(this, ea);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: Class1.cs プロジェクト: erickbp/IoT
        private void Interrupt(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            if (_mpu6050Device != null)
            {
                int interrupt_status = ReadByte(INT_STATUS);
                if ((interrupt_status & 0x10) != 0)
                {
                    WriteByte(USER_CTRL, 0x44); // reset and enable fifo
                }
                if ((interrupt_status & 0x1) != 0)
                {
                    MpuSensorEventArgs ea = new MpuSensorEventArgs();
                    ea.Status = (byte)interrupt_status;
                    ea.SamplePeriod = 0.02f;
                    List<MpuSensorValue> l = new List<MpuSensorValue>();

                    int count = ReadWord(FIFO_COUNT);

                    while (count >= SensorBytes)
                    {
                        byte[] data = ReadBytes(FIFO_R_W, (byte)SensorBytes);
                        count -= SensorBytes;

                        short xa = (short)((int)data[0] << 8 | (int)data[1]);
                        short ya = (short)((int)data[2] << 8 | (int)data[3]);
                        short za = (short)((int)data[4] << 8 | (int)data[5]);

                        short xg = (short)((int)data[6] << 8 | (int)data[7]);
                        short yg = (short)((int)data[8] << 8 | (int)data[9]);
                        short zg = (short)((int)data[10] << 8 | (int)data[11]);

                        MpuSensorValue sv = new MpuSensorValue();
                        sv.AccelerationX = (float)xa / (float)16384;
                        sv.AccelerationY = (float)ya / (float)16384;
                        sv.AccelerationZ = (float)za / (float)16384;
                        sv.GyroX = (float)xg / (float)131;
                        sv.GyroY = (float)yg / (float)131;
                        sv.GyroZ = (float)zg / (float)131;
                        l.Add(sv);
                    }
                    ea.Values = l.ToArray();

                    if (SensorInterruptEvent != null)
                    {
                        if (ea.Values.Length > 0)
                        {
                            SensorInterruptEvent(this, ea);
                        }
                    }
                }
            }
        }