WIP: feature/esp32-ng-basic #1
@ -125,37 +125,11 @@ void config_get_config(config_t *const cnf)
|
|||||||
cnf->localBtn_pin = current_config.localBtn_pin;
|
cnf->localBtn_pin = current_config.localBtn_pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t config_update_config(const config_t *config)
|
|
||||||
{
|
|
||||||
if (!config)
|
|
||||||
{
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reinitialize if pins changed
|
|
||||||
bool pins_changed = (current_config.led_pin_strip_a != config->led_pin_strip_a) ||
|
|
||||||
(current_config.led_pin_strip_b != config->led_pin_strip_b) ||
|
|
||||||
(current_config.pwm_pin != config->pwm_pin); // TODO: Count? LocalBtn? Needed?
|
|
||||||
|
|
||||||
memcpy(¤t_config, config, sizeof(config_t));
|
|
||||||
esp_err_t err = save_config_to_nvs();
|
|
||||||
|
|
||||||
if (err == ESP_OK && pins_changed)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG, "Restarting to apply new pin configuration...");
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
||||||
esp_restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main initialization
|
|
||||||
esp_err_t config_init(void)
|
esp_err_t config_init(void)
|
||||||
{
|
{
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initializing Config Controller...");
|
ESP_LOGI(TAG, "Initializing Config...");
|
||||||
|
|
||||||
// Initialize NVS
|
// Initialize NVS
|
||||||
ret = nvs_flash_init();
|
ret = nvs_flash_init();
|
||||||
@ -163,6 +137,7 @@ esp_err_t config_init(void)
|
|||||||
{
|
{
|
||||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
ret = nvs_flash_init();
|
ret = nvs_flash_init();
|
||||||
|
ESP_ERROR_CHECK(config_reset_config());
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
|
|
||||||
@ -181,7 +156,7 @@ esp_err_t config_init(void)
|
|||||||
// Load configuration
|
// Load configuration
|
||||||
load_config_from_nvs();
|
load_config_from_nvs();
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Config system initialized successfully");
|
ESP_LOGI(TAG, "Config initialized successfully");
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ typedef struct
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the config system
|
* @brief Initialize the config system
|
||||||
* Loads configuration from NVS and initializes subsystems
|
* Loads configuration from NVS
|
||||||
* @return ESP_OK on success
|
* @return ESP_OK on success
|
||||||
*/
|
*/
|
||||||
esp_err_t config_init(void);
|
esp_err_t config_init(void);
|
||||||
@ -38,13 +38,6 @@ esp_err_t config_init(void);
|
|||||||
*/
|
*/
|
||||||
void config_get_config(config_t *const cnf);
|
void config_get_config(config_t *const cnf);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Update configuration and save to NVS
|
|
||||||
* @param config New configuration
|
|
||||||
* @return ESP_OK on success
|
|
||||||
*/
|
|
||||||
esp_err_t config_update_config(const config_t *config);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reset configuration to defaults
|
* @brief Reset configuration to defaults
|
||||||
* @return ESP_OK on success
|
* @return ESP_OK on success
|
||||||
|
|||||||
Reference in New Issue
Block a user