From 14f4caf584ac2a03611cecd2bcb2c68f67ed4cb6 Mon Sep 17 00:00:00 2001 From: Sebastien L Date: Mon, 28 Nov 2022 09:22:46 -0500 Subject: [PATCH] Allow compiling out cspot --- components/platform_console/cmd_config.c | 11 +++++++- main/esp_app_main.c | 35 +++++++++++------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/components/platform_console/cmd_config.c b/components/platform_console/cmd_config.c index fb48a8a3..924cb67d 100644 --- a/components/platform_console/cmd_config.c +++ b/components/platform_console/cmd_config.c @@ -592,6 +592,8 @@ static int is_valid_gpio_number(int gpio, const char * name, FILE *f, bool manda } return 0; } + +#ifdef CONFIG_CSPOT_SINK static int do_cspot_config(int argc, char **argv){ int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&cspot_args); if (nerrors != 0) { @@ -639,6 +641,7 @@ static int do_cspot_config(int argc, char **argv){ FREE_AND_NULL(buf); return nerrors; } +#endif static int do_i2s_cmd(int argc, char **argv) { i2s_platform_config_t i2s_dac_pin = { @@ -746,6 +749,7 @@ cJSON * known_model_cb(){ } return values; } +#ifdef CONFIG_CSPOT_SINK cJSON * cspot_cb(){ cJSON * values = cJSON_CreateObject(); if(!values){ @@ -769,6 +773,7 @@ cJSON * cspot_cb(){ cJSON_Delete(cspot_config); return values; } +#endif cJSON * i2s_cb(){ cJSON * values = cJSON_CreateObject(); @@ -1172,7 +1177,7 @@ static void register_known_templates_config(){ cmd_to_json_with_cb(&cmd,&known_model_cb); ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); } - +#ifdef CONFIG_CSPOT_SINK static void register_cspot_config(){ cspot_args.deviceName = arg_str1(NULL,"deviceName","","Device Name"); cspot_args.bitrate = arg_int1(NULL,"bitrate","96|160|320","Streaming Bitrate (kbps)"); @@ -1188,6 +1193,7 @@ static void register_cspot_config(){ cmd_to_json_with_cb(&cmd,&cspot_cb); ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); } +#endif static void register_i2s_config(void){ i2s_args.model_name = arg_str1(NULL,"model_name",STR_OR_BLANK(get_dac_list()),"DAC Model Name"); i2s_args.clear = arg_lit0(NULL, "clear", "Clear configuration"); @@ -1329,8 +1335,11 @@ static void register_squeezelite_config(void){ void register_config_cmd(void){ if(!is_dac_config_locked()){ register_known_templates_config(); + } +#ifdef CONFIG_CSPOT_SINK register_cspot_config(); +#endif register_audio_config(); // register_squeezelite_config(); register_bt_source_config(); diff --git a/main/esp_app_main.c b/main/esp_app_main.c index 08db39a4..48d4a27c 100644 --- a/main/esp_app_main.c +++ b/main/esp_app_main.c @@ -312,8 +312,22 @@ void register_default_with_mac(const char* key, char* defval) { void register_default_nvs(){ #ifdef CONFIG_CSPOT_SINK register_default_string_val("enable_cspot", STR(CONFIG_CSPOT_SINK)); -#else - register_default_string_val("enable_cspot", "0"); + cJSON * cspot_config=config_alloc_get_cjson("cspot_config"); + if(!cspot_config){ + char * name = alloc_get_string_with_mac(DEFAULT_HOST_NAME); + if(name){ + cjson_update_string(&cspot_config,"deviceName",name); + cjson_update_number(&cspot_config,"bitrate",160); + // the call below saves the config and frees the json pointer + config_set_cjson_str_and_free("cspot_config",cspot_config); + FREE_AND_NULL(name); + } + else { + register_default_string_val("cspot_config", ""); + } + + } + #endif #ifdef CONFIG_AIRPLAY_SINK @@ -379,23 +393,6 @@ void register_default_nvs(){ register_default_string_val("ethtmout","8"); register_default_string_val("dhcp_tmout","8"); register_default_string_val("target", CONFIG_TARGET); - - cJSON * cspot_config=config_alloc_get_cjson("cspot_config"); - if(!cspot_config){ - char * name = alloc_get_string_with_mac(DEFAULT_HOST_NAME); - if(name){ - cjson_update_string(&cspot_config,"deviceName",name); - cjson_update_number(&cspot_config,"bitrate",160); - // the call below saves the config and frees the json pointer - config_set_cjson_str_and_free("cspot_config",cspot_config); - FREE_AND_NULL(name); - } - else { - register_default_string_val("cspot_config", ""); - } - - } - wait_for_commit(); ESP_LOGD(TAG,"Done setting default values in nvs."); }