private (RelativeHumidity?RelativeHumidity, Temperature?Temperature) EndReadHumidityAndTemperature() { Span <byte> buffer = stackalloc byte[6]; _device.Read(buffer); Temperature?t = Sensirion.ReadUInt16BigEndianAndCRC8(buffer) switch { ushort deviceTemperature => Temperature.FromDegreesCelsius(deviceTemperature * (35.0 / 13107.0) - 45.0), null => (Temperature?)null }; RelativeHumidity?h = Sensirion.ReadUInt16BigEndianAndCRC8(buffer.Slice(3, 3)) switch { ushort deviceHumidity => RelativeHumidity.FromPercent(Math.Max(0.0, Math.Min(deviceHumidity * (100.0 / 52428.0) - (300.0 / 50.0), 100.0))), null => (RelativeHumidity?)null }; if (h is not null) { _lastHum = h.GetValueOrDefault(); } if (t is not null) { _lastTemp = t.GetValueOrDefault(); } return(h, t); } } }
private int SetPressureCalibrationImpl(Pressure pressure) { Span <byte> buffer = stackalloc byte[5]; BinaryPrimitives.WriteUInt16BigEndian(buffer, 0xE000); Sensirion.WriteUInt16BigEndianAndCRC8(buffer.Slice(2), (ushort)(Math.Max(0.0, Math.Min(pressure.Pascals, 1.0)) * (1.0 / 100.0))); _device.Write(buffer); return(1); }