diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 9750f8f..92e94ea 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -1,3 +1,8 @@ +# Logger configuration. +CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE=y +CONFIG_LOG_MAXIMUM_LEVEL=5 +CONFIG_LOG_COLORS=y +CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM=y # OS/SDK configuration. CONFIG_AUTOSTART_ARDUINO=n CONFIG_FREERTOS_HZ=1000 diff --git a/src/command.c b/src/command.c index bdd0862..7b7a32c 100644 --- a/src/command.c +++ b/src/command.c @@ -4,12 +4,15 @@ */ #include "command.h" +#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/queue.h" #include "freertos/task.h" #include #include +#define LOGGER_TAG "command" + #define COMMAND_TASK_STACK_SIZE (2u * configMINIMAL_STACK_SIZE) #define COMMAND_TASK_PRIORITY tskIDLE_PRIORITY #define COMMAND_QUEUE_NB 16u @@ -57,7 +60,8 @@ static void command_task_handler(void *context) // Check if received command is in range. if (command >= COMMAND_NB_MAX) continue; - printf("Command received cmd='%s'\r\n", command_debug_str[command]); + ESP_LOGI(LOGGER_TAG, + "Command received cmd='%s'", command_debug_str[command]); } } } diff --git a/src/ir_decoder.c b/src/ir_decoder.c index 9fb1a83..20cfa02 100644 --- a/src/ir_decoder.c +++ b/src/ir_decoder.c @@ -6,12 +6,15 @@ #include "command.h" #include "ir_decoder.h" #include "driver/rmt_rx.h" +#include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/queue.h" #include "freertos/task.h" #include #include +#define LOGGER_TAG "ir_decoder" + #define IR_DECODER_TASK_STACK_SIZE (4u * configMINIMAL_STACK_SIZE) #define IR_DECODER_TASK_PRIORITY tskIDLE_PRIORITY #define IR_DECODER_QUEUE_NB 1u @@ -100,25 +103,36 @@ static void ir_decoder_task_handler(void *context) if (pdPASS == xQueueReceive( (QueueHandle_t) &handle->queue, &event, pdMS_TO_TICKS(1000))) { + ESP_LOGD(LOGGER_TAG, "IR event detected nb=%d", event.num_symbols); + for (int i = 0; i < event.num_symbols; i++) + { + ESP_LOGV(LOGGER_TAG, "event %3d: {%d, %5d} {%d, %5d}", + i, + event.received_symbols[i].level0, + event.received_symbols[i].duration0, + event.received_symbols[i].level1, + event.received_symbols[i].duration1); + } // Send to parsing method. uint16_t ir_address; uint16_t ir_command; if (ir_decoder_format_nec(&event, &ir_address, &ir_command)) { command_t command; - printf("IR decoder [NEC]: address=%04x command=%04x\r\n", + ESP_LOGD(LOGGER_TAG, + "NEC format found address=%04x command=%04x", ir_address, ir_command); // Convert command if not a repeat and push it. if (ir_command != 0u && ir_decoder_parse_codeset( handle->codeset, ir_command, &command) && command_push(command)) - printf("IR decoder: pushed\r\n"); + ESP_LOGD(LOGGER_TAG, "Command pushed"); else - printf("IR decoder: command ignored\r\n"); + ESP_LOGD(LOGGER_TAG, "Command ignored"); } else - printf("IR decoder failed\r\n"); + ESP_LOGW(LOGGER_TAG, "Formatter failed"); // Trigger next reception. ir_decoder_receive(handle); } diff --git a/src/ir_decoder_nec.c b/src/ir_decoder_nec.c index 00264ce..145306f 100644 --- a/src/ir_decoder_nec.c +++ b/src/ir_decoder_nec.c @@ -4,8 +4,11 @@ */ #include "ir_decoder.h" +#include "esp_log.h" #include +#define LOGGER_TAG "ir_decoder_nec" + #define NEC_FRAME_NORMAL 34u #define NEC_FRAME_REPEAT 2u #define NEC_RANGE_MARGIN 200u @@ -125,13 +128,13 @@ bool ir_decoder_format_nec( switch (event->num_symbols) { case NEC_FRAME_NORMAL: - printf("IR decoder [NEC]: parsing normal frame\r\n"); + ESP_LOGD(LOGGER_TAG, "Normal frame"); return nec_parse_normal(symbols, address, command); case NEC_FRAME_REPEAT: - printf("IR decoder [NEC]: parsing repeat frame\r\n"); + ESP_LOGD(LOGGER_TAG, "Repeat frame"); return nec_parse_repeat(symbols, address, command); default: - printf("IR decoder [NEC]: frame unsupported\r\n"); + ESP_LOGW(LOGGER_TAG, "Frame unsupported"); return false; } } diff --git a/src/main.c b/src/main.c index f1ed02d..5dbec54 100644 --- a/src/main.c +++ b/src/main.c @@ -13,9 +13,12 @@ #include "freertos/task.h" #include "esp_chip_info.h" #include "esp_flash.h" +#include "esp_log.h" #include #include +#define LOGGER_TAG "main" + static void display_chip_information(void) { // Get chip information. @@ -23,19 +26,19 @@ static void display_chip_information(void) uint32_t flash_size = 0; esp_chip_info(&chip_info); esp_flash_get_size(NULL, &flash_size); - printf( - "Chip: %s [%d] (%d core(s)) rev %d.%d\r\n", + ESP_LOGI(LOGGER_TAG, + "Chip: %s [%d] (%d core(s)) rev %d.%d", CONFIG_IDF_TARGET, chip_info.model, chip_info.cores, chip_info.revision / 100, chip_info.revision % 100); - printf( - "Flash: %lu MB (%s)\r\n", + ESP_LOGI(LOGGER_TAG, + "Flash: %lu MB (%s)", flash_size / (1024 * 1024), (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external"); - printf( - "PSRAM: %s\r\n", + ESP_LOGI(LOGGER_TAG, + "PSRAM: %s", (chip_info.features & CHIP_FEATURE_EMB_PSRAM) ? "Embedded" : "None"); - printf( - "Features:%s%s%s%s\r\n", + ESP_LOGI(LOGGER_TAG, + "Features:%s%s%s%s", (chip_info.features & CHIP_FEATURE_WIFI_BGN) ? " WiFi" : "", (chip_info.features & CHIP_FEATURE_BT) ? " BT" : "", (chip_info.features & CHIP_FEATURE_BLE) ? " BLE" : "", @@ -45,7 +48,8 @@ static void display_chip_information(void) void app_main(void) { board_initialise(); - printf("*** ESP UPnP remote ***\r\n"); + esp_log_level_set("*", ESP_LOG_INFO); + ESP_LOGI(LOGGER_TAG, "*** ESP UPnP remote ***"); display_chip_information(); // Initialise command processing. command_init();