Class Tmp117
A Texas Instruments TMP117 high-accuracy thermometer, and a driver for one on an I2C bus.
public sealed class Tmp117 : IDisposable
- Inheritance
-
Tmp117
- Implements
- Inherited Members
Remarks
The static members are the part's datasheet, decoded exactly as the manufacturer specifies, and Tmp117.Sim, a part that is not there.
An instance drives one part over an I2cBus, converting on demand in one-shot mode and leaving the part powered down between conversions. Nothing is sent until Init() or the first Measure(). The driver holds its own share of the bus, so the bus may be disposed once the driver is built.
Constructors
Tmp117(I2cBus, byte, Averaging)
Creates a driver for the part at address on bus.
public Tmp117(I2cBus bus, byte address, Tmp117.Averaging averaging = Averaging.X8)
Parameters
busI2cBusThe bus the part is on.
addressbyteOne of the
AddressAdd0constants, by where ADD0 is tied.averagingTmp117.AveragingHow many conversions are averaged into each result.
Exceptions
- PamojaException
The native driver could not be created.
Fields
AddressAdd0Gnd
The address with ADD0 tied to ground.
public const byte AddressAdd0Gnd = 72
Field Value
AddressAdd0Scl
The address with ADD0 tied to SCL.
public const byte AddressAdd0Scl = 75
Field Value
AddressAdd0Sda
The address with ADD0 tied to SDA.
public const byte AddressAdd0Sda = 74
Field Value
AddressAdd0Vplus
The address with ADD0 tied to V+.
public const byte AddressAdd0Vplus = 73
Field Value
Properties
SiliconRevision
The silicon revision read at initialization, or null before it.
public byte? SiliconRevision { get; }
Property Value
- byte?
Methods
Alerts()
Reads the alert flags, including results the driver's own reads saw since the last call.
public Tmp117Alerts Alerts()
Returns
- Tmp117Alerts
Whether a result was above the high limit or below the low limit.
Exceptions
- PamojaException
The transfer failed.
AveragingConversions(byte)
Returns how many conversions a TMP117 averaging code folds into one result.
public static byte AveragingConversions(byte code)
Parameters
codebyteThe code.
Returns
- byte
The value the C ABI computes.
AveragingMicros(byte)
Returns how long a TMP117 averaging code takes to convert.
public static uint AveragingMicros(byte code)
Parameters
codebyteThe code.
Returns
- uint
The value the C ABI computes.
Celsius(short)
Converts a raw TMP117 temperature register to degrees Celsius.
public static float Celsius(short raw)
Parameters
rawshortThe raw.
Returns
- float
The value the C ABI computes.
ConfigBits(PamojaTmp117Config)
Assembles the 16-bit TMP117 configuration register value.
public static ushort ConfigBits(PamojaTmp117Config config)
Parameters
configPamojaTmp117ConfigThe config.
Returns
- ushort
The value the C ABI computes.
ConfigFromBits(ushort)
Parses a 16-bit TMP117 configuration register value.
public static PamojaTmp117Config ConfigFromBits(ushort bits)
Parameters
bitsushortThe bits.
Returns
- PamojaTmp117Config
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
CycleMicros(byte, byte)
Returns how often a TMP117 updates its result for a cycle and averaging code.
public static uint CycleMicros(byte cycle, byte averaging)
Parameters
Returns
- uint
The value the C ABI computes.
CycleNominalMicros(byte)
Returns the nominal cycle a TMP117 conversion-cycle code selects.
public static uint CycleNominalMicros(byte code)
Parameters
codebyteThe code.
Returns
- uint
The value the C ABI computes.
DataReady(ushort)
Reports whether a TMP117 configuration register says a result is ready.
public static bool DataReady(ushort config)
Parameters
configushortThe config.
Returns
- bool
The value the C ABI computes.
DeviceId(ushort)
Reads the device identifier out of a TMP117 device-ID register.
public static ushort DeviceId(ushort raw)
Parameters
rawushortThe raw.
Returns
- ushort
The value the C ABI computes.
Dispose()
Releases the driver and its share of the bus.
public void Dispose()
EepromBusy(ushort)
Reports whether a TMP117 configuration register says an EEPROM write is running.
public static bool EepromBusy(ushort config)
Parameters
configushortThe config.
Returns
- bool
The value the C ABI computes.
EepromUnlockBusy(ushort)
Reports whether a TMP117 EEPROM unlock register says a write is running.
public static bool EepromUnlockBusy(ushort unlock)
Parameters
unlockushortThe unlock.
Returns
- bool
The value the C ABI computes.
HighAlert(ushort)
Reports whether a TMP117 configuration register flags a high alert.
public static bool HighAlert(ushort config)
Parameters
configushortThe config.
Returns
- bool
The value the C ABI computes.
Init()
Checks the part is a TMP117, waits for its EEPROM, and writes the settings with the part in shutdown.
public void Init()
Exceptions
- PamojaException
Nothing answered, the device id is not a TMP117's, or the EEPROM never reported ready.
LowAlert(ushort)
Reports whether a TMP117 configuration register flags a low alert.
public static bool LowAlert(ushort config)
Parameters
configushortThe config.
Returns
- bool
The value the C ABI computes.
Measure()
Runs one conversion and reads the temperature, initializing the part first if needed.
public Tmp117Reading Measure()
Returns
- Tmp117Reading
The temperature.
Exceptions
- PamojaException
As Init(), and when the conversion never finishes.
MicroCelsius(short)
Converts a raw TMP117 temperature register to micro-degrees Celsius.
public static int MicroCelsius(short raw)
Parameters
rawshortThe raw.
Returns
- int
The value the C ABI computes.
NanoCelsius(short)
Converts a raw TMP117 temperature register to nano-degrees Celsius.
public static long NanoCelsius(short raw)
Parameters
rawshortThe raw.
Returns
- long
The value the C ABI computes.
RawFromCelsius(float)
Builds the TMP117 temperature register that decodes to a temperature in Celsius.
public static short RawFromCelsius(float celsius)
Parameters
celsiusfloatThe celsius.
Returns
- short
The value the C ABI computes.
RawFromMicroCelsius(int)
Builds the TMP117 temperature register that decodes to a temperature.
public static short RawFromMicroCelsius(int microCelsius)
Parameters
microCelsiusintThe micro celsius.
Returns
- short
The value the C ABI computes.
Revision(ushort)
Reads the die revision out of a TMP117 device-ID register.
public static byte Revision(ushort raw)
Parameters
rawushortThe raw.
Returns
- byte
The value the C ABI computes.
SetAlertLimits(float, float)
Writes the high and low limits the part compares each result against.
public void SetAlertLimits(float highCelsius, float lowCelsius)
Parameters
highCelsiusfloatThe high limit; the factory value is 192 C.
lowCelsiusfloatThe low limit; the factory value is -256 C.
Exceptions
- PamojaException
The transfer failed.
TemperatureBytes(short)
Builds the two bytes a TMP117 sends for a temperature register.
public static byte[] TemperatureBytes(short raw)
Parameters
rawshortThe raw.
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
TemperatureFromBytes(ReadOnlySpan<byte>)
Reads the two bytes a TMP117 sends for a temperature register.
public static short TemperatureFromBytes(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>The bytes.
Returns
- short
The decoded value.
Exceptions
- PamojaException
The device data is not valid.