/// <summary>
        /// Lsm9Ds1 - Magnetometer bus
        /// </summary>
        public Lsm9Ds1Magnetometer(
            I2cDevice i2cDevice,
            MagneticInductionScale magneticInductionScale = MagneticInductionScale.Scale04G)
        {
            if (i2cDevice == null)
            {
                throw new ArgumentNullException(nameof(i2cDevice));
            }

            _i2c = i2cDevice;
            _magneticInductionScale = magneticInductionScale;

            byte temperatureCompensation = 1;     // enable temperature compensation
            byte operativeMode           = 0b11;  // Ultra high performance mode
            byte outputDataRate          = 0b111; // 80Hz
            byte fastOutputDataRate      = 0;     // disable fast ODR (> 80Hz)
            byte selfTestEnabled         = 0;     // disable self-test

            byte disableI2c    = 0;               // enable I2C
            byte lowPowerMode  = 0;               // higher power mode
            byte spiAllowReads = 0;               // only writes allowed
            byte operatingMode = 0b00;            // continous mode

            byte operativeModeForZAxis = 0b11;    // ultra-high performance mode
            byte bigEndianEnabled      = 0;       // little endian

            Span <byte> buff = stackalloc byte[5]
            {
                (byte)((temperatureCompensation << 7)
                       | (operativeMode << 5)
                       | (outputDataRate << 2)
                       | (fastOutputDataRate << 1)
                       | selfTestEnabled),
                (byte)((byte)magneticInductionScale << 5),
                (byte)((disableI2c << 7)
                       | (lowPowerMode << 5)
                       | (spiAllowReads << 2)
                       | operatingMode),
                (byte)((operativeModeForZAxis << 2)
                       | (bigEndianEnabled << 1)),
                0x00,
            };

            Write(RegisterM.Control1, buff);
        }
Esempio n. 2
0
 public SenseHatMagnetometer(
     I2cDevice i2cDevice = null,
     MagneticInductionScale magneticInduction = MagneticInductionScale.Scale04G)
     : base(i2cDevice ?? CreateDefaultI2cDevice(), magneticInduction)
 {
 }