#include "freertos/idf_additions.h" #include "freertos/projdefs.h" #include "portmacro.h" #include #include #include #include #include #include "tasks.h" QueueHandle_t blink_rate_q; void blink_cmd_print(const BlinkCmd_t *cmd) { printf("BlinkCmd {\n"); switch (cmd->variant) { case BLINK_RATE: printf(" variant: BLINK_RATE,\n"); printf(" rate: %lu\n", cmd->rate); break; case BLINK_STATE: printf(" variant: BLINK_STATE,\n"); printf(" state: %s\n", cmd->state ? "ON" : "OFF"); break; default: printf(" variant: UNKNOWN (%d)\n", cmd->variant); break; } printf("}\n"); } void task_blink(void *pvParams) { esp_rom_gpio_pad_select_gpio(LED_PIN); gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT); u32 level = 1; // For blinking // Set this to some initial value BlinkCmd_t command = { .variant = BLINK_RATE, .rate = 1000, }; if (pvParams != NULL) { command = *(BlinkCmd_t *)pvParams; printf("Got initial configuration for leds:\n"); blink_cmd_print(&command); } while (1) { if (pdPASS == xQueueReceive(blink_rate_q, &command, 0)) blink_cmd_print(&command); switch (command.variant) { case BLINK_RATE: level = !level; gpio_set_level(LED_PIN, level); vTaskDelay(command.rate / portTICK_PERIOD_MS); break; case BLINK_STATE: gpio_set_level(LED_PIN, command.state); vTaskDelay(pdMS_TO_TICKS(20)); break; } } }