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); }
/// <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()); }
/// <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()); }