Example #1
0
        public void getGyros(mpuCallbackData callback, int delay)
        {
            if (this.deviceReady && this.mpu != null)
            {
                try
                {
                    for (;;)
                    {
                        double[] data    = new double[3];
                        byte[]   ReadBuf = new byte[6];
                        this.mpu.WriteRead(new byte[] { GYRO_XOUT_H }, ReadBuf);

                        data[0] = BitConverter.ToInt16(new byte[] { ReadBuf[1], ReadBuf[0] }, 0);
                        data[1] = BitConverter.ToInt16(new byte[] { ReadBuf[3], ReadBuf[2] }, 0);
                        data[2] = BitConverter.ToInt16(new byte[] { ReadBuf[5], ReadBuf[4] }, 0);

                        callback(data);
                        Task.Delay(delay).Wait();
                    }
                }
                catch (Exception err)
                {
                    Debug.WriteLine(err.Message);
                }
            }
        }
Example #2
0
        public void getMotion6(mpuCallbackData callback, int delay)
        {
            if (this.deviceReady && this.mpu != null)
            {
                try
                {
                    for (;;)
                    {
                        double[] data    = new double[9];
                        byte[]   ReadBuf = new byte[14];
                        this.mpu.WriteRead(new byte[] { ACCEL_XOUT_H }, ReadBuf);

                        data[0] = BitConverter.ToInt16(new byte[] { ReadBuf[1], ReadBuf[0] }, 0);
                        data[1] = BitConverter.ToInt16(new byte[] { ReadBuf[3], ReadBuf[2] }, 0);
                        data[2] = BitConverter.ToInt16(new byte[] { ReadBuf[5], ReadBuf[4] }, 0);

                        data[3] = BitConverter.ToInt16(new byte[] { ReadBuf[7], ReadBuf[8] }, 0);
                        data[4] = BitConverter.ToInt16(new byte[] { ReadBuf[9], ReadBuf[10] }, 0);
                        data[5] = BitConverter.ToInt16(new byte[] { ReadBuf[13], ReadBuf[12] }, 0);

                        if (this.magnetometer != null)
                        {
                            var tmpData = this.magnetometer.getMagnetometer();
                            data[6] = tmpData[0];
                            data[7] = tmpData[1];
                            data[8] = tmpData[2];
                        }

                        callback(data);
                        Task.Delay(delay).Wait();
                    }
                }
                catch (Exception err)
                {
                    Debug.WriteLine(err.Message);
                }
            }
        }
Example #3
0
 public void getGyros(mpuCallbackData callback)
 {
     this.getGyros(callback, 1000);
 }
Example #4
0
 public void getAccel(mpuCallbackData callback)
 {
     this.getAccel(callback, 1000);
 }
Example #5
0
 public void getMotion6(mpuCallbackData callback)
 {
     this.getMotion6(callback, 1000);
 }