cleanup
This commit is contained in:
@ -10,34 +10,27 @@
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "soc/gpio_num.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static const char *TAG = "LOCALBTN";
|
||||
uint8_t current_mode;
|
||||
int8_t current_localBtnPin;
|
||||
bool initialized;
|
||||
TaskHandle_t localbtnTaskhandle;
|
||||
localbtn_mode_change_callback_t callback;
|
||||
|
||||
#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 localbtn_task(void *arg)
|
||||
{
|
||||
bool lastState = false;
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // TODO:Get btn state via interrupt instead of polling
|
||||
|
||||
bool currentState = boot_button_pressed();
|
||||
bool currentState = (gpio_get_level(current_localBtnPin) == 0);
|
||||
if ((currentState) && (lastState != currentState))
|
||||
{
|
||||
printf("BOOT button pressed\n");
|
||||
ESP_LOGI(TAG, "Local button pressed");
|
||||
|
||||
if (callback)
|
||||
{
|
||||
@ -49,11 +42,11 @@ static void localbtn_task(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t localbtn_init()
|
||||
esp_err_t localbtn_init(int8_t pin_localbtn)
|
||||
{
|
||||
|
||||
current_localBtnPin = pin_localbtn;
|
||||
gpio_config_t io_conf = {
|
||||
.pin_bit_mask = 1ULL << BOOT_BTN,
|
||||
.pin_bit_mask = 1ULL << current_localBtnPin,
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.pull_up_en = GPIO_PULLUP_ENABLE, // safe even if external pull-up exists
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
@ -61,14 +54,14 @@ esp_err_t localbtn_init()
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||
|
||||
// Create monitor task
|
||||
BaseType_t ret = xTaskCreate(localbtn_task, "localbtn_monitor", 2048, NULL, 5, &localbtnTaskhandle);
|
||||
BaseType_t ret = xTaskCreate(localbtn_task, "localbtn_task", 2048, NULL, 5, &localbtnTaskhandle);
|
||||
if (ret != pdPASS)
|
||||
{
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
ESP_LOGI(TAG, "local btn initialized on GPIO%d", BOOT_BTN);
|
||||
ESP_LOGI(TAG, "local btn initialized on GPIO%d", current_localBtnPin);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user