Small changes and corrections

This commit is contained in:
Gunar Schorcht 2017-09-15 11:11:14 +02:00 committed by GitHub
parent 9f60c98324
commit b225a01752
2 changed files with 20 additions and 18 deletions

View file

@ -3,7 +3,6 @@
#include "sht3x.h" #include "sht3x.h"
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "queue.h"
#include "task.h" #include "task.h"
#include "espressif/esp_common.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; sht3x_value_set_t avg = sht3x_sensors[id].average;
float w = sht3x_sensors[id].average_weight; float w = sht3x_sensors[id].average_weight;
act.c_temperature = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45; act.temperature_c = ((((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_f = ((((data[0] * 256.0) + data[1]) * 347) / 65535.0) - 49;
act.humidity = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0); act.humidity = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0);
if (sht3x_sensors[id].first_measurement) if (sht3x_sensors[id].first_measurement)
@ -133,8 +132,8 @@ static void sht3x_compute_values (uint8_t id, uint8_t* data)
} }
else else
{ {
avg.c_temperature = w * act.c_temperature + (1-w) * avg.c_temperature; avg.temperature_c = w * act.temperature_c + (1-w) * avg.temperature_c;
avg.f_temperature = w * act.f_temperature + (1-w) * avg.f_temperature; avg.temperature_f = w * act.temperature_f + (1-w) * avg.temperature_f;
avg.humidity = w * act.humidity + (1-w) * avg.humidity; 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); sht3x_compute_values(sensor, data);
// DEBUG_PRINTF3("%.2f C, %.2f F, %.2f \n", // DEBUG_PRINTF3("%.2f C, %.2f F, %.2f \n",
// sht3x_sensors[sensor].actual.c_temperature, // sht3x_sensors[sensor].actual.temperature_c,
// sht3x_sensors[sensor].actual.f_temperature, // sht3x_sensors[sensor].actual.temperature_f,
// sht3x_sensors[sensor].actual.humidity); // sht3x_sensors[sensor].actual.humidity);
if (sht3x_sensors[sensor].cb_function) 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__)) if (!sht3x_valid_sensor(sensor, __FUNCTION__))
return false; return false;
*actual = sht3x_sensors[sensor].actual; if (actual) *actual = sht3x_sensors[sensor].actual;
*average = sht3x_sensors[sensor].average; if (average) *average = sht3x_sensors[sensor].average;
return true; return true;
} }

View file

@ -19,7 +19,7 @@
#include "i2c/i2c.h" #include "i2c/i2c.h"
// Uncomment to enable debug output // Uncomment to enable debug output
#define SHT3x_DEBUG // #define SHT3x_DEBUG
// Change this if you need more than 3 SHT3x sensors // Change this if you need more than 3 SHT3x sensors
#define SHT3x_MAX_SENSORS 3 #define SHT3x_MAX_SENSORS 3
@ -29,9 +29,9 @@ extern "C" {
#endif #endif
typedef struct { typedef struct {
float c_temperature; float temperature_c; // temperature in degree Fahrenheit
float f_temperature; float temperature_f; // temperature in degree Celcius
float humidity; float humidity; // humidity in percent
} sht3x_value_set_t; } sht3x_value_set_t;
typedef void (*sht3x_cb_function_t)(uint32_t sensor, 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 * Initialize the SHT3x sensor connected to a certain bus with slave
* address, check its availability and start a background task for * address, check its availability and start a background task for
* measurments. * measurements.
* *
* The background task carries out measurements periodically using SHT3x's * 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. * This period be changed using function @set_measurment_period.
* *
* At each measurement, actual sensor values are determined and exponential * 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 * This function is only needed, if there is no callback function registered
* for the sensor. * for the sensor.
@ -156,8 +159,8 @@ bool sht3x_get_values (uint32_t sensor,
/** /**
* At each measurement carried out by the background task, actual * At each measurement carried out by the background task, actual
* sensor values are determined and exponential moving avarage values are * sensor values are determined and exponential moving average values are
* computed accoroding to following equation * computed according to following equation
* *
* Average[k] = W * Value + (1-W) * Average [k-1] * Average[k] = W * Value + (1-W) * Average [k-1]
* *