bool IsBME280Measuring() { byte[] writeBuf = { I2C_BMA280_REG_ADDR_STATUS }; byte[] readBuf = new byte[1]; I2CBMA280Sensor.WriteRead(writeBuf, readBuf); return((readBuf[0] & 0x08) != 0); }
async void InitBME280() { string aqs = I2cDevice.GetDeviceSelector(I2C_CONTROLLER_NAME); var dis = await DeviceInformation.FindAllAsync(aqs); var settings = new I2cConnectionSettings(BMA280_I2C_ADDR); settings.BusSpeed = I2cBusSpeed.FastMode; I2CBMA280Sensor = await I2cDevice.FromIdAsync(dis[0].Id, settings); if (I2CBMA280Sensor != null) { byte[] writeBuf_CTRL_MEAS = { I2C_BMA280_REG_CTRL_MEAS_ADDR, 0x27 }; I2CBMA280Sensor.Write(writeBuf_CTRL_MEAS); byte[] writeBuf_CTRL_HUM = { I2C_BMA280_REG_ADDR_CTRL_HUM, 0x01 }; I2CBMA280Sensor.Write(writeBuf_CTRL_HUM); I2CBMA280Sensor.WriteRead(new byte[] { I2C_BMA280_REG_ADDR_CARIB_00 }, carib_00_26); I2CBMA280Sensor.WriteRead(new byte[] { I2C_BMA280_REG_ADDR_CARIB_27 }, carib_27_41); dig_T1 = (carib_00_26[1] << 8) | carib_00_26[0]; dig_T2 = (carib_00_26[3] << 8) | carib_00_26[2]; dig_T3 = (carib_00_26[5] << 8) | carib_00_26[4]; dig_P1 = (carib_00_26[7] << 8) | carib_00_26[6]; dig_P2 = (carib_00_26[9] << 8) | carib_00_26[8]; dig_P3 = (carib_00_26[11] << 8) | carib_00_26[10]; dig_P4 = (carib_00_26[13] << 8) | carib_00_26[12]; dig_P5 = (carib_00_26[15] << 8) | carib_00_26[14]; dig_P6 = (carib_00_26[17] << 8) | carib_00_26[16]; dig_P7 = (carib_00_26[19] << 8) | carib_00_26[18]; dig_P8 = (carib_00_26[21] << 8) | carib_00_26[20]; dig_P9 = (carib_00_26[23] << 8) | carib_00_26[22]; dig_H1 = carib_00_26[24]; dig_H2 = (carib_27_41[1] << 8) | carib_27_41[0]; dig_H3 = carib_27_41[2]; dig_H4 = (carib_27_41[3] << 4) | (0x0f & carib_27_41[4]); dig_H5 = (carib_27_41[5] << 4) | ((carib_27_41[4] >> 4) & 0xf); dig_H6 = carib_27_41[6]; } }