Skip to content

Commit

Permalink
Use ESP logger
Browse files Browse the repository at this point in the history
  • Loading branch information
valletw committed May 13, 2024
1 parent f12f505 commit 031f3da
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
5 changes: 5 additions & 0 deletions sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
*/

#include "command.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include <assert.h>
#include <string.h>

#define LOGGER_TAG "command"

#define COMMAND_TASK_STACK_SIZE (2u * configMINIMAL_STACK_SIZE)
#define COMMAND_TASK_PRIORITY tskIDLE_PRIORITY
#define COMMAND_QUEUE_NB 16u
Expand Down Expand Up @@ -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]);
}
}
}
Expand Down
22 changes: 18 additions & 4 deletions src/ir_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <assert.h>
#include <string.h>

#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
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 6 additions & 3 deletions src/ir_decoder_nec.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
*/

#include "ir_decoder.h"
#include "esp_log.h"
#include <stdio.h>

#define LOGGER_TAG "ir_decoder_nec"

#define NEC_FRAME_NORMAL 34u
#define NEC_FRAME_REPEAT 2u
#define NEC_RANGE_MARGIN 200u
Expand Down Expand Up @@ -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;
}
}
22 changes: 13 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,32 @@
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_log.h"
#include <stdio.h>
#include <stdint.h>

#define LOGGER_TAG "main"

static void display_chip_information(void)
{
// Get chip information.
esp_chip_info_t chip_info;
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" : "",
Expand All @@ -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();
Expand Down

0 comments on commit 031f3da

Please sign in to comment.