示例#1
0
文件: Sht4x.cs 项目: destroyar/iot
        private int BeginReadHumidityAndTemperature(Sht4xRepeatability repeatability)
        {
            (byte cmd, int delayInMs) = repeatability switch
            {
                Sht4xRepeatability.Low => ((byte)0xE0, 2),
                Sht4xRepeatability.Medium => ((byte)0xF6, 5),
                Sht4xRepeatability.High => ((byte)0xFD, 9),
                _ => throw new ArgumentOutOfRangeException(nameof(repeatability))
            };

            _device.WriteByte(cmd);
            return(delayInMs);
        }
示例#2
0
文件: Sht4x.cs 项目: destroyar/iot
        /// <summary>
        /// Reads relative humidity and temperature.
        /// </summary>
        /// <returns>
        /// A tuple of relative humidity and temperature.
        /// If a CRC check failed for a measurement, it will be <see langword="null"/>.
        /// </returns>
        public (RelativeHumidity?RelativeHumidity, Temperature?Temperature) ReadHumidityAndTemperature(Sht4xRepeatability repeatability = Sht4xRepeatability.High)
        {
            int delay = BeginReadHumidityAndTemperature(repeatability);

            Thread.Sleep(delay);
            return(EndReadHumidityAndTemperature());
        }
示例#3
0
文件: Sht4x.cs 项目: destroyar/iot
        /// <inheritdoc cref="ReadHumidityAndTemperature(Sht4xRepeatability)"/>
        public async ValueTask <(RelativeHumidity?RelativeHumidity, Temperature?Temperature)> ReadHumidityAndTemperatureAsync(Sht4xRepeatability repeatability = Sht4xRepeatability.High)
        {
            int delay = BeginReadHumidityAndTemperature(repeatability);
            await Task.Delay(delay);

            return(EndReadHumidityAndTemperature());
        }