I can't get this task stuff working

Going to try simplify it by not using group bits
This commit is contained in:
2023-10-25 20:19:33 +01:00
parent 6354e937fb
commit a8c18feb81

View File

@@ -43,6 +43,8 @@ static volatile bool run_data_collection = true;
// TODO - figure out how to continually call this, maybe make a task for it? // TODO - figure out how to continually call this, maybe make a task for it?
void save_measurements() { void save_measurements() {
TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount ();
while (run_data_collection) { while (run_data_collection) {
EventBits_t bits = xEventGroupWaitBits( EventBits_t bits = xEventGroupWaitBits(
s_monitor_event_group, s_monitor_event_group,
@@ -65,13 +67,15 @@ void save_measurements() {
// TODO // TODO
xEventGroupClearBitsFromISR(s_monitor_event_group, SENSOR_PMS5003_BIT); xEventGroupClearBitsFromISR(s_monitor_event_group, SENSOR_PMS5003_BIT);
} }
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(100));
} }
} }
void read_from_pms5003() { void read_from_pms5003() {
BaseType_t xHigherPriorityTaskWoken, xResult; BaseType_t xHigherPriorityTaskWoken, xResult;
xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = pdFALSE;
TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount ();
while (run_pms5003) { while (run_pms5003) {
// TODO - actually collect some data // TODO - actually collect some data
ESP_LOGI(TAG, "Got PMS5003 data! Setting PMS bit now!"); ESP_LOGI(TAG, "Got PMS5003 data! Setting PMS bit now!");
@@ -79,13 +83,15 @@ void read_from_pms5003() {
if (xResult) { if (xResult) {
portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
} }
vTaskDelay(pdMS_TO_TICKS(1000)); // TODO: make this a config check vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(1000)); // TODO: make this a config check
} }
} }
void read_from_dht22() { void read_from_dht22() {
BaseType_t xHigherPriorityTaskWoken, xResult; BaseType_t xHigherPriorityTaskWoken, xResult;
xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = pdFALSE;
TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount ();
while (run_dht) { while (run_dht) {
// Data reading is based on time, so need to block interrups etc // Data reading is based on time, so need to block interrups etc
portDISABLE_INTERRUPTS(); portDISABLE_INTERRUPTS();
@@ -97,7 +103,8 @@ void read_from_dht22() {
portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
} }
ESP_LOGI(TAG, "Hello"); ESP_LOGI(TAG, "Hello");
vTaskDelay(pdMS_TO_TICKS(500)); // TODO: make this a config check vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(500)); // TODO: make this a config check
ESP_LOGI(TAG, "hello1");
} }
} }