/// <summary>
        /// Read the sensor values from the relevant registers and parse.
        /// </summary>
        public AccelerationAndGyroData GetSensorData()
        {
            byte[] registerList = new byte[]
            {
                MPU6050Registers.ACCEL_XOUT_H,
                MPU6050Registers.ACCEL_XOUT_L,
                MPU6050Registers.ACCEL_YOUT_H,
                MPU6050Registers.ACCEL_YOUT_L,
                MPU6050Registers.ACCEL_ZOUT_H,
                MPU6050Registers.ACCEL_ZOUT_L,
                MPU6050Registers.TEMP_OUT_H,
                MPU6050Registers.TEMP_OUT_L,
                MPU6050Registers.GYRO_XOUT_H,
                MPU6050Registers.GYRO_XOUT_L,
                MPU6050Registers.GYRO_YOUT_H,
                MPU6050Registers.GYRO_YOUT_L,
                MPU6050Registers.GYRO_ZOUT_H,
                MPU6050Registers.GYRO_ZOUT_L
            };

            // Funky - you need to do this, otherwise you won't get anything back. See MPU-6050 datasheet for details.
            //_I2C.Write(new byte[] { MPU6050Registers.ACCEL_XOUT_H });
            _I2CBus.Write(_i2cConfig, new byte[] { MPU6050Registers.ACCEL_XOUT_H }, _timeout);
            //_I2C.Read(registerList);
            _I2CBus.Read(_i2cConfig, registerList, _timeout);

            var result = AccelerationAndGyroDataBuilder.Build(registerList, _gyroRange, _accelRange);

            return(result);
        }
Esempio n. 2
0
 public override void Update()
 {
     _twiBus.Read(_i2cConfiguration, _buffer, 100);
     Throttle   = _settings.ThrottleScale.Calculate(BitConverter.ToShort(_buffer, 0));
     Axes.Pitch = _settings.AxesScale.Calculate(BitConverter.ToShort(_buffer, 2)) * _settings.RadioSensitivityFactor;
     Axes.Roll  = _settings.AxesScale.Calculate(BitConverter.ToShort(_buffer, 4)) * _settings.RadioSensitivityFactor;
     Axes.Yaw   = _settings.AxesScale.Calculate(BitConverter.ToShort(_buffer, 6)) * _settings.RadioSensitivityFactor;
     Gear       = BitConverter.ToShort(_buffer, 8) > 1500;
 }
Esempio n. 3
0
        /// <summary>
        /// Read operation from the BlinkM.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public int Read(Command.BaseCommand command)
        {
            I2CBus bus      = I2CBus.GetInstance();
            int    retValue = bus.Read(this._I2CConfig, command.GetReceiveBytes(), I2CTimeout);

            if (command.WaitMillis > 0)
            {
                Thread.Sleep(command.WaitMillis);
            }

            return(retValue);
        }
Esempio n. 4
0
        /// <summary>
        /// Reset the DS2482 and read the status byte
        /// </summary>
        private void ResetDS2482()
        {
            try
            {
                commandBytes = new byte[1] {
                    (byte)DS2482FunctionCommands.DeviceReset
                };
                readBuffer = new byte[1];

                i2cBus.Write(commandBytes, commTimeout);
                i2cBus.Read(readBuffer, commTimeout);

                // Verify that communication has occured. After reset RST bit should be 1
                if ((readBuffer[0] & (byte)DS2482StatusBits.DeviceReset) != (byte)DS2482StatusBits.DeviceReset)
                {
                    throw new Exception("DS2482 not found on I2C Bus");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }