#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "driver/gpio.h"
#include "esp_log.h"
#define TAG __func__
#define led GPIO_NUM_2 //ou gpio_num_t led = GPIO_NUM_2;

//ESP_LOGx SÓ FUNCIONA EM appmain()
#define CONFIG_LOG_DEFAULT_LEVEL_VERBOSE 1
//#define CONFIG_LOG_DEFAULT_LEVEL 5
//#define CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE 1
#define CONFIG_LOG_MAXIMUM_LEVEL 5
            //1 --> E
            //2 --> E e W
            //3 --> E, W e I
            //4 --> E, W, I e D
            //5 --> E, W, I, D e V

#define CONFIG_LOG_COLORS 1
//#define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 1 


uint8_t led_level = 0;
esp_err_t init_led(void);
esp_err_t blink_led(void);


void escreve(void){
  ESP_LOGW(TAG, "-> escreve.");
  printf("ESCREVE\n");
}

void app_main() {
  printf("Hello, Wokwi!\n");
  esp_log_level_set(TAG, ESP_LOG_VERBOSE);

  ESP_LOGW(TAG, "-> InícioW.");
  ESP_LOGI(TAG, "-> InícioI.");
  ESP_LOGE(TAG, "-> InícioE.");
  ESP_LOGD(TAG, "-> InícioD.");
  ESP_LOGV(TAG, "-> InícioV.");

  escreve();
  init_led();
  while (true) {
    vTaskDelay(1000 / portTICK_PERIOD_MS);
   // printf("dentro do app_main\n");
    blink_led();
   // ESP_LOGI(TAG,"esp_log\n");
  }
}

esp_err_t init_led(void){
  gpio_reset_pin(led);
  gpio_set_direction(led,GPIO_MODE_OUTPUT);
  printf("dentro init_led\n");
  return ESP_OK;
}

esp_err_t blink_led(void){
  led_level = !led_level;
  gpio_set_level(led,led_level);
  printf("led: %d\n",led_level);
  ESP_LOGI(TAG, "-> LED");

  return ESP_OK;
}