mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 21:17:18 +03:00
Start of 5.X work
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 services)
|
||||
PRIV_REQUIRES spi_flash bootloader_support partition_table bootloader_support console codecs squeezelite newlib pthread tools platform_config display services)
|
||||
|
||||
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=feof")
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "application_name.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_console.h"
|
||||
#include "../cmd_system.h"
|
||||
#include "Config.h"
|
||||
#include "application_name.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "esp_app_format.h"
|
||||
#include "esp_console.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "pthread.h"
|
||||
#include "platform_esp32.h"
|
||||
#include "Configurator.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);
|
||||
extern int squeezelite_main_start();
|
||||
#include "platform_esp32.h"
|
||||
#include "pthread.h"
|
||||
#include "tools.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "bootstate.h"
|
||||
|
||||
static const char * TAG = "squeezelite_cmd";
|
||||
#define SQUEEZELITE_THREAD_STACK_SIZE (8*1024)
|
||||
extern esp_err_t process_recovery_ota(const char* bin_url, char* bin_buffer, uint32_t length);
|
||||
extern int squeezelite_main_start();
|
||||
extern sys_dac_default_sets* default_dac_sets;
|
||||
|
||||
|
||||
static const char* TAG = "squeezelite_cmd";
|
||||
#define SQUEEZELITE_THREAD_STACK_SIZE (8 * 1024)
|
||||
#define ADDITIONAL_SQUEEZELITE_ARGS 5
|
||||
|
||||
const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
|
||||
@@ -45,112 +49,91 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
|
||||
extern void register_audio_config(void);
|
||||
// extern void register_rotary_config(void);
|
||||
extern void register_nvs();
|
||||
extern cJSON * get_gpio_list_handler(bool refresh);
|
||||
cJSON * get_gpio_list(bool refresh){
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
return get_gpio_list_handler(refresh);
|
||||
extern cJSON* get_gpio_list_handler(bool refresh);
|
||||
cJSON* get_gpio_list(bool refresh) {
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
return get_gpio_list_handler(refresh);
|
||||
#else
|
||||
return cJSON_CreateArray();
|
||||
return cJSON_CreateArray();
|
||||
#endif
|
||||
}
|
||||
void register_optional_cmd(void) {
|
||||
// #if CONFIG_WITH_CONFIG_UI
|
||||
// register_rotary_config();
|
||||
// #endif
|
||||
// #if CONFIG_WITH_CONFIG_UI
|
||||
// register_rotary_config();
|
||||
// #endif
|
||||
register_audio_config();
|
||||
// register_ledvu_config();
|
||||
|
||||
// register_ledvu_config();
|
||||
}
|
||||
|
||||
/** Arguments used by 'squeezelite' function */
|
||||
static struct {
|
||||
struct arg_str *parameters;
|
||||
struct arg_end *end;
|
||||
} squeezelite_args;
|
||||
static struct {
|
||||
int argc;
|
||||
char ** argv;
|
||||
} thread_parms ;
|
||||
int argc;
|
||||
char** argv;
|
||||
} thread_parms;
|
||||
|
||||
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_start(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);
|
||||
static void squeezelite_thread(void* arg) {
|
||||
ESP_LOGI(TAG, "Calling squeezelite");
|
||||
int wait = 60;
|
||||
int ret = squeezelite_main_start();
|
||||
|
||||
if (ret <= 1) {
|
||||
int wait = 60;
|
||||
// wait_for_commit();
|
||||
// TODO: Add support for the commented code
|
||||
cmd_send_messaging("cfg-audio-tmpl",MESSAGING_ERROR,"Rebooting in %d sec\n", wait);
|
||||
vTaskDelay( pdMS_TO_TICKS(wait * 1000));
|
||||
esp_restart();
|
||||
if (ret == -2) {
|
||||
cmd_send_messaging("cfg-audio-tmpl", MESSAGING_ERROR,
|
||||
"Squeezelite not configured. Rebooting to factory in %d sec\n", wait);
|
||||
vTaskDelay(pdMS_TO_TICKS(wait * 1000));
|
||||
guided_factory();
|
||||
} else {
|
||||
cmd_send_messaging("cfg-audio-tmpl",MESSAGING_ERROR,"Correct command line and reboot\n");
|
||||
vTaskSuspend(NULL);
|
||||
cmd_send_messaging("cfg-audio-tmpl", ret > 1 ? MESSAGING_ERROR : MESSAGING_WARNING,
|
||||
"squeezelite exited with error code %d\n", ret);
|
||||
if (ret <= 1) {
|
||||
|
||||
cmd_send_messaging(
|
||||
"cfg-audio-tmpl", MESSAGING_ERROR, "Rebooting to factory in %d sec\n", wait);
|
||||
vTaskDelay(pdMS_TO_TICKS(wait * 1000));
|
||||
guided_factory();
|
||||
} else {
|
||||
|
||||
cmd_send_messaging(
|
||||
"cfg-audio-tmpl", MESSAGING_ERROR, "Correct command line and reboot\n");
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Exited from squeezelite's main(). Freeing argv structure.");
|
||||
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);
|
||||
for (int i = 0; i < thread_parms.argc; i++)
|
||||
free(thread_parms.argv[i]);
|
||||
free(thread_parms.argv);
|
||||
}
|
||||
|
||||
static int launchsqueezelite(int argc, char **argv) {
|
||||
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__ ((aligned (4)));
|
||||
static EXT_RAM_ATTR StackType_t xStack[SQUEEZELITE_THREAD_STACK_SIZE] __attribute__ ((aligned (4)));
|
||||
static bool isRunning = false;
|
||||
static int launchsqueezelite(int argc, char** argv) {
|
||||
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__((aligned(4)));
|
||||
static EXT_RAM_ATTR StackType_t xStack[SQUEEZELITE_THREAD_STACK_SIZE]
|
||||
__attribute__((aligned(4)));
|
||||
static bool isRunning = false;
|
||||
|
||||
if (isRunning) {
|
||||
ESP_LOGE(TAG,"Squeezelite already running. Exiting!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG ,"Begin");
|
||||
isRunning = true;
|
||||
if (isRunning) {
|
||||
ESP_LOGE(TAG, "Squeezelite already running. Exiting!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ESP_LOGV(TAG, "Parameters:");
|
||||
// for(int i = 0;i<argc; i++){
|
||||
// ESP_LOGV(TAG, " %s",argv[i]);
|
||||
// }
|
||||
// ESP_LOGV(TAG,"Saving args in thread structure");
|
||||
ESP_LOGV(TAG, "Begin");
|
||||
isRunning = true;
|
||||
|
||||
// thread_parms.argc=0;
|
||||
// thread_parms.argv = malloc_init_external(sizeof(char**)*(argc+ADDITIONAL_SQUEEZELITE_ARGS));
|
||||
// load the presets here, as the squeezelite cannot access the
|
||||
// spiffs storage
|
||||
// proto_load_file("/spiffs/presets/default_sets.bin", &sys_dac_default_sets_msg, default_dac_sets, false);
|
||||
|
||||
// for(int i=0;i<argc;i++){
|
||||
// ESP_LOGD(TAG ,"assigning parm %u : %s",i,argv[i]);
|
||||
// thread_parms.argv[thread_parms.argc++]=strdup(argv[i]);
|
||||
// }
|
||||
|
||||
// if(argc==1){
|
||||
// // There isn't a default configuration that would actually work
|
||||
// // if no parameter is passed.
|
||||
// ESP_LOGV(TAG ,"Adding argv value at %u. Prev value: %s",thread_parms.argc,thread_parms.argv[thread_parms.argc-1]);
|
||||
// thread_parms.argv[thread_parms.argc++]=strdup("-?");
|
||||
// }
|
||||
|
||||
ESP_LOGD(TAG,"Starting Squeezelite Thread");
|
||||
xTaskCreateStaticPinnedToCore(squeezelite_thread, "squeezelite", SQUEEZELITE_THREAD_STACK_SIZE,
|
||||
NULL, CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT, xStack, &xTaskBuffer, CONFIG_PTHREAD_TASK_CORE_DEFAULT);
|
||||
ESP_LOGD(TAG ,"Back to console thread!");
|
||||
ESP_LOGD(TAG, "Starting Squeezelite Thread");
|
||||
xTaskCreateStaticPinnedToCore(squeezelite_thread, "squeezelite", SQUEEZELITE_THREAD_STACK_SIZE,
|
||||
NULL, CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT, xStack, &xTaskBuffer,
|
||||
CONFIG_PTHREAD_TASK_CORE_DEFAULT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
void start_squeezelite(){
|
||||
launchsqueezelite(0,NULL);
|
||||
}
|
||||
void start_squeezelite() { launchsqueezelite(0, NULL); }
|
||||
// void register_squeezelite() {
|
||||
// squeezelite_args.parameters = arg_str0(NULL, NULL, "<parms>", "command line for squeezelite. -h for help, --defaults to launch with default values.");
|
||||
// squeezelite_args.end = arg_end(1);
|
||||
// const esp_console_cmd_t launch_squeezelite = {
|
||||
// .command = "squeezelite",
|
||||
// .help = "Starts squeezelite",
|
||||
// squeezelite_args.parameters = arg_str0(NULL, NULL, "<parms>", "command line for squeezelite. -h
|
||||
// for help, --defaults to launch with default values."); squeezelite_args.end = arg_end(1); const
|
||||
// esp_console_cmd_t launch_squeezelite = { .command = "squeezelite", .help = "Starts squeezelite",
|
||||
// .hint = NULL,
|
||||
// .func = &launchsqueezelite,
|
||||
// .argtable = &squeezelite_args
|
||||
@@ -158,19 +141,19 @@ void start_squeezelite(){
|
||||
// ESP_ERROR_CHECK( esp_console_cmd_register(&launch_squeezelite) );
|
||||
// }
|
||||
|
||||
esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length) {
|
||||
if(!bin_url || strlen(bin_url)==0){
|
||||
ESP_LOGE(TAG,"missing URL parameter. Unable to start OTA");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_LOGW(TAG, "Called to update the firmware from url: %s",bin_url);
|
||||
configurator_set_string(&sys_State_msg,sys_State_ota_url_tag,sys_state,bin_url);
|
||||
configurator_raise_state_changed();
|
||||
esp_err_t start_ota(const char* bin_url, char* bin_buffer, uint32_t length) {
|
||||
if (!bin_url || strlen(bin_url) == 0) {
|
||||
ESP_LOGE(TAG, "missing URL parameter. Unable to start OTA");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_LOGW(TAG, "Called to update the firmware from url: %s", bin_url);
|
||||
system_set_string(&sys_state_data_msg, sys_state_data_ota_url_tag, sys_state, bin_url);
|
||||
config_raise_state_changed();
|
||||
|
||||
if(!configurator_waitcommit()){
|
||||
ESP_LOGW(TAG,"Unable to commit configuration. ");
|
||||
}
|
||||
ESP_LOGW(TAG, "Rebooting to recovery to complete the installation");
|
||||
return guided_factory();
|
||||
return ESP_OK;
|
||||
if (!config_waitcommit()) {
|
||||
ESP_LOGW(TAG, "Unable to commit configuration. ");
|
||||
}
|
||||
ESP_LOGW(TAG, "Rebooting to recovery to complete the installation");
|
||||
return guided_factory();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user