localbtn deinit & cleanup
This commit is contained in:
@ -16,17 +16,18 @@
|
||||
|
||||
static const char *TAG = "LOCALBTN";
|
||||
uint8_t current_mode;
|
||||
bool initialized;
|
||||
TaskHandle_t localbtnTaskhandle;
|
||||
localbtn_mode_change_callback_t callback;
|
||||
|
||||
#define BOOT_BTN GPIO_NUM_0
|
||||
#define MAX_MODES 14 // TODO: get from control
|
||||
#define BOOT_BTN GPIO_NUM_0 // TODO: move to config
|
||||
|
||||
bool boot_button_pressed(void)
|
||||
{
|
||||
return gpio_get_level(BOOT_BTN) == 0; // active LOW
|
||||
}
|
||||
|
||||
static void monitor_task(void *arg)
|
||||
static void localbtn_task(void *arg)
|
||||
{
|
||||
bool lastState = false;
|
||||
while (1)
|
||||
@ -38,10 +39,6 @@ static void monitor_task(void *arg)
|
||||
{
|
||||
printf("BOOT button pressed\n");
|
||||
|
||||
current_mode = (current_mode + 1) % MAX_MODES;
|
||||
|
||||
ESP_LOGI(TAG, "Mode changed to: %d ", current_mode);
|
||||
|
||||
if (callback)
|
||||
{
|
||||
callback(current_mode);
|
||||
@ -64,13 +61,13 @@ esp_err_t localbtn_init()
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||
|
||||
// Create monitor task
|
||||
BaseType_t ret = xTaskCreate(monitor_task, "localbtn_monitor", 2048, NULL, 5, NULL);
|
||||
BaseType_t ret = xTaskCreate(localbtn_task, "localbtn_monitor", 2048, NULL, 5, &localbtnTaskhandle);
|
||||
if (ret != pdPASS)
|
||||
{
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
// TODO: rcsignal.initialized = true;
|
||||
initialized = true;
|
||||
ESP_LOGI(TAG, "local btn initialized on GPIO%d", BOOT_BTN);
|
||||
|
||||
return ESP_OK;
|
||||
@ -78,7 +75,17 @@ esp_err_t localbtn_init()
|
||||
|
||||
void localbtn_deinit(void)
|
||||
{
|
||||
// TODO:
|
||||
if (!initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (localbtnTaskhandle)
|
||||
{
|
||||
vTaskDelete(localbtnTaskhandle);
|
||||
localbtnTaskhandle = NULL;
|
||||
}
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
void localbtn_register_callback(localbtn_mode_change_callback_t cb)
|
||||
|
||||
Reference in New Issue
Block a user