mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 13:07:03 +03:00
Update webpack and web ui to recent versions, bug fixes
This commit is contained in:
@@ -620,6 +620,31 @@ void config_delete_key(const char *key){
|
||||
void * config_alloc_get(nvs_type_t nvs_type, const char *key) {
|
||||
return config_alloc_get_default(nvs_type, key, NULL, 0);
|
||||
}
|
||||
cJSON * config_alloc_get_cjson(const char *key){
|
||||
char * conf_str = config_alloc_get_default(NVS_TYPE_STR, key, NULL, 0);
|
||||
if(conf_str==NULL){
|
||||
ESP_LOGE(TAG, "Unable to get config value for key [%s]", key);
|
||||
return NULL;
|
||||
}
|
||||
cJSON * conf_json = cJSON_Parse(conf_str);
|
||||
free(conf_str);
|
||||
if(conf_json==NULL){
|
||||
ESP_LOGE(TAG, "Unable to parse config value for key [%s]", key);
|
||||
return NULL;
|
||||
}
|
||||
return conf_json;
|
||||
}
|
||||
esp_err_t config_set_cjson_str(const char *key, cJSON *value){
|
||||
char * value_str = cJSON_PrintUnformatted(value);
|
||||
if(value_str==NULL){
|
||||
ESP_LOGE(TAG, "Unable to print cJSON for key [%s]", key);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
esp_err_t err = config_set_value(NVS_TYPE_STR,key, value_str);
|
||||
free(value_str);
|
||||
cJSON_Delete(value);
|
||||
return err;
|
||||
}
|
||||
void config_get_uint16t_from_str(const char *key, uint16_t *value, uint16_t default_value){
|
||||
char * str_value = config_alloc_get(NVS_TYPE_STR, key);
|
||||
if(str_value == NULL){
|
||||
@@ -725,7 +750,42 @@ esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, const void * va
|
||||
config_unlock();
|
||||
return result;
|
||||
}
|
||||
cJSON* cjson_update_string(cJSON** root, const char* key, const char* value) {
|
||||
if (*root == NULL) {
|
||||
*root = cJSON_CreateObject();
|
||||
if (*root == NULL) {
|
||||
ESP_LOGE(TAG, "Error creating cJSON object!");
|
||||
}
|
||||
}
|
||||
if (!key || !value || strlen(key) == 0) {
|
||||
ESP_LOGE(TAG, "cjson_update_string. Invalid key or value passed! key: %s, value: %s", STR_OR_ALT(key, ""), STR_OR_ALT(value, ""));
|
||||
return *root;
|
||||
}
|
||||
cJSON* cjsonvalue = cJSON_GetObjectItemCaseSensitive(*root, key);
|
||||
if (cjsonvalue && strcasecmp(cJSON_GetStringValue(cjsonvalue), value) != 0) {
|
||||
ESP_LOGD(TAG, "Value %s changed from %s to %s", key, cJSON_GetStringValue(cjsonvalue), value);
|
||||
cJSON_SetValuestring(cjsonvalue, value);
|
||||
} else if(!cjsonvalue){
|
||||
ESP_LOGD(TAG, "Adding new value %s: %s", key, value);
|
||||
cJSON_AddItemToObject(*root, key, cJSON_CreateString(value));
|
||||
}
|
||||
return *root;
|
||||
}
|
||||
cJSON* cjson_update_number(cJSON** root, const char* key, int value) {
|
||||
|
||||
if (*root == NULL) {
|
||||
*root = cJSON_CreateObject();
|
||||
}
|
||||
if (key && strlen(key) != 0) {
|
||||
cJSON* cjsonvalue = cJSON_GetObjectItemCaseSensitive(*root, key);
|
||||
if (cjsonvalue) {
|
||||
cJSON_SetNumberValue(cjsonvalue, value);
|
||||
} else {
|
||||
cJSON_AddNumberToObject(*root, key, value);
|
||||
}
|
||||
}
|
||||
return *root;
|
||||
}
|
||||
IMPLEMENT_SET_DEFAULT(uint8_t,NVS_TYPE_U8);
|
||||
IMPLEMENT_SET_DEFAULT(int8_t,NVS_TYPE_I8);
|
||||
IMPLEMENT_SET_DEFAULT(uint16_t,NVS_TYPE_U16);
|
||||
|
||||
@@ -52,6 +52,8 @@ void config_start_timer();
|
||||
void config_init();
|
||||
void * config_alloc_get_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size);
|
||||
void * config_alloc_get_str(const char *key, char *lead, char *fallback);
|
||||
cJSON * config_alloc_get_cjson(const char *key);
|
||||
esp_err_t config_set_cjson_str(const char *key, cJSON *value);
|
||||
void config_get_uint16t_from_str(const char *key, uint16_t *value, uint16_t default_value);
|
||||
void config_delete_key(const char *key);
|
||||
void config_set_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size);
|
||||
@@ -61,7 +63,8 @@ char * config_alloc_get_json(bool bFormatted);
|
||||
esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, const void * value);
|
||||
nvs_type_t config_get_item_type(cJSON * entry);
|
||||
void * config_safe_alloc_get_entry_value(nvs_type_t nvs_type, cJSON * entry);
|
||||
|
||||
cJSON* cjson_update_number(cJSON** root, const char* key, int value);
|
||||
cJSON* cjson_update_string(cJSON** root, const char* key, const char* value);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user