예제 #1
0
        /// <summary>
        /// SPI Accelerometer ADX1345
        /// </summary>
        /// <param name="sensor">The communications channel to a device on a SPI bus</param>
        /// <param name="gravityRange">Gravity Measurement Range</param>
        public Adxl345(SpiDevice sensor, GravityRange gravityRange)
        {
            if (gravityRange == GravityRange.Range02)
            {
                _range = 4;
            }
            else if (gravityRange == GravityRange.Range04)
            {
                _range = 8;
            }
            else if (gravityRange == GravityRange.Range08)
            {
                _range = 16;
            }
            else if (gravityRange == GravityRange.Range16)
            {
                _range = 32;
            }

            _gravityRangeByte = (byte)gravityRange;

            _sensor = sensor;

            Initialize();
        }
예제 #2
0
파일: Adxl345.cs 프로젝트: thecaptncode/iot
 /// <summary>
 /// SPI Accelerometer ADX1345
 /// </summary>
 /// <param name="sensor">The communications channel to a device on a SPI bus</param>
 /// <param name="gravityRange">Gravity Measurement Range</param>
 public Adxl345(SpiDevice sensor, GravityRange gravityRange)
 {
     _sensor = sensor ?? throw new ArgumentNullException(nameof(sensor));
     _range  = gravityRange switch
     {
         GravityRange.Range02 => 4,
         GravityRange.Range04 => 8,
         GravityRange.Range08 => 16,
         GravityRange.Range16 => 32,
         _ => 0
     };
     _gravityRangeByte = (byte)gravityRange;
     Initialize();
 }
예제 #3
0
        private const byte ACCEL_SPI_MB_BIT = 0x40;         // Bit used to indicate multi-byte SPI transactions

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="chipSelect">CS Port</param>
        /// <param name="gravityRange">Gravity Range, 2G, 4G, 8G, 16G</param>
        public ADXL345(int chipSelect, GravityRange gravityRange)
        {
            cs = chipSelect;
            if (gravityRange == GravityRange.Two)
            {
                range = 4;
            }
            else if (gravityRange == GravityRange.Four)
            {
                range = 8;
            }
            else if (gravityRange == GravityRange.Eight)
            {
                range = 16;
            }
            else if (gravityRange == GravityRange.Sixteen)
            {
                range = 32;
            }
            gravityRangeByte = (byte)gravityRange;
        }