Class Hdc1080
A Texas Instruments HDC1080 humidity and temperature sensor, and a driver for one on an I2C bus.
public sealed class Hdc1080 : IDisposable
- Inheritance
-
Hdc1080
- Implements
- Inherited Members
Remarks
The static members are the part's datasheet, decoded exactly as the manufacturer specifies, and Hdc1080.Sim, a part that is not there.
An instance drives the part over an I2cBus, measuring temperature then humidity from one trigger, as the datasheet's sequential mode does. The part has one address, Address. Nothing is sent until Init() or the first Measure().
Constructors
Hdc1080(I2cBus, TemperatureResolution, HumidityResolution)
Creates a driver for the part on bus.
public Hdc1080(I2cBus bus, Hdc1080.TemperatureResolution temperature = TemperatureResolution.Bits14, Hdc1080.HumidityResolution humidity = HumidityResolution.Bits14)
Parameters
busI2cBusThe bus the part is on.
temperatureHdc1080.TemperatureResolutionThe temperature resolution, which sets its conversion time.
humidityHdc1080.HumidityResolutionThe humidity resolution, which sets its conversion time.
Exceptions
- PamojaException
The native driver could not be created.
Fields
Address
The one address the part answers to.
public const byte Address = 64
Field Value
Properties
Configuration
The configuration the driver writes.
public PamojaHdc1080Config Configuration { get; }
Property Value
Methods
Celsius(ushort)
Converts a raw HDC1080 temperature register to degrees Celsius.
public static float Celsius(ushort raw)
Parameters
rawushortThe raw.
Returns
- float
The value the C ABI computes.
ConfigFromRegister(ushort)
Parses an HDC1080 configuration register value.
public static PamojaHdc1080Config ConfigFromRegister(ushort raw)
Parameters
rawushortThe raw.
Returns
- PamojaHdc1080Config
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
ConfigToRegister(PamojaHdc1080Config)
Assembles an HDC1080 configuration register value.
public static ushort ConfigToRegister(PamojaHdc1080Config config)
Parameters
configPamojaHdc1080ConfigThe config.
Returns
- ushort
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
ConversionTimeMicros(PamojaHdc1080Config)
Returns how long to wait after triggering an HDC1080 in a configuration.
public static uint ConversionTimeMicros(PamojaHdc1080Config config)
Parameters
configPamojaHdc1080ConfigThe config.
Returns
- uint
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
Dispose()
Releases the driver and its share of the bus.
public void Dispose()
Heater(bool)
Switches the on-die heater, which runs only during acquisitions, on or off.
public void Heater(bool on)
Parameters
onboolWhether the heater runs.
Exceptions
- PamojaException
The transfer failed.
HumidityConversionMicros(byte)
Returns how long an HDC1080 humidity conversion takes at a resolution.
public static uint HumidityConversionMicros(byte bits)
Parameters
bitsbyteThe bits.
Returns
- uint
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
HumidityRegister(uint)
Builds the HDC1080 humidity register that decodes to a relative humidity.
public static ushort HumidityRegister(uint milliPercent)
Parameters
milliPercentuintThe milli percent.
Returns
- ushort
The value the C ABI computes.
Init()
Checks the part is an HDC1080 and writes the configuration.
public void Init()
Exceptions
- PamojaException
Nothing answered, or either id register is not an HDC1080's.
Measure()
Triggers one acquisition of both channels and reads them, initializing the part first if needed.
public PamojaHdc1080Measurement Measure()
Returns
- PamojaHdc1080Measurement
The temperature and humidity.
Exceptions
- PamojaException
As Init(), and when the part does not acknowledge the read, which it refuses until its results are ready.
MeasurementBytes(ushort, ushort)
Builds the four bytes an HDC1080 sends for a pair of raw registers.
public static byte[] MeasurementBytes(ushort temperatureRaw, ushort humidityRaw)
Parameters
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
MeasurementFromPhysical(int, uint)
Builds the HDC1080 measurement a sensor reporting these physical values would send.
public static PamojaHdc1080Measurement MeasurementFromPhysical(int milliCelsius, uint milliPercent)
Parameters
Returns
- PamojaHdc1080Measurement
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
MilliCelsius(ushort)
Converts a raw HDC1080 temperature register to milli-degrees Celsius.
public static int MilliCelsius(ushort raw)
Parameters
rawushortThe raw.
Returns
- int
The value the C ABI computes.
MilliPercent(ushort)
Converts a raw HDC1080 humidity register to milli-percent.
public static uint MilliPercent(ushort raw)
Parameters
rawushortThe raw.
Returns
- uint
The value the C ABI computes.
ParseMeasurement(ReadOnlySpan<byte>)
Parses the four bytes an HDC1080 sequential read returns.
public static PamojaHdc1080Measurement ParseMeasurement(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>The bytes.
Returns
- PamojaHdc1080Measurement
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
RelativeHumidity(ushort)
Converts a raw HDC1080 humidity register to a relative humidity percentage.
public static float RelativeHumidity(ushort raw)
Parameters
rawushortThe raw.
Returns
- float
The value the C ABI computes.
SerialId(ushort, ushort, ushort)
Joins the three HDC1080 serial-ID registers into the 40-bit serial number.
public static ulong SerialId(ushort high, ushort mid, ushort low)
Parameters
Returns
- ulong
The value the C ABI computes.
SerialIdRegisters(ulong)
Splits a serial number back into the three HDC1080 serial-ID registers.
public static ushort SerialIdRegisters(ulong serial)
Parameters
serialulongThe serial.
Returns
- ushort
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
TemperatureConversionMicros(byte)
Returns how long an HDC1080 temperature conversion takes at a resolution.
public static uint TemperatureConversionMicros(byte bits)
Parameters
bitsbyteThe bits.
Returns
- uint
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
TemperatureRegister(int)
Builds the HDC1080 temperature register that decodes to a temperature.
public static ushort TemperatureRegister(int milliCelsius)
Parameters
milliCelsiusintThe milli celsius.
Returns
- ushort
The value the C ABI computes.