|
#include "UserButton.h" |
|
#include "freertos/FreeRTOS.h" |
|
#include "freertos/queue.h" |
|
#include <esp_log.h> |
|
|
|
namespace hmi { |
|
|
|
static xQueueHandle gpio_evt_queue = nullptr; |
|
|
|
static void IRAM_ATTR interruptIsrHandler(void* arg) |
|
{ |
|
xQueueSendFromISR(gpio_evt_queue, arg, NULL); |
|
} |
|
|
|
|
|
UserButton::UserButton() |
|
{ |
|
|
|
} |
|
|
|
void UserButton::in( gpio_num_t button, bool active ) |
|
{ |
|
Button* btn = new Button(button,true); |
|
|
|
btn->_gpio = button; |
|
// printf(">>>>>>>>>>>>>>>>>>CONSTRUCTOR BUTTON<<<<<<<<<<<<<<<<<<<<<"); |
|
if (active) { |
|
// the button connects the input pin to GND when pressed. |
|
btn->_buttonPressed = LOW; |
|
} else { |
|
// the button connects the input pin to VCC when pressed. |
|
btn->_buttonPressed = HIGH; |
|
} |
|
|
|
|
|
ESP_LOGE("el valor dentor e clase es ","ESTE %d", btn->_gpio); |
|
|
|
static Interrupt g_int_task; |
|
//printf(">>>>>>>>>>>>>>>>>>CONSTRUCTOR BUTTON<<<<<<<<<<<<<<<<<<<<<"); |
|
gpio_num_t USER_BUTTON = btn->_gpio; //32 in schematic but not work with interrupt service //works 27,25,23,21,26 //not work 32,34,36 this pins not work with interrupt handler |
|
gpio_num_t SYSOFF = GPIO_NUM_27; //32 wrong in schematic not accept IRQ |
|
const int ESP_INTR_FLAG_DEFAULT = 0; |
|
|
|
gpio_config_t io_conf = {}; |
|
io_conf.intr_type = GPIO_INTR_DISABLE; |
|
io_conf.mode = GPIO_MODE_OUTPUT; |
|
io_conf.pin_bit_mask = (1<<SYSOFF); |
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE; |
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE; |
|
gpio_config(&io_conf); |
|
|
|
//interrupt of rising edge |
|
io_conf.intr_type = GPIO_INTR_POSEDGE; |
|
io_conf.pin_bit_mask = (1ULL << USER_BUTTON);//GPIO_INPUT_PIN_SEL; |
|
io_conf.mode = GPIO_MODE_INPUT; |
|
io_conf.pull_up_en = GPIO_PULLUP_ENABLE; |
|
gpio_config(&io_conf); |
|
//change gpio intrrupt type |
|
gpio_set_intr_type(btn->_gpio, GPIO_INTR_ANYEDGE); |
|
//create a queue to handle gpio event from isr |
|
//static gpio_num_t gpoutTest = _gpio; |
|
//printf("el puerto es --->%d",gpoutTest ); |
|
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT); |
|
gpio_isr_handler_add(GPIO_NUM_21, interruptIsrHandler, &USER_BUTTON); |
|
gpio_evt_queue = xQueueCreate(10, sizeof(gpio_num_t)); |
|
|
|
|
|
g_int_task.start(this); |
|
|
|
} |
|
|
|
|
|
Interrupt::Interrupt() |
|
: Task("Interrupt", 2000, 5) |
|
{ |
|
} |
|
|
|
void Interrupt::run(void* task_data) |
|
{ |
|
Button* btn = static_cast<Button*>(task_data); |
|
|
|
|
|
printf("Running Task----------------------%d\n", btn->_gpio); |
|
//btn = new Button(); |
|
gpio_num_t io_pin = GPIO_NUM_MAX; |
|
/*printf("Arrancando la tarea-------------------------\n"); |
|
Button* btn = new Button();*/ |
|
while (true) { |
|
if (xQueueReceive(gpio_evt_queue, &io_pin, portMAX_DELAY)) { |
|
printf("LLEGO LA INTERRUPCION ESPERADA--> %d------%d\n", gpio_get_level(io_pin), io_pin); |
|
//printf("VARIABLE DE PRUEBA : %ld",_debounceTicks ); |
|
// btn.tick(); |
|
} |
|
} |
|
} |
|
|
|
} // namespace hmi |