/// <summary>
        /// Creates an instance at the specified I2C <paramref name="address"/> with custom settings.
        /// </summary>
        /// <param name="address">
        /// I2C slave address of the chip.
        /// This is a physical property, not a software option.
        /// </param>
        /// <param name="fast">
        /// Set true for I2C <see cref="I2cBusSpeed.FastMode"/> or false for <see cref="I2cBusSpeed.StandardMode"/>.
        /// </param>
        /// <param name="exclusive">
        /// Set true for I2C <see cref="I2cSharingMode.Exclusive"/> or false for <see cref="I2cSharingMode.Shared"/>.
        /// </param>
        /// <param name="rate">Sampling rate.</param>
        public Ms5611Device(int address, bool fast, bool exclusive, Ms5611Osr rate)
            : base(address, fast, exclusive)
        {
            // Initialize members
            Prom = new Ms5611PromData();
            Osr = rate;

            // Read current calibration data (potentially not stable until next reset)
            // We don't reset automatically so that it is possible for any ongoing tasks to complete
            ReadProm();
        }
Example #2
0
        /// <summary>
        /// Creates an instance at the specified I2C <paramref name="address"/> with custom settings.
        /// </summary>
        /// <param name="address">
        /// I2C slave address of the chip.
        /// This is a physical property, not a software option.
        /// </param>
        /// <param name="fast">
        /// Set true for I2C <see cref="I2cBusSpeed.FastMode"/> or false for <see cref="I2cBusSpeed.StandardMode"/>.
        /// </param>
        /// <param name="exclusive">
        /// Set true for I2C <see cref="I2cSharingMode.Exclusive"/> or false for <see cref="I2cSharingMode.Shared"/>.
        /// </param>
        /// <param name="rate">Sampling rate.</param>
        public Ms5611Device(int address, bool fast, bool exclusive, Ms5611Osr rate)
            : base(address, fast, exclusive)
        {
            // Initialize members
            Prom = new Ms5611PromData();
            Osr  = rate;

            // Read current calibration data (potentially not stable until next reset)
            // We don't reset automatically so that it is possible for any ongoing tasks to complete
            ReadProm();
        }
Example #3
0
        /// <summary>
        /// Executes the <see cref="Ms5611Command.ConvertD2Temperature"/> command to measure
        /// pressure at the specified OSR, waits then returns the result.
        /// </summary>
        protected virtual int ConvertTemperature(Ms5611Osr rate)
        {
            // Send command to hardware
            Hardware.WriteJoinByte((byte)(Ms5611Command.ConvertD2Temperature + (byte)rate), 0);

            // Wait for completion
            WaitForConversion(rate);

            // Return result
            var result = Hardware.WriteReadBytes((byte)Ms5611Command.AdcRead, 3);

            return(result[0] << 16 | result[1] << 8 | result[2]);
        }
Example #4
0
        /// <summary>
        /// Executes the <see cref="Ms5611Command.ConvertD2Temperature"/> command to measure
        /// pressure at the specified OSR, waits then returns the result.
        /// </summary>
        public int ConvertTemperature(Ms5611Osr rate)
        {
            // Send command to hardware
            I2cExtensions.WriteJoinByte(_hardware, (byte)(Ms5611Command.ConvertD2Temperature + (byte)rate), 0);

            // Wait for completion
            WaitForConversion(rate);

            // Return result
            var result = I2cExtensions.WriteReadBytes(_hardware, (byte)Ms5611Command.AdcRead, 3);

            return(result[0] << 16 | result[1] << 8 | result[2]);
        }
        public Ms5611Device(I2cDevice device, Ms5611Osr rate)
        {
            // Validate
            if (device == null) throw new ArgumentNullException(nameof(device));

            // Initialize members
            Hardware = device;
            Prom = new Ms5611PromData();
            Osr = rate;

            // Read current calibration data (potentially not stable until next reset)
            // We don't reset automatically so that it is possible for any ongoing tasks to complete
            ReadProm();
        }
        public Ms5611Device(I2cDevice device, Ms5611Osr rate)
        {
            // Validate
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            // Initialize members
            Hardware = device;
            Prom     = new Ms5611PromData();
            Osr      = rate;

            // Read current calibration data (potentially not stable until next reset)
            // We don't reset automatically so that it is possible for any ongoing tasks to complete
            ReadProm();
        }
