diff --git a/extras/sht3x/README.md b/extras/sht3x/README.md index afc3f5d..b09e491 100644 --- a/extras/sht3x/README.md +++ b/extras/sht3x/README.md @@ -6,59 +6,68 @@ Please note: The driver supports multiple sensors connected to different I2C int ## About the sensor -SHT3x is a digital temperature and humidity sensor that uses I2C interface with up to 1 MHz communication speed. It can operate with three levels of *repeatability* (low, medium and high) in two different modes, the *single shot data acquisition mode* and the *periodic data aquisition mode*. +SHT3x is a digital temperature and humidity sensor that uses an I2C interface with up to 1 MHz communication speed. It can operate with three levels of *repeatability* (low, medium and high) in two different modes, the *single shot data acquisition mode* and the *periodic data aquisition mode*. ### Single shot data acquisition mode -In this mode one issued measurement command triggers the acquisition of one data pair. Each data pair -consists of temperature and humidity as 16 bit decimal values. +In this mode, a measurement command triggers the acquisition of one data pair. Each data pair consists of temperature and humidity as 16-bit decimal values. -Repeatability setting influences the measurement duration as well as the current consumption of the sensor. The measurement takes 3 ms at low repeatability, 5 ms at low repeatability, and 13.5 ms at high repeatability, respectively. That is, the measurement produces a noticeable delay in execution. +The repeatability affects the measurement time as well as the power consumption of the sensor. The measurement takes 3 ms with low repeatability, 5 ms with medium repeatability and 13.5 ms with high repeatability. That is, the measurement produces a noticeable delay in execution. -Average current consumption of while sensor is measuring at lowest repeatability is 800 uA. That is, the higher the repeatability level is, the longer the measurement takes and the higher the power consumption is. The sensor consumes only 0.2 uA in standby mode. +While the sensor measures at the lowest repeatability, the average current consumption is 800 μA. That is, the higher the reproducibility level, the longer the measurement takes and the higher the power consumption. The sensor consumes only 0.2 μA in standby mode. ### Periodic data acquisition mode -In this mode one issued measurement command yields a stream of data pairs. Each data pair -consists of temperature and humidity as 16 bit decimal values. Once the measurement command is sent to the sensor, it executes measurements periodically by itself at a rate of 0.5, 1, 2, 4 or 10 measurements per second (mps). The data pairs can be read by a fetch command at the same rate. +In this mode one issued measurement command yields a stream of data pairs. Each data pair consists of temperature and humidity as 16-bit decimal values. As soon as the measurement command has been sent to the sensor, it itself carries out measurements periodically at a rate of 0.5, 1, 2, 4 or 10 measurements per second (mps). The data pairs can be read with a fetch command at the same rate. -As in *single shot data acquisition mode*, the repeatability setting influences the measurement duration as well as the current consumption of the sensor, see above. +As in the *single shot data acquisition mode*, the repeatability setting affects both the measurement time and the current consumption of the sensor, see above. ## How the driver works -To avoid blocking of user tasks during measurements due to their duration, separate tasks running in background are used to realize the measurements. These task are created implicitly when a user task calls function *sht3x_create_sensor* for each connected SHT3x sensor. The background tasks realize the measurement procedures which are executed periodically at a rate that can be defined by the user for each sensor separately using function *sht3x_set_measurement_period* (default period is 1000 ms). +To avoid blocking of user tasks during measurements due to their duration, separate tasks running in background are used to realize the measurements. These background tasks are created implicitly when a user task calls function *sht3x_create_sensor* for each connected SHT3x sensor. The background tasks realize the measurement procedures which are executed periodically at a rate that can be defined by the user for each sensor separately using function *sht3x_set_measurement_period* (default period is 1000 ms). -### Measurement +### Measurement method -Since predefined rates of *periodic data acquisition mode* of the sensor itself are normally not compatible with user requirements, the measurement procedures are realized in *single shot data acquisition mode* at the highest level of repeatability. Because of the sensor power characteristics, *single shot data acquisition mode* is more power efficient than using *periodic data acquisition mode* in most use cases. +Since the predefined rates of *periodic data acquisition mode* of the sensor itself are normally not compatible with user requirements, the measurements are realized by the background task in *single shot data acquisition mode* at the highest level of repeatability. Because of the sensor power characteristics, *single shot data acquisition mode* is more power efficient than using the *periodic data acquisition mode* in most use cases. -However, using the *single shot data acquisition mode* produces a delay of 20 ms for each measurement. This is the time needed from issuing the measurement command until measured sensor data are available and can be read. Since the delay is realized using *vTaskDelay* function in the background tasks, neither the system nor any user task is blocked during the measurements. +However, using the *single shot data acquisition mode* produces a delay of 20 ms for each measurement. This is just the time needed from issuing the measurement command until measured sensor data are available and can be read. Since this delay is realized using *vTaskDelay* function in the background tasks, neither the system nor any user task is blocked during the measurements. Please note: Since each measurement produces a delay of 20 ms, the minimum period that can be defined with function *sht3x_set_measurement_period* is 20 ms. Therefore, a maximum measurement rate of 50 mps could be reached. ### Measured data -At each measurement, *actual sensor values* for temperature as well as humidity are determined as floating point values from measured data pairs. Temperature is given in °C as well in °F. Humidity is given in percent. Based on these *actual sensor values* the background task also computes successively with each measurement the *average sensor values* using the exponential moving average +At each measurement, *actual sensor values* for temperature as well as humidity are determined as floating point values from the measured data pairs. Temperature is given in °C as well in °F. Humidity is given in percent. + +If average value computation is enabled (default), the background task also computes successively at each measurement the *average sensor values* based on these *actual sensor values* using the exponential moving average Average[k] = W * Actual + (1-W) * Average [k-1] -where coefficient W represents the degree of weighting decrease, a constant smoothing factor between 0 and 1. A higher W discounts older observations faster. The coefficient W (smoothing factor) can be defined by the user using function *sht3x_set_average_weight*. The default value of W is 0.2. +where coefficient W represents the degree of weighting decrease, a constant smoothing factor between 0 and 1. A higher W discounts older observations faster. The coefficient W (smoothing factor) can be defined by the user task using function *sht3x_set_average_weight*. The default value of W is 0.2. The average value computation can be enabled or disabled using function *sht3x_enable_average_computation*. + +If average computation is disabled, *average sensor values* correspont to the *actual sensor values*. ### Getting results. -Once a measurement has been finished, *actual sensor values* and *average sensor values* can be read by user tasks. There are two possibilities to do that, defining a callback function or the calling function *sht3x_get_values* explicitly. +As soon as a measurement is completed, the actual sensor values * and * average sensor values * can be read by user tasks. There are two ways to do this: + +- define a callback function or +- call the function * sht3x_get_values * explicitly. #### Using callback function -For each connected SHT3 sensor, the user can register a callback function using function *sht3x_set_callback_function*. If a callback function is registered, it is called by the background task after each measurement to pass *actual sensor values* and *average sensor values* to user tasks. Thus, the user gets the results of measurements automatically with same rate as the periodic measurements are executed. +For each connected SHT3 sensor, the user task can register a callback function using function *sht3x_set_callback_function*. If a callback function is registered, it is called by the background task after each measurement to pass *actual sensor values* and *average sensor values* to user tasks. Thus, the user gets the results of the measurements automatically with same rate as the periodic measurements are executed. Using the callback function is the easiest way to get the results. #### Using function sht3x_get_values -If there is no callback function registered, the user has to use function *sht3x_get_values* explicitly to get *actual sensor values* and *average sensor values*. To ensure that these values are up-to-date, the rate of periodic measurement in background task should be at least the same or higher as the rate of using function *sht3x_get_values*. That is, the period of measurements in background task set with function *sht3x_set_measurement_period* has to be less or equal than the rate of using function *sht3x_get_values*. +If there is no callback function registered, the user task has to call function *sht3x_get_values* to get *actual sensor values* and *average sensor values*. These values are stored in data structures that are specified as pointer parameters. Using NULL pointers for the parameters, the user task can decide which results are not interesting. -Please remember: The minimum measurement period can be 20 ms. +To ensure that the values are up-to-date, the rate of periodic measurement in background task should be at least the same or higher as the rate of using function *sht3x_get_values*. That is, the period of measurements in background task set with function *sht3x_set_measurement_period* has to be less or equal than the rate of using function *sht3x_get_values*. + +If average computation is disabled, *average sensor values* are just the same as *actual sensor values*. + +Please note: The minimum measurement period can be 20 ms. ## Usage @@ -101,7 +110,7 @@ static void my_callback_function (uint32_t sensor, } ``` -you have to register this callback function using *sht3x_set_callback_function*. +You have to register this callback function using *sht3x_set_callback_function*. ``` sht3x_set_callback_function (sensor, &my_callback_function); @@ -207,3 +216,4 @@ For further examples see [examples directory](../../examples/sht3x/README.md) + diff --git a/extras/sht3x/sht3x.c b/extras/sht3x/sht3x.c index 00d1153..e762579 100644 --- a/extras/sht3x/sht3x.c +++ b/extras/sht3x/sht3x.c @@ -1,3 +1,43 @@ +/* + * The BSD License (3-clause license) + * + * Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Driver for Sensirion SHT3x digital temperature and humity sensor + * connected to I2C + * + * Part of esp-open-rtos + */ + #include #include "sht3x.h" @@ -21,9 +61,9 @@ #define SHT3x_FETCH_DATA_CMD 0xE000 #ifdef SHT3x_DEBUG -#define DEBUG_PRINTF(s, ...) printf("%s: " s "\n", "SHT3x", ## __VA_ARGS__) +#define debug(s, ...) printf("%s: " s "\n", "SHT3x", ## __VA_ARGS__) #else -#define DEBUG_PRINTF(s, ...) +#define debug(s, ...) #endif @@ -34,8 +74,8 @@ static bool sht3x_send_command(uint32_t id, uint16_t cmd) { uint8_t data[2] = { cmd / 256, cmd % 256 }; - DEBUG_PRINTF("%s: Send MSB command byte %0x", __FUNCTION__, data[0]); - DEBUG_PRINTF("%s: Send LSB command byte %0x", __FUNCTION__, data[1]); + debug("%s: Send MSB command byte %0x", __FUNCTION__, data[0]); + debug("%s: Send LSB command byte %0x", __FUNCTION__, data[1]); int error = i2c_slave_write(sht3x_sensors[id].bus, sht3x_sensors[id].addr, 0, data, 2); @@ -77,10 +117,16 @@ static bool sht3x_is_available (uint32_t sensor) uint8_t data[3]; if (!sht3x_send_command(sensor, SHT3x_STATUS_CMD)) + { + debug("Called from %s", __FUNCTION__); return false; + } if (!sht3x_read_data(sensor, data, 3)) + { + debug("Called from %s", __FUNCTION__); return false; + } return true; } @@ -90,13 +136,13 @@ static bool sht3x_valid_sensor (uint32_t sensor, const char* function) { if (sensor < 0 || sensor > SHT3x_MAX_SENSORS) { - DEBUG_PRINTF("%s: Wrong sensor id %d.", function, sensor); + debug("%s: Wrong sensor id %d.", function, sensor); return false; } if (!sht3x_sensors[sensor].active) { - DEBUG_PRINTF("%s: Sensor with id %d is not active.", function, sensor); + debug("%s: Sensor with id %d is not active.", function, sensor); return false; } @@ -114,9 +160,9 @@ static void sht3x_compute_values (uint8_t id, uint8_t* data) act.temperature_f = ((((data[0] * 256.0) + data[1]) * 347) / 65535.0) - 49; act.humidity = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0); - if (sht3x_sensors[id].first_measurement) + if (sht3x_sensors[id].average_first_measurement || !sht3x_sensors[id].average_computation) { - sht3x_sensors[id].first_measurement = false; + sht3x_sensors[id].average_first_measurement = false; avg = act; } @@ -139,7 +185,7 @@ static void sht3x_callback_task (void *pvParameters) while (1) { - // DEBUG_PRINTF("%.3f Sensor %d: %s", (double)sdk_system_get_time()*1e-3, sensor, __FUNCTION__); + // debug("%.3f Sensor %d: %s", (double)sdk_system_get_time()*1e-3, sensor, __FUNCTION__); if (sht3x_send_command(sensor, SHT3x_MEASURE_ONE_SHOT_CMD)) { @@ -149,7 +195,7 @@ static void sht3x_callback_task (void *pvParameters) { sht3x_compute_values(sensor, data); - // DEBUG_PRINTF("%.2f C, %.2f F, %.2f", + // debug("%.2f C, %.2f F, %.2f", // sht3x_sensors[sensor].actual.temperature_c, // sht3x_sensors[sensor].actual.temperature_f, // sht3x_sensors[sensor].actual.humidity); @@ -160,10 +206,17 @@ static void sht3x_callback_task (void *pvParameters) sht3x_sensors[sensor].average); } + else + debug("Called from %s", __FUNCTION__); + vTaskDelay((sht3x_sensors[sensor].period-20) / portTICK_PERIOD_MS); } else + { + debug("Called from %s", __FUNCTION__); + vTaskDelay(sht3x_sensors[sensor].period / portTICK_PERIOD_MS); + } } } @@ -185,15 +238,15 @@ uint32_t sht3x_create_sensor(uint8_t bus, uint8_t addr) // search for first free sensor data structure for (id=0; id < SHT3x_MAX_SENSORS; id++) { - DEBUG_PRINTF("%s: id=%d active=%d", __FUNCTION__, id, sht3x_sensors[id].active); + debug("%s: id=%d active=%d", __FUNCTION__, id, sht3x_sensors[id].active); if (!sht3x_sensors[id].active) break; } - DEBUG_PRINTF("%s: id=%d", __FUNCTION__, id); + debug("%s: id=%d", __FUNCTION__, id); if (id == SHT3x_MAX_SENSORS) { - DEBUG_PRINTF("%s: No more sensor data structures available.", __FUNCTION__); + debug("%s: No more sensor data structures available.", __FUNCTION__); return -1; } @@ -201,7 +254,8 @@ uint32_t sht3x_create_sensor(uint8_t bus, uint8_t addr) sht3x_sensors[id].bus = bus; sht3x_sensors[id].addr = addr; sht3x_sensors[id].period = 1000; - sht3x_sensors[id].first_measurement = true; + sht3x_sensors[id].average_computation = true; + sht3x_sensors[id].average_first_measurement = true; sht3x_sensors[id].average_weight = 0.2; sht3x_sensors[id].cb_function = NULL; sht3x_sensors[id].cb_task = NULL; @@ -212,7 +266,10 @@ uint32_t sht3x_create_sensor(uint8_t bus, uint8_t addr) // clear sensor status register if (!sht3x_send_command(id, SHT3x_CLEAR_STATUS_CMD)) + { + debug("Called from %s", __FUNCTION__); return -1; + } snprintf (cb_task_name, 20, "sht3x_cb_task_%d", id); @@ -236,14 +293,10 @@ bool sht3x_delete_sensor(uint32_t sensor) if (!sht3x_valid_sensor(sensor, __FUNCTION__)) return false; + sht3x_sensors[sensor].active = false; + if (sht3x_sensors[sensor].cb_task) vTaskDelete(sht3x_sensors[sensor].cb_task); - - if (memset(&sht3x_sensors[sensor], 1, sizeof(sht3x_sensor_t)) == NULL) - { - DEBUG_PRINTF("%s: Could not initialize memory for sensor with id %d.", __FUNCTION__, sensor); - return false; - } return true; } @@ -255,7 +308,7 @@ bool sht3x_set_measurement_period (uint32_t sensor, uint32_t period) return false; if (period < 20) - DEBUG_PRINTF("%s: Period of %d ms is less than the minimum period of 20 ms for sensor with id %d.", __FUNCTION__, period, sensor); + debug("%s: Period of %d ms is less than the minimum period of 20 ms for sensor with id %d.", __FUNCTION__, period, sensor); sht3x_sensors[sensor].period = period; @@ -270,7 +323,7 @@ bool sht3x_set_callback_function (uint32_t sensor, sht3x_cb_function_t user_func sht3x_sensors[sensor].cb_function = user_function; - DEBUG_PRINTF("%s: Set callback mode done.", __FUNCTION__); + debug("%s: Set callback mode done.", __FUNCTION__); return false; } @@ -287,9 +340,19 @@ bool sht3x_get_values(uint32_t sensor, sht3x_value_set_t *actual, sht3x_value_se return true; } + +bool sht3x_enable_average_computation (uint32_t sensor, bool enabled) +{ + sht3x_sensors[sensor].average_computation = enabled; + sht3x_sensors[sensor].average_first_measurement = enabled; + + return true; +} + + bool sht3x_set_average_weight (uint32_t sensor, float weight) { - sht3x_sensors[sensor].first_measurement = true; + sht3x_sensors[sensor].average_first_measurement = true; sht3x_sensors[sensor].average_weight = weight; return true; diff --git a/extras/sht3x/sht3x.h b/extras/sht3x/sht3x.h index 0cd04c1..06f44e1 100644 --- a/extras/sht3x/sht3x.h +++ b/extras/sht3x/sht3x.h @@ -1,12 +1,43 @@ +/* + * The BSD License (3-clause license) + * + * Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /* * Driver for Sensirion SHT3x digital temperature and humity sensor * connected to I2C * * Part of esp-open-rtos - * Copyright (C) 2017 Gunar Schorcht (https://github.com/gschorcht) - * BSD Licensed as described in the file LICENSE */ - + #ifndef DRIVER_SHT3x_H_ #define DRIVER_SHT3x_H_ @@ -28,21 +59,28 @@ extern "C" { #endif +/** + * @brief actual or average value set type + */ typedef struct { float temperature_c; // temperature in degree Fahrenheit float temperature_f; // temperature in degree Celcius float humidity; // humidity in percent } sht3x_value_set_t; +/** + * @brief callback unction type to pass result of measurement to user tasks + */ typedef void (*sht3x_cb_function_t)(uint32_t sensor, sht3x_value_set_t actual, sht3x_value_set_t average); -// SHT3x sensor data structure +/** + * @brief SHT3x sensor device data structure type + */ typedef struct { bool active; - bool first_measurement; uint8_t bus; uint8_t addr; @@ -52,6 +90,8 @@ typedef struct { sht3x_value_set_t actual; sht3x_value_set_t average; + bool average_computation; + bool average_first_measurement; float average_weight; sht3x_cb_function_t cb_function; @@ -61,8 +101,10 @@ typedef struct { /** - * Initialize the SHT3x driver. This function must be called only once at the - * beginning. + * @brief Initialize the SHT3x driver + * + * This function initializes all internal data structures. It must be called + * exactly once at the beginning. * * @return true on success, false on error */ @@ -70,39 +112,50 @@ bool sht3x_init (); /** - * Initialize the SHT3x sensor connected to a certain bus with slave - * address, check its availability and start a background task for - * measurements. + * @brief Initialize a SHT3x sensor * - * The background task carries out measurements periodically using SHT3x's - * single shot data acquisition mode with a default period of 1000 ms. - * This period be changed using function @set_measurment_period. - * - * At each measurement, actual sensor values are determined and exponential - * moving average values are computed. The weight (smoothing factor) for this - * average computation is 0.2 by default. It can be changed using function - * @sht3x_set_average_weight. + * This function initializes the SHT3x sensor connected to a certain + * bus with given slave address and checks its availability. * - * If a callback method is registered using function - * @sht3x_set_callback_function, it is called after each measurement to pass - * measurement results to user tasks. Otherwise, user tasks have to use - * function @sht3x_get_values explicitly to get the results. + * Furthermore, it starts a background task for measurements with + * the sensor. The background task carries out the measurements periodically + * using SHT3x's single shot data acquisition mode with a default period + * of 1000 ms. This period be changed using function *set_measurment_period*. + * + * During each measurement the background task + * + * 1. determines *actual sensor values* + * 2. computes optionally *average sensor values* + * 3. calls back optionally a registered function of user task. + * + * The average value computation uses an exponential moving average + * and can be activated (default) or deactivated with function + * *sht3x_enable_average_computation*. If the average value computation is + * deactivated, *average sensor values* correspond to *actual sensor values*. + * The weight (smoothing factor) used in the average value computatoin is 0.2 + * by default and can be changed with function *sht3x_set_average_weight*. + * + * If a callback method has been registered with function + * *sht3x_set_callback_function*, it is called after each measurement + * to pass measurement results to user tasks. Otherwise, user tasks have to + * use function *sht3x_get_values* explicitly to get the results. * * @param bus I2C bus at which SHT3x sensor is connected * @param addr I2C addr of the SHT3x sensor * - * @return id of the sensor (0 or greater on success or -1 on error) + * @return ID of the sensor (0 or greater on success or -1 on error) */ uint32_t sht3x_create_sensor (uint8_t bus, uint8_t addr); /** - * Set the period of the background measurement task for a certain sensor. + * @brief Set the period of the background measurement task for the given + * sensor * - * Please note the minimum period is 20 ms since the measurement takes + * Please note: The minimum period is 20 ms since each measurement takes * about 20 ms. * - * @param sensor id of the sensor + * @param sensor ID of the sensor * @param period Measurement period in ms (default 1000 ms) * * @return true on success, false on error @@ -111,14 +164,14 @@ bool sht3x_set_measurement_period (uint32_t sensor, uint32_t period); /** - * Set the callback function for the background measurement task for a certain - * sensor. + * @brief Set the callback function for the background measurement task for + * the given sensor * * If a callback method is registered, it is called after each measurement to * pass measurement results to user tasks. Thus, callback function is executed - * at the same rate as measurements. + * at the same rate as the measurements. * - * @param sensor id of the sensor + * @param sensor ID of the sensor * @param function user function called after each measurement * (NULL to delete it for the sensor) * @@ -129,9 +182,9 @@ bool sht3x_set_callback_function (uint32_t sensor, /** - * Deletes the SHT3x sensor given by its id. + * @brief Deletes the SHT3x sensor given by its ID * - * @param sensor id of the sensor + * @param sensor ID of the sensor * * @return true on success, false on error */ @@ -139,17 +192,23 @@ bool sht3x_delete_sensor (uint32_t sensor); /** - * Returns actual and average sensor values of last measurement. Parameters - * @actual and @average are pointer to data structures of type - * @sht3x_value_set_t which are filled with measurement results. Use NULL for - * that pointers parameters, if you are not interested on certain results. + * @brief Get actual and average sensor values * - * This function is only needed, if there is no callback function registered - * for the sensor. + * This function returns the actual and average sensor values of the last + * measurement. The parameters *actual* and *average* are pointers to data + * structures of the type *sht3x_value_set_t*, which are filled with the + * of last measurement. Use NULL for the appropriate parameter if you are + * not interested in specific results. * - * @param sensor id of the sensor - * @param actual pointer to a data structure for actual sensor values - * @param average pointer to a data structure for average sensor values + * If average value computation is deactivated, average sensor values + * correspond to the actual sensor values. + * + * Please note: Calling this function is only necessary if no callback + * function has been registered for the sensor. + * + * @param sensor ID of the sensor + * @param actual Pointer to a data structure for actual sensor values + * @param average Pointer to a data structure for average sensor values * * @return true on success, false on error */ @@ -157,16 +216,34 @@ bool sht3x_get_values (uint32_t sensor, sht3x_value_set_t *actual, sht3x_value_set_t *average); + /** - * At each measurement carried out by the background task, actual - * sensor values are determined and exponential moving average values are - * computed according to following equation + * @brief Enable (default) or disable average value computation + * + * In case, the average value computation is disabled, average sensor values + * correspond to the actual sensor values. + * + * @param sensor id of the sensor + * @param enabled true to enable or false to disable average computation + * + * @return true on success, false on error +*/ +bool sht3x_enable_average_computation (uint32_t sensor, bool enabled); + + +/** + * @brief Set weight (smoothing factor) for average value computation + * + * At each measurement carried out by the background task, actual sensor + * values are determined. If average value computation is enabled (default), + * exponential moving average values are computed according to following + * equation * * Average[k] = W * Value + (1-W) * Average [k-1] * - * where coefficient W represents the degree of weighting decrease, a - * constant smoothing factor between 0 and 1. A higher W discounts older - * observations faster. + * where coefficient W represents the degree of weighting decrease, a constant + * smoothing factor between 0 and 1. A higher W discounts older observations + * faster. W is 0.2 by default. * * @param sensor id of the sensor * @param weight coefficient W (default is 0.2)