28 static TaskHandle_t xTaskDS18B20 = NULL; |
28 static TaskHandle_t xTaskDS18B20 = NULL; |
29 static TaskHandle_t xTaskADC = NULL; |
29 static TaskHandle_t xTaskADC = NULL; |
30 static TaskHandle_t xTaskWifi = NULL; |
30 static TaskHandle_t xTaskWifi = NULL; |
31 static TaskHandle_t xTaskMQTT = NULL; |
31 static TaskHandle_t xTaskMQTT = NULL; |
32 const esp_app_desc_t *app_desc = NULL; |
32 const esp_app_desc_t *app_desc = NULL; |
33 unit_t units[3]; ///< Pressure test units |
33 |
34 |
34 |
35 |
35 extern unit_t units[3]; ///< Pressure test units |
|
36 extern SemaphoreHandle_t xSemaphoreUnits; ///< Units lock semaphore |
36 extern DS18B20_State *ds18b20_state; ///< DS18B20 state |
37 extern DS18B20_State *ds18b20_state; ///< DS18B20 state |
37 extern SemaphoreHandle_t xSemaphoreDS18B20; ///< DS18B20 lock semaphore |
38 extern SemaphoreHandle_t xSemaphoreDS18B20; ///< DS18B20 lock semaphore |
38 extern ADC_State *adc_state; ///< ADC state |
39 extern ADC_State *adc_state; ///< ADC state |
39 extern SemaphoreHandle_t xSemaphoreADC; ///< ADC lock semaphore |
40 extern SemaphoreHandle_t xSemaphoreADC; ///< ADC lock semaphore |
40 |
41 |
201 //sprintf(config.lastSSID, "%s", "BREWER"); |
202 //sprintf(config.lastSSID, "%s", "BREWER"); |
202 //write_config(); |
203 //write_config(); |
203 |
204 |
204 xSemaphoreDS18B20 = xSemaphoreCreateMutex(); |
205 xSemaphoreDS18B20 = xSemaphoreCreateMutex(); |
205 xSemaphoreADC = xSemaphoreCreateMutex(); |
206 xSemaphoreADC = xSemaphoreCreateMutex(); |
|
207 xSemaphoreUnits = xSemaphoreCreateMutex(); |
206 |
208 |
207 xTaskCreate(&task_ds18b20, "task_ds18b20", 2560, NULL, 8, &xTaskDS18B20); |
209 xTaskCreate(&task_ds18b20, "task_ds18b20", 2560, NULL, 8, &xTaskDS18B20); |
208 xTaskCreate(&task_adc, "task_adc", 2560, NULL, 8, &xTaskADC); |
210 xTaskCreate(&task_adc, "task_adc", 2560, NULL, 8, &xTaskADC); |
209 esp_log_level_set("wifi", ESP_LOG_ERROR); |
211 esp_log_level_set("wifi", ESP_LOG_ERROR); |
210 xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); |
212 xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); |
289 strncpy(rom_code, ds18b20_state->sensor[0].rom_code, strlen(ds18b20_state->sensor[0].rom_code)); |
291 strncpy(rom_code, ds18b20_state->sensor[0].rom_code, strlen(ds18b20_state->sensor[0].rom_code)); |
290 xSemaphoreGive(xSemaphoreDS18B20); |
292 xSemaphoreGive(xSemaphoreDS18B20); |
291 } |
293 } |
292 |
294 |
293 /* Copy measured data and calculate results */ |
295 /* Copy measured data and calculate results */ |
294 for (int i = 0; i < 3; i++) { |
296 if (xSemaphoreTake(xSemaphoreUnits, 25) == pdTRUE) { |
295 units[i].temperature = temp; |
297 for (int i = 0; i < 3; i++) { |
296 units[i].temperature_state = state; |
298 units[i].temperature = temp; |
297 strncpy(units[i].temperature_rom_code, rom_code, strlen(rom_code)); |
299 units[i].temperature_state = state; |
298 if (xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE) { |
300 strncpy(units[i].temperature_rom_code, rom_code, 17); |
299 units[i].pressure_state = adc_state->Pressure[i].error; |
301 if (xSemaphoreTake(xSemaphoreADC, 10) == pdTRUE) { |
300 units[i].pressure_channel = adc_state->Pressure[i].channel; |
302 units[i].pressure_state = adc_state->Pressure[i].error; |
301 units[i].pressure_voltage = adc_state->Pressure[i].voltage; |
303 units[i].pressure_channel = adc_state->Pressure[i].channel; |
302 units[i].pressure_zero = 110; |
304 units[i].pressure_voltage = adc_state->Pressure[i].voltage; |
303 int P = (units[i].pressure_voltage / (adc_state->Batt_voltage / 1000) - units[i].pressure_zero) * 14; // in bar |
305 units[i].pressure_zero = 110; |
304 if (P < 0) |
306 int P = (units[i].pressure_voltage / (adc_state->Batt_voltage / 1000) - units[i].pressure_zero) * 14; // in bar |
305 P = 0; |
307 if (P < 0) |
306 units[i].pressure = P; |
308 P = 0; |
|
309 units[i].pressure = P; |
307 printf("%d volt: %d batt: %d scale: %d bar: %d\n", i, units[i].pressure_voltage, adc_state->Batt_voltage, |
310 printf("%d volt: %d batt: %d scale: %d bar: %d\n", i, units[i].pressure_voltage, adc_state->Batt_voltage, |
308 units[i].pressure_voltage / (adc_state->Batt_voltage / 1000) - units[i].pressure_zero, P); |
311 units[i].pressure_voltage / (adc_state->Batt_voltage / 1000) - units[i].pressure_zero, P); |
309 // Moet die echt op 5 volt? |
312 // Moet die echt op 5 volt? |
310 // Verbruik 10 mA |
313 // Verbruik 10 mA |
311 // Setup tijd max 2 mS |
314 // Setup tijd max 2 mS |
312 xSemaphoreGive(xSemaphoreADC); |
315 xSemaphoreGive(xSemaphoreADC); |
|
316 } |
313 } |
317 } |
|
318 write_units(); |
|
319 xSemaphoreGive(xSemaphoreUnits); |
314 } |
320 } |
315 write_units(); |
|
316 } |
321 } |
317 break; |
322 break; |
318 |
323 |
319 // calculate stap en data copy |
324 // calculate stap en data copy |
320 |
325 |