# -*- coding: utf-8 -*-
# (c) Copyright 2022 Sensirion AG, Switzerland
##############################################################################
##############################################################################
# _____ _ _ _______ _____ ____ _ _
# / ____| /\ | | | |__ __|_ _/ __ \| \ | |
# | | / \ | | | | | | | || | | | \| |
# | | / /\ \| | | | | | | || | | | . ` |
# | |____ / ____ \ |__| | | | _| || |__| | |\ |
# \_____/_/ \_\____/ |_| |_____\____/|_| \_|
#
# THIS FILE IS AUTOMATICALLY GENERATED AND MUST NOT BE EDITED MANUALLY!
#
# Generator: sensirion-i2c-interface-generator 0.6.0
# Product: SEN5x
# Version: 2.2.1
#
##############################################################################
##############################################################################
# flake8: noqa
from __future__ import absolute_import, division, print_function
from sensirion_i2c_driver import SensirionI2cCommand, CrcCalculator
from struct import pack, unpack
import logging
log = logging.getLogger(__name__)
class Sen5xI2cCmdBase(SensirionI2cCommand):
"""
SEN5x I²C base command.
"""
def __init__(self, command, tx_data, rx_length, read_delay, timeout,
post_processing_time=0.0):
"""
Constructs a new SEN5x I²C command.
:param int/None command:
The command ID to be sent to the device. None means that no
command will be sent, i.e. only ``tx_data`` (if not None) will
be sent. No CRC is added to these bytes since the command ID
usually already contains a CRC.
:param bytes-like/list/None tx_data:
Bytes to be extended with CRCs and then sent to the I²C device.
None means that no write header will be sent at all (if ``command``
is None too). An empty list means to send the write header (even if
``command`` is None), but without data following it.
:param int/None rx_length:
Number of bytes to be read from the I²C device, including CRC
bytes. None means that no read header is sent at all. Zero means
to send the read header, but without reading any data.
:param float read_delay:
Delay (in Seconds) to be inserted between the end of the write
operation and the beginning of the read operation. This is needed
if the device needs some time to prepare the RX data, e.g. if it
has to perform a measurement. Set to 0.0 to indicate that no delay
is needed, i.e. the device does not need any processing time.
:param float timeout:
Timeout (in Seconds) to be used in case of clock stretching. If the
device stretches the clock longer than this value, the transceive
operation will be aborted with a timeout error. Set to 0.0 to
indicate that the device will not stretch the clock for this
command.
:param float post_processing_time:
Maximum time in seconds the device needs for post processing of
this command until it is ready to receive the next command. For
example after a device reset command, the device might need some
time until it is ready again. Usually this is 0.0s, i.e. no post
processing is needed.
"""
super(Sen5xI2cCmdBase, self).__init__(
command=command,
tx_data=tx_data,
rx_length=rx_length,
read_delay=read_delay,
timeout=timeout,
crc=CrcCalculator(8, 0x31, 0xFF, 0x00),
command_bytes=2,
post_processing_time=post_processing_time,
)
[docs]class Sen5xI2cCmdStartMeasurement(Sen5xI2cCmdBase):
"""
Start Measurement I²C Command
Starts a continuous measurement.
After starting the measurement, it takes some time (~1s) until the first
measurement results are available. You could poll with the command 0x0202
"Read Data Ready" to check when the results are ready to read.
If the device is in measure mode without PM and the firmware version is
higher than 1.0, this command enables PM measurement without affecting the
already running RH/T/VOC/NOx measurements (except that the "data
ready"-flag will be cleared). If the device is in idle mode, this command
starts the normal measurement. In any other case (e.g. normal measure mode
already running), this command has no effect.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdStartMeasurement, self).__init__(
command=0x0021,
tx_data=None,
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.05,
)
[docs]class Sen5xI2cCmdStartMeasurementWithoutPm(Sen5xI2cCmdBase):
"""
Start Measurement Without PM I²C Command
Starts a continuous measurement without PM. Only humidity, temperature, VOC
and NOx are available in this mode. Laser and fan are switched off to keep
power consumption low.
After starting the measurement, it takes some time (~1s) until the first
measurement results are available. You could poll with the command 0x0202
"Read Data Ready" to check when the results are ready to read.
If the device is in the normal measure mode and the firmware version is
higher than 1.0, this command disables PM measurement without affecting the
already running RH/T/VOC/NOx measurements (except that the "data
ready"-flag will be cleared). If the device is in idle mode, this command
starts the measurement without PM. In any other case (e.g. measure mode
without PM already running), this command has no effect.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdStartMeasurementWithoutPm, self).__init__(
command=0x0037,
tx_data=None,
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.05,
)
[docs]class Sen5xI2cCmdStopMeasurement(Sen5xI2cCmdBase):
"""
Stop Measurement I²C Command
Stops the measurement and returns to idle mode.
If the device is already in idle mode, this command has no effect.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdStopMeasurement, self).__init__(
command=0x0104,
tx_data=None,
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.16,
)
class Sen5xI2cCmdReadDataReady(Sen5xI2cCmdBase):
"""
Read Data Ready I²C Command
This command can be used to check if new measurement results are ready to
read. The data ready flag is automatically reset after reading the
measurement values with the 0x03.. "Read Measured Values" commands.
.. note:: During fan (auto-)cleaning, no measurement data is available for
several seconds and thus this flag will not be set until cleaning
has finished. So please expect gaps of several seconds at any
time if fan auto-cleaning is enabled.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdReadDataReady, self).__init__(
command=0x0202,
tx_data=None,
rx_length=3,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return:
- padding (int) -
Padding byte, always 0x00.
- data_ready (bool) -
True (0x01) if data is ready, False (0x00) if not. When no
measurement is running, False will be returned.
:rtype: tuple
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
padding = int(unpack(">B", checked_data[0:1])[0]) # uint8
data_ready = bool(unpack(">?", checked_data[1:2])[0]) # bool
return padding, \
data_ready
class Sen5xI2cCmdReadMeasuredValues(Sen5xI2cCmdBase):
"""
Read Measured Values I²C Command
Returns the measured values.
The command 0x0202 "Read Data Ready" can be used to check if new data is
available since the last read operation. If no new data is available, the
previous values will be returned again. If no data is available at all
(e.g. measurement not running for at least one second), all values will be
at their upper limit (0xFFFF for ``uint16``, 0x7FFF for ``int16``).
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdReadMeasuredValues, self).__init__(
command=0x03C4,
tx_data=None,
rx_length=24,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return:
- mass_concentration_pm1p0 (int) -
Value is scaled with factor 10: PM1.0 [µg/m³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
- mass_concentration_pm2p5 (int) -
Value is scaled with factor 10: PM2.5 [µg/m³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
- mass_concentration_pm4p0 (int) -
Value is scaled with factor 10: PM4.0 [µg/m³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
- mass_concentration_pm10p0 (int) -
Value is scaled with factor 10: PM10.0 [µg/m³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
- ambient_humidity (int) -
Value is scaled with factor 100: RH [%] = value / 100
*Note: If this value is unknown, 0x7FFF is returned.*
- ambient_temperature (int) -
Value is scaled with factor 200: T [°C] = value / 200
*Note: If this value is unknown, 0x7FFF is returned.*
- voc_index (int) -
Value is scaled with factor 10: VOC Index = value / 10
*Note: If this value is unknown, 0x7FFF is returned.*
- nox_index (int) -
Value is scaled with factor 10: NOx Index = value / 10
*Note: If this value is unknown, 0x7FFF is returned. During the
first 10..11 seconds after power-on or device reset, this value
will be 0x7FFF as well.*
:rtype: tuple
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
mass_concentration_pm1p0 = int(unpack(">H", checked_data[0:2])[0]) # uint16
mass_concentration_pm2p5 = int(unpack(">H", checked_data[2:4])[0]) # uint16
mass_concentration_pm4p0 = int(unpack(">H", checked_data[4:6])[0]) # uint16
mass_concentration_pm10p0 = int(unpack(">H", checked_data[6:8])[0]) # uint16
ambient_humidity = int(unpack(">h", checked_data[8:10])[0]) # int16
ambient_temperature = int(unpack(">h", checked_data[10:12])[0]) # int16
voc_index = int(unpack(">h", checked_data[12:14])[0]) # int16
nox_index = int(unpack(">h", checked_data[14:16])[0]) # int16
return mass_concentration_pm1p0, \
mass_concentration_pm2p5, \
mass_concentration_pm4p0, \
mass_concentration_pm10p0, \
ambient_humidity, \
ambient_temperature, \
voc_index, \
nox_index
[docs]class Sen5xI2cCmdStartFanCleaning(Sen5xI2cCmdBase):
"""
Start Fan Cleaning I²C Command
Starts the fan cleaning manually. The "data ready"-flag will be cleared
immediately and during the next few seconds, no new measurement results
will be available (old values will be returned). Once the cleaning is
finished, the "data ready"-flag will be set and new measurement results
will be available.
When executing this command while cleaning is already active, the command
does nothing.
If you stop the measurement while fan cleaning is active, the cleaning will
be aborted immediately.
.. note:: This command is only available in measure mode with PM
measurement enabled, i.e. only if the fan is already running. In
any other state, this command does nothing.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdStartFanCleaning, self).__init__(
command=0x5607,
tx_data=None,
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.02,
)
class Sen5xI2cCmdGetTemperatureOffsetParameters(Sen5xI2cCmdBase):
"""
Get Temperature Offset Parameters I²C Command
Gets the temperature offset parameters from the device.
"""
def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetTemperatureOffsetParameters, self).__init__(
command=0x60B2,
tx_data=None,
rx_length=9,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return:
- offset (int) -
Constant temperature offset scaled with factor 200 (T [°C] =
value / 200).
- slope (int) -
Normalized temperature offset slope scaled with factor 10000
(applied factor = value / 10000).
- time_constant (int) -
Time constant [s] how fast the slope and offset are applied.
After the specified value in seconds, 63% of the new slope and
offset are applied.
:rtype: tuple
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
offset = int(unpack(">h", checked_data[0:2])[0]) # int16
slope = int(unpack(">h", checked_data[2:4])[0]) # int16
time_constant = int(unpack(">H", checked_data[4:6])[0]) # uint16
return offset, \
slope, \
time_constant
class Sen5xI2cCmdSetTemperatureOffsetParameters(Sen5xI2cCmdBase):
"""
Set Temperature Offset Parameters I²C Command
Sets the temperature offset parameters for the device.
"""
def __init__(self, offset, slope, time_constant):
"""
Constructor.
:param int offset:
Constant temperature offset scaled with factor 200 (T [°C] = value
/ 200). The default value is 0.
:param int slope:
Normalized temperature offset slope scaled with factor 10000
(applied factor = value / 10000). The default value is 0.
:param int time_constant:
Time constant [s] how fast the new slope and offset will be
applied. After the specified value in seconds, 63% of the new slope
and offset are applied. A time constant of zero means the new
values will be applied immediately (within the next measure
interval of 1 second).
"""
super(Sen5xI2cCmdSetTemperatureOffsetParameters, self).__init__(
command=0x60B2,
tx_data=b"".join([pack(">h", offset),
pack(">h", slope),
pack(">H", time_constant)]),
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.02,
)
class Sen5xI2cCmdGetWarmStartParameter(Sen5xI2cCmdBase):
"""
Get Warm Start Parameter I²C Command
Gets the warm start parameter from the device.
"""
def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetWarmStartParameter, self).__init__(
command=0x60C6,
tx_data=None,
rx_length=3,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return: Warm start behavior as a value in the range from 0 (cold
start) to 65535 (warm start).
:rtype: int
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
warm_start = int(unpack(">H", checked_data[0:2])[0]) # uint16
return warm_start
class Sen5xI2cCmdSetWarmStartParameter(Sen5xI2cCmdBase):
"""
Set Warm Start Parameter I²C Command
Sets the warm start parameter for the device.
.. note:: This parameter can be changed in any state of the device (and the
getter immediately returns the new value), but it is applied only
the next time starting a measurement, i.e. when sending a "Start
Measurement" command! So the parameter needs to be set *before* a
warm-start measurement is started.
"""
def __init__(self, warm_start):
"""
Constructor.
:param int warm_start:
Warm start behavior as a value in the range from 0 (cold start) to
65535 (warm start). The default value is 0.
"""
super(Sen5xI2cCmdSetWarmStartParameter, self).__init__(
command=0x60C6,
tx_data=b"".join([pack(">H", warm_start)]),
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.02,
)
[docs]class Sen5xI2cCmdGetVocAlgorithmTuningParameters(Sen5xI2cCmdBase):
"""
Get VOC Algorithm Tuning Parameters I²C Command
Gets the currently set tuning parameters of the VOC algorithm.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetVocAlgorithmTuningParameters, self).__init__(
command=0x60D0,
tx_data=None,
rx_length=18,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
[docs] def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return:
- index_offset (int) -
VOC index representing typical (average) conditions.
- learning_time_offset_hours (int) -
Time constant to estimate the VOC algorithm offset from the
history in hours. Past events will be forgotten after about twice
the learning time.
- learning_time_gain_hours (int) -
Time constant to estimate the VOC algorithm gain from the history
in hours. Past events will be forgotten after about twice the
learning time.
- gating_max_duration_minutes (int) -
Maximum duration of gating in minutes (freeze of estimator during
high VOC index signal). Zero disables the gating.
- std_initial (int) -
Initial estimate for standard deviation. Lower value boosts
events during initial learning period, but may result in larger
device-to-device variations.
- gain_factor (int) -
Gain factor to amplify or to attenuate the VOC index output.
:rtype: tuple
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
index_offset = int(unpack(">h", checked_data[0:2])[0]) # int16
learning_time_offset_hours = int(unpack(">h", checked_data[2:4])[0]) # int16
learning_time_gain_hours = int(unpack(">h", checked_data[4:6])[0]) # int16
gating_max_duration_minutes = int(unpack(">h", checked_data[6:8])[0]) # int16
std_initial = int(unpack(">h", checked_data[8:10])[0]) # int16
gain_factor = int(unpack(">h", checked_data[10:12])[0]) # int16
return index_offset, \
learning_time_offset_hours, \
learning_time_gain_hours, \
gating_max_duration_minutes, \
std_initial, \
gain_factor
[docs]class Sen5xI2cCmdSetVocAlgorithmTuningParameters(Sen5xI2cCmdBase):
"""
Set VOC Algorithm Tuning Parameters I²C Command
Sets the tuning parameters of the VOC algorithm.
.. note:: This command is available only in idle mode. In measure mode,
this command has no effect. In addition, it has no effect if at
least one parameter is outside the specified range.
"""
[docs] def __init__(self, index_offset, learning_time_offset_hours, learning_time_gain_hours, gating_max_duration_minutes, std_initial, gain_factor):
"""
Constructor.
:param int index_offset:
VOC index representing typical (average) conditions. Allowed values
are in range 1..250. The default value is 100.
:param int learning_time_offset_hours:
Time constant to estimate the VOC algorithm offset from the history
in hours. Past events will be forgotten after about twice the
learning time. Allowed values are in range 1..1000. The default
value is 12 hours.
:param int learning_time_gain_hours:
Time constant to estimate the VOC algorithm gain from the history
in hours. Past events will be forgotten after about twice the
learning time. Allowed values are in range 1..1000. The default
value is 12 hours.
:param int gating_max_duration_minutes:
Maximum duration of gating in minutes (freeze of estimator during
high VOC index signal). Set to zero to disable the gating. Allowed
values are in range 0..3000. The default value is 180 minutes.
:param int std_initial:
Initial estimate for standard deviation. Lower value boosts events
during initial learning period, but may result in larger
device-to-device variations. Allowed values are in range 10..5000.
The default value is 50.
:param int gain_factor:
Gain factor to amplify or to attenuate the VOC index output.
Allowed values are in range 1..1000. The default value is 230.
"""
super(Sen5xI2cCmdSetVocAlgorithmTuningParameters, self).__init__(
command=0x60D0,
tx_data=b"".join([pack(">h", index_offset),
pack(">h", learning_time_offset_hours),
pack(">h", learning_time_gain_hours),
pack(">h", gating_max_duration_minutes),
pack(">h", std_initial),
pack(">h", gain_factor)]),
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.02,
)
[docs]class Sen5xI2cCmdGetNoxAlgorithmTuningParameters(Sen5xI2cCmdBase):
"""
Get NOx Algorithm Tuning Parameters I²C Command
Gets the currently set tuning parameters of the NOx algorithm.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetNoxAlgorithmTuningParameters, self).__init__(
command=0x60E1,
tx_data=None,
rx_length=18,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
[docs] def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return:
- index_offset (int) -
NOx index representing typical (average) conditions.
- learning_time_offset_hours (int) -
Time constant to estimate the NOx algorithm offset from the
history in hours. Past events will be forgotten after about twice
the learning time.
- learning_time_gain_hours (int) -
The time constant to estimate the NOx algorithm gain from the
history has no impact for NOx. This parameter is still in place
for consistency reasons with the VOC tuning parameters command.
- gating_max_duration_minutes (int) -
Maximum duration of gating in minutes (freeze of estimator during
high NOx index signal). Zero disables the gating.
- std_initial (int) -
The initial estimate for standard deviation has no impact for
NOx. This parameter is still in place for consistency reasons
with the VOC tuning parameters command.
- gain_factor (int) -
Gain factor to amplify or to attenuate the NOx index output.
:rtype: tuple
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
index_offset = int(unpack(">h", checked_data[0:2])[0]) # int16
learning_time_offset_hours = int(unpack(">h", checked_data[2:4])[0]) # int16
learning_time_gain_hours = int(unpack(">h", checked_data[4:6])[0]) # int16
gating_max_duration_minutes = int(unpack(">h", checked_data[6:8])[0]) # int16
std_initial = int(unpack(">h", checked_data[8:10])[0]) # int16
gain_factor = int(unpack(">h", checked_data[10:12])[0]) # int16
return index_offset, \
learning_time_offset_hours, \
learning_time_gain_hours, \
gating_max_duration_minutes, \
std_initial, \
gain_factor
[docs]class Sen5xI2cCmdSetNoxAlgorithmTuningParameters(Sen5xI2cCmdBase):
"""
Set NOx Algorithm Tuning Parameters I²C Command
Sets the tuning parameters of the NOx algorithm.
.. note:: This command is available only in idle mode. In measure mode,
this command has no effect. In addition, it has no effect if at
least one parameter is outside the specified range.
"""
[docs] def __init__(self, index_offset, learning_time_offset_hours, learning_time_gain_hours, gating_max_duration_minutes, std_initial, gain_factor):
"""
Constructor.
:param int index_offset:
NOx index representing typical (average) conditions. Allowed values
are in range 1..250. The default value is 1.
:param int learning_time_offset_hours:
Time constant to estimate the NOx algorithm offset from the history
in hours. Past events will be forgotten after about twice the
learning time. Allowed values are in range 1..1000. The default
value is 12 hours.
:param int learning_time_gain_hours:
The time constant to estimate the NOx algorithm gain from the
history has no impact for NOx. This parameter is still in place for
consistency reasons with the VOC tuning parameters command. This
parameter must always be set to 12 hours.
:param int gating_max_duration_minutes:
Maximum duration of gating in minutes (freeze of estimator during
high NOx index signal). Set to zero to disable the gating. Allowed
values are in range 0..3000. The default value is 720 minutes.
:param int std_initial:
The initial estimate for standard deviation parameter has no impact
for NOx. This parameter is still in place for consistency reasons
with the VOC tuning parameters command. This parameter must always
be set to 50.
:param int gain_factor:
Gain factor to amplify or to attenuate the NOx index output.
Allowed values are in range 1..1000. The default value is 230.
"""
super(Sen5xI2cCmdSetNoxAlgorithmTuningParameters, self).__init__(
command=0x60E1,
tx_data=b"".join([pack(">h", index_offset),
pack(">h", learning_time_offset_hours),
pack(">h", learning_time_gain_hours),
pack(">h", gating_max_duration_minutes),
pack(">h", std_initial),
pack(">h", gain_factor)]),
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.02,
)
[docs]class Sen5xI2cCmdGetRhtAccelerationMode(Sen5xI2cCmdBase):
"""
Get RH/T Acceleration Mode I²C Command
Gets the RH/T acceleration mode.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetRhtAccelerationMode, self).__init__(
command=0x60F7,
tx_data=None,
rx_length=3,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
[docs] def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return: The current RH/T acceleration mode.
:rtype: int
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
mode = int(unpack(">H", checked_data[0:2])[0]) # uint16
return mode
[docs]class Sen5xI2cCmdSetRhtAccelerationMode(Sen5xI2cCmdBase):
"""
Set RH/T Acceleration Mode I²C Command
Sets the RH/T acceleration mode.
.. note:: This parameter can be changed in any state of the device (and the
getter immediately returns the new value), but it is applied only
the next time starting a measurement, i.e. when sending a "Start
Measurement" command. So the parameter needs to be set *before* a
new measurement is started.
"""
[docs] def __init__(self, mode):
"""
Constructor.
:param int mode:
The new RH/T acceleration mode.
"""
super(Sen5xI2cCmdSetRhtAccelerationMode, self).__init__(
command=0x60F7,
tx_data=b"".join([pack(">H", mode)]),
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.02,
)
[docs]class Sen5xI2cCmdGetVocAlgorithmState(Sen5xI2cCmdBase):
"""
Get VOC Algorithm State I²C Command
Gets the current VOC algorithm state. This data can be used to restore the
state with the "Set VOC Algorithm State" command after a short power cycle
or device reset.
This command can be used either in measure mode or in idle mode (which will
then return the state at the time when the measurement was stopped). In
measure mode, the state can be read each measure interval to always have
the latest state available, even in case of a sudden power loss.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetVocAlgorithmState, self).__init__(
command=0x6181,
tx_data=None,
rx_length=12,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
[docs] def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return: Current VOC algorithm state.
:rtype: bytes
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
state = bytes(checked_data[0:8]) # bytearray<8>
return state
[docs]class Sen5xI2cCmdSetVocAlgorithmState(Sen5xI2cCmdBase):
"""
Set VOC Algorithm State I²C Command
Sets the VOC algorithm state previously received with the "Get VOC
Algorithm State" command.
.. note:: This command is only available in idle mode and the state will be
applied only once when starting the next measurement. Any further
measurements (i.e. when stopping and restarting the measure mode)
will reset the state to initial values. In measure mode, this
command has no effect.
"""
[docs] def __init__(self, state):
"""
Constructor.
:param bytes state:
VOC algorithm state to restore.
"""
super(Sen5xI2cCmdSetVocAlgorithmState, self).__init__(
command=0x6181,
tx_data=b"".join([bytes(bytearray(state))]),
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.02,
)
[docs]class Sen5xI2cCmdGetFanAutoCleaningInterval(Sen5xI2cCmdBase):
"""
Get Fan Auto Cleaning Interval I²C Command
Gets the fan auto cleaning interval from the device.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetFanAutoCleaningInterval, self).__init__(
command=0x8004,
tx_data=None,
rx_length=6,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
[docs] def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return: Fan auto cleaning interval [s]. Zero means auto cleaning is
disabled.
:rtype: int
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
interval = int(unpack(">I", checked_data[0:4])[0]) # uint32
return interval
[docs]class Sen5xI2cCmdSetFanAutoCleaningInterval(Sen5xI2cCmdBase):
"""
Set Fan Auto Cleaning Interval I²C Command
Sets the fan auto cleaning interval for the device.
"""
[docs] def __init__(self, interval):
"""
Constructor.
:param int interval:
Fan auto cleaning interval [s]. Set to zero to disable auto
cleaning.
"""
super(Sen5xI2cCmdSetFanAutoCleaningInterval, self).__init__(
command=0x8004,
tx_data=b"".join([pack(">I", interval)]),
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.02,
)
[docs]class Sen5xI2cCmdGetProductName(Sen5xI2cCmdBase):
"""
Get Product Name I²C Command
Gets the product name from the device.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetProductName, self).__init__(
command=0xD014,
tx_data=None,
rx_length=48,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
[docs] def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return: Null-terminated ASCII string containing the product name. Up
to 32 characters can be read from the device.
:rtype: str
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
product_name = str(checked_data[0:32].decode('utf-8').rstrip('\0')) # string<32>
return product_name
[docs]class Sen5xI2cCmdGetSerialNumber(Sen5xI2cCmdBase):
"""
Get Serial Number I²C Command
Gets the serial number from the device.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetSerialNumber, self).__init__(
command=0xD033,
tx_data=None,
rx_length=48,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
[docs] def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return: Null-terminated ASCII string containing the serial number. Up
to 32 characters can be read from the device.
:rtype: str
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
serial_number = str(checked_data[0:32].decode('utf-8').rstrip('\0')) # string<32>
return serial_number
class Sen5xI2cCmdGetVersion(Sen5xI2cCmdBase):
"""
Get Version I²C Command
Gets the version information for the hardware, firmware and communication
protocol.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdGetVersion, self).__init__(
command=0xD100,
tx_data=None,
rx_length=12,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return:
- firmware_major (int) -
Firmware major version number.
- firmware_minor (int) -
Firmware minor version number.
- firmware_debug (bool) -
Firmware debug state. If the debug state is set, the firmware is
in development.
- hardware_major (int) -
Hardware major version number.
- hardware_minor (int) -
Hardware minor version number.
- protocol_major (int) -
Protocol major version number.
- protocol_minor (int) -
Protocol minor version number.
- padding (int) -
Padding byte, ignore this.
:rtype: tuple
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
firmware_major = int(unpack(">B", checked_data[0:1])[0]) # uint8
firmware_minor = int(unpack(">B", checked_data[1:2])[0]) # uint8
firmware_debug = bool(unpack(">?", checked_data[2:3])[0]) # bool
hardware_major = int(unpack(">B", checked_data[3:4])[0]) # uint8
hardware_minor = int(unpack(">B", checked_data[4:5])[0]) # uint8
protocol_major = int(unpack(">B", checked_data[5:6])[0]) # uint8
protocol_minor = int(unpack(">B", checked_data[6:7])[0]) # uint8
padding = int(unpack(">B", checked_data[7:8])[0]) # uint8
return firmware_major, \
firmware_minor, \
firmware_debug, \
hardware_major, \
hardware_minor, \
protocol_major, \
protocol_minor, \
padding
class Sen5xI2cCmdReadDeviceStatus(Sen5xI2cCmdBase):
"""
Read Device Status I²C Command
Reads the current device status.
Use this command to get detailed information about the device status. The
device status is encoded in flags. Each device status flag represents a
single bit in a 32-bit integer value. If more than one error is present,
the device status register value is the sum of the corresponding flag
values. For details about the available flags, refer to the device status
flags documentation.
.. note:: The status flags of type "Error" are sticky, i.e. they are not
cleared automatically even if the error condition no longer
exists. So they can only be cleared manually with the command
0xD210 "Read And Clear Device Status" or with a device reset. All
other flags are not sticky, i.e. they are cleared automatically
if the trigger condition disappears.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdReadDeviceStatus, self).__init__(
command=0xD206,
tx_data=None,
rx_length=6,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return: Device status (32 flags as an integer value). For details,
please refer to the device status flags documentation.
:rtype: int
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
device_status = int(unpack(">I", checked_data[0:4])[0]) # uint32
return device_status
class Sen5xI2cCmdReadAndClearDeviceStatus(Sen5xI2cCmdBase):
"""
Read And Clear Device Status I²C Command
Reads the current device status (like command 0xD206 "Read Device Status")
and afterwards clears all flags.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdReadAndClearDeviceStatus, self).__init__(
command=0xD210,
tx_data=None,
rx_length=6,
read_delay=0.02,
timeout=0,
post_processing_time=0.0,
)
def interpret_response(self, data):
"""
Validates the CRCs of the received data from the device and returns
the interpreted data.
:param bytes data:
Received raw bytes from the read operation.
:return: Device status (32 flags as an integer value) **before**
clearing it. For details, please refer to the device status
flags documentation.
:rtype: int
:raise ~sensirion_i2c_driver.errors.I2cChecksumError:
If a received CRC was wrong.
"""
# check and remove CRCs
checked_data = Sen5xI2cCmdBase.interpret_response(self, data)
# convert raw received data into proper data types
device_status = int(unpack(">I", checked_data[0:4])[0]) # uint32
return device_status
[docs]class Sen5xI2cCmdDeviceReset(Sen5xI2cCmdBase):
"""
Device Reset I²C Command
Executes a reset on the device. This has the same effect as a power cycle.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sen5xI2cCmdDeviceReset, self).__init__(
command=0xD304,
tx_data=None,
rx_length=None,
read_delay=0.0,
timeout=0,
post_processing_time=0.1,
)