mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 21:17:18 +03:00
Merge branch 'master-v4.3' of https://github.com/wizmo2/squeezelite-esp32 into led_visu-v4.3
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
idf_build_get_property(idf_path IDF_PATH)
|
||||
idf_component_register( SRCS cmd_squeezelite.c
|
||||
INCLUDE_DIRS .
|
||||
PRIV_REQUIRES spi_flash bootloader_support partition_table bootloader_support console codecs squeezelite newlib pthread tools platform_config display tools)
|
||||
PRIV_REQUIRES spi_flash bootloader_support partition_table bootloader_support console codecs squeezelite newlib pthread tools platform_config display tools services)
|
||||
|
||||
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=feof")
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "platform_config.h"
|
||||
#include "esp_app_format.h"
|
||||
#include "tools.h"
|
||||
#include "messaging.h"
|
||||
|
||||
extern esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t length);
|
||||
static const char * TAG = "squeezelite_cmd";
|
||||
@@ -39,7 +40,8 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
|
||||
#endif
|
||||
};
|
||||
|
||||
extern int main(int argc, char **argv);
|
||||
extern int squeezelite_main(int argc, char **argv);
|
||||
|
||||
static int launchsqueezelite(int argc, char **argv);
|
||||
|
||||
/** Arguments used by 'squeezelite' function */
|
||||
@@ -53,31 +55,32 @@ static struct {
|
||||
} thread_parms ;
|
||||
|
||||
#define ADDITIONAL_SQUEEZELITE_ARGS 5
|
||||
static void squeezelite_thread(void *arg){
|
||||
static void squeezelite_thread(void *arg){
|
||||
ESP_LOGV(TAG ,"Number of args received: %u",thread_parms.argc );
|
||||
ESP_LOGV(TAG ,"Values:");
|
||||
for(int i = 0;i<thread_parms.argc; i++){
|
||||
ESP_LOGV(TAG ," %s",thread_parms.argv[i]);
|
||||
}
|
||||
ESP_LOGI(TAG ,"Calling squeezelite");
|
||||
int ret = squeezelite_main(thread_parms.argc, thread_parms.argv);
|
||||
|
||||
cmd_send_messaging("cfg-audio-tmpl",ret > 1 ? MESSAGING_ERROR : MESSAGING_WARNING,"squeezelite exited with error code %d\n", ret);
|
||||
|
||||
ESP_LOGI(TAG ,"Calling squeezelite");
|
||||
main(thread_parms.argc,thread_parms.argv);
|
||||
ESP_LOGV(TAG ,"Exited from squeezelite's main(). Freeing argv structure.");
|
||||
if (ret == 1) {
|
||||
int wait = 60;
|
||||
wait_for_commit();
|
||||
cmd_send_messaging("cfg-audio-tmpl",MESSAGING_ERROR,"Rebooting in %d sec\n", wait);
|
||||
vTaskDelay( pdMS_TO_TICKS(wait * 1000));
|
||||
esp_restart();
|
||||
} else {
|
||||
cmd_send_messaging("cfg-audio-tmpl",MESSAGING_ERROR,"Correct command line and reboot\n");
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
|
||||
for(int i=0;i<thread_parms.argc;i++){
|
||||
ESP_LOGV(TAG ,"Freeing char buffer for parameter %u", i+1);
|
||||
free(thread_parms.argv[i]);
|
||||
}
|
||||
ESP_LOGV(TAG ,"Freeing argv pointer");
|
||||
ESP_LOGV(TAG, "Exited from squeezelite's main(). Freeing argv structure.");
|
||||
|
||||
for(int i=0;i<thread_parms.argc;i++) free(thread_parms.argv[i]);
|
||||
free(thread_parms.argv);
|
||||
|
||||
ESP_LOGE(TAG, "Exited from squeezelite thread, something's wrong ... rebooting (wait 30s for user to take action)");
|
||||
if(!wait_for_commit()){
|
||||
ESP_LOGW(TAG,"Unable to commit configuration. ");
|
||||
}
|
||||
|
||||
vTaskDelay( pdMS_TO_TICKS( 30*1000 ) );
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
static int launchsqueezelite(int argc, char **argv) {
|
||||
|
||||
@@ -602,8 +602,9 @@ 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){
|
||||
char * name = NULL;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&cspot_args);
|
||||
if (nerrors != 0) {
|
||||
return 1;
|
||||
@@ -620,32 +621,37 @@ static int do_cspot_config(int argc, char **argv){
|
||||
cJSON * cspot_config = config_alloc_get_cjson("cspot_config");
|
||||
if(!cspot_config){
|
||||
nerrors++;
|
||||
fprintf(f,"error: Unable to get cspot config.\n");
|
||||
fprintf(f,"error: Unable to get default cspot config.\n");
|
||||
}
|
||||
else {
|
||||
cjson_update_string(&cspot_config,cspot_args.deviceName->hdr.longopts,cspot_args.deviceName->count>0?cspot_args.deviceName->sval[0]:NULL);
|
||||
// cjson_update_number(&cspot_config,cspot_args.volume->hdr.longopts,cspot_args.volume->count>0?cspot_args.volume->ival[0]:0);
|
||||
cjson_update_number(&cspot_config,cspot_args.bitrate->hdr.longopts,cspot_args.bitrate->count>0?cspot_args.bitrate->ival[0]:0);
|
||||
if(cspot_args.deviceName->count>0){
|
||||
cjson_update_string(&cspot_config,cspot_args.deviceName->hdr.longopts,cspot_args.deviceName->sval[0]);
|
||||
}
|
||||
if(cspot_args.bitrate->count>0){
|
||||
cjson_update_number(&cspot_config,cspot_args.bitrate->hdr.longopts,cspot_args.bitrate->ival[0]);
|
||||
}
|
||||
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Storing cspot parameters.\n");
|
||||
nerrors+=(config_set_cjson_str("cspot_config",cspot_config) !=ESP_OK);
|
||||
nerrors+=(config_set_cjson_str_and_free("cspot_config",cspot_config) !=ESP_OK);
|
||||
}
|
||||
if(nerrors==0){
|
||||
fprintf(f,"Device name changed to %s\n",name);
|
||||
if(nerrors==0 ){
|
||||
if(cspot_args.deviceName->count>0){
|
||||
fprintf(f,"Device name changed to %s\n",cspot_args.deviceName->sval[0]);
|
||||
}
|
||||
if(cspot_args.bitrate->count>0){
|
||||
fprintf(f,"Bitrate changed to %u\n",cspot_args.bitrate->ival[0]);
|
||||
}
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
FREE_AND_NULL(name);
|
||||
fflush (f);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
return nerrors;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int do_ledvu_cmd(int argc, char **argv){
|
||||
ledvu_struct_t ledvu={ .type = "WS2812", .gpio = -1, .length = 0};
|
||||
@@ -800,6 +806,7 @@ cJSON * known_model_cb(){
|
||||
}
|
||||
return values;
|
||||
}
|
||||
#ifdef CONFIG_CSPOT_SINK
|
||||
cJSON * cspot_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
if(!values){
|
||||
@@ -819,13 +826,11 @@ cJSON * cspot_cb(){
|
||||
if(cspot_values){
|
||||
cJSON_AddNumberToObject(values,cspot_args.bitrate->hdr.longopts,cJSON_GetNumberValue(cspot_values));
|
||||
}
|
||||
// cspot_values = cJSON_GetObjectItem(cspot_config,cspot_args.volume->hdr.longopts);
|
||||
// if(cspot_values){
|
||||
// cJSON_AddNumberToObject(values,cspot_args.volume->hdr.longopts,cJSON_GetNumberValue(cspot_values));
|
||||
// }
|
||||
|
||||
cJSON_Delete(cspot_config);
|
||||
return values;
|
||||
}
|
||||
#endif
|
||||
cJSON * i2s_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
|
||||
@@ -1247,7 +1252,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)");
|
||||
@@ -1263,6 +1268,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");
|
||||
@@ -1422,8 +1428,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();
|
||||
|
||||
@@ -101,6 +101,7 @@ static struct {
|
||||
struct arg_int *reset;
|
||||
struct arg_lit *clear;
|
||||
struct arg_lit *invert;
|
||||
struct arg_int *mode;
|
||||
struct arg_end *end;
|
||||
} i2cdisp_args;
|
||||
|
||||
@@ -377,6 +378,13 @@ static int do_i2c_set_display(int argc, char **argv)
|
||||
}
|
||||
/* Check "--cs" option */
|
||||
nerrors +=is_output_gpio(i2cdisp_args.cs,f,&config.CS_pin, false);
|
||||
/* Check "--mode" option */
|
||||
if (i2cdisp_args.mode->count) {
|
||||
config.mode=i2cdisp_args.mode->ival[0];
|
||||
}
|
||||
else {
|
||||
config.mode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
nerrors +=is_output_gpio(i2cdisp_args.reset,f,&config.RST_pin, false);
|
||||
@@ -964,6 +972,9 @@ cJSON * i2c_set_display_cb(){
|
||||
cJSON_AddBoolToObject(values,"hf",conf->hflip);
|
||||
cJSON_AddBoolToObject(values,"vf",conf->vflip);
|
||||
cJSON_AddBoolToObject(values,"invert",conf->invert);
|
||||
if(conf->mode>=0){
|
||||
cJSON_AddNumberToObject(values,"mode",conf->mode);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
@@ -986,6 +997,7 @@ static void register_i2c_set_display(){
|
||||
i2cdisp_args.rotate = arg_lit0("r", "rotate", "Rotate 180 degrees");
|
||||
i2cdisp_args.invert = arg_lit0("i", "invert", "Invert colors");
|
||||
i2cdisp_args.clear = arg_lit0(NULL, "clear", "clear configuration and return");
|
||||
i2cdisp_args.mode = arg_int0("m", "mode", "<n>","SPI Only. Transaction Line Mode (Default 0)");
|
||||
i2cdisp_args.end = arg_end(8);
|
||||
const esp_console_cmd_t i2c_set_display= {
|
||||
.command = CFG_TYPE_HW("display"),
|
||||
|
||||
@@ -69,7 +69,6 @@ static void register_deep_sleep();
|
||||
static void register_light_sleep();
|
||||
static void register_factory_boot();
|
||||
static void register_restart_ota();
|
||||
static void register_update_certs();
|
||||
static void register_set_services();
|
||||
#if WITH_TASKS_INFO
|
||||
static void register_tasks();
|
||||
@@ -86,7 +85,6 @@ void register_system()
|
||||
register_restart();
|
||||
register_deep_sleep();
|
||||
register_light_sleep();
|
||||
register_update_certs();
|
||||
register_factory_boot();
|
||||
register_restart_ota();
|
||||
#if WITH_TASKS_INFO
|
||||
@@ -562,23 +560,6 @@ static void register_tasks()
|
||||
|
||||
#endif // WITH_TASKS_INFO
|
||||
|
||||
extern esp_err_t update_certificates(bool force);
|
||||
static int force_update_cert(int argc, char **argv){
|
||||
return update_certificates(true);
|
||||
}
|
||||
|
||||
static void register_update_certs()
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "update_certificates",
|
||||
.help = "Force updating the certificates from binary",
|
||||
.hint = NULL,
|
||||
.func = &force_update_cert,
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 'deep_sleep' command puts the chip into deep sleep mode */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user