mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 20:47:08 +03:00
Reduce system load when loading HTTP UI - release
This commit is contained in:
4
.github/workflows/CrossBuild.yml
vendored
4
.github/workflows/CrossBuild.yml
vendored
@@ -38,9 +38,9 @@ jobs:
|
|||||||
submodules: true
|
submodules: true
|
||||||
- name: Cache build
|
- name: Cache build
|
||||||
id: cache-build
|
id: cache-build
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: ${{github.workspace}}/build
|
path: build
|
||||||
key: ${{ runner.os }}-${{ matrix.node }}
|
key: ${{ runner.os }}-${{ matrix.node }}
|
||||||
- name: Set build parameters
|
- name: Set build parameters
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
static const char *TAG = "services";
|
static const char *TAG = "services";
|
||||||
const char *i2c_name_type="I2C";
|
const char *i2c_name_type="I2C";
|
||||||
const char *spi_name_type="SPI";
|
const char *spi_name_type="SPI";
|
||||||
static cJSON * gpio_list=NULL;
|
cJSON * gpio_list=NULL;
|
||||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||||
#ifndef QUOTE
|
#ifndef QUOTE
|
||||||
#define QUOTE(name) #name
|
#define QUOTE(name) #name
|
||||||
@@ -392,6 +392,80 @@ const i2c_config_t * config_i2c_get(int * i2c_port) {
|
|||||||
return &i2c;
|
return &i2c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const gpio_with_level_t * get_gpio_struct_member(const char * nvs_item, const char * name){
|
||||||
|
static gpio_with_level_t gpio_member={
|
||||||
|
.gpio=-1,
|
||||||
|
.level=0
|
||||||
|
};
|
||||||
|
if(!nvs_item) return &gpio_member;
|
||||||
|
const char * p=nvs_item;
|
||||||
|
char type[20]={0};
|
||||||
|
int match=0;
|
||||||
|
do {
|
||||||
|
if ((match=sscanf(p, "%d=%19[^,:]:%d", &gpio_member.gpio, type,&gpio_member.level)) >0 && (GPIO_IS_VALID_GPIO(gpio_member.gpio) || gpio_member.gpio==GPIO_NUM_NC) && strcasestr(type,name)){
|
||||||
|
return &gpio_member;
|
||||||
|
}
|
||||||
|
p = strchr(p, ',');
|
||||||
|
} while (p++);
|
||||||
|
gpio_member.gpio=-1;
|
||||||
|
gpio_member.level=0;
|
||||||
|
return &gpio_member;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HANDLE_GPIO_STRUCT_MEMBER(name,fixval) memcpy(&gpio_struct.name, get_gpio_struct_member(nvs_item, QUOTE(name)), sizeof(gpio_struct.name)); gpio_struct.name.fixed=fixval
|
||||||
|
#define ADD_GPIO_STRUCT_MEMBER_TO_ARRAY(array,structvar,name,type) if(((set_GPIO_struct_t *)structvar)->name.gpio>=0){cJSON_AddItemToArray(array,get_gpio_entry(QUOTE(name),type,((set_GPIO_struct_t *)structvar)->name.gpio, ((set_GPIO_struct_t *)structvar)->name.fixed));}
|
||||||
|
/****************************************************************************************
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const set_GPIO_struct_t * get_gpio_struct(){
|
||||||
|
static set_GPIO_struct_t gpio_struct;
|
||||||
|
char * nvs_item=config_alloc_get(NVS_TYPE_STR, "set_GPIO");
|
||||||
|
#ifdef CONFIG_LED_GREEN_GPIO_LEVEL
|
||||||
|
gpio_struct.green.level = CONFIG_LED_GREEN_GPIO_LEVEL;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_LED_GREEN_GPIO
|
||||||
|
gpio_struct.green.gpio = CONFIG_LED_GREEN_GPIO;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_LED_RED_GPIO_LEVEL
|
||||||
|
gpio_struct.green.level = CONFIG_LED_RED_GPIO_LEVEL;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_LED_RED_GPIO
|
||||||
|
gpio_struct.red.gpio = CONFIG_LED_RED_GPIO;
|
||||||
|
#endif
|
||||||
|
if(nvs_item){
|
||||||
|
HANDLE_GPIO_STRUCT_MEMBER(amp,false);
|
||||||
|
#ifndef CONFIG_LED_LOCKED
|
||||||
|
HANDLE_GPIO_STRUCT_MEMBER(green,false);
|
||||||
|
HANDLE_GPIO_STRUCT_MEMBER(red,false);
|
||||||
|
#endif
|
||||||
|
HANDLE_GPIO_STRUCT_MEMBER(jack,false);
|
||||||
|
HANDLE_GPIO_STRUCT_MEMBER(spkfault,false);
|
||||||
|
HANDLE_GPIO_STRUCT_MEMBER(vcc,false);
|
||||||
|
HANDLE_GPIO_STRUCT_MEMBER(gnd,false);
|
||||||
|
HANDLE_GPIO_STRUCT_MEMBER(ir,false);
|
||||||
|
free(nvs_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_LED_LOCKED
|
||||||
|
gpio_struct.red.locked=true;
|
||||||
|
gpio_struct.green.locked=true;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_JACK_LOCKED
|
||||||
|
gpio_struct.jack.gpio=CONFIG_JACK_GPIO
|
||||||
|
gpio_struct.jack.fixed=true;
|
||||||
|
gpio_struct.jack.level=CONFIG_JACK_GPIO_LEVEL;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_SPKFAULT_LOCKED
|
||||||
|
gpio_struct.spkfault.gpio=CONFIG_SPKFAULT_GPIO
|
||||||
|
gpio_struct.spkfault.fixed=true;
|
||||||
|
gpio_struct.spkfault.level=CONFIG_SPKFAULT_GPIO_LEVEL;
|
||||||
|
#endif
|
||||||
|
return &gpio_struct;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -448,55 +522,34 @@ cJSON * get_gpio_entry(const char * name, const char * prefix, int gpio, bool fi
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
cJSON * add_gpio_for_name(cJSON * list,const char * nvs_entry,const char * name, const char * prefix, bool fixed){
|
||||||
|
cJSON * llist = list?list:cJSON_CreateArray();
|
||||||
|
char *p;
|
||||||
|
int gpioNum=0;
|
||||||
|
if ((p = strcasestr(nvs_entry, name)) != NULL) {
|
||||||
|
gpioNum = atoi(strchr(p, '=') + 1);
|
||||||
|
cJSON_AddItemToArray(llist,get_gpio_entry(name,prefix,gpioNum,fixed));
|
||||||
|
}
|
||||||
|
return llist;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
cJSON * get_GPIO_nvs_list(cJSON * list) {
|
cJSON * get_GPIO_nvs_list(cJSON * list) {
|
||||||
cJSON * ilist = list?list:cJSON_CreateArray();
|
cJSON * ilist = list?list:cJSON_CreateArray();
|
||||||
char *nvs_item, *p, type[16];
|
const set_GPIO_struct_t * gpios = get_gpio_struct();
|
||||||
int gpio;
|
ADD_GPIO_STRUCT_MEMBER_TO_ARRAY(ilist,gpios,vcc,"other");
|
||||||
bool fixed=false;
|
ADD_GPIO_STRUCT_MEMBER_TO_ARRAY(ilist,gpios,gnd,"other");
|
||||||
#ifdef CONFIG_JACK_LOCKED
|
ADD_GPIO_STRUCT_MEMBER_TO_ARRAY(ilist,gpios,amp,"other");
|
||||||
bool bFoundJack=false;
|
ADD_GPIO_STRUCT_MEMBER_TO_ARRAY(ilist,gpios,ir,"other");
|
||||||
#endif
|
ADD_GPIO_STRUCT_MEMBER_TO_ARRAY(ilist,gpios,jack,"other");
|
||||||
#ifdef CONFIG_SPKFAULT_LOCKED
|
ADD_GPIO_STRUCT_MEMBER_TO_ARRAY(ilist,gpios,green,"other");
|
||||||
bool bFoundSpkFault = false;
|
ADD_GPIO_STRUCT_MEMBER_TO_ARRAY(ilist,gpios,red,"other");
|
||||||
#endif
|
ADD_GPIO_STRUCT_MEMBER_TO_ARRAY(ilist,gpios,spkfault,"other");
|
||||||
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, "set_GPIO")) == NULL) return ilist;
|
|
||||||
p = nvs_item;
|
|
||||||
|
|
||||||
do {
|
|
||||||
fixed=false;
|
|
||||||
if (sscanf(p, "%d=%15[^,]", &gpio, type) > 0 && (GPIO_IS_VALID_GPIO(gpio) || gpio==GPIO_NUM_NC)){
|
|
||||||
#ifdef CONFIG_JACK_LOCKED
|
|
||||||
if(strcasecmp(type,"jack")==0){
|
|
||||||
fixed=true;
|
|
||||||
bFoundJack=true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_SPKFAULT_LOCKED
|
|
||||||
if(strcasecmp(type,"spkfault")==0){
|
|
||||||
fixed=true;
|
|
||||||
bFoundSpkFault=true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
cJSON_AddItemToArray(ilist,get_gpio_entry(type,"gpio", gpio, fixed));
|
|
||||||
}
|
|
||||||
p = strchr(p, ',');
|
|
||||||
} while (p++);
|
|
||||||
#ifdef CONFIG_JACK_LOCKED
|
|
||||||
if(!bFoundJack){
|
|
||||||
monitor_gpio_t *jack= get_jack_insertion_gpio();
|
|
||||||
cJSON_AddItemToArray(list,get_gpio_entry("jack", "other", jack->gpio, true));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_SPKFAULT_LOCKED
|
|
||||||
if(!bFoundSpkFault){
|
|
||||||
monitor_gpio_t *jack= get_spkfault_gpio();
|
|
||||||
cJSON_AddItemToArray(list,get_gpio_entry("spkfault", "other", jack->gpio, true));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
free(nvs_item);
|
|
||||||
return ilist;
|
return ilist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,47 +638,30 @@ cJSON * get_SPI_GPIO(cJSON * list){
|
|||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
cJSON * get_GPIO_from_string(const char * nvs_item, const char * prefix, cJSON * list, bool fixed){
|
cJSON * get_SPDIF_GPIO(cJSON * list, bool fixed){
|
||||||
cJSON * llist = list;
|
cJSON * llist = list?list:cJSON_CreateArray();
|
||||||
int gpio=0,offset=0,soffset=0,ret1=0,sret=0;
|
char * spdif_config = config_spdif_get_string();
|
||||||
|
if(spdif_config){
|
||||||
if(!llist){
|
llist = add_gpio_for_name(llist,spdif_config,"bck", "spdif", fixed);
|
||||||
llist = cJSON_CreateArray();
|
llist = add_gpio_for_name(llist,spdif_config,"ws", "spdif", fixed);
|
||||||
}
|
llist = add_gpio_for_name(llist,spdif_config,"do", "spdif", fixed);
|
||||||
const char *p=NULL;
|
free(spdif_config);
|
||||||
char type[16];
|
}
|
||||||
int slen=strlen(nvs_item)+1;
|
|
||||||
char * buf1=malloc(slen);
|
|
||||||
char * buf2=malloc(slen);
|
|
||||||
ESP_LOGD(TAG,"Parsing string %s",nvs_item);
|
|
||||||
p = strchr(nvs_item, ':');
|
|
||||||
p=p?p+1:nvs_item;
|
|
||||||
while((((ret1=sscanf(p, "%[^=]=%d%n", type,&gpio,&offset)) ==2) || ((sret=sscanf(p, "%[^=]=%[^, ],%n", buf1,buf2,&soffset)) > 0 )) && (offset || soffset)){
|
|
||||||
if(ret1==2 && (GPIO_IS_VALID_GPIO(gpio) || gpio==GPIO_NUM_NC)){
|
|
||||||
if(gpio>0){
|
|
||||||
cJSON_AddItemToArray(llist,get_gpio_entry(type,prefix,gpio,fixed));
|
|
||||||
}
|
|
||||||
p+=offset;
|
|
||||||
} else {
|
|
||||||
p+=soffset;
|
|
||||||
}
|
|
||||||
while(*p==' ' || *p==',') p++;
|
|
||||||
gpio=-1;
|
|
||||||
}
|
|
||||||
free(buf1);
|
|
||||||
free(buf2);
|
|
||||||
return llist;
|
return llist;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
cJSON * get_GPIO_from_nvs(const char * item, const char * prefix, cJSON * list, bool fixed){
|
cJSON * get_Rotary_GPIO(cJSON * list){
|
||||||
char * nvs_item=NULL;
|
cJSON * llist = list?list:cJSON_CreateArray();
|
||||||
cJSON * llist=list;
|
char *config = config_alloc_get_default(NVS_TYPE_STR, "rotary_config", NULL, 0);
|
||||||
if ((nvs_item = config_alloc_get(NVS_TYPE_STR, item)) == NULL) return list;
|
if(config){
|
||||||
llist = get_GPIO_from_string(nvs_item,prefix,list, fixed);
|
llist = add_gpio_for_name(llist,config,"A", "rotary", false);
|
||||||
free(nvs_item);
|
llist = add_gpio_for_name(llist,config,"B", "rotary", false);
|
||||||
|
llist = add_gpio_for_name(llist,config,"SW", "rotary", false);
|
||||||
|
free(config);
|
||||||
|
}
|
||||||
return llist;
|
return llist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,9 +723,7 @@ esp_err_t free_gpio_entry( gpio_entry_t ** gpio) {
|
|||||||
gpio_entry_t * get_gpio_by_no(int gpionum, bool refresh){
|
gpio_entry_t * get_gpio_by_no(int gpionum, bool refresh){
|
||||||
cJSON * gpio_header=NULL;
|
cJSON * gpio_header=NULL;
|
||||||
gpio_entry_t * gpio=NULL;
|
gpio_entry_t * gpio=NULL;
|
||||||
if(refresh){
|
get_gpio_list(refresh);
|
||||||
get_gpio_list();
|
|
||||||
}
|
|
||||||
cJSON_ArrayForEach(gpio_header,gpio_list)
|
cJSON_ArrayForEach(gpio_header,gpio_list)
|
||||||
{
|
{
|
||||||
if(get_gpio_structure(gpio_header, &gpio)==ESP_OK && gpio->gpio==gpionum){
|
if(get_gpio_structure(gpio_header, &gpio)==ESP_OK && gpio->gpio==gpionum){
|
||||||
@@ -704,10 +738,8 @@ gpio_entry_t * get_gpio_by_no(int gpionum, bool refresh){
|
|||||||
*/
|
*/
|
||||||
gpio_entry_t * get_gpio_by_name(char * name,char * group, bool refresh){
|
gpio_entry_t * get_gpio_by_name(char * name,char * group, bool refresh){
|
||||||
cJSON * gpio_header=NULL;
|
cJSON * gpio_header=NULL;
|
||||||
if(refresh){
|
|
||||||
get_gpio_list();
|
|
||||||
}
|
|
||||||
gpio_entry_t * gpio=NULL;
|
gpio_entry_t * gpio=NULL;
|
||||||
|
get_gpio_list(refresh);
|
||||||
cJSON_ArrayForEach(gpio_header,gpio_list)
|
cJSON_ArrayForEach(gpio_header,gpio_list)
|
||||||
{
|
{
|
||||||
if(get_gpio_structure(gpio_header, &gpio)==ESP_OK && strcasecmp(gpio->name,name)&& strcasecmp(gpio->group,group)){
|
if(get_gpio_structure(gpio_header, &gpio)==ESP_OK && strcasecmp(gpio->name,name)&& strcasecmp(gpio->group,group)){
|
||||||
@@ -809,12 +841,17 @@ cJSON * get_psram_gpio_list(cJSON * list){
|
|||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
cJSON * get_gpio_list() {
|
cJSON * get_gpio_list(bool refresh) {
|
||||||
gpio_num_t gpio_num;
|
gpio_num_t gpio_num;
|
||||||
|
if(gpio_list && !refresh){
|
||||||
|
return gpio_list;
|
||||||
|
}
|
||||||
|
|
||||||
if(gpio_list){
|
if(gpio_list){
|
||||||
cJSON_Delete(gpio_list);
|
cJSON_Delete(gpio_list);
|
||||||
}
|
}
|
||||||
gpio_list = cJSON_CreateArray();
|
gpio_list= cJSON_CreateArray();
|
||||||
|
|
||||||
#ifndef CONFIG_BAT_LOCKED
|
#ifndef CONFIG_BAT_LOCKED
|
||||||
char *bat_config = config_alloc_get_default(NVS_TYPE_STR, "bat_config", NULL, 0);
|
char *bat_config = config_alloc_get_default(NVS_TYPE_STR, "bat_config", NULL, 0);
|
||||||
if (bat_config) {
|
if (bat_config) {
|
||||||
@@ -835,10 +872,9 @@ cJSON * get_gpio_list() {
|
|||||||
cJSON_AddItemToArray(gpio_list,get_gpio_entry("bat","other",gpio_num,true));
|
cJSON_AddItemToArray(gpio_list,get_gpio_entry("bat","other",gpio_num,true));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
gpio_list = get_GPIO_nvs_list(gpio_list);
|
gpio_list=get_GPIO_nvs_list(gpio_list);
|
||||||
char * spdif_config = config_spdif_get_string();
|
gpio_list=get_SPDIF_GPIO(gpio_list,is_spdif_config_locked());
|
||||||
gpio_list=get_GPIO_from_string(spdif_config,"spdif", gpio_list, is_spdif_config_locked());
|
gpio_list=get_Rotary_GPIO(gpio_list);
|
||||||
free(spdif_config);
|
|
||||||
gpio_list=get_Display_GPIO(gpio_list);
|
gpio_list=get_Display_GPIO(gpio_list);
|
||||||
gpio_list=get_SPI_GPIO(gpio_list);
|
gpio_list=get_SPI_GPIO(gpio_list);
|
||||||
gpio_list=get_I2C_GPIO(gpio_list);
|
gpio_list=get_I2C_GPIO(gpio_list);
|
||||||
|
|||||||
@@ -39,6 +39,24 @@ typedef struct {
|
|||||||
int sda;
|
int sda;
|
||||||
int scl;
|
int scl;
|
||||||
} i2s_platform_config_t;
|
} i2s_platform_config_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int gpio;
|
||||||
|
int level;
|
||||||
|
bool fixed;
|
||||||
|
} gpio_with_level_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
gpio_with_level_t vcc;
|
||||||
|
gpio_with_level_t gnd;
|
||||||
|
gpio_with_level_t amp;
|
||||||
|
gpio_with_level_t ir;
|
||||||
|
gpio_with_level_t jack;
|
||||||
|
gpio_with_level_t green;
|
||||||
|
gpio_with_level_t red;
|
||||||
|
gpio_with_level_t spkfault;
|
||||||
|
} set_GPIO_struct_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool fixed;
|
bool fixed;
|
||||||
char * name;
|
char * name;
|
||||||
@@ -61,6 +79,6 @@ bool is_spdif_config_locked();
|
|||||||
esp_err_t free_gpio_entry( gpio_entry_t ** gpio);
|
esp_err_t free_gpio_entry( gpio_entry_t ** gpio);
|
||||||
gpio_entry_t * get_gpio_by_name(char * name,char * group, bool refresh);
|
gpio_entry_t * get_gpio_by_name(char * name,char * group, bool refresh);
|
||||||
gpio_entry_t * get_gpio_by_no(int gpionum, bool refresh);
|
gpio_entry_t * get_gpio_by_no(int gpionum, bool refresh);
|
||||||
cJSON * get_gpio_list();
|
cJSON * get_gpio_list(bool refresh);
|
||||||
bool is_dac_config_locked();
|
bool is_dac_config_locked();
|
||||||
bool are_statistics_enabled();
|
bool are_statistics_enabled();
|
||||||
@@ -584,7 +584,7 @@ esp_err_t config_get_handler(httpd_req_t *req){
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ESP_LOGD_LOC(TAG, "config json : %s",json );
|
ESP_LOGD_LOC(TAG, "config json : %s",json );
|
||||||
cJSON * gplist=get_gpio_list();
|
cJSON * gplist=get_gpio_list(false);
|
||||||
char * gpliststr=cJSON_PrintUnformatted(gplist);
|
char * gpliststr=cJSON_PrintUnformatted(gplist);
|
||||||
httpd_resp_sendstr_chunk(req,"{ \"gpio\":");
|
httpd_resp_sendstr_chunk(req,"{ \"gpio\":");
|
||||||
httpd_resp_sendstr_chunk(req,gpliststr);
|
httpd_resp_sendstr_chunk(req,gpliststr);
|
||||||
|
|||||||
Reference in New Issue
Block a user