diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild new file mode 100644 index 0000000..2a28103 --- /dev/null +++ b/main/Kconfig.projbuild @@ -0,0 +1,14 @@ +menu "Project Configuration" + config WIFI_SSID + string "WiFi SSID" + default "myssid" + help + Network Name (SSID) of the WIFI to connect to. + + config WIFI_PASSWORD + string "WiFi PASSWORD" + default "hunter2" + help + Password of the WiFi network to connect to. + +endmenu \ No newline at end of file diff --git a/main/main.c b/main/main.c index 5630b2c..de8cb8c 100644 --- a/main/main.c +++ b/main/main.c @@ -4,40 +4,98 @@ * License: GPLv3+ */ +#include #include #include "freertos/FreeRTOS.h" +//#include "freertos/projdefs.h" #include "freertos/task.h" #include "dht22.h" #include "esp_log.h" #include "esp_wifi.h" +#include "portmacro.h" static const char *TAG = "YASPAM"; -struct air_monitor_data { +static EventGroupHandle_t s_monitor_event_group; + +static volatile bool run_dht = true; +static volatile bool run_pms5003 = true; + #ifdef CONFIG_DHT22_DATA_GPIO - deci_percent dht22_relative_humidity; - deci_degrees_c dht22_temperature; + #define SENSOR_DHT22_BIT (1 << 0) +#else + #define SENSOR_DHT22_BIT 0 #endif /* CONFIG_DHT22_DATA_GPIO */ -#ifdef CONFIG_PMS5003_DATA_GPIO - // TODO -#endif /* CONFIG_PMS5003_DATA_GPIO */ - int64_t time; // TODO think about how best to store this. -}; +#ifdef CONFIG_PMS5003_ENABLED + #define SENSOR_PMS5003_BIT (1 << 1) +#else + #define SENSOR_PMS5003_BIT 0 +#endif /* CONFIG_PMS5003_ENABLED */ -void app_main(void) -{ -#ifdef CONFIG_DHT22_DATA_GPIO - int ret = dht22_read(); -#endif /* CONFIG_DHT22_DATA_GPIO */ +#define SENSOR_ALL SENSOR_DHT22_BIT | SENSOR_PMS5003_BIT - - - for (int i = 10; i >= 0; i--) { - printf("Restarting in %d seconds...\n", i); - vTaskDelay(1000 / portTICK_PERIOD_MS); + +// TODO - figure out how to continually call this, maybe make a task for it? +void save_measurements() { + EventBits_t bits = xEventGroupWaitBits( + s_monitor_event_group, + SENSOR_ALL, + pdFALSE, + pdFALSE, + portMAX_DELAY); + if (bits & SENSOR_DHT22_BIT) { + + deci_percent rh = dht22_relative_humidity(); + deci_degrees_c temp = dht22_temperature(); + // TODO - think about how to actually store this somewhere (for pushing and/or pulling) + // and what sort of structures I could use } - printf("Restarting now.\n"); - fflush(stdout); + if (bits & SENSOR_PMS5003_BIT) { + // TODO + } +} + +void read_from_pms5003() { + while (run_pms5003) { + // Data reading is based on time spent high, so need to block interrups etc + portDISABLE_INTERRUPTS(); + //int ret = pms5003_read(); + portENABLE_INTERRUPTS(); + ESP_LOGI(TAG, "Got PMS5003 data! Setting PMS bit now!"); + xEventGroupSetBits(s_monitor_event_group, SENSOR_DHT22_BIT); + vTaskDelay(pdMS_TO_TICKS(1000)); // TODO: make this a config check + } +} + +void read_from_dht22() { + while (run_dht) { + // Data reading is based on time spent high, so need to block interrups etc + portDISABLE_INTERRUPTS(); + int ret = dht22_read(); + portENABLE_INTERRUPTS(); + ESP_LOGI(TAG, "Got DHT22 data! Setting DHT bit now!"); + xEventGroupSetBits(s_monitor_event_group, SENSOR_DHT22_BIT); + vTaskDelay(pdMS_TO_TICKS(2000)); // TODO: make this a config check + } +} + + +void app_main(void) { + xTaskCreate(read_from_dht22, + "READ DHT22", + 1024, // honestly I have _no_ idea + NULL, + 5, // no idea either + NULL); // will probably change this so that I can cancel the delay + + xTaskCreate(read_from_pms5003, + "READ PMS5003", + 1024, // honestly I have _no_ idea + NULL, + 5, // no idea either + NULL); // will probably change this so that I can cancel the delay + + esp_restart(); }