示例#1
0
        private async Task InitializeAdF_LSM303_Accel_I2CDevice()
        {
            try
            {
                // Initialize I2C device
                var settings = new I2cConnectionSettings(Adafruit_LSM303_Accel_Unified.LSM303_ADDRESS_ACCEL);

                settings.BusSpeed    = I2cBusSpeed.FastMode;
                settings.SharingMode = I2cSharingMode.Shared;

                string aqs = I2cDevice.GetDeviceSelector("I2C1");               /* Find the selector string for the I2C bus controller                   */
                var    dis = await DeviceInformation.FindAllAsync(aqs);         /* Find the I2C bus controller device with our selector string           */

                I2CDevaccel = await I2cDevice.FromIdAsync(dis[0].Id, settings); /* Create an I2cDevice with our selected bus controller and I2C settings */

                accel       = new Adafruit_LSM303_Accel_Unified(ref I2CDevaccel, 30301);
                accelSensor = accel.getSensorObj();
                accel.getSensor(ref accelSensor);
                Debug.WriteLine("------------- ACCELEROMETER -----------");
                Debug.WriteLine("Sensor:       " + accelSensor.name);
                Debug.WriteLine("Driver Ver:   " + accelSensor.version);
                Debug.WriteLine("Unique ID:    " + accelSensor.sensor_id);
                Debug.WriteLine("Max Value:    " + accelSensor.max_value + " m/s^2");
                Debug.WriteLine("Min Value:    " + accelSensor.min_value + " m/s^2");
                Debug.WriteLine("Resolution:   " + accelSensor.resolution + " m/s^2");
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());

                return;
            }
        }