diff --git a/extras/sht3x/sht3x.c b/extras/sht3x/sht3x.c index 0d8787e..f01bbdf 100644 --- a/extras/sht3x/sht3x.c +++ b/extras/sht3x/sht3x.c @@ -3,7 +3,6 @@ #include "sht3x.h" #include "FreeRTOS.h" -#include "queue.h" #include "task.h" #include "espressif/esp_common.h" @@ -121,8 +120,8 @@ static void sht3x_compute_values (uint8_t id, uint8_t* data) sht3x_value_set_t avg = sht3x_sensors[id].average; float w = sht3x_sensors[id].average_weight; - act.c_temperature = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45; - act.f_temperature = ((((data[0] * 256.0) + data[1]) * 347) / 65535.0) - 49; + act.temperature_c = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45; + 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) @@ -133,8 +132,8 @@ static void sht3x_compute_values (uint8_t id, uint8_t* data) } else { - avg.c_temperature = w * act.c_temperature + (1-w) * avg.c_temperature; - avg.f_temperature = w * act.f_temperature + (1-w) * avg.f_temperature; + avg.temperature_c = w * act.temperature_c + (1-w) * avg.temperature_c; + avg.temperature_f = w * act.temperature_f + (1-w) * avg.temperature_f; avg.humidity = w * act.humidity + (1-w) * avg.humidity; } @@ -161,8 +160,8 @@ static void sht3x_callback_task (void *pvParameters) sht3x_compute_values(sensor, data); // DEBUG_PRINTF3("%.2f C, %.2f F, %.2f \n", - // sht3x_sensors[sensor].actual.c_temperature, - // sht3x_sensors[sensor].actual.f_temperature, + // sht3x_sensors[sensor].actual.temperature_c, + // sht3x_sensors[sensor].actual.temperature_f, // sht3x_sensors[sensor].actual.humidity); if (sht3x_sensors[sensor].cb_function) @@ -292,8 +291,8 @@ bool sht3x_get_values(uint32_t sensor, sht3x_value_set_t *actual, sht3x_value_se if (!sht3x_valid_sensor(sensor, __FUNCTION__)) return false; - *actual = sht3x_sensors[sensor].actual; - *average = sht3x_sensors[sensor].average; + if (actual) *actual = sht3x_sensors[sensor].actual; + if (average) *average = sht3x_sensors[sensor].average; return true; } diff --git a/extras/sht3x/sht3x.h b/extras/sht3x/sht3x.h index fbfa7ea..0cd04c1 100644 --- a/extras/sht3x/sht3x.h +++ b/extras/sht3x/sht3x.h @@ -19,7 +19,7 @@ #include "i2c/i2c.h" // Uncomment to enable debug output -#define SHT3x_DEBUG +// #define SHT3x_DEBUG // Change this if you need more than 3 SHT3x sensors #define SHT3x_MAX_SENSORS 3 @@ -29,9 +29,9 @@ extern "C" { #endif typedef struct { - float c_temperature; - float f_temperature; - float humidity; + float temperature_c; // temperature in degree Fahrenheit + float temperature_f; // temperature in degree Celcius + float humidity; // humidity in percent } sht3x_value_set_t; typedef void (*sht3x_cb_function_t)(uint32_t sensor, @@ -72,10 +72,10 @@ bool sht3x_init (); /** * Initialize the SHT3x sensor connected to a certain bus with slave * address, check its availability and start a background task for - * measurments. + * measurements. * * The background task carries out measurements periodically using SHT3x's - * single shot data aquisition mode with a default period of 1000 ms. + * 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 @@ -139,7 +139,10 @@ bool sht3x_delete_sensor (uint32_t sensor); /** - * Returns actual and average sensor values of last measurement. + * 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. * * This function is only needed, if there is no callback function registered * for the sensor. @@ -156,8 +159,8 @@ bool sht3x_get_values (uint32_t sensor, /** * At each measurement carried out by the background task, actual - * sensor values are determined and exponential moving avarage values are - * computed accoroding to following equation + * sensor values are determined and exponential moving average values are + * computed according to following equation * * Average[k] = W * Value + (1-W) * Average [k-1] *