fix variables
This commit is contained in:
parent
73f603db41
commit
18ece975ba
@ -41,12 +41,5 @@ menu "Pump Controller Configuration"
|
|||||||
default 4
|
default 4
|
||||||
range 4 33
|
range 4 33
|
||||||
help
|
help
|
||||||
Digital pin for pump control (use 4,5,18,19,21,22,23,25,26,27,32,33).
|
Digital pin for pump control.
|
||||||
|
|
||||||
config SENSOR_PIN
|
|
||||||
int "Pressure sensor analog pin"
|
|
||||||
default 34
|
|
||||||
range 34 39
|
|
||||||
help
|
|
||||||
Analog pin for pressure sensor.
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|||||||
31
main/main.c
31
main/main.c
@ -32,6 +32,8 @@
|
|||||||
#define ADC_CHAN1 ADC_CHANNEL_5
|
#define ADC_CHAN1 ADC_CHANNEL_5
|
||||||
#define ADC_ATTEN_DB ADC_ATTEN_DB_12
|
#define ADC_ATTEN_DB ADC_ATTEN_DB_12
|
||||||
|
|
||||||
|
#define SENSOR_ADC_CHAN 0
|
||||||
|
|
||||||
static adc_oneshot_unit_handle_t adc_handle;
|
static adc_oneshot_unit_handle_t adc_handle;
|
||||||
static adc_cali_handle_t cali_handle;
|
static adc_cali_handle_t cali_handle;
|
||||||
static bool is_calibrated = false;
|
static bool is_calibrated = false;
|
||||||
@ -268,7 +270,7 @@ static esp_err_t root_get_handler(httpd_req_t *req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static esp_err_t current_pressure_handler(httpd_req_t *req) {
|
static esp_err_t current_pressure_handler(httpd_req_t *req) {
|
||||||
int sensor_value = g_current_pressure;
|
int sensor_value = atomic_load(&g_current_pressure);
|
||||||
char response[100];
|
char response[100];
|
||||||
snprintf(response, sizeof(response),
|
snprintf(response, sizeof(response),
|
||||||
"{\"value\":%d}",
|
"{\"value\":%d}",
|
||||||
@ -449,8 +451,8 @@ static esp_err_t set_thresholds_handler(httpd_req_t *req) {
|
|||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_threshold_low = low_value;
|
atomic_store(&g_threshold_low, low_value);
|
||||||
g_threshold_up = up_value;
|
atomic_store(&g_threshold_up, up_value);
|
||||||
|
|
||||||
// Формирование успешного ответа
|
// Формирование успешного ответа
|
||||||
snprintf(response, sizeof(response), "{\"success\":true,\"low\":%d,\"up\":%d}", low_value, up_value);
|
snprintf(response, sizeof(response), "{\"success\":true,\"low\":%d,\"up\":%d}", low_value, up_value);
|
||||||
@ -522,24 +524,23 @@ static void enablePump(void) {
|
|||||||
|
|
||||||
static void vPumpControllTask(void *pvParameters) {
|
static void vPumpControllTask(void *pvParameters) {
|
||||||
while (1) {
|
while (1) {
|
||||||
int current_pressure = g_current_pressure;
|
int current_pressure = atomic_load(&g_current_pressure);
|
||||||
int low_treshhold = g_threshold_low;
|
int low_treshhold = atomic_load(&g_threshold_low);
|
||||||
int up_treshhold = g_threshold_up;
|
int up_treshhold = atomic_load(&g_threshold_up);
|
||||||
|
|
||||||
if (current_pressure < low_treshhold) {
|
if (current_pressure < low_treshhold) {
|
||||||
enablePump();
|
enablePump();
|
||||||
} else if (current_pressure >= up_treshhold) {
|
} else if (current_pressure >= up_treshhold) {
|
||||||
disablePump();
|
disablePump();
|
||||||
}
|
}
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vReadSensorTask(void *pvParameters) {
|
static void vReadSensorTask(void *pvParameters) {
|
||||||
while (1) {
|
while (1) {
|
||||||
g_current_pressure = adc_read_voltage(0);
|
int pressure = adc_read_voltage(SENSOR_ADC_CHAN);
|
||||||
|
atomic_store(&g_current_pressure, pressure);
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -612,18 +613,18 @@ void app_main(void) {
|
|||||||
ESP_LOGE("TAG", "Error opening NVS");
|
ESP_LOGE("TAG", "Error opening NVS");
|
||||||
}
|
}
|
||||||
|
|
||||||
err = nvs_get_i32(my_handle, "treshhold_low", &g_threshold_low);
|
err = nvs_get_i32(my_handle, "treshhold_low", atomic_load(&g_threshold_low));
|
||||||
if (err == ESP_ERR_NVS_NOT_FOUND) {
|
if (err == ESP_ERR_NVS_NOT_FOUND) {
|
||||||
g_threshold_low = 0;
|
atomic_store(&g_threshold_low, 100);
|
||||||
} else {
|
} else {
|
||||||
ESP_ERROR_CHECK(err); // Обработка других ошибок
|
ESP_ERROR_CHECK(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = nvs_get_i32(my_handle, "treshhold_low", &g_threshold_up);
|
err = nvs_get_i32(my_handle, "treshhold_low", atomic_load(&g_threshold_up));
|
||||||
if (err == ESP_ERR_NVS_NOT_FOUND) {
|
if (err == ESP_ERR_NVS_NOT_FOUND) {
|
||||||
g_threshold_up = 1;
|
atomic_store(&g_threshold_up, 300);
|
||||||
} else {
|
} else {
|
||||||
ESP_ERROR_CHECK(err); // Обработка других ошибок
|
ESP_ERROR_CHECK(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user