# -*- coding: utf-8 -*-
# (c) Copyright 2021 Sensirion AG, Switzerland
##############################################################################
##############################################################################
# _____ _ _ _______ _____ ____ _ _
# / ____| /\ | | | |__ __|_ _/ __ \| \ | |
# | | / \ | | | | | | | || | | | \| |
# | | / /\ \| | | | | | | || | | | . ` |
# | |____ / ____ \ |__| | | | _| || |__| | |\ |
# \_____/_/ \_\____/ |_| |_____\____/|_| \_|
#
# THIS FILE IS AUTOMATICALLY GENERATED AND MUST NOT BE EDITED MANUALLY!
#
# Generator: sensirion-shdlc-interface-generator 0.9.0
# Product: SVM41
# Version: 0.8.4
#
##############################################################################
##############################################################################
# flake8: noqa
from __future__ import absolute_import, division, print_function
from sensirion_shdlc_driver.command import ShdlcCommand
from struct import pack, unpack
import logging
log = logging.getLogger(__name__)
[docs]class Svm41CmdReadMeasuredValuesBase(ShdlcCommand):
"""
SHDLC command 0x03: "Read Measured Values".
"""
[docs] def __init__(self, *args, **kwargs):
"""
Constructor.
"""
super(Svm41CmdReadMeasuredValuesBase, self).__init__(
0x03, *args, **kwargs)
[docs]class Svm41CmdReadMeasuredValuesAsIntegers(Svm41CmdReadMeasuredValuesBase):
"""
Read Measured Values As Integers Command
Returns the new measurement results as integers.
.. note:: This command is only available in measurement mode. The firmware
updates the measurement values every second. Polling data with a
faster sampling rate will return the same values. The first
measurement is available 1 second after the start measurement
command is issued. Any readout prior to this will return zero
initialized values.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Svm41CmdReadMeasuredValuesAsIntegers, self).__init__(
data=b"".join([bytes(bytearray([0x10]))]),
max_response_time=0.05,
post_processing_time=0.0,
min_response_length=8,
max_response_length=8
)
[docs] @staticmethod
def interpret_response(data):
"""
:return:
- humidity (int) -
Compensated ambient humidity in % RH with a scaling factor of
100.
- temperature (int) -
Compensated ambient temperature in degrees celsius with a scaling
of 200.
- voc_index (int) -
VOC index with a scaling value of 10.
- nox_index (int) -
NOx index with a scaling value of 10.
:rtype: tuple
"""
humidity = int(unpack(">h", data[0:2])[0]) # int16
temperature = int(unpack(">h", data[2:4])[0]) # int16
voc_index = int(unpack(">h", data[4:6])[0]) # int16
nox_index = int(unpack(">h", data[6:8])[0]) # int16
return humidity,\
temperature,\
voc_index,\
nox_index
[docs]class Svm41CmdReadMeasuredRawValues(Svm41CmdReadMeasuredValuesBase):
"""
Read Measured Raw Values Command
Returns the measured raw values.
.. note:: This command is only available in measurement mode. The firmware
updates the measurement values every second. Polling data with a
faster sampling rate will return the same values. The first
measurement is available 1 second after the start measurement
command is issued. Any readout prior to this will return zero
initialized values.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Svm41CmdReadMeasuredRawValues, self).__init__(
data=b"".join([bytes(bytearray([0x0D]))]),
max_response_time=0.05,
post_processing_time=0.0,
min_response_length=8,
max_response_length=8
)
[docs] @staticmethod
def interpret_response(data):
"""
:return:
- raw_humidity (int) -
Uncompensated raw humidity in % RH as read from the SHT40 with a
scaling factor of 100.
- raw_temperature (int) -
Uncompensated raw temperature in degrees celsius as read from the
SHT40 with a scaling of 200.
- raw_voc_ticks (int) -
Raw VOC output ticks as read from the SGP sensor.
- raw_nox_ticks (int) -
Raw NOx output ticks as read from the SGP sensor.
:rtype: tuple
"""
raw_humidity = int(unpack(">h", data[0:2])[0]) # int16
raw_temperature = int(unpack(">h", data[2:4])[0]) # int16
raw_voc_ticks = int(unpack(">H", data[4:6])[0]) # uint16
raw_nox_ticks = int(unpack(">H", data[6:8])[0]) # uint16
return raw_humidity,\
raw_temperature,\
raw_voc_ticks,\
raw_nox_ticks