コード例 #1
0
        public void initTemp(I2cDevice device)
        {
            byte[] twoByte = new byte[2];
            byte[] oneByte = new byte[1];

            if (!RTI2C.Read(device, 0x2a + 0x80, twoByte))
            {
                var ErrorMessage = "Failed to read HTS221 temperature";
                return;
            }

            if (!RTI2C.Read(device, 0x33 + 0x80, oneByte))
            {
                var ErrorMessage = "Failed to read HTS221 T1_C_8";
                return;
            }
            var temp0 = oneByte[0];

            if (!RTI2C.Read(device, 0x32 + 0x80, oneByte))
            {
                var ErrorMessage = "Failed to read HTS221 T0_C_8";
                return;
            }
            byte temp1 = oneByte[0];

            var T1_C_8 = (UInt16)(((UInt16)(temp1 & 0xC) << 6) | (UInt16)temp0);
            var T1     = (double)T1_C_8 / 8.0;

            var T0_C_8 = (UInt16)((((UInt16)temp1 & 0x3) << 8) | (UInt16)temp0);
            var T0     = (double)T0_C_8 / 8.0;


            if (!RTI2C.Read(device, 0x3e + 0x80, twoByte))
            {
                var ErrorMessage = "Failed to read HTS221 T1_OUT";
                return;
            }
            var T1_OUT = (Int16)((((UInt16)twoByte[1]) << 8) | (UInt16)twoByte[0]);


            if (!RTI2C.Read(device, 0x3c + 0x80, twoByte))
            {
                var ErrorMessage = "Failed to read HTS221 T0_OUT";
                return;
            }
            var T0_OUT = (Int16)((((UInt16)twoByte[1]) << 8) | (UInt16)twoByte[0]);

            mTemperature_m = (T1 - T0) / (T1_OUT - T0_OUT);
            mTemperature_c = T0 - (mTemperature_m * T0_OUT);
        }
コード例 #2
0
        public async void CallmeBaby()
        {
            string aqsFilter = I2cDevice.GetDeviceSelector("I2C1");

            DeviceInformationCollection collection = await DeviceInformation.FindAllAsync(aqsFilter);

            if (collection.Count == 0)
            {
                return;
            }
            I2cConnectionSettings settings = new I2cConnectionSettings(0x5f);

            settings.BusSpeed = I2cBusSpeed.FastMode;

            I2cDevice device = await I2cDevice.FromIdAsync(collection[0].Id, settings);


            if (!RTI2C.Write(device, 0x20, 0x87))
            {
                var ErrorMessage = "Failed to set HTS221 CTRL_REG_1";
                return;
            }

            if (!RTI2C.Write(device, 0x10, 0x1b))
            {
                var ErrorMessage = "Failed to set HTS221 AV_CONF";
                return;
            }

            initTemp(device);
            byte[] twoByte = new byte[2];

            if (!RTI2C.Read(device, 0x2a + 0x80, twoByte))
            {
                var ErrorMessage = "Failed to read HTS221 temperature";
                return;
            }

            double mTemperature = (Int16)((((UInt16)twoByte[1]) << 8) | (UInt16)twoByte[0]);

            mTemperature = mTemperature * mTemperature_m + mTemperature_c;
            var mTemperatureValid = true;


            //double mTemperature = (Int16)((((UInt16)twoByte[1]) << 8) | (UInt16)twoByte[0]);
            // mTemperature = mTemperature * mTemperature_m + mTemperature_c;
            //var mTemperatureValid = true;
            //var q = mTemperature;
        }