main/task_ds18b20.c

Tue, 08 Oct 2019 15:47:34 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 08 Oct 2019 15:47:34 +0200
changeset 2
c0184362d48c
parent 0
88d965579617
child 3
cd760fd45271
permissions
-rw-r--r--

Prepare ds18b20 sensors for multiple sensors on the onewire bus.

0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file task_ds18b20.c
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief The FreeRTOS task to query the DS18B20 sensors on one or two
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * one-wire busses. Each bus must have only one sensor. That way
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * we don't need to care about the DS18B20 internal ROM address.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * The task will update the DS18B20_State structure.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 #include "owb.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 #include "owb_rmt.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 #include "ds18b20.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 #include "config.h"
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 #define GPIO_DS18B20_BUS (CONFIG_ONE_WIRE_BUS)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #define MAX_DEVICES (8)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #define DS18B20_RESOLUTION (DS18B20_RESOLUTION_12_BIT)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #define SAMPLE_PERIOD (2000) // milliseconds
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 static const char *TAG = "task_ds18b20";
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 static const char *dsErrors[] = { "Ok", "No sensor", "Too many sensors", "CRC error", "Read error" };
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 SemaphoreHandle_t xSemaphoreDS18B20 = NULL; ///< Semaphire DS18B20 task
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 EventGroupHandle_t xEventGroupDS18B20; ///< Events DS18B20 task
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 DS18B20_State *ds18b20_state; ///< Public state for other tasks
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 const int TASK_DS18B20_REQUEST_TEMPS = BIT0; ///< Request temperature measurements
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 const int TASK_DS18B20_REQUEST_DONE = BIT1; ///< Request is completed
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 void request_ds18b20(void)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 xEventGroupClearBits(xEventGroupDS18B20, TASK_DS18B20_REQUEST_DONE);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 xEventGroupSetBits(xEventGroupDS18B20, TASK_DS18B20_REQUEST_TEMPS);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 bool ready_ds18b20(void)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 if (xEventGroupGetBits(xEventGroupDS18B20) & TASK_DS18B20_REQUEST_DONE)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 return true;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 return false;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 * Task to read temperature sensors on request.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 void task_ds18b20(void *pvParameter)
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 int num_devices = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 float readings = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 bool found = false;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 DS18B20_ERROR errors = 0;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 ESP_LOGI(TAG, "Starting DS18B20 sensors");
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 ds18b20_state = malloc(sizeof(DS18B20_State));
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
64 ds18b20_state->valid = false;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
65 ds18b20_state->num_sensors = 0;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
66
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
67 for (int i = 0; i < DS18B20_MAX; i++) {
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
68 ds18b20_state->sensor[i].temperature = 0.0;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
69 ds18b20_state->sensor[i].rom_code[0] = '\0';
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
70 ds18b20_state->sensor[i].error = DS18B20_ERR_READ;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
71 }
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 /* event handler and event group for the wifi driver */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 xEventGroupDS18B20 = xEventGroupCreate();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 * Initialize the MLT and HLT one-wire busses.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 */
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
79 OneWireBus *owb;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 owb_rmt_driver_info rmt_driver_info_bottle;
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
81 owb = owb_rmt_initialize(&rmt_driver_info_bottle, GPIO_DS18B20_BUS, RMT_CHANNEL_1, RMT_CHANNEL_0);
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
82 owb_use_crc(owb, true); // enable CRC check for ROM code
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 DS18B20_Info * ds18b20_info = ds18b20_malloc();
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 EventBits_t uxBits;
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 * Task loop forever.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 while (1) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 uxBits = xEventGroupWaitBits(xEventGroupDS18B20, TASK_DS18B20_REQUEST_TEMPS, pdFALSE, pdFALSE, portMAX_DELAY );
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 if (uxBits & TASK_DS18B20_REQUEST_TEMPS) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 num_devices = 0;
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
96 OneWireBus_SearchState search_state = {0};
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 found = false;
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
98 owb_search_first(owb, &search_state, &found);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 while (found) {
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
100 char rom_code_s[17];
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
101 owb_string_from_rom_code(search_state.rom_code, rom_code_s, sizeof(rom_code_s));
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
102 rom_code_s[16] = '\0';
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
103 printf(" %d : %s %d\n", num_devices + 1, rom_code_s, strlen(rom_code_s));
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
104 sprintf(ds18b20_state->sensor[num_devices].rom_code, "%s", rom_code_s);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 ++num_devices;
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
106 owb_search_next(owb, &search_state, &found);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 if (num_devices == 1) {
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
110 ds18b20_init_solo(ds18b20_info, owb); // only one device on bus
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 ds18b20_use_crc(ds18b20_info, true); // enable CRC check for temperature readings
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 ds18b20_set_resolution(ds18b20_info, DS18B20_RESOLUTION); // returns true if ok.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 // Read temperatures more efficiently by starting conversions on all devices at the same time
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
115 ds18b20_convert_all(owb);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 ds18b20_wait_for_conversion(ds18b20_info);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 errors = ds18b20_read_temp(ds18b20_info, &readings);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 if (xSemaphoreTake(xSemaphoreDS18B20, 25) == pdTRUE) {
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
121 ds18b20_state->num_sensors = 1;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 if (errors == DS18B20_OK) {
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
123 ds18b20_state->sensor[0].error = DS18B20_ERR_NONE;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
124 ds18b20_state->valid = true;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
125 ds18b20_state->sensor[0].temperature = readings;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 } else {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 if (errors == DS18B20_ERROR_CRC)
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
128 ds18b20_state->sensor[0].error = DS18B20_ERR_CRC;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 if (errors == DS18B20_ERROR_OWB)
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
130 ds18b20_state->sensor[0].error = DS18B20_ERR_READ;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 if (errors == DS18B20_ERROR_DEVICE)
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
132 ds18b20_state->sensor[0].error = DS18B20_ERR_READ;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
133 ds18b20_state->valid = false;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
134 ds18b20_state->sensor[0].temperature = 0.0;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 xSemaphoreGive(xSemaphoreDS18B20);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 } else {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 /*
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 * Zero or more then one device, this is an error.
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 */
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 if (xSemaphoreTake(xSemaphoreDS18B20, 25) == pdTRUE) {
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 if (num_devices == 0)
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
145 ds18b20_state->sensor[0].error = DS18B20_ERR_READ;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 else
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
147 ds18b20_state->sensor[0].error = DS18B20_ERR_READ;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
148 ds18b20_state->valid = false;
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
149 ds18b20_state->num_sensors = 0;
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 xSemaphoreGive(xSemaphoreDS18B20);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 } // if num_devices == 1
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 xEventGroupClearBits(xEventGroupDS18B20, TASK_DS18B20_REQUEST_TEMPS);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 xEventGroupSetBits(xEventGroupDS18B20, TASK_DS18B20_REQUEST_DONE);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 #if 1
2
c0184362d48c Prepare ds18b20 sensors for multiple sensors on the onewire bus.
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
157 ESP_LOGI(TAG, "Temperature %.3f %s", ds18b20_state->sensor[0].temperature, dsErrors[ds18b20_state->sensor[0].error]);
0
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 #endif
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 vTaskDelay( (TickType_t)10);
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 }
88d965579617 Initial import of the CO2 meter application.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163

mercurial