Commit 5acce1e0 authored by natalie's avatar natalie 💜
Browse files

Implement runtime log level options

parent 911904fa
#include "logmgr.h"
#include "esp_log.h"
static const char* TAG = "LogMgr";
volatile uint8_t logmgr_loglevel = 0;
void logmgr_update_loglevel() {
//map from our loglevels to espressif's. could probably use theirs, but we don't want to screw up the settings if they change it...
esp_log_level_t l = ESP_LOG_VERBOSE;
switch (logmgr_loglevel) {
case 0:
l = ESP_LOG_WARN;
break;
case 1:
l = ESP_LOG_INFO;
break;
case 2:
l = ESP_LOG_DEBUG;
break;
case 3:
l = ESP_LOG_VERBOSE;
break;
default:
ESP_LOGE(TAG, "Trying to set invalid loglevel %d!", logmgr_loglevel);
break;
}
ESP_LOGE(TAG, "/!\\ Updating global loglevel to %d /!\\", logmgr_loglevel);
esp_log_level_set("*", l);
}
\ No newline at end of file
#ifndef AGR_LOGMGR_H
#define AGR_LOGMGR_H
#include "freertos/FreeRTOS.h"
extern volatile uint8_t logmgr_loglevel;
void logmgr_update_loglevel();
#endif
\ No newline at end of file
......@@ -54,6 +54,7 @@
#include "hspi.h"
#include "ver.h"
#include "key.h"
#include "logmgr.h"
#ifndef FWUPDATE
#include "battery.h"
#include "dacstream.h"
......@@ -235,9 +236,9 @@ void checkcore() {
LcdDma_Mutex_Give();
}
void app_main(void)
{
void app_main(void) {
assert(configUSE_16_BIT_TICKS == 0);
esp_log_level_set("*", ESP_LOG_DEBUG);
//uint8_t r = rtc_get_reset_reason(0);
#ifdef FWUPDATE
......@@ -589,6 +590,13 @@ void app_main(void)
LcdDma_Mutex_Give();
OptionsMgr_Setup();
MAIN_PROGRESS_UPDATE;
if (IoExp_PowerOnKeys & ((1<<KEY_LEFT) | (1<<KEY_RIGHT) | (1<<KEY_A))) {
ESP_LOGE(TAG, "/!\\ SETTING LOGLEVEL TO ESP_LOG_INFO! /!\\");
logmgr_loglevel = 1;
logmgr_update_loglevel();
ESP_LOGI(TAG, "Queueing options save");
OptionsMgr_Touch();
}
LcdDma_Mutex_Take(pdMS_TO_TICKS(1000));
lv_ta_add_text(textarea, "Setting up ChannelMgr... ");
......@@ -740,7 +748,14 @@ void app_main(void)
LcdDma_Mutex_Give();
crash();
}
ESP_LOGI(TAG, "Starting tasks !!");
if (logmgr_loglevel == 0) {
ESP_LOGE(TAG, "/!\\ WARNING: SYSTEM LOGLEVEL IS ABOUT TO CHANGE TO ESP_LOG_WARNING /!\\");
ESP_LOGE(TAG, "/!\\ Change in the settings menu, or hold LEFT + RIGHT + A while rebooting to force to ESP_LOG_INFO /!\\");
logmgr_update_loglevel();
}
ESP_LOGE(TAG, "Starting tasks");
LcdDma_Mutex_Take(pdMS_TO_TICKS(1000));
lv_ta_add_text(textarea, "Starting tasks!");
LcdDma_Mutex_Give();
......
......@@ -14,6 +14,7 @@
#include "queue.h"
#include "sdcard.h"
#include "ui/modal.h"
#include "logmgr.h"
static const char* TAG = "OptionsMgr";
......@@ -39,7 +40,7 @@ static void opts_pitchupdate() {
static bool loaded[OPTION_COUNT];
//last used: 12
//last used: 14
const option_t Options[OPTION_COUNT] = {
{
0x0001,
......@@ -296,6 +297,18 @@ const option_t Options[OPTION_COUNT] = {
NULL,
NULL
},
{
0x0014,
"Log level",
"Change the serial port log level. Values other than Normal will cause slight performance decrease.",
OPTION_CATEGORY_ADVANCED,
OPTION_TYPE_NUMERIC,
OPTION_SUBTYPE_LOGLEVEL,
&logmgr_loglevel,
0,
logmgr_update_loglevel,
NULL
}
};
static void file_error() {
......
......@@ -20,6 +20,7 @@ typedef enum {
OPTION_SUBTYPE_FADELENGTH,
OPTION_SUBTYPE_SCROLLTYPE,
OPTION_SUBTYPE_SHUFFLE,
OPTION_SUBTYPE_LOGLEVEL,
OPTION_SUBTYPE_COUNT
} optionsubtype_t;
......@@ -47,7 +48,7 @@ typedef struct {
void (*cb_initial)();
} option_t;
#define OPTION_COUNT 19
#define OPTION_COUNT 20
//options version. this was 0xA0 before the crc was added, so we will support 0xA0 files.
#define OPTIONS_VER 0xA1
......
......@@ -152,6 +152,24 @@ static void displayvalue(char *buf, bool def) {
break;
}
break;
case OPTION_SUBTYPE_LOGLEVEL:
switch (val) {
case 0:
strcpy(buf, "Normal");
break;
case 1:
strcpy(buf, "High");
break;
case 2:
strcpy(buf, "Higher");
break;
case 3:
strcpy(buf, "Highest (O_O;)");
break;
default:
break;
}
break;
default:
strcpy(buf, "OPTION_TYPE_NUMERIC");
break;
......@@ -269,6 +287,17 @@ static void changevalue(bool inc) {
lv_label_set_long_mode(optiondesc, Ui_GetScrollType());
lv_obj_set_width(optiondesc, 220);
break;
case OPTION_SUBTYPE_LOGLEVEL:
if (inc) {
if (*var < 3) {
*var += 1;
}
} else {
if (*var > 0) {
*var -= 1;
}
}
break;
default:
//uh oh
break;
......
......@@ -463,10 +463,10 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
CONFIG_LOG_DEFAULT_LEVEL_NONE=
CONFIG_LOG_DEFAULT_LEVEL_ERROR=
CONFIG_LOG_DEFAULT_LEVEL_WARN=
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=
CONFIG_LOG_DEFAULT_LEVEL_INFO=
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_LOG_COLORS=y
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment