Class Sht3x
A Sensirion SHT3x-DIS humidity and temperature sensor, and a driver for one on an I2C bus.
public sealed class Sht3x : IDisposable
- Inheritance
-
Sht3x
- Implements
- Inherited Members
Remarks
The static members are the part's datasheet, decoded exactly as the manufacturer specifies, and Sht3x.Sim, a part that is not there.
An instance drives one part over an I2cBus, measuring on demand in single-shot mode. The part has no id register, so Init() soft-resets it and reads its status: a status word whose checksum holds is what confirms an SHT3x answers. Nothing is sent until Init() or the first Measure().
Constructors
Sht3x(I2cBus, byte, Repeatability)
Creates a driver for the part at address on bus.
public Sht3x(I2cBus bus, byte address, Sht3x.Repeatability repeatability = Repeatability.High)
Parameters
busI2cBusThe bus the part is on.
addressbyterepeatabilitySht3x.RepeatabilityHow repeatable each measurement is, against how long it takes.
Exceptions
- PamojaException
The native driver could not be created.
Fields
AddressA
The address with ADDR low.
public const byte AddressA = 68
Field Value
AddressB
The address with ADDR high.
public const byte AddressB = 69
Field Value
Properties
LastStatus
The status register as it was last read, or null before it has been.
public PamojaSht3xStatus? LastStatus { get; }
Property Value
Methods
Celsius(ushort)
Converts a raw SHT3x temperature word to degrees Celsius.
public static float Celsius(ushort raw)
Parameters
rawushortThe raw.
Returns
- float
The value the C ABI computes.
Crc(ReadOnlySpan<byte>)
Computes the CRC-8 an SHT3x appends to every data word.
public static byte Crc(ReadOnlySpan<byte> data)
Parameters
dataReadOnlySpan<byte>The data.
Returns
- byte
The value the C ABI computes.
Dispose()
Releases the driver and its share of the bus.
public void Dispose()
Fahrenheit(ushort)
Converts a raw SHT3x temperature word to degrees Fahrenheit.
public static float Fahrenheit(ushort raw)
Parameters
rawushortThe raw.
Returns
- float
The value the C ABI computes.
HeaterOff()
Switches the heater off, which is its state after any reset.
public void HeaterOff()
Exceptions
HeaterOn()
Switches the plausibility-check heater on, initializing the part first if needed.
public void HeaterOn()
Exceptions
HumidityRawFromMilliPercent(uint)
Builds the SHT3x humidity word that decodes to a relative humidity.
public static ushort HumidityRawFromMilliPercent(uint milliPercent)
Parameters
milliPercentuintThe milli percent.
Returns
- ushort
The value the C ABI computes.
HumidityRawFromRelativeHumidity(float)
Builds the SHT3x humidity word that decodes to a relative humidity percentage.
public static ushort HumidityRawFromRelativeHumidity(float percent)
Parameters
percentfloatThe percent.
Returns
- ushort
The value the C ABI computes.
Init()
Soft-resets the part and reads its status.
public void Init()
Exceptions
- PamojaException
Nothing answered, or the status word failed its checksum.
IntervalMicros(byte)
Returns the gap between SHT3x periodic measurements at a rate.
public static uint IntervalMicros(byte rate)
Parameters
ratebyteThe rate.
Returns
- uint
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
MaxMeasurementMicros(byte)
Returns how long an SHT3x measurement may take at a repeatability.
public static uint MaxMeasurementMicros(byte repeatability)
Parameters
repeatabilitybyteThe repeatability.
Returns
- uint
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
Measure()
Runs one single-shot measurement, initializing the part first if needed.
public PamojaSht3xMeasurement Measure()
Returns
- PamojaSht3xMeasurement
The checksum-checked temperature and humidity.
Exceptions
- PamojaException
As Init(), and when a data word fails its checksum.
MeasurementBytes(ushort, ushort)
Builds the six bytes an SHT3x sends for a pair of raw words.
public static byte[] MeasurementBytes(ushort temperatureRaw, ushort humidityRaw)
Parameters
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
MilliCelsius(ushort)
Converts a raw SHT3x temperature word to milli-degrees Celsius.
public static int MilliCelsius(ushort raw)
Parameters
rawushortThe raw.
Returns
- int
The value the C ABI computes.
MilliFahrenheit(ushort)
Converts a raw SHT3x temperature word to milli-degrees Fahrenheit.
public static int MilliFahrenheit(ushort raw)
Parameters
rawushortThe raw.
Returns
- int
The value the C ABI computes.
MilliPercent(ushort)
Converts a raw SHT3x humidity word to milli-percent.
public static uint MilliPercent(ushort raw)
Parameters
rawushortThe raw.
Returns
- uint
The value the C ABI computes.
ParseMeasurement(ReadOnlySpan<byte>)
Parses and CRC-checks a six-byte SHT3x measurement frame.
public static PamojaSht3xMeasurement ParseMeasurement(ReadOnlySpan<byte> frame)
Parameters
frameReadOnlySpan<byte>The frame.
Returns
- PamojaSht3xMeasurement
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
ParseStatus(ReadOnlySpan<byte>)
Parses and CRC-checks a three-byte SHT3x status frame.
public static PamojaSht3xStatus ParseStatus(ReadOnlySpan<byte> frame)
Parameters
frameReadOnlySpan<byte>The frame.
Returns
- PamojaSht3xStatus
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
Periodic(byte, byte)
Returns the SHT3x periodic-mode command for a repeatability and rate.
public static ushort Periodic(byte repeatability, byte rate)
Parameters
Returns
- ushort
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
ReadStatus()
Reads the status register.
public PamojaSht3xStatus ReadStatus()
Returns
- PamojaSht3xStatus
The status, which LastStatus keeps as well.
Exceptions
- PamojaException
The transfer failed, or the word failed its checksum.
RelativeHumidity(ushort)
Converts a raw SHT3x humidity word to a relative humidity percentage.
public static float RelativeHumidity(ushort raw)
Parameters
rawushortThe raw.
Returns
- float
The value the C ABI computes.
SingleShot(byte, bool)
Returns the SHT3x single-shot command for a repeatability and clock mode.
public static ushort SingleShot(byte repeatability, bool clockStretching)
Parameters
Returns
- ushort
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
StatusBytes(ushort)
Builds the three bytes an SHT3x sends for a status word, CRC last.
public static byte[] StatusBytes(ushort bits)
Parameters
bitsushortThe bits.
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
StatusFromBits(ushort)
Splits an SHT3x status word into its flags.
public static PamojaSht3xStatus StatusFromBits(ushort bits)
Parameters
bitsushortThe bits.
Returns
- PamojaSht3xStatus
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
TemperatureRawFromCelsius(float)
Builds the SHT3x temperature word that decodes to a temperature in Celsius.
public static ushort TemperatureRawFromCelsius(float celsius)
Parameters
celsiusfloatThe celsius.
Returns
- ushort
The value the C ABI computes.
TemperatureRawFromMilliCelsius(int)
Builds the SHT3x temperature word that decodes to a temperature.
public static ushort TemperatureRawFromMilliCelsius(int milliCelsius)
Parameters
milliCelsiusintThe milli celsius.
Returns
- ushort
The value the C ABI computes.
TemperatureRawFromMilliFahrenheit(int)
Builds the SHT3x temperature word that decodes to a temperature in Fahrenheit.
public static ushort TemperatureRawFromMilliFahrenheit(int milliFahrenheit)
Parameters
milliFahrenheitintThe milli fahrenheit.
Returns
- ushort
The value the C ABI computes.
TypicalMeasurementMicros(byte)
Returns how long an SHT3x measurement typically takes at a repeatability.
public static uint TypicalMeasurementMicros(byte repeatability)
Parameters
repeatabilitybyteThe repeatability.
Returns
- uint
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
Word(ReadOnlySpan<byte>)
Reads a CRC-checked three-byte SHT3x word frame.
public static ushort Word(ReadOnlySpan<byte> frame)
Parameters
frameReadOnlySpan<byte>The frame.
Returns
- ushort
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
WordBytes(ushort)
Builds the three bytes an SHT3x sends for a word: the word then its CRC.
public static byte[] WordBytes(ushort value)
Parameters
valueushortThe value.
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.