Compare commits

...

7 Commits

Author SHA1 Message Date
Sebastien
5ff673ae7d Fix build issue - release 2020-09-08 17:11:52 -04:00
Sebastien
2eb995d621 Merge branch 'master-cmake' of https://github.com/sle118/squeezelite-esp32.git into master-cmake 2020-09-08 16:47:08 -04:00
Sebastien
573ddb6fda Bug fix - some values weren't passed back in the command call - release 2020-09-08 16:46:50 -04:00
Philippe G
708a3f9c4a small tweaks 2020-09-06 17:06:52 -07:00
Philippe G
a73c659a1e solving mistery of component made of external static libs only
(and I hate CMake)
2020-09-06 16:54:09 -07:00
Philippe G
b22143a3b6 typos 2020-09-06 00:49:04 -07:00
Sebastien
6195750b41 Minor fix to the UI and command line help text - release 2020-09-04 16:24:12 -04:00
8 changed files with 219 additions and 164 deletions

View File

@@ -1,6 +1,5 @@
idf_component_register(SRC_DIRS . idf_component_register(
INCLUDE_DIRS . ./inc inc/alac inc/FLAC inc/helix-aac inc/mad inc/ogg inc/opus inc/opusfile inc/resample16 inc/soxr inc/vorbis INCLUDE_DIRS . ./inc inc/alac inc/FLAC inc/helix-aac inc/mad inc/ogg inc/opus inc/opusfile inc/resample16 inc/soxr inc/vorbis
PRIV_REQUIRES newlib
) )
add_prebuilt_library(libmad lib/libmad.a) add_prebuilt_library(libmad lib/libmad.a)
@@ -9,16 +8,16 @@ add_prebuilt_library(libhelix-aac lib/libhelix-aac.a )
add_prebuilt_library(libvorbisidec lib/libvorbisidec.a ) add_prebuilt_library(libvorbisidec lib/libvorbisidec.a )
add_prebuilt_library(libogg lib/libogg.a ) add_prebuilt_library(libogg lib/libogg.a )
add_prebuilt_library(libalac lib/libalac.a ) add_prebuilt_library(libalac lib/libalac.a )
add_prebuilt_library(libremple16 lib/libresample16.a ) add_prebuilt_library(libresample16 lib/libresample16.a )
add_prebuilt_library(libopusfile lib/libopusfile.a ) add_prebuilt_library(libopusfile lib/libopusfile.a )
add_prebuilt_library(libopus lib/libopus.a ) add_prebuilt_library(libopus lib/libopus.a )
target_link_libraries(${COMPONENT_LIB} PRIVATE libmad)
target_link_libraries(${COMPONENT_LIB} PRIVATE libFLAC)
target_link_libraries(${COMPONENT_LIB} PRIVATE libhelix-aac)
target_link_libraries(${COMPONENT_LIB} PRIVATE libvorbisidec)
target_link_libraries(${COMPONENT_LIB} PRIVATE libogg) target_link_libraries(${COMPONENT_LIB} INTERFACE libmad)
target_link_libraries(${COMPONENT_LIB} PRIVATE libalac) target_link_libraries(${COMPONENT_LIB} INTERFACE libFLAC)
target_link_libraries(${COMPONENT_LIB} PRIVATE libremple16) target_link_libraries(${COMPONENT_LIB} INTERFACE libhelix-aac)
target_link_libraries(${COMPONENT_LIB} PRIVATE libopusfile) target_link_libraries(${COMPONENT_LIB} INTERFACE libvorbisidec)
target_link_libraries(${COMPONENT_LIB} PRIVATE libopus) target_link_libraries(${COMPONENT_LIB} INTERFACE libogg)
target_link_libraries(${COMPONENT_LIB} INTERFACE libalac)
target_link_libraries(${COMPONENT_LIB} INTERFACE libresample16)
target_link_libraries(${COMPONENT_LIB} INTERFACE libopusfile)
target_link_libraries(${COMPONENT_LIB} INTERFACE libopus)

View File

@@ -1,3 +0,0 @@
void dummy_obj() {
return;
}

View File

