#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "sdkconfig.h"

//ATENÇÃO
/*
PARA SE USAR O FRAMEWORK ESP-LOG É NECESSÁRIO
1- incluir em diagram.json --- "serialMonitor": {"display":"terminal"},
2- incluir o componente --- #include "esp_log.h"
inserir as defines --- #define CONFIG_LOG_DEFAULT_LEVEL_VERBOSE 1
                       #define CONFIG_LOG_MAXIMUM_LEVEL  5
3-Em cada função onde for usar, inserir: esp_log_level_set(TAG, ESP_LOG_VERBOSE);
Crie a TAG com define --- #define TAG __func__

*/

#define TAG __func__

#define CONFIG_LOG_DEFAULT_LEVEL_VERBOSE 1
#define CONFIG_LOG_MAXIMUM_LEVEL  5

//#define led LED_BUILTIN

uint8_t level =0;
gpio_num_t led = GPIO_NUM_2;
int x=1;

esp_err_t init_led(void);
esp_err_t blink_led(void);

void app_main() {
  esp_log_level_set(TAG, ESP_LOG_VERBOSE);
  ESP_LOGI(TAG,"-->Hello, Wokwi!");

  init_led();

  while (true) {
    vTaskDelay(3000 / portTICK_PERIOD_MS);
    blink_led();
  }
}


esp_err_t init_led(void){
  esp_log_level_set(TAG, ESP_LOG_VERBOSE);
  ESP_LOGW(TAG,"-->init_led");
  gpio_reset_pin(led);
  gpio_set_direction(led, GPIO_MODE_OUTPUT);
  
  return ESP_OK;
}

esp_err_t blink_led(void){
  level = !level;
  x++;
  esp_log_level_set(TAG, ESP_LOG_VERBOSE);
  if(x%2)  ESP_LOGE(TAG,"-->blink_led");
  else     ESP_LOGW(TAG,"-->blink_led");
  gpio_set_level(led,level);
  
  return ESP_OK;
}