main/task_ds18b20.c

changeset 3
cd760fd45271
parent 2
c0184362d48c
child 5
4b1c65e4d863
equal deleted inserted replaced
2:c0184362d48c 3:cd760fd45271
12 #include "ds18b20.h" 12 #include "ds18b20.h"
13 #include "config.h" 13 #include "config.h"
14 14
15 15
16 #define GPIO_DS18B20_BUS (CONFIG_ONE_WIRE_BUS) 16 #define GPIO_DS18B20_BUS (CONFIG_ONE_WIRE_BUS)
17 #define MAX_DEVICES (8)
18 #define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT) 17 #define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT)
19 #define SAMPLE_PERIOD (2000) // milliseconds
20 18
21 19
22 static const char *TAG = "task_ds18b20"; 20 static const char *TAG = "task_ds18b20";
23 static const char *dsErrors[] = { "Ok", "No sensor", "Too many sensors", "CRC error", "Read error" }; 21 static const char *dsErrors[] = { "Ok", "CRC error", "Read error" };
24 22
25 SemaphoreHandle_t xSemaphoreDS18B20 = NULL; ///< Semaphire DS18B20 task 23 SemaphoreHandle_t xSemaphoreDS18B20 = NULL; ///< Semaphire DS18B20 task
26 EventGroupHandle_t xEventGroupDS18B20; ///< Events DS18B20 task 24 EventGroupHandle_t xEventGroupDS18B20; ///< Events DS18B20 task
27 DS18B20_State *ds18b20_state; ///< Public state for other tasks 25 DS18B20_State *ds18b20_state; ///< Public state for other tasks
28 26
124 ds18b20_state->valid = true; 122 ds18b20_state->valid = true;
125 ds18b20_state->sensor[0].temperature = readings; 123 ds18b20_state->sensor[0].temperature = readings;
126 } else { 124 } else {
127 if (errors == DS18B20_ERROR_CRC) 125 if (errors == DS18B20_ERROR_CRC)
128 ds18b20_state->sensor[0].error = DS18B20_ERR_CRC; 126 ds18b20_state->sensor[0].error = DS18B20_ERR_CRC;
129 if (errors == DS18B20_ERROR_OWB) 127 else
130 ds18b20_state->sensor[0].error = DS18B20_ERR_READ; 128 ds18b20_state->sensor[0].error = DS18B20_ERR_READ; // All other errors
131 if (errors == DS18B20_ERROR_DEVICE)
132 ds18b20_state->sensor[0].error = DS18B20_ERR_READ;
133 ds18b20_state->valid = false; 129 ds18b20_state->valid = false;
134 ds18b20_state->sensor[0].temperature = 0.0; 130 ds18b20_state->sensor[0].temperature = 0.0;
135 } 131 }
136 xSemaphoreGive(xSemaphoreDS18B20); 132 xSemaphoreGive(xSemaphoreDS18B20);
137 } 133 }

mercurial