/// <summary> /// Reads calibration information from BMP280. /// </summary> /// <returns>Task.</returns> private async Task <BMP280CalibrationInformation> ReadCalibrationInformation() { // Read information from I2C device. var information = new BMP280CalibrationInformation { // Read temperatur calibration information Temperatur1 = ReadUIntFromLittleEndian(REGISTER_DIGIT_TEMPERATUR_1), Temperatur2 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_TEMPERATUR_2), Temperatur3 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_TEMPERATUR_3), // Read pressure calibration information. Pressure1 = ReadUIntFromLittleEndian(REGISTER_DIGIT_PRESSURE_1), Pressure2 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_PRESSURE_2), Pressure3 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_PRESSURE_3), Pressure4 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_PRESSURE_4), Pressure5 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_PRESSURE_5), Pressure6 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_PRESSURE_6), Pressure7 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_PRESSURE_7), Pressure8 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_PRESSURE_8), Pressure9 = (short)ReadUIntFromLittleEndian(REGISTER_DIGIT_PRESSURE_9) }; // Ensure that every request has been read and processed. await Task.Delay(1); // Return the information. return(information); }
/// <summary> /// Initializes the BMP280 async. /// /// Caution: /// This is required before accessing other /// methods in this class. /// </summary> /// <param name="i2cController">Underlying I2C controller.</param> /// <returns>Task.</returns> public async Task InitializeAsync(I2cController i2cController) { Logger.Log(this, "InitializeAsync"); // Setup device. bmp280 = i2cController.GetDevice(new I2cConnectionSettings(BMP280_ADDRESS) { BusSpeed = I2cBusSpeed.FastMode }); // Ensure device has been found. if (bmp280 == null) { throw new OperationCanceledException("BPM280 device not found."); } // Setup device. byte[] writeBuffer = new byte[] { REGISTER_CHIPID }; byte[] readBuffer = new byte[] { 0xFF }; // Read signature. bmp280.WriteRead(writeBuffer, readBuffer); byte signature = readBuffer[0]; // Ensure valid signature has been found. if (signature != BMP280_SIGNATURE) { Logger.Log(this, $"Found signature {signature.ToString()} does not match required signature: '{BMP280_SIGNATURE.ToString()}'"); return; } // Set state as initialized. isInitialized = true; // Read calibration information from i2c device. calibrationInformation = await ReadCalibrationInformation(); // Write /enable(?) control register await WriteControlRegister(); }