Early logging initialization

This commit is contained in:
2026-02-02 19:40:34 +01:00
parent 26dced7cee
commit 3b6b97011b
3 changed files with 35 additions and 4 deletions

View File

@@ -79,10 +79,12 @@ private:
std::map<String, ConfigValue> values; std::map<String, ConfigValue> values;
std::map<String, const ConfigDef*> defs; std::map<String, const ConfigDef*> defs;
void updateValue(const char* key, ConfigType type, ConfigValue newvalue); void updateValue(const char* key, ConfigType type, ConfigValue newvalue);
ConfigValue getValue(const ConfigDef* def);
[[noreturn]] void error_abort() const; [[noreturn]] void error_abort() const;
public: public:
explicit Config(Preferences& prefs); explicit Config(Preferences& prefs);
void load(); void load();
void loadValue(const char* key);
void save(); void save();
void dump(); void dump();

View File

@@ -24,6 +24,33 @@ Config::Config(Preferences& prefs)
abort(); abort();
} }
ConfigValue Config::getValue(const ConfigDef *def) {
switch (def->type) {
case ConfigType::BYTE:
return (uint8_t)prefs.getUChar(def->key, std::get<uint8_t>(def->defval));
case ConfigType::SHORT:
return (int16_t)prefs.getShort(def->key, std::get<int16_t>(def->defval));
case ConfigType::INT:
return prefs.getInt(def->key, std::get<int32_t>(def->defval));
case ConfigType::BOOL:
return prefs.getBool(def->key, std::get<bool>(def->defval));
case ConfigType::FLOAT:
return prefs.getFloat(def->key, std::get<float>(def->defval));
case ConfigType::CHAR:
return (char)prefs.getChar(def->key, std::get<char>(def->defval));
case ConfigType::STRING:
return prefs.getString(def->key, std::get<String>(def->defval));
}
return prefs.getString(def->key, std::get<String>(def->defval));
}
void Config::loadValue(const char* key) {
// Load single value, e.g. to receive loglevel early
prefs.begin(PREF_NAME, true);
values[key] = getValue(defs.at(key));
prefs.end();
}
void Config::load() { void Config::load() {
LOGD(TAG, "Loading configuration"); LOGD(TAG, "Loading configuration");
prefs.begin(PREF_NAME, true); prefs.begin(PREF_NAME, true);

View File

@@ -214,11 +214,9 @@ void setup() {
digitalWrite(RGBLED_G, LOW); digitalWrite(RGBLED_G, LOW);
digitalWrite(RGBLED_B, LOW); digitalWrite(RGBLED_B, LOW);
// early logging initialization
LOGI(TAG, "Starting ..."); LOGI(TAG, "Starting ...");
config.loadValue("logLevel");
config.load();
config.dump();
loglevel = config.getByte("logLevel"); loglevel = config.getByte("logLevel");
if (loglevel > ESP_LOG_VERBOSE) { if (loglevel > ESP_LOG_VERBOSE) {
loglevel = ESP_LOG_VERBOSE; loglevel = ESP_LOG_VERBOSE;
@@ -228,6 +226,10 @@ void setup() {
LOGI(TAG, "Setting loglevel to %d", loglevel); LOGI(TAG, "Setting loglevel to %d", loglevel);
esp_log_level_set("*", static_cast<esp_log_level_t>(loglevel)); esp_log_level_set("*", static_cast<esp_log_level_t>(loglevel));
// configuration from nvs
config.load();
config.dump();
keycode[0] = config.getByte("key1"); keycode[0] = config.getByte("key1");
keycode[1] = config.getByte("key2"); keycode[1] = config.getByte("key2");
keycode[2] = config.getByte("key3"); keycode[2] = config.getByte("key3");