@@ -400,7 +400,7 @@ const char *display_conf_get_driver_name(char * driver){
/**************************************************************************************** /****************************************************************************************
* *
*/ */
char * display_get_supported_drivers(){ char * display_get_supported_drivers(void){
int total_size = 1; int total_size = 1;
char * supported_drivers=NULL; char * supported_drivers=NULL;
const char * separator = "|"; const char * separator = "|";

View File

@@ -39,4 +39,4 @@ void displayer_scroll(char *string, int speed, int pause);
void displayer_control(enum displayer_cmd_e cmd, ...); void displayer_control(enum displayer_cmd_e cmd, ...);
void displayer_metadata(char *artist, char *album, char *title); void displayer_metadata(char *artist, char *album, char *title);
void displayer_timer(enum displayer_time_e mode, int elapsed, int duration); void displayer_timer(enum displayer_time_e mode, int elapsed, int duration);
char * display_get_supported_drivers(); char * display_get_supported_drivers(void);

View File

@@ -30,7 +30,8 @@
#define NACK_VAL 0x1 /*!< I2C nack value */ #define NACK_VAL 0x1 /*!< I2C nack value */
static const char *TAG = "cmd_i2ctools"; static const char *TAG = "cmd_i2ctools";
#define NOT_OUTPUT "has input capabilities only"
#define NOT_GPIO "is not a GPIO"
static gpio_num_t i2c_gpio_sda = 19; static gpio_num_t i2c_gpio_sda = 19;
static gpio_num_t i2c_gpio_scl = 18; static gpio_num_t i2c_gpio_scl = 18;
static uint32_t i2c_frequency = 100000; static uint32_t i2c_frequency = 100000;
@@ -62,11 +63,12 @@ static struct {
} i2cdump_args; } i2cdump_args;
static struct { static struct {
struct arg_lit *load;
struct arg_int *port; struct arg_int *port;
struct arg_int *freq; struct arg_int *freq;
struct arg_int *sda; struct arg_int *sda;
struct arg_int *scl; struct arg_int *scl;
struct arg_lit *load;
struct arg_lit *clear;
struct arg_end *end; struct arg_end *end;
} i2cconfig_args; } i2cconfig_args;
@@ -371,7 +373,6 @@ static int do_i2c_show_display(int argc, char **argv){
static int do_i2c_set_display(int argc, char **argv) static int do_i2c_set_display(int argc, char **argv)
{ {
int width=0, height=0, address=60, back=-1, speed=8000000 ; int width=0, height=0, address=60, back=-1, speed=8000000 ;
int result = 0;
char * name = NULL; char * name = NULL;
char * driver= NULL; char * driver= NULL;
char config_string[200]={}; char config_string[200]={};
@@ -439,15 +440,12 @@ static int do_i2c_set_display(int argc, char **argv)
driver=strdup(i2cdisp_args.driver->sval[0]); driver=strdup(i2cdisp_args.driver->sval[0]);
} }
/* Check "--speed" option */
if (i2cdisp_args.speed->count) {
speed=i2cdisp_args.speed->ival[0];
}
/* Check "--back" option */ /* Check "--back" option */
if (i2cdisp_args.back->count) { if (i2cdisp_args.back->count) {
back=i2cdisp_args.back->ival[0]; back=i2cdisp_args.back->ival[0];
if(!GPIO_IS_VALID_OUTPUT_GPIO(back)){ if(!GPIO_IS_VALID_OUTPUT_GPIO(back)){
fprintf(f,"Invalid GPIO for back light: %d %s\n", back, GPIO_IS_VALID_GPIO(back)?"has input capabilities only":"is not a GPIO"); fprintf(f,"Invalid GPIO for back light: %d %s\n", back, GPIO_IS_VALID_GPIO(back)?NOT_OUTPUT:NOT_GPIO );
back=-1; back=-1;
nerrors ++; nerrors ++;
} }
@@ -455,6 +453,20 @@ static int do_i2c_set_display(int argc, char **argv)
if(!name) name = strdup("I2C"); if(!name) name = strdup("I2C");
/* Check "--speed" option */
if (i2cdisp_args.speed->count) {
speed=i2cdisp_args.speed->ival[0];
}
else {
if(strcasestr(name,"I2C")){
speed = 250000;
}
else {
speed = 8000000;
}
}
if(!driver) driver = strdup("SSD1306"); if(!driver) driver = strdup("SSD1306");
@@ -478,29 +490,40 @@ static int do_i2c_set_display(int argc, char **argv)
name,back,speed,width,height,address,driver,rotate || i2cdisp_args.hflip->count?",HFlip":"",rotate || i2cdisp_args.vflip->count?",VFlip":"" ); name,back,speed,width,height,address,driver,rotate || i2cdisp_args.hflip->count?",HFlip":"",rotate || i2cdisp_args.vflip->count?",VFlip":"" );
fprintf(f,"Updating display configuration string configuration to :\n" fprintf(f,"Updating display configuration string configuration to :\n"
"display_config = \"%s\"",config_string ); "display_config = \"%s\"",config_string );
result = config_set_value(NVS_TYPE_STR, "display_config", config_string)!=ESP_OK; nerrors = config_set_value(NVS_TYPE_STR, "display_config", config_string)!=ESP_OK;
}
else {
result = 1;
} }
FREE_AND_NULL(name); FREE_AND_NULL(name);
FREE_AND_NULL(driver); FREE_AND_NULL(driver);
fflush (f); fflush (f);
log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf); log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
fclose(f); fclose(f);
FREE_AND_NULL(buf); FREE_AND_NULL(buf);
return result; return nerrors==0;
} }
static int do_i2cconfig_cmd(int argc, char **argv) static int do_i2cconfig_cmd(int argc, char **argv)
{ {
esp_err_t err=ESP_OK; esp_err_t err=ESP_OK;
int res=0;
char * err_message=malloc(1);
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cconfig_args); int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cconfig_args);
if (nerrors != 0) { if (nerrors != 0) {
return 0; return 0;
} }
/* Check "--clear" option */
if (i2cconfig_args.clear->count) {
log_send_messaging(MESSAGING_WARNING,"i2c config cleared");
config_set_value(NVS_TYPE_STR, "i2c_config", "");
return 0;
}
char *buf = NULL;
size_t buf_size = 0;
FILE *f = open_memstream(&buf, &buf_size);
if (f == NULL) {
log_send_messaging(MESSAGING_ERROR,"Unable to open memory stream.");
return 0;
}
/* Check "--load" option */ /* Check "--load" option */
if (i2cconfig_args.load->count) { if (i2cconfig_args.load->count) {
log_send_messaging(MESSAGING_WARNING,"Loading i2c config"); log_send_messaging(MESSAGING_WARNING,"Loading i2c config");
@@ -511,8 +534,8 @@ static int do_i2cconfig_cmd(int argc, char **argv)
/* Check "--port" option */ /* Check "--port" option */
if (i2cconfig_args.port->count) { if (i2cconfig_args.port->count) {
if (i2c_get_port(i2cconfig_args.port->ival[0], &i2c_port) != ESP_OK) { if (i2c_get_port(i2cconfig_args.port->ival[0], &i2c_port) != ESP_OK) {
log_send_messaging(MESSAGING_ERROR, "Invalid port %u ",i2cconfig_args.port->ival[0]); fprintf(f,"Invalid port %u \n",i2cconfig_args.port->ival[0]);
return 1; nerrors ++;
} }
} }
/* Check "--freq" option */ /* Check "--freq" option */
@@ -522,60 +545,67 @@ static int do_i2cconfig_cmd(int argc, char **argv)
if (i2cconfig_args.sda->count){ if (i2cconfig_args.sda->count){
/* Check "--sda" option */ /* Check "--sda" option */
i2c_gpio_sda = i2cconfig_args.sda->ival[0]; i2c_gpio_sda = i2cconfig_args.sda->ival[0];
if(!GPIO_IS_VALID_OUTPUT_GPIO(i2c_gpio_sda )){
fprintf(f,"Invalid SDA gpio: %d %s\n", i2c_gpio_sda , GPIO_IS_VALID_GPIO(i2c_gpio_sda )?NOT_OUTPUT:NOT_GPIO );
nerrors ++;
}
} }
else { else {
REALLOC_CAT(err_message,"Missing --sda option."); fprintf(f,"Missing SDA GPIO\n");
res=1; nerrors ++;
} }
if (i2cconfig_args.scl->count){ if (i2cconfig_args.scl->count){
/* Check "--sda" option */ /* Check "--scl" option */
i2c_gpio_scl = i2cconfig_args.scl->ival[0]; i2c_gpio_scl = i2cconfig_args.scl->ival[0];
if(!GPIO_IS_VALID_OUTPUT_GPIO(i2c_gpio_scl )){
fprintf(f,"Invalid SCL gpio: %d %s\n", i2c_gpio_scl , GPIO_IS_VALID_GPIO(i2c_gpio_scl )?NOT_OUTPUT:NOT_GPIO );
nerrors ++;
}
} }
else { else {
REALLOC_CAT(err_message,"Missing --scl option."); fprintf(f,"Missing SCL GPIO\n");
res=1; nerrors ++;
} }
} }
#ifdef CONFIG_SQUEEZEAMP #ifdef CONFIG_SQUEEZEAMP
if (i2c_port == I2C_NUM_0) { if (i2c_port == I2C_NUM_0) {
i2c_port = I2C_NUM_1; i2c_port = I2C_NUM_1;
log_send_messaging(MESSAGING_ERROR, "can't use i2c port 0 on SqueezeAMP. Changing to port 1."); fprintf(f,"can't use i2c port 0 on SqueezeAMP. Changing to port 1.\n");
} }
#endif #endif
if(!res){ if(!nerrors){
log_send_messaging(MESSAGING_INFO,"Uninstall i2c driver from port %u if needed",i2c_port); fprintf(f,"Uninstalling i2c driver from port %u if needed\n",i2c_port);
if(is_i2c_started(i2c_port)){ if(is_i2c_started(i2c_port)){
if((err=i2c_driver_delete(i2c_port))!=ESP_OK){ if((err=i2c_driver_delete(i2c_port))!=ESP_OK){
log_send_messaging(MESSAGING_ERROR, "i2c driver delete failed. %s", esp_err_to_name(err)); fprintf(f,"i2c driver delete failed. %s\n", esp_err_to_name(err));
res = 1; nerrors++;
} }
} }
} }
if(!res){ if(!nerrors){
log_send_messaging(MESSAGING_INFO, "Initializing driver with config scl=%u sda=%u speed=%u port=%u",i2c_gpio_scl,i2c_gpio_sda,i2c_frequency,i2c_port); fprintf(f,"Initializing driver with config scl=%u sda=%u speed=%u port=%u\n",i2c_gpio_scl,i2c_gpio_sda,i2c_frequency,i2c_port);
if((err=i2c_master_driver_initialize())==ESP_OK){ if((err=i2c_master_driver_initialize())==ESP_OK){
log_send_messaging(MESSAGING_INFO, "Initalize success."); fprintf(f,"Initalize success.\n");
// now start the i2c driver // now start the i2c driver
log_send_messaging(MESSAGING_INFO,"Starting the i2c driver."); fprintf(f,"Starting the i2c driver.");
if((err=i2c_master_driver_install())!=ESP_OK){ if((err=i2c_master_driver_install())!=ESP_OK){
log_send_messaging(MESSAGING_ERROR,"I2C master driver install failed. %s", esp_err_to_name(err)); fprintf(f,"I2C master driver install failed. %s\n", esp_err_to_name(err));
res=1; nerrors++;
} }
else else
{ {
log_send_messaging(MESSAGING_INFO,"i2c driver successfully started."); fprintf(f,"i2c driver successfully started.\n");
} }
} }
else { else {
log_send_messaging(MESSAGING_ERROR,"I2C initialization failed. %s", esp_err_to_name(err)); fprintf(f,"I2C initialization failed. %s\n", esp_err_to_name(err));
res=1; nerrors++;
} }
} }
if(!res && !i2cconfig_args.load->count){ if(!nerrors && !i2cconfig_args.load->count){
log_send_messaging(MESSAGING_INFO,"Storing i2c parameters."); fprintf(f,"Storing i2c parameters.\n");
i2c_config_t config={ i2c_config_t config={
.mode = I2C_MODE_MASTER, .mode = I2C_MODE_MASTER,
.sda_io_num = i2c_gpio_sda, .sda_io_num = i2c_gpio_sda,
@@ -586,11 +616,12 @@ static int do_i2cconfig_cmd(int argc, char **argv)
}; };
config_i2c_set(&config, i2c_port); config_i2c_set(&config, i2c_port);
} }
if(res){ fflush (f);
log_send_messaging(MESSAGING_ERROR,"%s", err_message); log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
} fclose(f);
free(err_message); FREE_AND_NULL(buf);
return res;
return nerrors==0;
} }
#define RUN_SHOW_ERROR(c) #define RUN_SHOW_ERROR(c)
@@ -927,7 +958,7 @@ static void register_i2c_set_display(){
i2cdisp_args.vflip = arg_lit0(NULL, "vf", "Flip picture vertically"); i2cdisp_args.vflip = arg_lit0(NULL, "vf", "Flip picture vertically");
i2cdisp_args.rotate = arg_lit0("r", "rotate", "Rotate the picture 180 deg"); i2cdisp_args.rotate = arg_lit0("r", "rotate", "Rotate the picture 180 deg");
i2cdisp_args.back = arg_int0("b", "back", "<n>","Backlight GPIO (if applicable)"); i2cdisp_args.back = arg_int0("b", "back", "<n>","Backlight GPIO (if applicable)");
i2cdisp_args.speed = arg_int0("s", "speed", "<n>","Default speed is 8000000 (8MHz) but SPI can work up to 26MHz or even 40MHz"); i2cdisp_args.speed = arg_int0("s", "speed", "<n>","Default speed is 8000000 (8MHz) for SPI and 250000 for I2C. The SPI interface can work up to 26MHz~40MHz");
i2cdisp_args.end = arg_end(8); i2cdisp_args.end = arg_end(8);
const esp_console_cmd_t i2c_set_display= { const esp_console_cmd_t i2c_set_display= {
.command = "setdisplay", .command = "setdisplay",
@@ -1060,6 +1091,7 @@ cJSON * i2config_cb(){
} }
static void register_i2cconfig(void) static void register_i2cconfig(void)
{ {
i2cconfig_args.clear = arg_lit0(NULL, "clear", "clear configuration and return");
i2cconfig_args.port = arg_int0("p", "port", "0|1", "Set the I2C bus port number"); i2cconfig_args.port = arg_int0("p", "port", "0|1", "Set the I2C bus port number");
i2cconfig_args.freq = arg_int0("f", "freq", "int", "Set the frequency(Hz) of I2C bus. e.g. 100000"); i2cconfig_args.freq = arg_int0("f", "freq", "int", "Set the frequency(Hz) of I2C bus. e.g. 100000");
i2cconfig_args.sda = arg_int0("d", "sda", "int", "Set the gpio for I2C SDA. e.g. 19"); i2cconfig_args.sda = arg_int0("d", "sda", "int", "Set the gpio for I2C SDA. e.g. 19");

View File

@@ -1,6 +1,6 @@
idf_component_register(SRC_DIRS . idf_component_register(SRC_DIRS .
INCLUDE_DIRS . ${IDF_PATH}/components/driver INCLUDE_DIRS . ${IDF_PATH}/components/driver
REQUIRES json tools platform_config display REQUIRES json tools platform_config display
) )

View File

@@ -65,7 +65,17 @@ var RefreshAPIIntervalActive = false;
var LastRecoveryState=null; var LastRecoveryState=null;
var LastCommandsState=null; var LastCommandsState=null;
var output = ''; var output = '';
function delay_msg(t, v) {
return new Promise(function(resolve) {
setTimeout(resolve.bind(null, v), t)
});
}
Promise.prototype.delay = function(t) {
return this.then(function(v) {
return delay_msg(t, v);
});
}
function stopCheckStatusInterval(){ function stopCheckStatusInterval(){
if(checkStatusInterval != null){ if(checkStatusInterval != null){
clearTimeout(checkStatusInterval); clearTimeout(checkStatusInterval);
@@ -1024,34 +1034,37 @@ function checkStatus(){
function runCommand(button,reboot) { function runCommand(button,reboot) {
pardiv = button.parentNode.parentNode; pardiv = button.parentNode.parentNode;
fields=document.getElementById("flds-"+button.value); cmdstring = button.attributes.cmdname.value;
cmdstring=button.value+' '; fields=document.getElementById("flds-"+cmdstring);
cmdstring+=' ';
if(fields){ if(fields){
hint = pardiv.hint; hint = pardiv.hint;
allfields=fields.getElementsByTagName("input"); allfields=fields.querySelectorAll("select,input");
for (i = 0; i < allfields.length; i++) { for (i = 0; i < allfields.length; i++) {
attr=allfields[i].attributes; attr=allfields[i].attributes;
qts=''; qts='';
opt=''; opt='';
optspacer=' '; optspacer=' ';
isSelect=allfields[i].attributes?.class?.value=="custom-select";
if (attr.longopts.value!== "undefined"){ if(( isSelect && allfields[i].selectedIndex != 0 )|| !isSelect ){
opt+= '--' + attr.longopts.value; if (attr.longopts.value!== "undefined"){
optspacer='='; opt+= '--' + attr.longopts.value;
} optspacer='=';
else if(attr.shortopts.value!== "undefined"){ }
opt= '-' + attr.shortopts.value; else if(attr.shortopts.value!== "undefined"){
} opt= '-' + attr.shortopts.value;
}
if(attr.hasvalue.value== "true" ){
if(allfields[i].value!=''){ if(attr.hasvalue.value== "true" ){
qts = (/\s/.test(allfields[i].value))?'"':''; if(allfields[i].value!=''){
cmdstring+=opt+optspacer+qts +allfields[i].value +qts+ ' '; qts = (/\s/.test(allfields[i].value))?'"':'';
cmdstring+=opt+optspacer+qts +allfields[i].value +qts+ ' ';
}
}
else {
// this is a checkbox
if(allfields[i].checked) cmdstring+=opt+ ' ';
} }
}
else {
// this is a checkbox
if(allfields[i].checked) cmdstring+=opt+ ' ';
} }
} }
} }
@@ -1093,6 +1106,10 @@ function runCommand(button,reboot) {
}, },
complete: function(response) { complete: function(response) {
console.log('reboot call completed'); console.log('reboot call completed');
Promise.resolve().delay(5000).then(function(v) {
console.log('Getting updated commands');
getCommands();
});
} }
}); });
} }
@@ -1106,81 +1123,94 @@ function getCommands() {
$.getJSON("/commands.json", function(data) { $.getJSON("/commands.json", function(data) {
console.log(data); console.log(data);
var advancedtabhtml=''; var advancedtabhtml='';
data.commands.forEach(function(command) { data.commands.forEach(function(command) {
isConfig=($('#'+command.name+'-list').length>0); if($("#flds-"+command.name).length == 0){
innerhtml=''; isConfig=($('#'+command.name+'-list').length>0);
innerhtml+='<tr><td>'+(isConfig?'<h1>':''); innerhtml='';
innerhtml+=escapeHTML(command.help).replace(/\n/g, '<br />')+(isConfig?'</h1>':'<br>'); innerhtml+='<tr><td>'+(isConfig?'<h1>':'');
innerhtml+='<div >'; innerhtml+=escapeHTML(command.help).replace(/\n/g, '<br />')+(isConfig?'</h1>':'<br>');
if(command.hasOwnProperty("argtable")){ innerhtml+='<div >';
innerhtml+='<table class="table table-hover" id="flds-'+command.name+'"><tbody>'; if(command.hasOwnProperty("argtable")){
command.argtable.forEach(function (arg){ innerhtml+='<table class="table table-hover" id="flds-'+command.name+'"><tbody>';
placeholder=arg?.datatype || ''; command.argtable.forEach(function (arg){
ctrlname=command.name+'-'+arg.longopts; placeholder=arg?.datatype || '';
curvalue=data.values?.[command.name]?.[arg.longopts] || ''; ctrlname=command.name+'-'+arg.longopts;
innerhtml+="<tr>"; curvalue=data.values?.[command.name]?.[arg.longopts] || '';
var attributes ='datatype="'+arg.datatype+'" '; innerhtml+="<tr>";
attributes+='hasvalue='+arg.hasvalue+' '; var attributes ='datatype="'+arg.datatype+'" ';
attributes+='longopts="'+arg.longopts+'" '; attributes+='hasvalue='+arg.hasvalue+' ';
attributes+='shortopts="'+arg.shortopts+'" '; attributes+='longopts="'+arg.longopts+'" ';
attributes+='checkbox='+arg.checkbox+' '; attributes+='shortopts="'+arg.shortopts+'" ';
attributes+='checkbox='+arg.checkbox+' ';
attributes+='cmdname="'+command.name+'" ';
if(placeholder.includes('|')){ attributes+= 'id="'+ctrlname+'" name="'+ctrlname+'" placeholder="'+placeholder+'" hasvalue="'+arg.hasvalue+'" ';
placeholder = placeholder.replace('<','').replace('>','');
innerhtml+='<td><select name="'+ctrlname+'" ';
innerhtml+=attributes;
innerhtml+=' class="custom-select">';
innerhtml+='<option '+(curvalue.length>0?'value':'selected')+'>'+arg.glossary+'</option>'
placeholder.split('|').forEach(function(choice){
innerhtml+='<option '+(curvalue.length>0&&curvalue==choice?'selected':'value')+'="'+choice+'">'+choice+'</option>';
});
innerhtml+='</select></td>';
}
else {
ctrltype="text";
if(arg.checkbox){
ctrltype="checkbox";
}
innerhtml+='<td><label for="'+ctrlname+'">'+ arg.glossary+'</label></td>';
innerhtml+='<td><input type="'+ctrltype+'" id="'+ctrlname+'" name="'+ctrlname+'" placeholder="'+placeholder+'" hasvalue="'+arg.hasvalue+'" ';
innerhtml+=attributes;
if(arg.checkbox){
if(data.values?.[command.name]?.[arg.longopts] ){
innerhtml+='checked=true ';
}
else{
innerhtml+='checked=false ';
}
innerhtml+='></input></td>';
if(placeholder.includes('|')){
placeholder = placeholder.replace('<','').replace('>','');
innerhtml+='<td><select ';
innerhtml+=attributes;
innerhtml+=' class="custom-select">';
innerhtml+='<option '+(curvalue.length>0?'value':'selected')+'>'+arg.glossary+'</option>'
placeholder.split('|').forEach(function(choice){
innerhtml+='<option '+(curvalue.length>0&&curvalue==choice?'selected':'value')+'="'+choice+'">'+choice+'</option>';
});
innerhtml+='</select></td>';
} }
else { else {
innerhtml+='value="'+curvalue+'" '; ctrltype="text";
innerhtml+='></input></td>'+ curvalue.length>0?'<td>last: '+curvalue+'</td>':''; if(arg.checkbox){
ctrltype="checkbox";
}
innerhtml+='<td><label for="'+ctrlname+'">'+ arg.glossary+'</label></td>';
innerhtml+='<td><input type="'+ctrltype+'"';
innerhtml+=attributes;
if(arg.checkbox){
if(data.values?.[command.name]?.[arg.longopts] ){
innerhtml+='checked ';
}
innerhtml+='></input></td>';
}
else {
innerhtml+='value="'+curvalue+'" ';
innerhtml+='></input></td>'+ curvalue.length>0?'<td>last: '+curvalue+'</td>':'';
}
} }
} innerhtml+="</tr>";
innerhtml+="</tr>"; });
}); innerhtml+='</tbody></table>';
innerhtml+='</tbody></table>';
}
} if(isConfig){
if(isConfig){ innerhtml+='<div class="buttons"><input id="btn-'+ command.name + '" type="button" class="btn btn-success" cmdname="'+command.name+'" value="Save" onclick="runCommand(this,false);">';
innerhtml+='<div class="buttons"><input id="btn-'+ command.name + '" type="button" class="btn btn-success" value="Save" onclick="runCommand(this,false);">'; innerhtml+='<input id="btn-'+ command.name + '-apply" type="button" class="btn btn-success" cmdname="'+command.name+'" value="Apply" onclick="runCommand(this,true);"></div></div><td></tr>';
innerhtml+='<input id="btn-'+ command.name + '-apply" type="button" class="btn btn-success" value="Apply" onclick="runCommand(this,true);"></div></div><td></tr>'; $('#'+command.name+'-list').append(innerhtml);
$('#'+command.name+'-list').append(innerhtml); }
} else {
else { advancedtabhtml+='<br>'+innerhtml;
advancedtabhtml+='<br>'+innerhtml; advancedtabhtml+='<div class="buttons"><input id="btn-'+ command.name + '" type="button" class="btn btn-danger btn-sm" cmdname="'+command.name+'" value="'+command.name+'" onclick="runCommand(this, false);"></div></div><td></tr>';
advancedtabhtml+='<div class="buttons"><input id="btn-'+ command.name + '" type="button" class="btn btn-danger btn-sm" value="'+command.name+'" onclick="runCommand(this);"></div></div><td></tr>'; }
} }
});
});
$("#commands-list").append(advancedtabhtml); $("#commands-list").append(advancedtabhtml);
data.commands.forEach(function(command) {
if(command.hasOwnProperty("argtable")){
command.argtable.forEach(function (arg){
ctrlselector='#'+command.name+'-'+arg.longopts;
if(arg.checkbox){
$(ctrlselector)[0].checked=data.values?.[command.name]?.[arg.longopts];
}
else {
$(ctrlselector)[0].value=data.values?.[command.name]?.[arg.longopts] || '';
}
});
}
});
}) })
.fail(function(xhr, ajaxOptions, thrownError) { .fail(function(xhr, ajaxOptions, thrownError) {
@@ -1248,7 +1278,6 @@ function getConfig() {
}); });
} }
function showMessage(message, severity, age=0) { function showMessage(message, severity, age=0) {
if (severity == 'MESSAGING_INFO') { if (severity == 'MESSAGING_INFO') {
$('#message').css('background', '#6af'); $('#message').css('background', '#6af');
@@ -1259,7 +1288,7 @@ function showMessage(message, severity, age=0) {
} else { } else {
$('#message').css('background', '#f00'); $('#message').css('background', '#f00');
} }
$('#message').html(message); $('#message').html(message);
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
$("#content").fadeTo("slow", 0.3, function() { $("#content").fadeTo("slow", 0.3, function() {
@@ -1278,5 +1307,5 @@ function inRange(x, min, max) {
} }
function sleep(ms) { function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }

View File

@@ -68,7 +68,7 @@
<a class="nav-link" data-toggle="tab" href="#tab-firmware">Firmware</a> <a class="nav-link" data-toggle="tab" href="#tab-firmware">Firmware</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-setdisplay">Display</a> <a class="nav-link" data-toggle="tab" href="#tab-setdisplay">Configuration</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-syslog">Syslog</a> <a class="nav-link" data-toggle="tab" href="#tab-syslog">Syslog</a>
@@ -83,8 +83,7 @@
<a class="nav-link" data-toggle="tab" href="#tab-credits">Credits</a> <a class="nav-link" data-toggle="tab" href="#tab-credits">Credits</a>
</li> </li>
</ul> </ul>
<div id="message"></div> <div id="message"></div>
<div id="content"> <div id="content">
<div id="myTabContent" class="tab-content"> <div id="myTabContent" class="tab-content">
<div class="tab-pane fade active show" id="tab-wifi"> <div class="tab-pane fade active show" id="tab-wifi">
@@ -199,10 +198,9 @@
</div> </div>
</div> <!-- wifi --> </div> <!-- wifi -->
<div class="tab-pane fade" id="tab-setdisplay"> <div class="tab-pane fade" id="tab-setdisplay">
<table class="table table-hover" id="setdisplay-table"> <table class="table table-hover" id="setdisplay-table"><tbody id="setdisplay-list"></tbody></table>
<tbody id="setdisplay-list"> <table class="table table-hover" id="i2cconfig-table"><tbody id="i2cconfig-list"></tbody></table>
</tbody> <table class="table table-hover" id="spiset-table"><tbody id="spiset-list"></tbody></table>
</table>
</div> <!-- display --> </div> <!-- display -->
<div class="tab-pane fade" id="tab-audio"> <div class="tab-pane fade" id="tab-audio">