diff --git a/.gitignore b/.gitignore index ce66cbf..898cee8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ build/ +.cache/ sdkconfig sdkconfig.old +compile_commands.json diff --git a/components/dht22/Kconfig.projbuild b/components/dht22/Kconfig.projbuild index cb50db1..6e4674a 100644 --- a/components/dht22/Kconfig.projbuild +++ b/components/dht22/Kconfig.projbuild @@ -1,6 +1,15 @@ menu "DHT22" + config DHT22_ENABLED + bool "DHT22 Enabled" + default y + config DHT22_DATA_GPIO int "DHT22 Data GPIO Pin" default -1 + depends on DHT22_ENABLED + config DHT22_PERIOD_POLL + int "Period to poll the DHT22 in ms" + default 2000 + depends on DHT22_ENABLED endmenu \ No newline at end of file diff --git a/components/pms5003/CMakeLists.txt b/components/pms5003/CMakeLists.txt new file mode 100644 index 0000000..b550c2e --- /dev/null +++ b/components/pms5003/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "pms5003.c" + INCLUDE_DIRS "." + REQUIRES driver) diff --git a/components/pms5003/Kconfig.projbuild b/components/pms5003/Kconfig.projbuild new file mode 100644 index 0000000..4b7ce04 --- /dev/null +++ b/components/pms5003/Kconfig.projbuild @@ -0,0 +1,15 @@ +menu "PMS5003" + config PMS5003_ENABLED + bool "PMS5003 Enabled" + default y + + config PMS5003_UART + int "PMS5003 UART Port" + default 1 + depends on PMS5003_ENABLED + + config PMS5003_PERIOD_POLL + int "Period to poll the PMS5003 in ms" + default 8000 + depends on PMS5003_ENABLED +endmenu \ No newline at end of file diff --git a/components/pms5003/pms5003.c b/components/pms5003/pms5003.c new file mode 100644 index 0000000..e69de29 diff --git a/components/pms5003/pms5003.h b/components/pms5003/pms5003.h new file mode 100644 index 0000000..e69de29 diff --git a/main/main.c b/main/main.c index b40c9df..bc44e37 100644 --- a/main/main.c +++ b/main/main.c @@ -20,36 +20,41 @@ static const char* TAG = "YASPAM"; static volatile bool run_dht = true; static volatile bool run_pms5003 = true; +static TaskHandle_t dht22_handle; +static TaskHandle_t pms5003_handle; + +#ifdef CONFIG_PMS5003_ENABLED +#include "pms5003.h" + void read_from_pms5003() { - TickType_t xLastWakeTime; - xLastWakeTime = xTaskGetTickCount(); while (run_pms5003) { - // TODO - actually collect some data + // TODO: actually collect some data ESP_LOGI(TAG, "Got PMS5003 data!"); - vTaskDelayUntil(&xLastWakeTime, - pdMS_TO_TICKS(1000)); // TODO: make this a config check + // TODO: Write the data out somewhere + vTaskDelay(pdMS_TO_TICKS(CONFIG_PMS5003_PERIOD_POLL)); } } +#endif /* CONFIG_PMS5003_ENABLED */ + +#ifdef CONFIG_DHT22_ENABLED +#include "dht22.h" void read_from_dht22() { - TickType_t xLastWakeTime; - xLastWakeTime = xTaskGetTickCount(); - while (run_dht) { // Data reading is based on time, so need to block interrups etc portDISABLE_INTERRUPTS(); int ret = dht22_read(); portENABLE_INTERRUPTS(); ESP_LOGI(TAG, "Got DHT22 data!"); - //vTaskDelayUntil(&xLastWakeTime, - // pdMS_TO_TICKS(500)); // TODO: make this a config check - vTaskDelay(pdMS_TO_TICKS(500)); + // TODO: Write the data out somewhere - into RAM maybe? + vTaskDelay(pdMS_TO_TICKS(CONFIG_DHT22_PERIOD_POLL)); } } +#endif /* CONFIG DHT22_ENABLED */ void app_main(void) @@ -62,17 +67,24 @@ app_main(void) } ESP_ERROR_CHECK(ret); +#ifdef CONFIG_DHT22_ENABLED xTaskCreate(read_from_dht22, "DHT22", 4 * 1024, // honestly I have _no_ idea NULL, 5, // no idea either - NULL); // will probably change this so that I can cancel the delay + &dht22_handle); + +#endif /* CONFIG_DHT22_ENABLED */ +#ifdef CONFIG_PMS5003_ENABLED + xTaskCreate(read_from_pms5003, "PMS5003", 4 * 1024, // honestly I have _no_ idea NULL, 5, // no idea either - NULL); // will probably change this so that I can cancel the delay + &pms5003_handle); + +#endif /* CONFIG_PMS5003_ENABLED */ }