Example #7
0
        public Ms5611Device(int busNumber, bool csb, Ms5611Osr rate,
                            I2cBusSpeed speed = I2cBusSpeed.FastMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive)
        {
            // Get address
            ChipSelectBit = csb;
            Address       = GetI2cAddress(csb);

            // Connect to hardware
            _hardware = I2cExtensions.Connect(busNumber, Address, speed, sharingMode);

            // Initialize members
            Prom = new Ms5611PromData();
            Osr  = rate;

            // Read current calibration data (potentially not stable until next reset)
            // We don't reset automatically so that it is possible for any ongoing tasks to complete
            ReadProm();
        }
Example #8
0
        /// <summary>
        /// Gets the time to wait in milliseconds for conversion with the specified OSR.
        /// </summary>
        /// <param name="rate">Over-Sampling Rate for which to return the delay.</param>
        /// <returns>Delay in milliseconds.</returns>
        protected virtual int GetConvertDelay(Ms5611Osr rate)
        {
            switch (rate)
            {
            case Ms5611Osr.Osr256:
                return(ConvertOsr256Time);

            case Ms5611Osr.Osr512:
                return(ConvertOsr512Time);

            case Ms5611Osr.Osr1024:
                return(ConvertOsr1024Time);

            case Ms5611Osr.Osr2048:
                return(ConvertOsr2048Time);

            case Ms5611Osr.Osr4096:
                return(ConvertOsr4096Time);

            default:        // Future proof
                throw new NotImplementedException();
            }
        }
Example #9
0
        /// <summary>
        /// Waits for conversion at the specified OSR.
        /// </summary>
        /// <param name="rate">Over-Sampling Rate to wait for.</param>
        protected virtual void WaitForConversion(Ms5611Osr rate)
        {
            var delay = TimeSpanExtensions.FromMicroseconds(GetConvertDelay(rate));

            Task.Delay(delay).Wait();
        }
 /// <summary>
 /// Waits for conversion at the specified OSR.
 /// </summary>
 /// <param name="rate">Over-Sampling Rate to wait for.</param>
 protected virtual void WaitForConversion(Ms5611Osr rate)
 {
     var delay = TimeSpanExtensions.FromMicroseconds(GetConvertDelay(rate));
     Task.Delay(delay).Wait();
 }
        /// <summary>
        /// Gets the time to wait in milliseconds for conversion with the specified OSR.
        /// </summary>
        /// <param name="rate">Over-Sampling Rate for which to return the delay.</param>
        /// <returns>Delay in milliseconds.</returns>
        protected virtual int GetConvertDelay(Ms5611Osr rate)
        {
            switch (rate)
            {
                case Ms5611Osr.Osr256:
                    return ConvertOsr256Time;

                case Ms5611Osr.Osr512:
                    return ConvertOsr512Time;

                case Ms5611Osr.Osr1024:
                    return ConvertOsr1024Time;

                case Ms5611Osr.Osr2048:
                    return ConvertOsr2048Time;

                case Ms5611Osr.Osr4096:
                    return ConvertOsr4096Time;

                default:    // Future proof
                    throw new NotImplementedException();
            }
        }
        /// <summary>
        /// Executes the <see cref="Ms5611Command.ConvertD2Temperature"/> command to measure
        /// pressure at the specified OSR, waits then returns the result.
        /// </summary>
        protected virtual int ConvertTemperature(Ms5611Osr rate)
        {
            // Send command to hardware
            Hardware.WriteJoinByte((byte)(Ms5611Command.ConvertD2Temperature + (byte)rate), 0);

            // Wait for completion
            WaitForConversion(rate);

            // Return result
            var result = Hardware.WriteReadBytes((byte)Ms5611Command.AdcRead, 3);
            return result[0] << 16 | result[1] << 8 | result[2];
        }
Example #13
0
        /// <summary>
        /// Waits for conversion at the specified OSR.
        /// </summary>
        /// <param name="rate">Over-Sampling Rate to wait for.</param>
        private static void WaitForConversion(Ms5611Osr rate)
        {
            var delay = TimeSpanExtensions.FromMicroseconds(GetConvertDelay(rate));

            Task.Delay(delay).Wait();
        }