SHT3x driver - small changes
This commit is contained in:
parent
3fee4b8f0c
commit
6d0545837c
1 changed files with 16 additions and 19 deletions
|
|
@ -16,6 +16,8 @@
|
|||
* | GPIO 4 (SDA) ------- SDA |
|
||||
* +------------------------+ +----------+
|
||||
*/
|
||||
|
||||
// #define SINGLE_SHOT_MODE
|
||||
|
||||
#include "espressif/esp_common.h"
|
||||
#include "esp/uart.h"
|
||||
|
|
@ -33,13 +35,11 @@
|
|||
|
||||
static sht3x_sensor_t* sensor; // sensor device data structure
|
||||
|
||||
// #define SINGLE_SHOT_MODE
|
||||
|
||||
#ifdef SINGLE_SHOT_MODE
|
||||
/*
|
||||
* User task that triggers measurements of sensor every 5 seconds. Due to
|
||||
* power efficiency reasons, it uses the SHT3x *single_shot* and *vTaskDelay*
|
||||
* to wait for measurement results.
|
||||
* User task that triggers a measurement every 5 seconds. Due to
|
||||
* power efficiency reasons, it uses the SHT3x *single_shot* and
|
||||
* *vTaskDelay* to wait for measurement results.
|
||||
*/
|
||||
void user_task (void *pvParameters)
|
||||
{
|
||||
|
|
@ -78,23 +78,23 @@ void user_task (void *pvParameters)
|
|||
{
|
||||
sht3x_values_t values;
|
||||
|
||||
// start periodic measurement mode
|
||||
// start periodic measurements with 1 measurement per second
|
||||
sht3x_start_measurement (sensor, periodic_1mps);
|
||||
|
||||
// busy waiting until measurement results are available
|
||||
// busy waiting until first measurement results are available
|
||||
while (sht3x_is_measuring (sensor) > 0) ;
|
||||
|
||||
TickType_t last_wakeup = xTaskGetTickCount();
|
||||
|
||||
while (1)
|
||||
{
|
||||
// retrieve the values and do something with them
|
||||
// get the values and do something with them
|
||||
if (sht3x_get_results (sensor, &values))
|
||||
printf("%.3f SHT3x Sensor: %.2f °C, %.2f %%\n",
|
||||
(double)sdk_system_get_time()*1e-3,
|
||||
values.temperature, values.humidity);
|
||||
|
||||
// passive waiting until 2 seconds are over
|
||||
|
||||
// passive waiting until 2 seconds (cycle time) are over
|
||||
vTaskDelayUntil(&last_wakeup, 2000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
|
@ -102,10 +102,6 @@ void user_task (void *pvParameters)
|
|||
|
||||
void user_init(void)
|
||||
{
|
||||
// Please note: Return values are not considered in this example for
|
||||
// readability reasons. All functions return boolean and set an error
|
||||
// code that allows effective error handling.
|
||||
|
||||
// Set UART Parameter
|
||||
uart_set_baud(0, 115200);
|
||||
|
||||
|
|
@ -117,10 +113,11 @@ void user_init(void)
|
|||
i2c_init(I2C_BUS, I2C_SCL_PIN, I2C_SDA_PIN, I2C_FREQ_100K);
|
||||
|
||||
// Create sensors
|
||||
sensor = sht3x_init_sensor (I2C_BUS, SHT3x_ADDR_2);
|
||||
|
||||
// Create a user task that uses the sensor
|
||||
xTaskCreate(user_task, "user_task", 256, NULL, 2, 0);
|
||||
|
||||
if ((sensor = sht3x_init_sensor (I2C_BUS, SHT3x_ADDR_2)))
|
||||
{
|
||||
// Create a user task that uses the sensor
|
||||
xTaskCreate(user_task, "user_task", 256, NULL, 2, 0);
|
||||
}
|
||||
|
||||
// That's it.
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue