#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2024 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 0.37.0
# Product: sfm_sf06
# Model-Version: 1.5.0
#
"""
The class SfmSf06DeviceBase implements the low level interface of the sensor.
The class SfmSf06Device extends the SfmSf06DeviceBase. It provides additional functions to ease the use of the
sensor.
"""
from sensirion_driver_adapters.transfer import execute_transfer
from sensirion_driver_support_types.mixin_access import MixinAccess
from sensirion_i2c_sfm_sf06.commands import (ConfigureAveraging, EnterSleep, ExitSleep, ReadMeasurementData,
ReadProductIdentifier, ReadScaleOffsetUnit,
StartAirO2ContinuousMeasurement, StartAirContinuousMeasurement,
StartCO2O2ContinuousMeasurement, StartCO2ContinuousMeasurement,
StartN2OO2ContinuousMeasurement, StartN2OContinuousMeasurement,
StartO2ContinuousMeasurement, StatusWordT, StopContinuousMeasurement,
UpdateConcentrationActivate, UpdateConcentrationSet)
from sensirion_i2c_sfm_sf06.result_types import (SignalFlow, SignalTemperature)
[docs]class SfmSf06DeviceBase:
"""Low level API implementation of SFM_SF06"""
[docs] def __init__(self, channel):
self._channel = channel
@property
def channel(self):
return self._channel
[docs] def start_o2_continuous_measurement(self):
"""
The sensor starts measuring both O₂ flow and temperature and provides a status word. All three measurement results can
be read out through one single I2C read when the continuous measurement is running. The specific command code used for the
start continuous measurement command selects the calibrated gas or binary gas mixture (lookup table) for the flow signal.
Supported by products:
- SFM3003
- SFM4300-20
- SFM4300-50
- SFM3119
- SFM3013-300-CL
- SFM3013-300-CLM
- SFM3019
.. note::
The first measurement result will be available after 12ms. Small accuracy deviations (few % of reading) can occur during
the first 30ms (including the 12ms)
"""
transfer = StartO2ContinuousMeasurement()
return execute_transfer(self._channel, transfer)
[docs] def start_air_continuous_measurement(self):
"""
The sensor starts measuring both Air flow and temperature and provides a status word. All three measurement results can
be read out through one single I2C read when the continuous measurement is running. The specific command code used for the
start continuous measurement command selects the calibrated gas or binary gas mixture (lookup table) for the flow signal.
Supported by products:
- SFM3003
- SFM4300-20
- SFM4300-50
- SFM3119
- SFM3013-300-CL
- SFM3013-300-CLM
- SFM3019
.. note::
The first measurement result will be available after 12ms. Small accuracy deviations (few % of reading) can occur during
the first 30ms (including the 12ms)
"""
transfer = StartAirContinuousMeasurement()
return execute_transfer(self._channel, transfer)
[docs] def start_n2o_continuous_measurement(self):
"""
The sensor starts measuring both N₂O (*HeOx for SMF3013-300-CLM*) flow and temperature and provides a status word. All three measurement results
can be read out through one single I2C read when the continuous measurement is running. The specific command code used
for the start continuous measurement command selects the calibrated gas or binary gas mixture (lookup table) for the flow
signal.
Supported by products:
- SFM4300-20
- SFM3013-300-CLM (HeOx)
.. note::
The first measurement result will be available after 12ms. Small accuracy deviations (few % of reading) can occur during the first 30ms
(including the 12ms)
"""
transfer = StartN2OContinuousMeasurement()
return execute_transfer(self._channel, transfer)
[docs] def start_co2_continuous_measurement(self):
"""
The sensor starts measuring both CO₂ flow and temperature and provides a status word. All three measurement results
can be read out through one single I2C read when the continuous measurement is running.
The specific command code used for the start continuous measurement command selects the calibrated gas or binary
gas mixture (lookup table) for the flow signal.
Supported by products:
- SFM4300-20
.. note::
The first measurement result will be available after 12ms. Small accuracy deviations (few % of reading) can occur during
the first 30ms (including the 12ms)
"""
transfer = StartCO2ContinuousMeasurement()
return execute_transfer(self._channel, transfer)
[docs] def start_air_o2_continuous_measurement(self, volume_fraction):
"""
The sensor starts measuring the Air/O₂ flow and temperature and provides a status word. All three measurement results
can be read out through one single I2C read when the continuous measurement is running.
The specific command code used for the start continuous measurement command selects the calibrated gas or binary
gas mixture (lookup table) for the flow signal.
Supported by products:
- SFM3003
- SFM4300-20
- SFM4300-50
- SFM3119
- SFM3013-300-CL
- SFM3013-300-CLM
- SFM3019
:param volume_fraction:
Volume fraction of dioxigen in ‰.
"""
transfer = StartAirO2ContinuousMeasurement(volume_fraction)
return execute_transfer(self._channel, transfer)
[docs] def start_n2o_o2_continuous_measurement(self, volume_fraction):
"""
The sensor starts measuring the N₂O / O₂ (*HeOx for SMF3013-300-CLM*) flow and temperature and provides a status word. All
three measurement results can be read out through one single I2C read when the continuous measurement is running.
The specific command code used for the start continuous measurement command selects the calibrated gas or binary
gas mixture (lookup table) for the flow signal.
Supported by products:
- SFM4300-20
- SFM3013-300-CLM (HeOx)
:param volume_fraction:
Volume fraction of O₂ in ‰.
"""
transfer = StartN2OO2ContinuousMeasurement(volume_fraction)
return execute_transfer(self._channel, transfer)
[docs] def start_co2_o2_continuous_measurement(self, volume_fraction):
"""
The sensor starts measuring the CO₂ / O₂ flow and temperature and provides a status word. All three measurement results
can be read out through one single I2C read when the continuous measurement is running.
The specific command code used for the start continuous measurement command selects the calibrated gas or binary
gas mixture (lookup table) for the flow signal.
Supported by products:
- SFM4300-20
:param volume_fraction:
Volume fraction of O₂ in ‰.
"""
transfer = StartCO2O2ContinuousMeasurement(volume_fraction)
return execute_transfer(self._channel, transfer)
[docs] def read_measurement_data(self):
"""
After the command *start_xx_continuous_measurement* has been sent, the chip continuously measures and updates the
measurement results.
New results (flow, temperature, and status word) can be read continuously with this command.
:return flow:
Calibrated flow signal.
:return temperature:
Calibrated temperature.
:return status_word:
Gives information about the measurement command that is currently running, information on the currently selected
averaging mode, and the defined gas concentration of the current measurement command.
A detailed description of the *status_word* can be found in the data sheet.
.. note::
The first measurement result will be available after 12ms. Small accuracy deviations (few % of reading) can occur during
the first 30ms (including the 12ms)
"""
transfer = ReadMeasurementData()
return execute_transfer(self._channel, transfer)
[docs] def update_concentration_set(self, volume_fraction):
"""
Together with the instruction *update_concentration_activate* this instruction allows to update the concentration
of a binary gas mixture dynamically, i.e. without exiting the running measurement mode.
This first instruction transmits the new concentration value to the flow sensor.
This instruction refers to *Transmit concentration*. For more details see data-sheet section *Update Concentration*
:param volume_fraction:
Fraction value
.. note::
- The concentration value must not be updated more than once per millisecond
- If a concentration value greater than 1000 is passed to the sensor, the measurement mode will stop.
:Example:
.. code-block:: python
sensor.update_concentration_set(50)
"""
transfer = UpdateConcentrationSet(volume_fraction)
return execute_transfer(self._channel, transfer)
[docs] def update_concentration_activate(self):
"""
By executing this instruction the previously with *update_concentration_set* set value becomes active.
The instruction resets the I2C address pointer to the regular result output buffer such that the measurement
data as described by the transfer read_measurement_data are optained upon a subsequent read.
This instruction refers to *Reset-i2c address pointer*. For more details see data-sheet section *Update Concentration*
.. note::
- The concentration value must not be updated more than once per millisecond
- If a concentration value greater than 1000 is passed to the sensor, the measurement mode will stop.
"""
transfer = UpdateConcentrationActivate()
return execute_transfer(self._channel, transfer)
[docs] def stop_continuous_measurement(self):
"""
This command stops the continuous measurement and puts
the sensor in idle mode. After it receives the stop command,
the sensor needs up to 0.5ms to power down the heater, enter
idle mode and be receptive for a new command.
"""
transfer = StopContinuousMeasurement()
return execute_transfer(self._channel, transfer)
[docs] def read_scale_offset_unit(self, command_code):
"""
This command provides the scale factor and offset to convert flow readings into physical units. The scale factor
and offset are specific to the calibrated gas / gas mixture and its corresponding lookup table used for the
flow measurement. Therefore, the gas / gas mixture needs to be specified in the command argument by the command code
of the corresponding start continuous measurement. For detailed information see data-sheet.
:param command_code:
Code of measurement from which we want to have that information.
:return flow_scale_factor:
Scale factor used by the sensor.
:return flow_offset:
Offset used by the sensor.
:return flow_unit:
Applicable flow unit.
"""
transfer = ReadScaleOffsetUnit(command_code)
return execute_transfer(self._channel, transfer)
[docs] def enter_sleep(self):
"""
In sleep mode the sensor uses a minimum amount of power. The mode can only be entered from idle mode, i.e. when the
sensor is not performing measurements.
This mode is particularly useful for battery operated devices. To minimize the current in this mode, the complexity of the sleep
mode circuit has been reduced as much as possible, which is mainly reflected by the way the sensor exits the sleep mode. In
sleep mode the sensor cannot be soft reset.
"""
transfer = EnterSleep()
return execute_transfer(self._channel, transfer)
[docs] def exit_sleep(self):
"""
The sensor exits the sleep mode and enters the idle mode when
it receives the valid I2C address and a write bit (‘0’).
Note that the I2C address is not acknowledged. It is necessary to
poll the sensor to see whether the sensor has received the
address and has woken up. This should take typically 16ms.
"""
transfer = ExitSleep()
return execute_transfer(self._channel, transfer)
[docs] def read_product_identifier(self):
"""
This command allows to read product identifier and the serial number.
The command can only be executed from the idle mode, i.e. when the sensor is not performing measurements
:return product_identifier:
32-bit unique product and revision number
:return serial_number:
64 bit unique serial number of the device
"""
transfer = ReadProductIdentifier()
return execute_transfer(self._channel, transfer)
[docs]class SfmSf06Device(SfmSf06DeviceBase):
"""Driver class implementation of SFM_SF06"""
#: Access to base class
sf06 = MixinAccess()
[docs] def __init__(self, channel):
super().__init__(channel)
self._flow_offset = 0.0
self._flow_scale_factor = 1.0
self._flow_unit = 0
[docs] def start_o2_continuous_measurement(self):
"""Start measurement and update internal state"""
(self._flow_scale_factor, self._flow_offset, self._flow_unit
) = self.read_scale_offset_unit(StartO2ContinuousMeasurement.CMD_ID)
return self.sf06.start_o2_continuous_measurement()
[docs] def start_air_continuous_measurement(self):
"""Start measurement and update internal state"""
(self._flow_scale_factor, self._flow_offset, self._flow_unit
) = self.read_scale_offset_unit(StartAirContinuousMeasurement.CMD_ID)
return self.sf06.start_air_continuous_measurement()
[docs] def start_n2o_continuous_measurement(self):
"""Start NO2 measurement and readout the corresponding scale factor from the sensor"""
(self._flow_scale_factor, self._flow_offset, self._flow_unit
) = self.read_scale_offset_unit(StartN2OContinuousMeasurement.CMD_ID)
return self.sf06.start_n2o_continuous_measurement()
[docs] def start_co2_continuous_measurement(self):
"""Start measurement and update internal state"""
(self._flow_scale_factor, self._flow_offset, self._flow_unit
) = self.read_scale_offset_unit(StartCO2ContinuousMeasurement.CMD_ID)
return self.sf06.start_co2_continuous_measurement()
[docs] def start_n2o_o2_continuous_measurement(self, volume_fraction):
"""
Start measurement and update internal state
:param volume_fraction:
Volume fraction of O₂ in ‰.
"""
(self._flow_scale_factor, self._flow_offset, self._flow_unit
) = self.read_scale_offset_unit(StartN2OO2ContinuousMeasurement.CMD_ID)
return self.sf06.start_n2o_o2_continuous_measurement(volume_fraction)
[docs] def start_co2_o2_continuous_measurement(self, volume_fraction):
"""
Start measurement and update internal state
:param volume_fraction:
Volume fraction of O₂ in ‰.
"""
(self._flow_scale_factor, self._flow_offset, self._flow_unit
) = self.read_scale_offset_unit(StartCO2O2ContinuousMeasurement.CMD_ID)
return self.sf06.start_co2_o2_continuous_measurement(volume_fraction)
[docs] def start_air_o2_continuous_measurement(self, volume_fraction):
"""
Start measurement and update internal state
:param volume_fraction:
Volume fraction of dioxigen in ‰.
"""
(self._flow_scale_factor, self._flow_offset, self._flow_unit
) = self.read_scale_offset_unit(StartAirO2ContinuousMeasurement.CMD_ID)
return self.sf06.start_air_o2_continuous_measurement(volume_fraction)
[docs] def read_measurement_data_raw(self):
"""
Rename overwritten function.
:return flow:
Calibrated flow signal.
:return temperature:
Calibrated temperature.
:return status_word:
Gives information about the measurement command that is currently running, information on the currently selected
averaging mode, and the defined gas concentration of the current measurement command.
A detailed description of the *status_word* can be found in the data sheet.
"""
return self.sf06.read_measurement_data()
[docs] def read_measurement_data(self):
"""
Read measurement data and apply appropriate scaling.
:return a_flow:
This signal represents the mesured flow. It is scaled with the corresponding scaling factor and
offset
:return a_temperature:
Measured temperature in degrees celsius. The raw value is scaled appropriately.
:return a_status_word:
"""
(raw_flow, raw_temp, status
) = self.read_measurement_data_raw()
return (SignalFlow(raw_flow, self._flow_scale_factor, self._flow_offset), SignalTemperature(raw_temp),
StatusWordT(status))
[docs] def update_concentration(self, volume_fraction):
"""
Configure and apply new concentration value.
:param volume_fraction:
Fraction value
"""
self.update_concentration_set(volume_fraction)
return self.update_concentration_activate()