Class Scd4x
A Sensirion SCD40 or SCD41 carbon dioxide sensor. Every call goes straight to the pamoja C ABI, which decodes exactly what the manufacturer's datasheet specifies.
public static class Scd4x
- Inheritance
-
Scd4x
- Inherited Members
Methods
AllowedDuringMeasurement(ushort)
Reports whether an SCD4x accepts a command while it is measuring.
public static bool AllowedDuringMeasurement(ushort command)
Parameters
commandushortThe command.
Returns
- bool
The value the C ABI computes.
AmbientPressurePascals(ushort)
Reads an SCD4x ambient-pressure word back as a pressure.
public static uint AmbientPressurePascals(ushort word)
Parameters
wordushortThe word.
Returns
- uint
The value the C ABI computes.
AmbientPressureWord(uint)
Builds the SCD4x ambient-pressure word for a pressure.
public static ushort AmbientPressureWord(uint pascals)
Parameters
pascalsuintThe pascals.
Returns
- ushort
The value the C ABI computes.
AutomaticSelfCalibrationEnabled(ushort)
Reports whether an SCD4x word says automatic self-calibration is on.
public static bool AutomaticSelfCalibrationEnabled(ushort word)
Parameters
wordushortThe word.
Returns
- bool
The value the C ABI computes.
AutomaticSelfCalibrationWord(bool)
Builds the SCD4x word that turns automatic self-calibration on or off.
public static ushort AutomaticSelfCalibrationWord(bool enabled)
Parameters
enabledboolThe enabled.
Returns
- ushort
The value the C ABI computes.
Celsius(ushort)
Converts a raw SCD4x temperature word to degrees Celsius.
public static float Celsius(ushort raw)
Parameters
rawushortThe raw.
Returns
- float
The value the C ABI computes.
CommandFrame(ushort)
Builds the two bytes that address an SCD4x command, most significant first.
public static byte[] CommandFrame(ushort command)
Parameters
commandushortThe command.
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
Crc(ReadOnlySpan<byte>)
Computes the CRC-8 an SCD4x 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.
DataReady(ushort)
Reports whether an SCD4x data-ready word says a fresh result is waiting.
public static bool DataReady(ushort word)
Parameters
wordushortThe word.
Returns
- bool
The value the C ABI computes.
ForcedRecalibrationCorrectionPpm(ushort)
Reads the correction a forced recalibration applied.
public static int? ForcedRecalibrationCorrectionPpm(ushort word)
Parameters
wordushortThe word.
Returns
- int?
The value, or null where the part defines none.
ForcedRecalibrationWord(bool, int)
Builds the word an SCD4x returns for a forced-recalibration outcome.
public static ushort ForcedRecalibrationWord(bool succeeded, int correctionPpm)
Parameters
Returns
- ushort
The value the C ABI computes.
HumidityMilliPercent(ushort)
Converts a raw SCD4x humidity word to milli-percent.
public static uint HumidityMilliPercent(ushort raw)
Parameters
rawushortThe raw.
Returns
- uint
The value the C ABI computes.
HumidityRaw(uint)
Builds the SCD4x humidity word that decodes to a relative humidity.
public static ushort HumidityRaw(uint milliPercent)
Parameters
milliPercentuintThe milli percent.
Returns
- ushort
The value the C ABI computes.
MaxDurationMs(ushort)
Returns how long an SCD4x command may take before its result can be read.
public static ushort? MaxDurationMs(ushort command)
Parameters
commandushortThe command.
Returns
- ushort?
The value, or null where the part defines none.
MeasurementBytes(ushort, ushort, ushort)
Builds the nine bytes an SCD4x sends for a set of raw words, each CRC included.
public static byte[] MeasurementBytes(ushort co2Ppm, ushort temperatureRaw, ushort humidityRaw)
Parameters
co2PpmushortThe co2 ppm.
temperatureRawushortThe temperature raw.
humidityRawushortThe humidity raw.
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
MeasurementFromPhysical(ushort, int, uint)
Builds the SCD4x measurement a sensor reporting these physical values would send.
public static PamojaScd4xMeasurement MeasurementFromPhysical(ushort co2Ppm, int milliCelsius, uint humidityMilliPercent)
Parameters
co2PpmushortThe co2 ppm.
milliCelsiusintThe milli celsius.
humidityMilliPercentuintThe humidity milli percent.
Returns
- PamojaScd4xMeasurement
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
MilliCelsius(ushort)
Converts a raw SCD4x temperature word to milli-degrees Celsius.
public static int MilliCelsius(ushort raw)
Parameters
rawushortThe raw.
Returns
- int
The value the C ABI computes.
ParseMeasurement(ReadOnlySpan<byte>)
Parses and CRC-checks a nine-byte SCD4x measurement frame.
public static PamojaScd4xMeasurement ParseMeasurement(ReadOnlySpan<byte> frame)
Parameters
frameReadOnlySpan<byte>The frame.
Returns
- PamojaScd4xMeasurement
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
RelativeHumidityPercent(ushort)
Converts a raw SCD4x humidity word to a relative humidity percentage.
public static float RelativeHumidityPercent(ushort raw)
Parameters
rawushortThe raw.
Returns
- float
The value the C ABI computes.
SelfTestPassed(ushort)
Reports whether an SCD4x self-test word says the part is healthy.
public static bool SelfTestPassed(ushort word)
Parameters
wordushortThe word.
Returns
- bool
The value the C ABI computes.
SerialNumber(ReadOnlySpan<byte>)
Reads the 48-bit serial number out of a nine-byte SCD4x frame.
public static ulong SerialNumber(ReadOnlySpan<byte> frame)
Parameters
frameReadOnlySpan<byte>The frame.
Returns
- ulong
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
SerialNumberFrame(ulong)
Builds the nine bytes an SCD4x sends for a serial number, each CRC included.
public static byte[] SerialNumberFrame(ulong serial)
Parameters
serialulongThe serial.
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
TemperatureOffsetMilliCelsius(ushort)
Reads an SCD4x temperature-offset word back as an offset.
public static uint TemperatureOffsetMilliCelsius(ushort word)
Parameters
wordushortThe word.
Returns
- uint
The value the C ABI computes.
TemperatureOffsetWord(uint)
Builds the SCD4x temperature-offset word for an offset.
public static ushort TemperatureOffsetWord(uint milliCelsius)
Parameters
milliCelsiusuintThe milli celsius.
Returns
- ushort
The value the C ABI computes.
TemperatureRaw(int)
Builds the SCD4x temperature word that decodes to a temperature.
public static ushort TemperatureRaw(int milliCelsius)
Parameters
milliCelsiusintThe milli celsius.
Returns
- ushort
The value the C ABI computes.
Word(ReadOnlySpan<byte>)
Reads a CRC-checked three-byte SCD4x 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.
WordFrame(ushort)
Builds the three bytes an SCD4x sends for a word: the word then its CRC.
public static byte[] WordFrame(ushort value)
Parameters
valueushortThe value.
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
WriteFrame(ushort, ushort)
Builds the five bytes that write a word to an SCD4x: command, word, CRC.
public static byte[] WriteFrame(ushort command, ushort value)
Parameters
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.