mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 11:36:59 +03:00
Major UI Update
- Bug fixes - Jack doesn't show as plugged in if no jack detection is configured - New layout - Updated jQuery to latest version - Updated bootstrap to latest version - Updated the command processing backend to support UI interactions - Added a number of accessors to normalize read/update various configuration entries - Added more GPIOs to the status tab GPIO list - Added several configuration sections for hardware and system - Removed pop-over windows from system messages - Added a message count pill to the status tab - Added support for message count pill based on the highest severity - Updated the message list table to set colours based on messages severity - Added command processing message area close to the action buttons to provide feedback from running the commands
This commit is contained in:
@@ -5,6 +5,7 @@ idf_component_register( SRCS
|
||||
cmd_system.c
|
||||
cmd_wifi.c
|
||||
platform_console.c
|
||||
cmd_config.c
|
||||
INCLUDE_DIRS .
|
||||
REQUIRES nvs_flash
|
||||
PRIV_REQUIRES console app_update tools services spi_flash platform_config vfs pthread wifi-manager platform_config newlib telnet display )
|
||||
|
||||
535
components/platform_console/cmd_config.c
Normal file
535
components/platform_console/cmd_config.c
Normal file
@@ -0,0 +1,535 @@
|
||||
/* cmd_i2ctools.c
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
|
||||
#include <stdio.h>
|
||||
#include "cmd_config.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "platform_console.h"
|
||||
#include "esp_log.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "platform_config.h"
|
||||
#include "trace.h"
|
||||
#include "messaging.h"
|
||||
#include "accessors.h"
|
||||
|
||||
const char * desc_squeezelite ="Squeezelite Options";
|
||||
const char * desc_dac= "DAC Options";
|
||||
const char * desc_spdif= "SPDIF Options";
|
||||
|
||||
|
||||
#define CODECS_BASE "flac,pcm,mp3,ogg"
|
||||
#if NO_FAAD
|
||||
#define CODECS_AAC ""
|
||||
#else
|
||||
#define CODECS_AAC ",aac"
|
||||
#endif
|
||||
#if FFMPEG
|
||||
#define CODECS_FF ",wma,alac"
|
||||
#else
|
||||
#define CODECS_FF ""
|
||||
#endif
|
||||
#if DSD
|
||||
#define CODECS_DSD ",dsd"
|
||||
#else
|
||||
#define CODECS_DSD ""
|
||||
#endif
|
||||
#define CODECS_MP3 " (mad,mpg for specific mp3 codec)"
|
||||
|
||||
#define CODECS CODECS_BASE CODECS_AAC CODECS_FF CODECS_DSD CODECS_MP3
|
||||
#define NOT_OUTPUT "has input capabilities only"
|
||||
#define NOT_GPIO "is not a GPIO"
|
||||
|
||||
static const char *TAG = "cmd_config";
|
||||
extern struct arg_end *getParmsEnd(struct arg_hdr * * argtable);
|
||||
//bck=<gpio>,ws=<gpio>,do=<gpio>[,mute=<gpio>[:0|1][,model=TAS57xx|TAS5713|AC101|I2S][,sda=<gpio>,scl=gpio[,i2c=<addr>]]
|
||||
static struct {
|
||||
struct arg_str *model_name;
|
||||
struct arg_int *clock;
|
||||
struct arg_int *wordselect;
|
||||
struct arg_int *data;
|
||||
struct arg_int *mute_gpio;
|
||||
struct arg_lit *mute_level;
|
||||
struct arg_int *dac_sda;
|
||||
struct arg_int *dac_scl;
|
||||
struct arg_int *dac_i2c;
|
||||
struct arg_lit *clear;
|
||||
struct arg_end *end;
|
||||
} i2s_args;
|
||||
static struct {
|
||||
struct arg_int *clock;
|
||||
struct arg_int *wordselect;
|
||||
struct arg_int *data;
|
||||
struct arg_lit *clear;
|
||||
struct arg_end *end;
|
||||
} spdif_args;
|
||||
static struct {
|
||||
struct arg_str * server; // -s <server>[:<port>]\tConnect to specified server, otherwise uses autodiscovery to find server\n"
|
||||
struct arg_str * buffers;// " -b <stream>:<output>\tSpecify internal Stream and Output buffer sizes in Kbytes\n"
|
||||
struct arg_str * codecs;// " -c <codec1>,<codec2>\tRestrict codecs to those specified, otherwise load all available codecs; known codecs: " CODECS "\n"
|
||||
struct arg_int * timeout;// " -C <timeout>\t\tClose output device when idle after timeout seconds, default is to keep it open while player is 'on'\n"
|
||||
struct arg_str * log_level; // " -d <log>=<level>\tSet logging level, logs: all|slimproto|stream|decode|output|ir, level: info|debug|sdebug\n"
|
||||
// struct arg_str * log_level_all; // " -d <log>=<level>\tSet logging level, logs: all|slimproto|stream|decode|output|ir, level: info|debug|sdebug\n"
|
||||
// struct arg_str * log_level_slimproto; // " -d <log>=<level>\tSet logging level, logs: all|slimproto|stream|decode|output|ir, level: info|debug|sdebug\n"
|
||||
// struct arg_str * log_level_stream;
|
||||
// struct arg_str * log_level_decode;
|
||||
// struct arg_str * log_level_output;
|
||||
#if IR
|
||||
struct arg_str * log_level_ir;
|
||||
#endif
|
||||
struct arg_str * output_device; // " -d <log>=<level>\tSet logging level, logs: all|slimproto|stream|decode|output|ir, level: info|debug|sdebug\n"
|
||||
// " -e <codec1>,<codec2>\tExplicitly exclude native support of one or more codecs; known codecs: " CODECS "\n"
|
||||
// " -f <logfile>\t\tWrite debug to logfile\n"
|
||||
// #if IR
|
||||
// " -i [<filename>]\tEnable lirc remote control support (lirc config file ~/.lircrc used if filename not specified)\n"
|
||||
// #endif
|
||||
struct arg_str * mac_addr; // " -m <mac addr>\t\tSet mac address, format: ab:cd:ef:12:34:56\n"
|
||||
struct arg_str * model_name;// " -M <modelname>\tSet the squeezelite player model name sent to the server (default: " MODEL_NAME_STRING ")\n"
|
||||
struct arg_str * name;// " -n <name>\t\tSet the player name\n"
|
||||
struct arg_lit * header_format;// " -W\t\t\tRead wave and aiff format from header, ignore server parameters\n"
|
||||
struct arg_str * rates; // " -r <rates>[:<delay>]\tSample rates supported, allows output to be off when squeezelite is started; rates = <maxrate>|<minrate>-<maxrate>|<rate1>,<rate2>,<rate3>; delay = optional delay switching rates in ms\n"
|
||||
#if RESAMPLE
|
||||
struct arg_lit * resample;
|
||||
struct arg_str * resample_parms; //" -R -u [params]\tResample, params = <recipe>:<flags>:<attenuation>:<precision>:<passband_end>:<stopband_start>:<phase_response>,\n"
|
||||
#endif
|
||||
#if RESAMPLE16
|
||||
struct arg_lit * resample;
|
||||
struct arg_str * resample_parms; //" -R -u [params]\tResample, params = (b|l|m)[:i],\n"
|
||||
// " \t\t\t b = basic linear interpolation, l = 13 taps, m = 21 taps, i = interpolate filter coefficients\n"
|
||||
#endif
|
||||
struct arg_int * rate;// " -Z <rate>\t\tReport rate to server in helo as the maximum sample rate we can support\n"
|
||||
|
||||
struct arg_end *end;
|
||||
} squeezelite_args;
|
||||
|
||||
int is_output_gpio(struct arg_int * gpio, FILE * f, int * gpio_out, bool mandatory){
|
||||
int res = 0;
|
||||
const char * name = gpio->hdr.longopts?gpio->hdr.longopts:gpio->hdr.glossary;
|
||||
*gpio_out=-1;
|
||||
int t_gpio=gpio->ival[0];
|
||||
if(gpio->count==0){
|
||||
if(mandatory){
|
||||
fprintf(f,"Missing: %s\n", name);
|
||||
res++;
|
||||
}
|
||||
} else if(!GPIO_IS_VALID_OUTPUT_GPIO(t_gpio)){
|
||||
fprintf(f,"Invalid %s gpio: [%d] %s\n",name, t_gpio, GPIO_IS_VALID_GPIO(t_gpio)?NOT_OUTPUT:NOT_GPIO );
|
||||
res++;
|
||||
}
|
||||
else{
|
||||
*gpio_out = t_gpio;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int check_missing_parm(struct arg_int * int_parm, FILE * f){
|
||||
int res=0;
|
||||
const char * name = int_parm->hdr.longopts?int_parm->hdr.longopts:int_parm->hdr.glossary;
|
||||
if(int_parm->count==0){
|
||||
fprintf(f,"Missing: %s\n", name);
|
||||
res++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static int do_spdif_cmd(int argc, char **argv){
|
||||
i2s_platform_config_t i2s_dac_pin = {
|
||||
.i2c_addr = -1,
|
||||
.sda= -1,
|
||||
.scl = -1,
|
||||
.mute_gpio = -1,
|
||||
.mute_level = -1
|
||||
};
|
||||
if(is_spdif_config_locked()){
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"SPDIF Configuration is locked on this platform\n");
|
||||
return 1;
|
||||
}
|
||||
esp_err_t err=ESP_OK;
|
||||
int nerrors = arg_parse(argc, argv,(void **)&spdif_args);
|
||||
if (spdif_args.clear->count) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"SPDIF config cleared");
|
||||
config_set_value(NVS_TYPE_STR, "spdif_config", "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors >0){
|
||||
arg_print_errors(f,spdif_args.end,desc_dac);
|
||||
return 1;
|
||||
}
|
||||
nerrors+=is_output_gpio(spdif_args.clock, f, &i2s_dac_pin.pin.bck_io_num, true);
|
||||
nerrors+=is_output_gpio(spdif_args.wordselect, f, &i2s_dac_pin.pin.ws_io_num, true);
|
||||
nerrors+=is_output_gpio(spdif_args.data, f, &i2s_dac_pin.pin.data_out_num, true);
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Storing SPDIF parameters.\n");
|
||||
nerrors+=(config_spdif_set(&i2s_dac_pin )!=ESP_OK);
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
fflush (f);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
return (nerrors==0 && err==ESP_OK)?0:1;
|
||||
}
|
||||
|
||||
static int do_i2s_cmd(int argc, char **argv)
|
||||
{
|
||||
i2s_platform_config_t i2s_dac_pin = {
|
||||
.i2c_addr = -1,
|
||||
.sda= -1,
|
||||
.scl = -1,
|
||||
.mute_gpio = -1,
|
||||
.mute_level = -1
|
||||
};
|
||||
if(is_dac_config_locked()){
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"DAC Configuration is locked on this platform\n");
|
||||
return 1;
|
||||
}
|
||||
strcpy(i2s_dac_pin.model, "I2S");
|
||||
|
||||
esp_err_t err=ESP_OK;
|
||||
int nerrors = arg_parse(argc, argv,(void **)&i2s_args);
|
||||
if (i2s_args.clear->count) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"DAC config cleared");
|
||||
config_set_value(NVS_TYPE_STR, "dac_config", "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors >0){
|
||||
arg_print_errors(f,i2s_args.end,desc_dac);
|
||||
return 1;
|
||||
}
|
||||
nerrors+=is_output_gpio(i2s_args.clock, f, &i2s_dac_pin.pin.bck_io_num, true);
|
||||
nerrors+=is_output_gpio(i2s_args.wordselect, f, &i2s_dac_pin.pin.ws_io_num, true);
|
||||
nerrors+=is_output_gpio(i2s_args.data, f, &i2s_dac_pin.pin.data_out_num, true);
|
||||
nerrors+=is_output_gpio(i2s_args.mute_gpio, f, &i2s_dac_pin.mute_gpio, false);
|
||||
if(i2s_dac_pin.mute_gpio>0){
|
||||
i2s_dac_pin.mute_level = i2s_args.mute_level->count>0?1:0;
|
||||
}
|
||||
if(i2s_args.dac_sda->count>0 && i2s_args.dac_sda->ival[0]>=0){
|
||||
// if SDA specified, then SDA and SCL are both mandatory
|
||||
nerrors+=is_output_gpio(i2s_args.dac_sda, f, &i2s_dac_pin.sda, false);
|
||||
nerrors+=is_output_gpio(i2s_args.dac_scl, f, &i2s_dac_pin.scl, false);
|
||||
}
|
||||
if(i2s_args.dac_sda->count==0&& i2s_args.dac_i2c->count>0){
|
||||
fprintf(f,"warning: ignoring i2c address, since dac i2c gpios config is incomplete\n");
|
||||
}
|
||||
else if(i2s_args.dac_i2c->count>0){
|
||||
i2s_dac_pin.i2c_addr = i2s_args.dac_i2c->ival[0];
|
||||
}
|
||||
if(i2s_args.model_name->count>0 && strlen(i2s_args.model_name->sval[0])>0){
|
||||
strncpy(i2s_dac_pin.model,i2s_args.model_name->sval[0],sizeof(i2s_dac_pin.model));
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Storing i2s parameters.\n");
|
||||
nerrors+=(config_i2s_set(&i2s_dac_pin, "dac_config")!=ESP_OK);
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
fflush (f);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
return (nerrors==0 && err==ESP_OK)?0:1;
|
||||
}
|
||||
|
||||
cJSON * example_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
// int i2c_port;
|
||||
// const i2c_config_t * i2c= config_i2c_get(&i2c_port);
|
||||
// if(i2c->scl_io_num>0) {
|
||||
// cJSON_AddNumberToObject(values,"scl",i2c->scl_io_num);
|
||||
// }
|
||||
// if(i2c->sda_io_num>0) {
|
||||
// cJSON_AddNumberToObject(values,"sda",i2c->sda_io_num);
|
||||
// }
|
||||
// if(i2c->master.clk_speed>0) {
|
||||
// cJSON_AddNumberToObject(values,"freq",i2c->master.clk_speed);
|
||||
// }
|
||||
// if(i2c_port>0) {
|
||||
// cJSON_AddNumberToObject(values,"port",i2c_port);
|
||||
// }
|
||||
return values;
|
||||
}
|
||||
|
||||
//const i2s_pin_config_t * config_get_spdif_pin_struct( );
|
||||
|
||||
cJSON * i2s_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
const i2s_platform_config_t * i2s_conf= config_dac_get( );
|
||||
if(i2s_conf->pin.bck_io_num>0 ) {
|
||||
cJSON_AddNumberToObject(values,"clock",i2s_conf->pin.bck_io_num);
|
||||
}
|
||||
if(i2s_conf->pin.ws_io_num>=0 ) {
|
||||
cJSON_AddNumberToObject(values,"wordselect",i2s_conf->pin.ws_io_num);
|
||||
}
|
||||
if(i2s_conf->pin.data_out_num>=0 ) {
|
||||
cJSON_AddNumberToObject(values,"data",i2s_conf->pin.data_out_num);
|
||||
}
|
||||
if(i2s_conf->sda>=0 ) {
|
||||
cJSON_AddNumberToObject(values,"dac_sda",i2s_conf->sda);
|
||||
}
|
||||
if(i2s_conf->scl>=0 ) {
|
||||
cJSON_AddNumberToObject(values,"dac_scl",i2s_conf->scl);
|
||||
}
|
||||
if(i2s_conf->i2c_addr>=0 ) {
|
||||
cJSON_AddNumberToObject(values,"dac_i2c",i2s_conf->i2c_addr);
|
||||
}
|
||||
if(i2s_conf->mute_gpio>=0 ) {
|
||||
cJSON_AddNumberToObject(values,"mute_gpio",i2s_conf->mute_gpio);
|
||||
}
|
||||
if(i2s_conf->mute_level>=0 ) {
|
||||
cJSON_AddBoolToObject(values,"mute_level",i2s_conf->mute_level>0);
|
||||
}
|
||||
if(strlen(i2s_conf->model)>0){
|
||||
cJSON_AddStringToObject(values,"model_name",i2s_conf->model);
|
||||
}
|
||||
else {
|
||||
cJSON_AddStringToObject(values,"model_name","I2S");
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
cJSON * spdif_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
const i2s_platform_config_t * spdif_conf= config_spdif_get( );
|
||||
if(spdif_conf->pin.bck_io_num>0 ) {
|
||||
cJSON_AddNumberToObject(values,"clock",spdif_conf->pin.bck_io_num);
|
||||
}
|
||||
if(spdif_conf->pin.ws_io_num>=0 ) {
|
||||
cJSON_AddNumberToObject(values,"wordselect",spdif_conf->pin.ws_io_num);
|
||||
}
|
||||
if(spdif_conf->pin.data_out_num>=0 ) {
|
||||
cJSON_AddNumberToObject(values,"data",spdif_conf->pin.data_out_num);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
void get_str_parm_json(struct arg_str * parm, cJSON * entry){
|
||||
const char * name = parm->hdr.longopts?parm->hdr.longopts:parm->hdr.glossary;
|
||||
if(parm->count>0){
|
||||
cJSON_AddStringToObject(entry,name,parm->sval[0]);
|
||||
}
|
||||
}
|
||||
void get_file_parm_json(struct arg_file * parm, cJSON * entry){
|
||||
const char * name = parm->hdr.longopts?parm->hdr.longopts:parm->hdr.glossary;
|
||||
if(parm->count>0){
|
||||
cJSON_AddStringToObject(entry,name,parm->filename[0]);
|
||||
}
|
||||
}
|
||||
void get_lit_parm_json(struct arg_lit * parm, cJSON * entry){
|
||||
const char * name = parm->hdr.longopts?parm->hdr.longopts:parm->hdr.glossary;
|
||||
cJSON_AddBoolToObject(entry,name,(parm->count>0));
|
||||
}
|
||||
void get_int_parm_json(struct arg_int * parm, cJSON * entry){
|
||||
const char * name = parm->hdr.longopts?parm->hdr.longopts:parm->hdr.glossary;
|
||||
if(parm->count>0){
|
||||
cJSON_AddNumberToObject(entry,name,parm->ival[0]);
|
||||
}
|
||||
}
|
||||
|
||||
static int do_squeezelite_cmd(int argc, char **argv)
|
||||
{
|
||||
esp_err_t err=ESP_OK;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr ** )&squeezelite_args);
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
fprintf(f,"Not yet implemented!");
|
||||
nerrors+=1;
|
||||
fflush (f);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
return (nerrors==0 && err==ESP_OK)?0:1;
|
||||
}
|
||||
|
||||
cJSON * squeezelite_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
char * nvs_config= config_alloc_get(NVS_TYPE_STR, "autoexec1");
|
||||
char **argv = NULL;
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
int nerrors=1;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to parse squeezelite parameters");
|
||||
}
|
||||
else {
|
||||
|
||||
if(nvs_config && strlen(nvs_config)>0){
|
||||
ESP_LOGD(TAG,"Parsing command %s",nvs_config);
|
||||
argv = (char **) calloc(22, sizeof(char *));
|
||||
if (argv == NULL) {
|
||||
FREE_AND_NULL(nvs_config);
|
||||
return values;
|
||||
}
|
||||
size_t argc = esp_console_split_argv(nvs_config, argv,22);
|
||||
if (argc != 0) {
|
||||
nerrors = arg_parse(argc, argv,(void **)&squeezelite_args);
|
||||
ESP_LOGD(TAG,"Parsing completed");
|
||||
}
|
||||
}
|
||||
if (nerrors == 0) {
|
||||
get_str_parm_json(squeezelite_args.buffers, values);
|
||||
get_str_parm_json(squeezelite_args.codecs, values);
|
||||
get_lit_parm_json(squeezelite_args.header_format, values);
|
||||
get_str_parm_json(squeezelite_args.log_level, values);
|
||||
|
||||
// get_str_parm_json(squeezelite_args.log_level_all, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_decode, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_output, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_slimproto, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_stream, values);
|
||||
get_str_parm_json(squeezelite_args.mac_addr, values);
|
||||
get_str_parm_json(squeezelite_args.output_device, values);
|
||||
get_str_parm_json(squeezelite_args.model_name, values);
|
||||
get_str_parm_json(squeezelite_args.name, values);
|
||||
get_int_parm_json(squeezelite_args.rate, values);
|
||||
get_str_parm_json(squeezelite_args.rates, values);
|
||||
get_str_parm_json(squeezelite_args.server, values);
|
||||
get_int_parm_json(squeezelite_args.timeout, values);
|
||||
char * p = cJSON_Print(values);
|
||||
ESP_LOGD(TAG,"%s",p);
|
||||
free(p);
|
||||
}
|
||||
else {
|
||||
arg_print_errors(f, squeezelite_args.end, desc_squeezelite);
|
||||
}
|
||||
fflush (f);
|
||||
if(strlen(buf)>0){
|
||||
log_send_messaging(nerrors?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
}
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
}
|
||||
FREE_AND_NULL(nvs_config);
|
||||
FREE_AND_NULL(argv);
|
||||
return values;
|
||||
}
|
||||
static char * get_log_level_options(const char * longname){
|
||||
const char * template = "<%s=info|%s=debug|%s=sdebug>";
|
||||
char * options = NULL;
|
||||
int len = snprintf(NULL,0,template,longname,longname,longname);
|
||||
if(len>0){
|
||||
options = malloc(len+1);
|
||||
snprintf(options,len,template,longname,longname,longname);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
static void register_i2s_config(void){
|
||||
i2s_args.model_name = arg_str1(NULL,"model_name","TAS57xx|TAS5713|AC101|I2S","DAC Model Name");
|
||||
i2s_args.clear = arg_lit0(NULL, "clear", "Clear configuration");
|
||||
i2s_args.clock = arg_int1(NULL,"clock","<n>","Clock GPIO. e.g. 33");
|
||||
i2s_args.wordselect = arg_int1(NULL,"wordselect","<n>","Word Select GPIO. e.g. 25");
|
||||
i2s_args.data = arg_int1(NULL,"data","<n>","Data GPIO. e.g. 32");
|
||||
i2s_args.mute_gpio = arg_int0(NULL,"mute_gpio", "<n>", "Mute GPIO. e.g. 14");
|
||||
i2s_args.mute_level = arg_lit0(NULL,"mute_level","Mute GPIO level. Checked=HIGH, Unchecked=LOW");
|
||||
i2s_args.dac_sda = arg_int0(NULL,"dac_sda", "<n>", "SDA GPIO. e.g. 27");
|
||||
i2s_args.dac_scl = arg_int0(NULL,"dac_scl", "<n>", "SCL GPIO. e.g. 26");
|
||||
i2s_args.dac_i2c = arg_int0(NULL,"dac_i2c", "<n>", "I2C device address. e.g. 106");
|
||||
i2s_args.end = arg_end(6);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = CFG_TYPE_HW("dac"),
|
||||
.help = desc_dac,
|
||||
.hint = NULL,
|
||||
.func = &do_i2s_cmd,
|
||||
.argtable = &i2s_args
|
||||
};
|
||||
cmd_to_json_with_cb(&cmd,&i2s_cb);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
static void register_spdif_config(void){
|
||||
spdif_args.clear = arg_lit0(NULL, "clear", "Clear configuration");
|
||||
spdif_args.clock = arg_int1(NULL,"clock","<n>","Clock GPIO. e.g. 33");
|
||||
spdif_args.wordselect = arg_int1(NULL,"wordselect","<n>","Word Select GPIO. e.g. 25");
|
||||
spdif_args.data = arg_int1(NULL,"data","<n>","Data GPIO. e.g. 32");
|
||||
spdif_args.end = arg_end(6);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = CFG_TYPE_HW("spdif"),
|
||||
.help = desc_spdif,
|
||||
.hint = NULL,
|
||||
.func = &do_spdif_cmd,
|
||||
.argtable = &spdif_args
|
||||
};
|
||||
cmd_to_json_with_cb(&cmd,&spdif_cb);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
static void register_squeezelite_config(void){
|
||||
squeezelite_args.server = arg_str0("s","server","<server>[:<port>]","Connect to specified server, otherwise uses autodiscovery to find server");
|
||||
squeezelite_args.buffers = arg_str0("b","buffers","<stream>:<output>","Internal Stream and Output buffer sizes in Kbytes");
|
||||
squeezelite_args.codecs = arg_strn("c","codecs","<codec1>,<codec2>",0,20,"Restrict codecs to those specified, otherwise load all available codecs; known codecs");
|
||||
squeezelite_args.timeout = arg_int0("C","timeout","<n>","Close output device when idle after timeout seconds, default is to keep it open while player is 'on");
|
||||
squeezelite_args.log_level = arg_str0("d","loglevel","log=level","Set logging level, logs: all|slimproto|stream|decode|output|ir, level: info|debug|sdebug"); // " -d <log>=<level>\tSet logging level, logs: all|slimproto|stream|decode|output|ir, level: info|debug|sdebug\n"
|
||||
// squeezelite_args.log_level_all = arg_str0(NULL,"all",get_log_level_options("all"),"Overall Logging Level");
|
||||
// squeezelite_args.log_level_slimproto = arg_str0(NULL,"loglevel_slimproto",get_log_level_options("slimproto"),"Slimproto Logging Level");
|
||||
// squeezelite_args.log_level_stream= arg_str0(NULL,"loglevel_stream",get_log_level_options("stream"),"Stream Logging Level");
|
||||
// squeezelite_args.log_level_decode= arg_str0(NULL,"loglevel_decode",get_log_level_options("decode"),"Decode Logging Level");
|
||||
// squeezelite_args.log_level_output= arg_str0(NULL,"loglevel_output",get_log_level_options("output"),"Output Logging Level");
|
||||
#if IR
|
||||
squeezelite_args.log_level_ir= arg_str0(NULL,"loglevel_ir",get_log_level_options("ir"),"IR Logging Level");
|
||||
#endif
|
||||
|
||||
squeezelite_args.output_device = arg_str0("o","output_device","<string>","Output device");
|
||||
squeezelite_args.mac_addr = arg_str0("m","mac_addr","<string>","Mac address, format: ab:cd:ef:12:34:56");
|
||||
squeezelite_args.model_name = arg_str0("M", "modelname", "<string>","Squeezelite player model name sent to the server");
|
||||
squeezelite_args.name = arg_str0("n","name","<string>","Player name");
|
||||
squeezelite_args.header_format = arg_lit0("W","header_format","Read wave and aiff format from header, ignore server parameters");
|
||||
squeezelite_args.rates = arg_str0("r","rates","<rates>[:<delay>]", "Sample rates supported, allows output to be off when squeezelite is started; rates = <maxrate>|<minrate>-<maxrate>|<rate1>,<rate2>,<rate3>; delay = optional delay switching rates in ms\n");
|
||||
#if RESAMPLE
|
||||
squeezelite_args.resample = arg_lit0("R","resample","Activate Resample");
|
||||
squeezelite_args.resample_parms = arg_str0("u","resample_parms","<recipe>:<flags>:<attenuation>:<precision>:<passband_end>:<stopband_start>:<phase_response>","Resample, params");
|
||||
#endif
|
||||
#if RESAMPLE16
|
||||
squeezelite_args.resample = arg_lit0("R","resample","Activate Resample");
|
||||
squeezelite_args.resample_parms = arg_str0("u","resample_parms","(b|l|m)[:i]","Resample, params. b = basic linear interpolation, l = 13 taps, m = 21 taps, i = interpolate filter coefficients");
|
||||
#endif
|
||||
squeezelite_args.rate = arg_int0("Z","max_rate", "<n>", "Report rate to server in helo as the maximum sample rate we can support");
|
||||
squeezelite_args.end = arg_end(6);
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = CFG_TYPE_SYST("squeezelite"),
|
||||
.help = desc_squeezelite,
|
||||
.hint = NULL,
|
||||
.func = &do_squeezelite_cmd,
|
||||
.argtable = &squeezelite_args
|
||||
};
|
||||
cmd_to_json_with_cb(&cmd,&squeezelite_cb);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
|
||||
void register_config_cmd(void){
|
||||
register_squeezelite_config();
|
||||
register_i2s_config();
|
||||
register_spdif_config();
|
||||
}
|
||||
|
||||
19
components/platform_console/cmd_config.h
Normal file
19
components/platform_console/cmd_config.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/* cmd_i2ctools.h
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "stdbool.h"
|
||||
#include "stdio.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void register_config_cmd(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -17,6 +17,7 @@ extern "C" {
|
||||
#include "cmd_nvs.h"
|
||||
#include "cmd_i2ctools.h"
|
||||
#include "cmd_ota.h"
|
||||
#include "cmd_config.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "trace.h"
|
||||
#include "messaging.h"
|
||||
#include "display.h"
|
||||
#include "config.h"
|
||||
|
||||
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
@@ -31,13 +32,12 @@
|
||||
#define NACK_VAL 0x1 /*!< I2C nack value */
|
||||
extern int spi_system_host;
|
||||
extern int spi_system_dc_gpio;
|
||||
|
||||
extern int is_output_gpio(struct arg_int * gpio, FILE * f, int * gpio_out, bool mandatory);
|
||||
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_scl = 18;
|
||||
static uint32_t i2c_frequency = 100000;
|
||||
const char * desc_spiconfig="SPI Bus Parameters";
|
||||
const char * desc_i2c = "I2C Bus Parameters";
|
||||
const char * desc_display="Display";
|
||||
|
||||
#ifdef CONFIG_I2C_LOCKED
|
||||
static i2c_port_t i2c_port = I2C_NUM_1;
|
||||
#else
|
||||
@@ -70,7 +70,6 @@ static struct {
|
||||
struct arg_int *freq;
|
||||
struct arg_int *sda;
|
||||
struct arg_int *scl;
|
||||
struct arg_lit *load;
|
||||
struct arg_lit *clear;
|
||||
struct arg_end *end;
|
||||
} i2cconfig_args;
|
||||
@@ -85,18 +84,9 @@ static struct {
|
||||
} spiconfig_args;
|
||||
|
||||
static struct {
|
||||
struct arg_int *port;
|
||||
struct arg_end *end;
|
||||
} i2cstop_args;
|
||||
|
||||
static struct {
|
||||
struct arg_int *port;
|
||||
struct arg_end *end;
|
||||
} i2ccheck_args;
|
||||
|
||||
static struct {
|
||||
struct arg_str *name;
|
||||
struct arg_str *type;
|
||||
struct arg_str *driver;
|
||||
struct arg_int *depth;
|
||||
struct arg_int *address;
|
||||
struct arg_int *width;
|
||||
struct arg_int *height;
|
||||
@@ -104,28 +94,13 @@ static struct {
|
||||
struct arg_lit *hflip;
|
||||
struct arg_lit *vflip;
|
||||
struct arg_int *speed;
|
||||
struct arg_int *cs;
|
||||
struct arg_int *back;
|
||||
struct arg_int *reset;
|
||||
struct arg_lit *clear;
|
||||
struct arg_end *end;
|
||||
} i2cdisp_args;
|
||||
|
||||
int is_output_gpio(struct arg_int * gpio, FILE * f, int * gpio_out){
|
||||
int res = 0;
|
||||
const char * name = gpio->hdr.longopts?gpio->hdr.longopts:gpio->hdr.glossary;
|
||||
*gpio_out=-1;
|
||||
int t_gpio=gpio->ival[0];
|
||||
if(gpio->count==0){
|
||||
fprintf(f,"Missing: %s\n", name);
|
||||
res++;
|
||||
} else if(!GPIO_IS_VALID_OUTPUT_GPIO(t_gpio)){
|
||||
fprintf(f,"Invalid %s gpio: [%d] %s\n",name, t_gpio, GPIO_IS_VALID_GPIO(t_gpio)?NOT_OUTPUT:NOT_GPIO );
|
||||
res++;
|
||||
}
|
||||
else{
|
||||
*gpio_out = t_gpio;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
bool is_i2c_started(i2c_port_t port){
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_LOGD(TAG,"Determining if i2c is started on port %u", port);
|
||||
@@ -267,13 +242,6 @@ static const i2c_db_t i2c_db[] = {
|
||||
{ .address = 0x7f, .description = "PCA9685"},
|
||||
{ .address = 0, .description = NULL}
|
||||
};
|
||||
void i2c_load_configuration(){
|
||||
ESP_LOGD(TAG,"Loading configuration from nvs");
|
||||
const i2c_config_t * conf = config_i2c_get((int *)&i2c_port);
|
||||
i2c_gpio_scl = conf->scl_io_num;
|
||||
i2c_gpio_sda = conf->sda_io_num;
|
||||
i2c_frequency = conf->master.clk_speed;
|
||||
}
|
||||
|
||||
const char * i2c_get_description(uint8_t address){
|
||||
uint8_t i=0;
|
||||
@@ -300,114 +268,35 @@ static esp_err_t i2c_get_port(int port, i2c_port_t *i2c_port)
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
static esp_err_t i2c_master_driver_install(){
|
||||
static esp_err_t i2c_master_driver_install(const char * cmdname){
|
||||
esp_err_t err=ESP_OK;
|
||||
ESP_LOGD(TAG,"Installing i2c driver on port %u", i2c_port);
|
||||
cmd_send_messaging(cmdname,MESSAGING_INFO,"Installing i2c driver on port %u\n", i2c_port);
|
||||
if((err=i2c_driver_install(i2c_port, I2C_MODE_MASTER, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0))!=ESP_OK){
|
||||
log_send_messaging(MESSAGING_ERROR,"Driver install failed! %s", esp_err_to_name(err));
|
||||
cmd_send_messaging(cmdname,MESSAGING_ERROR,"Driver install failed! %s\n", esp_err_to_name(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t i2c_master_driver_initialize()
|
||||
static esp_err_t i2c_master_driver_initialize(const char * cmdname, i2c_config_t * conf)
|
||||
{
|
||||
esp_err_t err=ESP_OK;
|
||||
i2c_config_t conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = i2c_gpio_sda,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_io_num = i2c_gpio_scl,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = i2c_frequency
|
||||
};
|
||||
log_send_messaging(MESSAGING_INFO,"Initializing i2c driver configuration.\n mode = I2C_MODE_MASTER, \n scl_pullup_en = GPIO_PULLUP_ENABLE, \n i2c port = %u, \n sda_io_num = %u, \n sda_pullup_en = GPIO_PULLUP_ENABLE, \n scl_io_num = %u, \n scl_pullup_en = GPIO_PULLUP_ENABLE, \n master.clk_speed = %u", i2c_port, i2c_gpio_sda,i2c_gpio_scl,i2c_frequency);
|
||||
if((err=i2c_param_config(i2c_port, &conf))!=ESP_OK){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c driver config load failed. %s", esp_err_to_name(err));
|
||||
cmd_send_messaging(cmdname,MESSAGING_INFO,"Initializing i2c driver configuration.\n mode = I2C_MODE_MASTER, \n scl_pullup_en = GPIO_PULLUP_ENABLE, \n i2c port = %u, \n sda_io_num = %u, \n sda_pullup_en = GPIO_PULLUP_ENABLE, \n scl_io_num = %u, \n scl_pullup_en = GPIO_PULLUP_ENABLE, \n master.clk_speed = %u\n", i2c_port, conf->sda_io_num,conf->scl_io_num,conf->master.clk_speed);
|
||||
if((err=i2c_param_config(i2c_port, conf))!=ESP_OK){
|
||||
cmd_send_messaging(cmdname,MESSAGING_ERROR,"i2c driver config load failed. %s\n", esp_err_to_name(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t i2c_initialize_driver_from_config(){
|
||||
esp_err_t err = ESP_OK;
|
||||
ESP_LOGD(TAG,"Initializing driver from configuration.");
|
||||
i2c_load_configuration();
|
||||
if(is_i2c_started(i2c_port)){
|
||||
log_send_messaging(MESSAGING_WARNING,"Stopping i2c driver on port %u", i2c_port);
|
||||
// stop the current driver instance
|
||||
if((err=i2c_driver_delete(i2c_port))!=ESP_OK){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c driver delete failed. %s", esp_err_to_name(err));
|
||||
}
|
||||
}
|
||||
if(err==ESP_OK){
|
||||
err = i2c_master_driver_initialize();
|
||||
}
|
||||
if(err == ESP_OK){
|
||||
err = i2c_master_driver_install();
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static int do_i2c_stop(int argc, char **argv ){
|
||||
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cstop_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
}
|
||||
if (i2cstop_args.port->count && i2c_get_port(i2cstop_args.port->ival[0], &i2c_port) != ESP_OK) {
|
||||
return 1;
|
||||
}
|
||||
log_send_messaging(MESSAGING_WARNING,"Stopping i2c on port %u.",i2c_port);
|
||||
i2c_driver_delete(i2c_port);
|
||||
return 0;
|
||||
}
|
||||
static int do_i2c_check(int argc, char **argv ){
|
||||
|
||||
i2c_port_t port=0;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2ccheck_args);
|
||||
if (nerrors != 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
port=i2c_port;
|
||||
|
||||
if (i2ccheck_args.port->count && i2c_get_port(i2ccheck_args.port->ival[0], &port) != ESP_OK) {
|
||||
return 1;
|
||||
}
|
||||
bool started=is_i2c_started(port);
|
||||
log_send_messaging(MESSAGING_INFO,"i2c is %s on port %u.", started?"started":"not started",port );
|
||||
return 0;
|
||||
}
|
||||
static int do_i2c_show_display(int argc, char **argv){
|
||||
char * config_string = (char * )config_alloc_get(NVS_TYPE_STR, "display_config") ;
|
||||
if(config_string){
|
||||
log_send_messaging(MESSAGING_INFO,"Display configuration string is : \n"
|
||||
"display_config = \"%s\"",config_string);
|
||||
free(config_string);
|
||||
}
|
||||
else {
|
||||
log_send_messaging(MESSAGING_WARNING,"No display configuration found in nvs config display_config");
|
||||
}
|
||||
char * nvs_item = config_alloc_get(NVS_TYPE_STR, "i2c_config");
|
||||
if (nvs_item) {
|
||||
log_send_messaging(MESSAGING_INFO,"I2C configuration is: %s", nvs_item);
|
||||
free(nvs_item);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_i2c_set_display(int argc, char **argv)
|
||||
{
|
||||
int width=0, height=0, address=60, back=-1, speed=8000000 ;
|
||||
char * name = NULL;
|
||||
char * driver= NULL;
|
||||
char config_string[200]={};
|
||||
bool bHasi2cConfig = false, bHasSpiConfig=false;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cdisp_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
display_config_t config = {
|
||||
.back = -1,
|
||||
.CS_pin = -1,
|
||||
.RST_pin = -1,
|
||||
.depth = 0
|
||||
};
|
||||
char * nvs_item = config_alloc_get(NVS_TYPE_STR, "i2c_config");
|
||||
if (nvs_item && strlen(nvs_item)>0) {
|
||||
bHasi2cConfig=true;
|
||||
@@ -420,9 +309,9 @@ static int do_i2c_set_display(int argc, char **argv)
|
||||
}
|
||||
FREE_AND_NULL(nvs_item);
|
||||
|
||||
/* Check "--clear" option */
|
||||
/* Check "--clear" option */
|
||||
if (i2cdisp_args.clear->count) {
|
||||
log_send_messaging(MESSAGING_WARNING,"Display config cleared");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"Display config cleared");
|
||||
config_set_value(NVS_TYPE_STR, "display_config", "");
|
||||
return 0;
|
||||
}
|
||||
@@ -430,95 +319,105 @@ static int do_i2c_set_display(int argc, char **argv)
|
||||
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;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors>0){
|
||||
arg_print_errors(f,i2cdisp_args.end,desc_display);
|
||||
return 1;
|
||||
}
|
||||
/* Check "--type" option */
|
||||
if (i2cdisp_args.type->count ) {
|
||||
if(strcasecmp(i2c_name_type, i2cdisp_args.type->sval[0])==0){
|
||||
config.type = i2c_name_type;
|
||||
}
|
||||
else {
|
||||
config.type = spi_name_type;
|
||||
}
|
||||
}
|
||||
else {
|
||||
config.type = i2c_name_type;
|
||||
}
|
||||
/* Check "--address" option */
|
||||
if (i2cdisp_args.address->count) {
|
||||
address=i2cdisp_args.address->ival[0];
|
||||
if(strcasecmp(config.type,"I2C")==0){
|
||||
if (i2cdisp_args.address->count>0) {
|
||||
config.address=i2cdisp_args.address->ival[0];
|
||||
}
|
||||
else {
|
||||
config.address = 60;
|
||||
}
|
||||
if(!bHasi2cConfig){
|
||||
fprintf(f,"I2C bus has to be configured first. \n");
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// SPI Bus connection
|
||||
if(!bHasSpiConfig){
|
||||
fprintf(f,"SPI bus has to be configured first. \n");
|
||||
nerrors++;
|
||||
}
|
||||
/* Check "--speed" option */
|
||||
if (i2cdisp_args.speed->count) {
|
||||
config.speed=i2cdisp_args.speed->ival[0];
|
||||
}
|
||||
else {
|
||||
config.speed = 8000000;
|
||||
}
|
||||
/* Check "--cs" option */
|
||||
nerrors +=is_output_gpio(i2cdisp_args.cs,f,&config.CS_pin, true);
|
||||
}
|
||||
|
||||
nerrors +=is_output_gpio(i2cdisp_args.reset,f,&config.RST_pin, false);
|
||||
/* Check "--width" option */
|
||||
if (i2cdisp_args.width->count) {
|
||||
width=i2cdisp_args.width->ival[0];
|
||||
config.width=i2cdisp_args.width->ival[0];
|
||||
}
|
||||
else {
|
||||
fprintf(f,"Missing parameter: --width\n");
|
||||
nerrors ++;
|
||||
}
|
||||
|
||||
/* Check "--height" option */
|
||||
if (i2cdisp_args.height->count) {
|
||||
height=i2cdisp_args.height->ival[0];
|
||||
}
|
||||
else {
|
||||
fprintf(f,"Missing parameter: --height\n");
|
||||
nerrors ++;
|
||||
}
|
||||
|
||||
/* Check "--name" option */
|
||||
if (i2cdisp_args.name->count) {
|
||||
name=strdup(i2cdisp_args.name->sval[0]);
|
||||
config.height=i2cdisp_args.height->ival[0];
|
||||
}
|
||||
|
||||
/* Check "--driver" option */
|
||||
if (i2cdisp_args.driver->count) {
|
||||
driver=strdup(i2cdisp_args.driver->sval[0]);
|
||||
}
|
||||
|
||||
|
||||
/* Check "--back" option */
|
||||
nerrors +=is_output_gpio(i2cdisp_args.back,f,&back);
|
||||
|
||||
|
||||
if(!name) name = strdup("I2C");
|
||||
/* Check "--speed" option */
|
||||
if (i2cdisp_args.speed->count) {
|
||||
speed=i2cdisp_args.speed->ival[0];
|
||||
config.drivername=display_conf_get_driver_name(i2cdisp_args.driver->sval[0]) ;
|
||||
}
|
||||
else {
|
||||
if(strcasestr(name,"I2C")){
|
||||
speed = 250000;
|
||||
}
|
||||
else {
|
||||
speed = 8000000;
|
||||
}
|
||||
config.drivername = display_conf_get_driver_name("SSD1306");
|
||||
}
|
||||
|
||||
|
||||
if(!driver) driver = strdup("SSD1306");
|
||||
|
||||
|
||||
if(!display_is_valid_driver(driver)){
|
||||
fprintf(f,"Unsupported display driver %s\n",driver);
|
||||
if(i2cdisp_args.depth->count > 0 && strcasecmp(config.drivername,"SSD1326")==0) {
|
||||
config.depth = i2cdisp_args.depth->ival[0];
|
||||
}
|
||||
/* Check "--back" option */
|
||||
nerrors +=is_output_gpio(i2cdisp_args.back,f,&config.back, false);
|
||||
if(!display_is_valid_driver(config.drivername)){
|
||||
fprintf(f,"Unsupported display driver %s\n",config.drivername);
|
||||
nerrors++;
|
||||
}
|
||||
|
||||
if(strcasestr(name,"I2C") && !bHasi2cConfig){
|
||||
fprintf(f,"Please configure I2C bus first. \n");
|
||||
}else if(strcasestr(name,"SPI") && !bHasSpiConfig){
|
||||
fprintf(f,"Please configure SPI bus first. \n");
|
||||
if(!strcasestr(config.type,"I2C") && !strcasestr(config.type,"SPI")){
|
||||
fprintf(f,"Invalid display type %s\n",config.type);
|
||||
nerrors++;
|
||||
}
|
||||
else if(!strcasestr(name,"I2C") && !strcasestr(name,"SPI")){
|
||||
fprintf(f,"Invalid display type %s\n",name);
|
||||
}
|
||||
bool rotate = i2cdisp_args.rotate->count>0;
|
||||
config.rotate = i2cdisp_args.rotate->count>0;
|
||||
config.hflip = i2cdisp_args.hflip->count>0;
|
||||
config.vflip = i2cdisp_args.vflip->count>0;
|
||||
|
||||
if(nerrors==0){
|
||||
snprintf(config_string, sizeof(config_string),"%s:back=%i,speed=%i,width=%i,height=%i,address=%i,driver=%s%s%s",
|
||||
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"
|
||||
"display_config = \"%s\"",config_string );
|
||||
nerrors = config_set_value(NVS_TYPE_STR, "display_config", config_string)!=ESP_OK;
|
||||
fprintf(f,"Saving display configuration\n");
|
||||
esp_err_t err = config_display_set(&config);
|
||||
if(err!=ESP_OK){
|
||||
fprintf(f,"Error: %s\n",esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
|
||||
FREE_AND_NULL(name);
|
||||
FREE_AND_NULL(driver);
|
||||
fflush (f);
|
||||
log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
return nerrors==0;
|
||||
return nerrors;
|
||||
}
|
||||
|
||||
|
||||
@@ -530,17 +429,13 @@ static int do_spiconfig_cmd(int argc, char **argv){
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1
|
||||
};
|
||||
|
||||
int data, clk, dc, host = 0;
|
||||
int dc=-1,host = 0;
|
||||
esp_err_t err=ESP_OK;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&spiconfig_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check "--clear" option */
|
||||
if (spiconfig_args.clear->count) {
|
||||
log_send_messaging(MESSAGING_WARNING,"spi config cleared");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"SPI config cleared.\n");
|
||||
config_set_value(NVS_TYPE_STR, "spi_config", "");
|
||||
return 0;
|
||||
}
|
||||
@@ -549,51 +444,72 @@ static int do_spiconfig_cmd(int argc, char **argv){
|
||||
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;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors>0){
|
||||
arg_print_errors(f,spiconfig_args.end,desc_spiconfig);
|
||||
return 1;
|
||||
}
|
||||
/* Check "--clk" option */
|
||||
nerrors+=is_output_gpio(spiconfig_args.clk, f, &clk);
|
||||
nerrors+=is_output_gpio(spiconfig_args.data, f, &data);
|
||||
nerrors+=is_output_gpio(spiconfig_args.dc, f, &dc);
|
||||
nerrors+=is_output_gpio(spiconfig_args.host, f, &host);
|
||||
nerrors+=is_output_gpio(spiconfig_args.clk, f, &spi_config.sclk_io_num, true);
|
||||
nerrors+=is_output_gpio(spiconfig_args.data, f, &spi_config.mosi_io_num, true);
|
||||
nerrors+=is_output_gpio(spiconfig_args.dc, f, &dc, true);
|
||||
nerrors+=is_output_gpio(spiconfig_args.host, f, &host, true);
|
||||
|
||||
if(!nerrors){
|
||||
spi_config.mosi_io_num=data;
|
||||
spi_config.sclk_io_num=clk;
|
||||
|
||||
fprintf(f,"Configuring SPI data:%d clk:%d host:%u dc:%d", spi_config.mosi_io_num, spi_config.sclk_io_num, host, dc);
|
||||
if((err=spi_bus_initialize( host, &spi_config, 1 ))!=ESP_OK){
|
||||
fprintf(f,"SPI bus initialization failed. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
fprintf(f,"Configuring SPI data=%d clock=%d host=%u dc: %d\n", spi_config.mosi_io_num, spi_config.sclk_io_num, host, dc);
|
||||
err=spi_bus_initialize( host, &spi_config, 1 );
|
||||
if(err!=ESP_OK){
|
||||
if(err==ESP_ERR_INVALID_STATE){
|
||||
// if user is changing the host number, we need to try freeing both hosts
|
||||
if((err = spi_bus_free(host))!=ESP_OK && (err = spi_bus_free(host==1?2:1))!=ESP_OK){
|
||||
fprintf(f,"SPI bus init failed. Please clear SPI configuration, restart the device and try again. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
else if((err=spi_bus_initialize( host, &spi_config, 1 ))!=ESP_OK){
|
||||
fprintf(f,"Failed to initialize SPI Bus. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(f,"SPI bus initialization failed. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!nerrors){
|
||||
fprintf(f,"Storing SPI parameters.\n");
|
||||
config_spi_set(&spi_config, host, dc);
|
||||
nerrors += (config_spi_set(&spi_config, host, dc)!=ESP_OK);
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
fflush (f);
|
||||
log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
return nerrors==0;
|
||||
|
||||
|
||||
return nerrors;
|
||||
}
|
||||
|
||||
|
||||
static int do_i2cconfig_cmd(int argc, char **argv)
|
||||
{
|
||||
esp_err_t err=ESP_OK;
|
||||
i2c_config_t conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = 19,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_io_num = 18,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = 100000
|
||||
};
|
||||
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cconfig_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
}
|
||||
/* Check "--clear" option */
|
||||
if (i2cconfig_args.clear->count) {
|
||||
log_send_messaging(MESSAGING_WARNING,"i2c config cleared");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"i2c config cleared\n");
|
||||
config_set_value(NVS_TYPE_STR, "i2c_config", "");
|
||||
return 0;
|
||||
}
|
||||
@@ -602,32 +518,27 @@ static int do_i2cconfig_cmd(int argc, char **argv)
|
||||
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;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors>0){
|
||||
arg_print_errors(f,i2cconfig_args.end,desc_i2c);
|
||||
return 1;
|
||||
}
|
||||
/* Check "--port" option */
|
||||
if (i2cconfig_args.port->count) {
|
||||
if (i2c_get_port(i2cconfig_args.port->ival[0], &i2c_port) != ESP_OK) {
|
||||
fprintf(f,"Invalid port %u \n",i2cconfig_args.port->ival[0]);
|
||||
nerrors ++;
|
||||
}
|
||||
}
|
||||
/* Check "--freq" option */
|
||||
if (i2cconfig_args.freq->count) {
|
||||
conf.master.clk_speed = i2cconfig_args.freq->ival[0];
|
||||
}
|
||||
|
||||
/* Check "--load" option */
|
||||
if (i2cconfig_args.load->count) {
|
||||
log_send_messaging(MESSAGING_WARNING,"Loading i2c config");
|
||||
i2c_load_configuration();
|
||||
}
|
||||
else {
|
||||
|
||||
/* Check "--port" option */
|
||||
if (i2cconfig_args.port->count) {
|
||||
if (i2c_get_port(i2cconfig_args.port->ival[0], &i2c_port) != ESP_OK) {
|
||||
fprintf(f,"Invalid port %u \n",i2cconfig_args.port->ival[0]);
|
||||
nerrors ++;
|
||||
}
|
||||
}
|
||||
/* Check "--freq" option */
|
||||
if (i2cconfig_args.freq->count) {
|
||||
i2c_frequency = i2cconfig_args.freq->ival[0];
|
||||
}
|
||||
|
||||
nerrors +=is_output_gpio(i2cconfig_args.sda,f,&i2c_gpio_sda);
|
||||
nerrors +=is_output_gpio(i2cconfig_args.scl,f,&i2c_gpio_scl);
|
||||
}
|
||||
nerrors +=is_output_gpio(i2cconfig_args.sda,f,&conf.sda_io_num, true);
|
||||
nerrors +=is_output_gpio(i2cconfig_args.scl,f,&conf.scl_io_num, true);
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
if (i2c_port == I2C_NUM_0) {
|
||||
@@ -645,54 +556,38 @@ static int do_i2cconfig_cmd(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
if(!nerrors){
|
||||
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){
|
||||
fprintf(f,"Initalize success.\n");
|
||||
// now start the i2c driver
|
||||
fprintf(f,"Starting the i2c driver.");
|
||||
if((err=i2c_master_driver_install())!=ESP_OK){
|
||||
fprintf(f,"I2C master driver install failed. %s\n", esp_err_to_name(err));
|
||||
if((err=i2c_master_driver_initialize(argv[0],&conf))==ESP_OK){
|
||||
if((err=i2c_master_driver_install(argv[0]))!=ESP_OK){
|
||||
nerrors++;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
fprintf(f,"i2c driver successfully started.\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
fprintf(f,"I2C initialization failed. %s\n", esp_err_to_name(err));
|
||||
nerrors++;
|
||||
}
|
||||
}
|
||||
if(!nerrors && !i2cconfig_args.load->count){
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Storing i2c parameters.\n");
|
||||
i2c_config_t config={
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = i2c_gpio_sda,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_io_num = i2c_gpio_scl,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = i2c_frequency
|
||||
};
|
||||
config_i2c_set(&config, i2c_port);
|
||||
config_i2c_set(&conf, i2c_port);
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
fflush (f);
|
||||
log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
return nerrors==0;
|
||||
return nerrors;
|
||||
}
|
||||
|
||||
#define RUN_SHOW_ERROR(c)
|
||||
|
||||
|
||||
static int do_i2cdump_cmd(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cdump_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check chip address: "-c" option */
|
||||
@@ -704,24 +599,19 @@ static int do_i2cdump_cmd(int argc, char **argv)
|
||||
}
|
||||
i2c_port_t loc_i2c_port=i2c_port;
|
||||
if (i2cset_args.port->count && i2c_get_port(i2cset_args.port->ival[0], &loc_i2c_port) != ESP_OK) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (size != 1 && size != 2 && size != 4) {
|
||||
log_send_messaging(MESSAGING_ERROR, "Wrong read size. Only support 1,2,4");
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "Wrong read size. Only support 1,2,4\n");
|
||||
return 1;
|
||||
}
|
||||
i2c_load_configuration();
|
||||
if(i2c_gpio_scl==-1 ||i2c_gpio_sda ==-1){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c set failed. i2c needs to be configured first.");
|
||||
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;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t data_addr;
|
||||
@@ -777,19 +667,16 @@ static int do_i2cdump_cmd(int argc, char **argv)
|
||||
// Don't stop the driver; our firmware may be using it for screen, etc
|
||||
//i2c_driver_delete(i2c_port);
|
||||
fflush (f);
|
||||
log_send_messaging(MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int do_i2cset_cmd(int argc, char **argv)
|
||||
{
|
||||
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cset_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check chip address: "-c" option */
|
||||
@@ -802,18 +689,12 @@ static int do_i2cset_cmd(int argc, char **argv)
|
||||
|
||||
i2c_port_t loc_i2c_port=i2c_port;
|
||||
if (i2cset_args.port->count && i2c_get_port(i2cset_args.port->ival[0], &loc_i2c_port) != ESP_OK) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check data: "-d" option */
|
||||
int len = i2cset_args.data->count;
|
||||
|
||||
i2c_load_configuration();
|
||||
if(i2c_gpio_scl==-1 ||i2c_gpio_sda ==-1){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c set failed. i2c needs to be configured first.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, chip_addr << 1 | WRITE_BIT, ACK_CHECK_EN);
|
||||
@@ -827,11 +708,11 @@ static int do_i2cset_cmd(int argc, char **argv)
|
||||
esp_err_t ret = i2c_master_cmd_begin(loc_i2c_port, cmd, 1000 / portTICK_RATE_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if (ret == ESP_OK) {
|
||||
log_send_messaging(MESSAGING_INFO, "i2c Write OK");
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "i2c Write OK\n");
|
||||
} else if (ret == ESP_ERR_TIMEOUT) {
|
||||
log_send_messaging(MESSAGING_WARNING, "i2c Bus is busy");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "i2c Bus is busy\n");
|
||||
} else {
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c Read failed");
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"i2c Read failed\n");
|
||||
}
|
||||
// Don't stop the driver; our firmware may be using it for screen, etc
|
||||
//i2c_driver_delete(i2c_port);
|
||||
@@ -842,7 +723,7 @@ static int do_i2cget_cmd(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cget_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check chip address: "-c" option */
|
||||
@@ -859,21 +740,15 @@ static int do_i2cget_cmd(int argc, char **argv)
|
||||
}
|
||||
i2c_port_t loc_i2c_port=i2c_port;
|
||||
if (i2cset_args.port->count && i2c_get_port(i2cset_args.port->ival[0], &loc_i2c_port) != ESP_OK) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
i2c_load_configuration();
|
||||
if(i2c_gpio_scl==-1 ||i2c_gpio_sda ==-1){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c set failed. i2c needs to be configured first.");
|
||||
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;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
@@ -902,19 +777,18 @@ static int do_i2cget_cmd(int argc, char **argv)
|
||||
fprintf(f,"\r\n");
|
||||
}
|
||||
} else if (ret == ESP_ERR_TIMEOUT) {
|
||||
log_send_messaging(MESSAGING_WARNING, "i2c Bus is busy");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "i2c Bus is busy\n");
|
||||
} else {
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c Read failed");
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"i2c Read failed\n");
|
||||
}
|
||||
free(data);
|
||||
|
||||
// Don't stop the driver; our firmware may be using it for screen, etc
|
||||
//i2c_driver_delete(i2c_port);
|
||||
fflush (f);
|
||||
log_send_messaging(MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -923,14 +797,9 @@ static int do_i2cdetect_cmd(int argc, char **argv)
|
||||
uint8_t matches[128]={};
|
||||
int last_match=0;
|
||||
esp_err_t ret = ESP_OK;
|
||||
i2c_load_configuration();
|
||||
if(i2c_gpio_scl==-1 ||i2c_gpio_sda ==-1){
|
||||
log_send_messaging(MESSAGING_ERROR,"i2c set failed. i2c needs to be configured first.");
|
||||
return 0;
|
||||
}
|
||||
i2c_port_t loc_i2c_port=i2c_port;
|
||||
if (i2cset_args.port->count && i2c_get_port(i2cset_args.port->ival[0], &loc_i2c_port) != ESP_OK) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t address;
|
||||
@@ -938,8 +807,8 @@ static int do_i2cdetect_cmd(int argc, char **argv)
|
||||
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;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -979,7 +848,7 @@ static int do_i2cdetect_cmd(int argc, char **argv)
|
||||
}
|
||||
|
||||
fflush (f);
|
||||
log_send_messaging(MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
|
||||
@@ -989,19 +858,40 @@ cJSON * i2c_set_display_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
const display_config_t * conf= config_display_get();
|
||||
if(conf){
|
||||
cJSON_AddNumberToObject(values,"address",conf->address);
|
||||
cJSON_AddNumberToObject(values,"width",conf->width);
|
||||
cJSON_AddNumberToObject(values,"height",conf->height);
|
||||
cJSON_AddStringToObject(values,"type",conf->type);
|
||||
cJSON_AddStringToObject(values,"driver",conf->drivername);
|
||||
if(conf->width>0){
|
||||
cJSON_AddNumberToObject(values,"width",conf->width);
|
||||
}
|
||||
if(conf->height>0) {
|
||||
cJSON_AddNumberToObject(values,"height",conf->height);
|
||||
}
|
||||
if(conf->address>0){
|
||||
cJSON_AddNumberToObject(values,"address",conf->address);
|
||||
}
|
||||
if(conf->RST_pin>=0) {
|
||||
cJSON_AddNumberToObject(values,"reset",conf->RST_pin);
|
||||
}
|
||||
if(conf->drivername && strlen(conf->drivername)>0){
|
||||
cJSON_AddStringToObject(values,"driver",conf->drivername);
|
||||
}
|
||||
if(conf->CS_pin>=0) {
|
||||
cJSON_AddNumberToObject(values,"cs",conf->CS_pin);
|
||||
}
|
||||
if(conf->speed>0){
|
||||
cJSON_AddNumberToObject(values,"speed",conf->speed);
|
||||
}
|
||||
if(conf->back>=0){
|
||||
cJSON_AddNumberToObject(values,"back",conf->back);
|
||||
}
|
||||
if(conf->depth>0){
|
||||
cJSON_AddNumberToObject(values,"depth",conf->depth);
|
||||
}
|
||||
if(conf->type && strlen(conf->type)){
|
||||
cJSON_AddStringToObject(values,"type",conf->type);
|
||||
}
|
||||
cJSON_AddBoolToObject(values,"rotate",conf->rotate);
|
||||
cJSON_AddBoolToObject(values,"hf",conf->hflip);
|
||||
cJSON_AddBoolToObject(values,"vf",conf->vflip);
|
||||
if(conf->vflip && conf->hflip){
|
||||
cJSON_AddBoolToObject(values,"rotate",true);
|
||||
}
|
||||
else {
|
||||
cJSON_AddBoolToObject(values,"rotate",false);
|
||||
}
|
||||
|
||||
}
|
||||
return values;
|
||||
}
|
||||
@@ -1009,37 +899,30 @@ cJSON * i2c_set_display_cb(){
|
||||
static void register_i2c_set_display(){
|
||||
char * supported_drivers = display_get_supported_drivers();
|
||||
|
||||
i2cdisp_args.address = arg_int0("a", "address", "<n>", "I2C address (default 60)");
|
||||
i2cdisp_args.width = arg_int0("w", "width", "<n>", "Width");
|
||||
i2cdisp_args.height = arg_int0("h", "height", "<n>", "Height");
|
||||
i2cdisp_args.name = arg_str0("t", "type", "<I2C|SPI>", "Interface (default I2C)");
|
||||
i2cdisp_args.driver = arg_str0("d", "driver", supported_drivers?supported_drivers:"<string>", "Driver (default SSD1306)");
|
||||
i2cdisp_args.clear = arg_lit0(NULL, "clear", "clear configuration and return");
|
||||
i2cdisp_args.hflip = arg_lit0(NULL, "hf", "Flip horizontally");
|
||||
i2cdisp_args.vflip = arg_lit0(NULL, "vf", "Flip vertically");
|
||||
i2cdisp_args.rotate = arg_lit0("r", "rotate", "Rotate 180 degrees");
|
||||
i2cdisp_args.back = arg_int0("b", "back", "<n>","Backlight GPIO (if applicable)");
|
||||
i2cdisp_args.speed = arg_int0("s", "speed", "<n>","Bus Speed (Default 8000000 for SPI, 250000 for I2C). SPI interface can work up to 26MHz~40MHz");
|
||||
i2cdisp_args.end = arg_end(8);
|
||||
i2cdisp_args.width = arg_int1("w", "width", "<n>", "Width");
|
||||
i2cdisp_args.height = arg_int1("h", "height", "<n>", "Height");
|
||||
i2cdisp_args.address = arg_int0("a", "address", "<n>", "I2C address (default 60)");
|
||||
i2cdisp_args.reset = arg_int0(NULL, "reset", "<n>", "Reset GPIO");
|
||||
i2cdisp_args.hflip = arg_lit0(NULL, "hf", "Flip horizontally");
|
||||
i2cdisp_args.vflip = arg_lit0(NULL, "vf", "Flip vertically");
|
||||
i2cdisp_args.driver = arg_str0("d", "driver", supported_drivers?supported_drivers:"<string>", "Driver (default SSD1306)");
|
||||
i2cdisp_args.cs = arg_int0("b", "cs", "<n>","SPI Only. CS GPIO (for SPI displays)");
|
||||
i2cdisp_args.speed = arg_int0("s", "speed", "<n>","SPI Only. Bus Speed (Default 8000000). SPI interface can work up to 26MHz~40MHz");
|
||||
i2cdisp_args.back = arg_int0("b", "back", "<n>","Backlight GPIO (if applicable)");
|
||||
i2cdisp_args.depth = arg_int0("p", "depth", "1|4", "Bit Depth (only for SSD1326 displays)");
|
||||
i2cdisp_args.type = arg_str0("t", "type", "<I2C|SPI>", "Interface (default I2C)");
|
||||
i2cdisp_args.rotate = arg_lit0("r", "rotate", "Rotate 180 degrees");
|
||||
i2cdisp_args.clear = arg_lit0(NULL, "clear", "clear configuration and return");
|
||||
i2cdisp_args.end = arg_end(8);
|
||||
const esp_console_cmd_t i2c_set_display= {
|
||||
.command = "setdisplay",
|
||||
.help="Display",
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_set_display,
|
||||
.argtable = &i2cdisp_args
|
||||
};
|
||||
|
||||
const esp_console_cmd_t i2c_show_display= {
|
||||
.command = "getdisplay",
|
||||
.help="Shows display options and global i2c configuration",
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_show_display,
|
||||
.argtable = NULL
|
||||
.command = CFG_TYPE_HW("display"),
|
||||
.help=desc_display,
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_set_display,
|
||||
.argtable = &i2cdisp_args
|
||||
};
|
||||
cmd_to_json_with_cb(&i2c_set_display,&i2c_set_display_cb);
|
||||
cmd_to_json(&i2c_show_display);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2c_set_display));
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2c_show_display));
|
||||
}
|
||||
static void register_i2cdectect(void)
|
||||
{
|
||||
@@ -1090,9 +973,6 @@ static void register_i2cset(void)
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cset_cmd));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void register_i2cdump(void)
|
||||
{
|
||||
i2cdump_args.chip_address = arg_int1("c", "chip", "<chip_addr>", "Specify the address of the chip on that bus");
|
||||
@@ -1109,36 +989,6 @@ static void register_i2cdump(void)
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cdump_cmd));
|
||||
}
|
||||
|
||||
static void register_i2ccheck(){
|
||||
i2ccheck_args.port = arg_int0("p", "port", "<0|1>", "Set the I2C bus port number");
|
||||
i2ccheck_args.end = arg_end(2);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "i2ccheck",
|
||||
.help = "Check if the I2C bus is installed",
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_check,
|
||||
.argtable = &i2ccheck_args
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
|
||||
|
||||
static void register_i2cstop(){
|
||||
i2cstop_args.port = arg_int0("p", "port", "<0|1>", "I2C bus port number");
|
||||
i2cstop_args.end = arg_end(2);
|
||||
|
||||
const esp_console_cmd_t i2cconfig_cmd = {
|
||||
.command = "i2cstop",
|
||||
.help = "Stop the I2C bus",
|
||||
.hint = NULL,
|
||||
.func = &do_i2c_stop,
|
||||
.argtable = &i2cstop_args
|
||||
};
|
||||
cmd_to_json(&i2cconfig_cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cconfig_cmd));
|
||||
}
|
||||
|
||||
cJSON * i2config_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
@@ -1151,9 +1001,9 @@ cJSON * i2config_cb(){
|
||||
cJSON_AddNumberToObject(values,"sda",i2c->sda_io_num);
|
||||
}
|
||||
if(i2c->master.clk_speed>0) {
|
||||
cJSON_AddNumberToObject(values,"freq",i2c->master.clk_speed);
|
||||
cJSON_AddNumberToObject(values,"speed",i2c->master.clk_speed);
|
||||
}
|
||||
if(i2c_port>0) {
|
||||
if(i2c_port>=0) {
|
||||
cJSON_AddNumberToObject(values,"port",i2c_port);
|
||||
}
|
||||
return values;
|
||||
@@ -1182,11 +1032,11 @@ static void register_spiconfig(void)
|
||||
spiconfig_args.clk = arg_int0("k", "clk", "<n>", "Clock GPIO");
|
||||
spiconfig_args.data = arg_int0("d","data", "<n>","Data GPIO");
|
||||
spiconfig_args.dc = arg_int0("c","dc", "<n>", "DC GPIO");
|
||||
spiconfig_args.host= arg_int0("h", "host", "int", "SPI Host Number");
|
||||
spiconfig_args.host= arg_int0("h", "host", "1|2", "SPI Host Number");
|
||||
spiconfig_args.end = arg_end(4);
|
||||
const esp_console_cmd_t spiconfig_cmd = {
|
||||
.command = "spiconfig",
|
||||
.help = "SPI Bus Parameters",
|
||||
.command = CFG_TYPE_HW("spi"),
|
||||
.help = desc_spiconfig,
|
||||
.hint = NULL,
|
||||
.func = &do_spiconfig_cmd,
|
||||
.argtable = &spiconfig_args
|
||||
@@ -1201,11 +1051,10 @@ static void register_i2cconfig(void)
|
||||
i2cconfig_args.freq = arg_int0("f", "speed", "int", "Frequency (Hz) e.g. 100000");
|
||||
i2cconfig_args.sda = arg_int0("d", "sda", "<n>", "SDA GPIO. e.g. 19");
|
||||
i2cconfig_args.scl = arg_int0("c", "scl", "<n>", "SCL GPIO. e.g. 18");
|
||||
i2cconfig_args.load = arg_lit0("l", "load", "Load Existing Configuration");
|
||||
i2cconfig_args.end = arg_end(4);
|
||||
const esp_console_cmd_t i2cconfig_cmd = {
|
||||
.command = "i2cconfig",
|
||||
.help = "I2C Bus Parameters",
|
||||
.command = CFG_TYPE_HW("i2c"),
|
||||
.help = desc_i2c,
|
||||
.hint = NULL,
|
||||
.func = &do_i2cconfig_cmd,
|
||||
.argtable = &i2cconfig_args
|
||||
@@ -1223,6 +1072,4 @@ void register_i2ctools(void)
|
||||
register_i2cset();
|
||||
register_i2cdump();
|
||||
register_i2c_set_display();
|
||||
register_i2cstop();
|
||||
register_i2ccheck();
|
||||
}
|
||||
|
||||
@@ -330,11 +330,11 @@ static int set_value(int argc, char **argv)
|
||||
const char *key = set_args.key->sval[0];
|
||||
const char *type = set_args.type->sval[0];
|
||||
const char *values = set_args.value->sval[0];
|
||||
log_send_messaging(MESSAGING_INFO, "Setting '%s' (type %s)", key,type);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "Setting '%s' (type %s)", key,type);
|
||||
esp_err_t err = set_value_in_nvs(key, type, values);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
log_send_messaging(MESSAGING_ERROR, "%s", esp_err_to_name(err));
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "%s", esp_err_to_name(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ static int get_value(int argc, char **argv)
|
||||
esp_err_t err = get_value_from_nvs(key, type);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
log_send_messaging(MESSAGING_ERROR, "%s", esp_err_to_name(err));
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "%s", esp_err_to_name(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ static int erase_value(int argc, char **argv)
|
||||
esp_err_t err = erase(key);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
log_send_messaging(MESSAGING_ERROR, "%s", esp_err_to_name(err));
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "%s", esp_err_to_name(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ static int erase_namespace(int argc, char **argv)
|
||||
|
||||
esp_err_t err = erase_all(name);
|
||||
if (err != ESP_OK) {
|
||||
log_send_messaging(MESSAGING_ERROR, "%s", esp_err_to_name(err));
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "%s", esp_err_to_name(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -411,11 +411,11 @@ static int erase_wifi_manager(int argc, char **argv)
|
||||
}
|
||||
nvs_close(nvs);
|
||||
if (err != ESP_OK) {
|
||||
log_send_messaging(MESSAGING_ERROR, "wifi manager configuration was not erase. %s", esp_err_to_name(err));
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "wifi manager configuration was not erase. %s", esp_err_to_name(err));
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
log_send_messaging(MESSAGING_WARNING, "Wifi manager configuration was erased");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Wifi manager configuration was erased");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -32,25 +32,30 @@
|
||||
#include "messaging.h"
|
||||
#include "platform_console.h"
|
||||
#include "trace.h"
|
||||
|
||||
#ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
|
||||
#ifdef CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
|
||||
#define WITH_TASKS_INFO 1
|
||||
#endif
|
||||
|
||||
static struct {
|
||||
struct arg_str *scanmode;
|
||||
struct arg_lit *disable_power_save;
|
||||
struct arg_end *end;
|
||||
} wifi_parms_arg;
|
||||
static struct {
|
||||
struct arg_str *name;
|
||||
struct arg_end *end;
|
||||
} name_args;
|
||||
static struct {
|
||||
struct arg_lit *telnet;
|
||||
struct arg_lit *btspeaker;
|
||||
struct arg_lit *airplay;
|
||||
struct arg_str *telnet;
|
||||
#if WITH_TASKS_INFO
|
||||
struct arg_lit *stats;
|
||||
#endif
|
||||
struct arg_end *end;
|
||||
} set_services_args;
|
||||
static const char * TAG = "cmd_system";
|
||||
|
||||
static void register_setbtsource();
|
||||
//static void register_setbtsource();
|
||||
static void register_free();
|
||||
static void register_setdevicename();
|
||||
static void register_heap();
|
||||
@@ -62,13 +67,15 @@ static void register_factory_boot();
|
||||
static void register_restart_ota();
|
||||
static void register_update_certs();
|
||||
static void register_set_services();
|
||||
static void register_set_wifi_parms();
|
||||
#if WITH_TASKS_INFO
|
||||
static void register_tasks();
|
||||
#endif
|
||||
extern BaseType_t wifi_manager_task;
|
||||
void register_system()
|
||||
{
|
||||
register_setbtsource();
|
||||
register_set_wifi_parms();
|
||||
// register_setbtsource();
|
||||
register_free();
|
||||
register_set_services();
|
||||
register_heap();
|
||||
@@ -90,7 +97,7 @@ static int get_version(int argc, char **argv)
|
||||
{
|
||||
esp_chip_info_t info;
|
||||
esp_chip_info(&info);
|
||||
log_send_messaging(MESSAGING_INFO,
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,
|
||||
"IDF Version:%s\r\n"
|
||||
"Chip info:\r\n"
|
||||
"\tmodel:%s\r\n"
|
||||
@@ -196,7 +203,7 @@ static int restart(int argc, char **argv)
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING, "\n\nPerforming a simple restart to the currently active partition.");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
@@ -205,7 +212,7 @@ static int restart(int argc, char **argv)
|
||||
|
||||
void simple_restart()
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING,"\n\n Called to perform a simple system reboot.");
|
||||
log_send_messaging(MESSAGING_WARNING,"System reboot requested.");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
@@ -216,24 +223,24 @@ void simple_restart()
|
||||
}
|
||||
|
||||
esp_err_t guided_restart_ota(){
|
||||
log_send_messaging(MESSAGING_WARNING,"\n\nCalled for a reboot to OTA Application");
|
||||
log_send_messaging(MESSAGING_WARNING,"System reboot to Application requested");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_OTA_0);
|
||||
return ESP_FAIL; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
esp_err_t guided_factory(){
|
||||
log_send_messaging(MESSAGING_WARNING,"\n\nCalled for a reboot to recovery application");
|
||||
log_send_messaging(MESSAGING_WARNING,"System reboot to recovery requested");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_FACTORY);
|
||||
return ESP_FAIL; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
static int restart_factory(int argc, char **argv)
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING, "Executing guided boot into recovery");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Executing guided boot into recovery");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_FACTORY);
|
||||
return 0; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
static int restart_ota(int argc, char **argv)
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING, "Executing guided boot into ota app 0");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Executing guided boot into ota app 0");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_OTA_0);
|
||||
return 0; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
@@ -241,7 +248,7 @@ static void register_restart()
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "restart",
|
||||
.help = "Software reset of the chip",
|
||||
.help = "Reboot system",
|
||||
.hint = NULL,
|
||||
.func = &restart,
|
||||
};
|
||||
@@ -252,7 +259,7 @@ static void register_restart_ota()
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "restart_ota",
|
||||
.help = "Selects the ota app partition to boot from and performa a software reset of the chip",
|
||||
.help = "Reboot system to Squeezelite",
|
||||
.hint = NULL,
|
||||
.func = &restart_ota,
|
||||
};
|
||||
@@ -264,7 +271,7 @@ static void register_factory_boot()
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "recovery",
|
||||
.help = "Resets and boot to recovery (if available)",
|
||||
.help = "Reboot system to Recovery",
|
||||
.hint = NULL,
|
||||
.func = &restart_factory,
|
||||
};
|
||||
@@ -275,94 +282,10 @@ static void register_factory_boot()
|
||||
|
||||
static int free_mem(int argc, char **argv)
|
||||
{
|
||||
log_send_messaging(MESSAGING_INFO,"%d", esp_get_free_heap_size());
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"%d", esp_get_free_heap_size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
static struct {
|
||||
struct arg_str *a2dp_dev_name;
|
||||
struct arg_str *a2dp_sink_name;
|
||||
struct arg_str *wakeup_gpio_level;
|
||||
struct arg_str *bt_sink_pin;
|
||||
struct arg_str *enable_bt_sink;
|
||||
struct arg_end *end;
|
||||
} set_btsource_args;
|
||||
*/
|
||||
|
||||
//static int do_set_btsource(int argc, char **argv)
|
||||
//{
|
||||
// a2dp_dev_name;
|
||||
// a2dp_sink_name;
|
||||
// wakeup_gpio_level;
|
||||
// bt_sink_pin;
|
||||
// enable_bt_sink;
|
||||
|
||||
|
||||
|
||||
// int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&deep_sleep_args);
|
||||
// if (nerrors != 0) {
|
||||
// return 1;
|
||||
// }
|
||||
// if (deep_sleep_args.wakeup_time->count) {
|
||||
// uint64_t timeout = 1000ULL * deep_sleep_args.wakeup_time->ival[0];
|
||||
// log_send_messaging(MESSAGING_INFO, "Enabling timer wakeup, timeout=%lluus", timeout);
|
||||
// ESP_ERROR_CHECK( esp_sleep_enable_timer_wakeup(timeout) );
|
||||
// }
|
||||
// if (deep_sleep_args.wakeup_gpio_num->count) {
|
||||
// int io_num = deep_sleep_args.wakeup_gpio_num->ival[0];
|
||||
// if (!rtc_gpio_is_valid_gpio(io_num)) {
|
||||
// log_send_messaging(MESSAGING_ERROR, "GPIO %d is not an RTC IO", io_num);
|
||||
// return 1;
|
||||
// }
|
||||
// int level = 0;
|
||||
// if (deep_sleep_args.wakeup_gpio_level->count) {
|
||||
// level = deep_sleep_args.wakeup_gpio_level->ival[0];
|
||||
// if (level != 0 && level != 1) {
|
||||
// log_send_messaging(MESSAGING_ERROR, "Invalid wakeup level: %d", level);
|
||||
// return 1;
|
||||
// }
|
||||
// }
|
||||
// log_send_messaging(MESSAGING_INFO, "Enabling wakeup on GPIO%d, wakeup on %s level",
|
||||
// io_num, level ? "HIGH" : "LOW");
|
||||
//
|
||||
// ESP_ERROR_CHECK( esp_sleep_enable_ext1_wakeup(1ULL << io_num, level) );
|
||||
// }
|
||||
// rtc_gpio_isolate(GPIO_NUM_12);
|
||||
// esp_deep_sleep_start();
|
||||
//return 0;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
static void register_setbtsource(){
|
||||
|
||||
// a2dp_dev_name;
|
||||
// a2dp_sink_name;
|
||||
// wakeup_gpio_level;
|
||||
// bt_sink_pin;
|
||||
// enable_bt_sink;
|
||||
//
|
||||
// set_btsource_args.wakeup_time =
|
||||
// arg_int0("t", "time", "<t>", "Wake up time, ms");
|
||||
// set_btsource_args.wakeup_gpio_num =
|
||||
// arg_int0(NULL, "io", "<n>",
|
||||
// "If specified, wakeup using GPIO with given number");
|
||||
// set_btsource_args.wakeup_gpio_level =
|
||||
// arg_int0(NULL, "io_level", "<0|1>", "GPIO level to trigger wakeup");
|
||||
// set_btsource_args.end = arg_end(3);
|
||||
//
|
||||
// const esp_console_cmd_t cmd = {
|
||||
// .command = "deep_sleep",
|
||||
// .help = "Enter deep sleep mode. "
|
||||
// "Two wakeup modes are supported: timer and GPIO. "
|
||||
// "If no wakeup option is specified, will sleep indefinitely.",
|
||||
// .hint = NULL,
|
||||
// .func = &do_set_btsource,
|
||||
// .argtable = &set_btsource_args
|
||||
// };
|
||||
// ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
static void register_free()
|
||||
{
|
||||
@@ -380,7 +303,7 @@ static void register_free()
|
||||
static int heap_size(int argc, char **argv)
|
||||
{
|
||||
uint32_t heap_size = heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT);
|
||||
log_send_messaging(MESSAGING_INFO, "min heap size: %u", heap_size);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "min heap size: %u", heap_size);
|
||||
return 0;
|
||||
}
|
||||
cJSON * setdevicename_cb(){
|
||||
@@ -397,12 +320,82 @@ static int setnamevar(char * nvsname, FILE *f, char * value){
|
||||
}
|
||||
return err==ESP_OK?0:1;
|
||||
}
|
||||
typedef enum {
|
||||
SCANNING,
|
||||
PROCESSING_NAME
|
||||
} scanstate_t;
|
||||
int set_squeezelite_player_name(FILE * f,const char * name){
|
||||
char * nvs_config= config_alloc_get(NVS_TYPE_STR, "autoexec1");
|
||||
char **argv = NULL;
|
||||
esp_err_t err=ESP_OK;
|
||||
int nerrors=0;
|
||||
bool bFoundParm=false;
|
||||
scanstate_t state=SCANNING;
|
||||
char * newCommandLine = NULL;
|
||||
char * parm = " -n ";
|
||||
char * cleaned_name = strdup(name);
|
||||
for(char * p=cleaned_name;*p!='\0';p++){
|
||||
if(*p == ' '){
|
||||
*p='_'; // no spaces allowed
|
||||
}
|
||||
}
|
||||
if(nvs_config && strlen(nvs_config)>0){
|
||||
// allocate enough memory to hold the new command line
|
||||
size_t cmdLength = strlen(nvs_config) + strlen(cleaned_name) + strlen(parm) +1 ;
|
||||
newCommandLine = malloc(cmdLength);
|
||||
memset(newCommandLine,0x00, cmdLength);
|
||||
ESP_LOGD(TAG,"Parsing command %s",nvs_config);
|
||||
argv = (char **) calloc(22, sizeof(char *));
|
||||
if (argv == NULL) {
|
||||
FREE_AND_NULL(nvs_config);
|
||||
return 1;
|
||||
}
|
||||
size_t argc = esp_console_split_argv(nvs_config, argv,22);
|
||||
for(int i=0;i<argc;i++) {
|
||||
if(i>0){
|
||||
strcat(newCommandLine," ");
|
||||
}
|
||||
switch (state)
|
||||
{
|
||||
case SCANNING:
|
||||
strcat(newCommandLine,argv[i]);
|
||||
if(strcasecmp(argv[i],"--name")==0 || strcasecmp(argv[i],"-n")==0 ){
|
||||
state = PROCESSING_NAME;
|
||||
}
|
||||
break;
|
||||
case PROCESSING_NAME:
|
||||
bFoundParm=true;
|
||||
strcat(newCommandLine,cleaned_name);
|
||||
state = SCANNING;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!bFoundParm){
|
||||
strcat(newCommandLine,parm);
|
||||
strcat(newCommandLine,name);
|
||||
}
|
||||
fprintf(f,"Squeezelite player name changed to %s\n",newCommandLine);
|
||||
if((err=config_set_value(NVS_TYPE_STR, "autoexec1",newCommandLine))!=ESP_OK){
|
||||
nerrors++;
|
||||
fprintf(f,"Failed updating squeezelite command. %s", esp_err_to_name(err));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FREE_AND_NULL(nvs_config);
|
||||
FREE_AND_NULL(argv);
|
||||
return nerrors;
|
||||
|
||||
}
|
||||
static int setdevicename(int argc, char **argv)
|
||||
{
|
||||
char * name = NULL;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&name_args);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check "--name" option */
|
||||
@@ -410,32 +403,35 @@ static int setdevicename(int argc, char **argv)
|
||||
name=strdup(name_args.name->sval[0]);
|
||||
}
|
||||
else {
|
||||
log_send_messaging(MESSAGING_ERROR,"Name must be specified.");
|
||||
return 0;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Name must be specified.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
nerrors+=setnamevar("a2dp_dev_name", f, name);
|
||||
nerrors+=setnamevar("airplay_name", f, name);
|
||||
nerrors+=setnamevar("ap_ssid", f, name);
|
||||
nerrors+=setnamevar("bt_name", f, name);
|
||||
nerrors+=setnamevar("host_name", f, name);
|
||||
nerrors+=set_squeezelite_player_name(f, name);
|
||||
if(nerrors==0){
|
||||
fprintf(f,"Device name changed to %s\n",name);
|
||||
}
|
||||
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
FREE_AND_NULL(name);
|
||||
fflush (f);
|
||||
log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
return nerrors==0;
|
||||
return nerrors;
|
||||
|
||||
}
|
||||
|
||||
@@ -459,7 +455,7 @@ static void register_setdevicename()
|
||||
name_args.name = arg_str0("n", "name", default_host_name, "New Name");
|
||||
name_args.end = arg_end(8);
|
||||
const esp_console_cmd_t set_name= {
|
||||
.command = "setname",
|
||||
.command = CFG_TYPE_SYST("name"),
|
||||
.help="Device Name",
|
||||
.hint = NULL,
|
||||
.func = &setdevicename,
|
||||
@@ -476,16 +472,16 @@ static int tasks_info(int argc, char **argv)
|
||||
const size_t bytes_per_task = 40; /* see vTaskList description */
|
||||
char *task_list_buffer = malloc(uxTaskGetNumberOfTasks() * bytes_per_task);
|
||||
if (task_list_buffer == NULL) {
|
||||
log_send_messaging(MESSAGING_ERROR, "failed to allocate buffer for vTaskList output");
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "failed to allocate buffer for vTaskList output");
|
||||
return 1;
|
||||
}
|
||||
log_send_messaging(MESSAGING_INFO,"Task Name\tStatus\tPrio\tHWM\tTask#"
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"Task Name\tStatus\tPrio\tHWM\tTask#"
|
||||
#ifdef CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
|
||||
"\tAffinity"
|
||||
#endif
|
||||
"\n");
|
||||
vTaskList(task_list_buffer);
|
||||
log_send_messaging(MESSAGING_INFO,"%s", task_list_buffer);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"%s", task_list_buffer);
|
||||
free(task_list_buffer);
|
||||
return 0;
|
||||
}
|
||||
@@ -505,7 +501,7 @@ static void register_tasks()
|
||||
|
||||
extern esp_err_t update_certificates(bool force);
|
||||
static int force_update_cert(int argc, char **argv){
|
||||
return update_certificates(true)==ESP_OK;
|
||||
return update_certificates(true);
|
||||
}
|
||||
|
||||
static void register_update_certs()
|
||||
@@ -539,30 +535,31 @@ static int deep_sleep(int argc, char **argv)
|
||||
}
|
||||
if (deep_sleep_args.wakeup_time->count) {
|
||||
uint64_t timeout = 1000ULL * deep_sleep_args.wakeup_time->ival[0];
|
||||
log_send_messaging(MESSAGING_INFO, "Enabling timer wakeup, timeout=%lluus", timeout);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "Enabling timer wakeup, timeout=%lluus", timeout);
|
||||
ESP_ERROR_CHECK( esp_sleep_enable_timer_wakeup(timeout) );
|
||||
}
|
||||
if (deep_sleep_args.wakeup_gpio_num->count) {
|
||||
int io_num = deep_sleep_args.wakeup_gpio_num->ival[0];
|
||||
if (!rtc_gpio_is_valid_gpio(io_num)) {
|
||||
log_send_messaging(MESSAGING_ERROR, "GPIO %d is not an RTC IO", io_num);
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "GPIO %d is not an RTC IO", io_num);
|
||||
return 1;
|
||||
}
|
||||
int level = 0;
|
||||
if (deep_sleep_args.wakeup_gpio_level->count) {
|
||||
level = deep_sleep_args.wakeup_gpio_level->ival[0];
|
||||
if (level != 0 && level != 1) {
|
||||
log_send_messaging(MESSAGING_ERROR, "Invalid wakeup level: %d", level);
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "Invalid wakeup level: %d", level);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
log_send_messaging(MESSAGING_INFO, "Enabling wakeup on GPIO%d, wakeup on %s level",
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "Enabling wakeup on GPIO%d, wakeup on %s level",
|
||||
io_num, level ? "HIGH" : "LOW");
|
||||
|
||||
ESP_ERROR_CHECK( esp_sleep_enable_ext1_wakeup(1ULL << io_num, level) );
|
||||
}
|
||||
rtc_gpio_isolate(GPIO_NUM_12);
|
||||
esp_deep_sleep_start();
|
||||
return 0; // this code will never run. deep sleep will cause the system to restart
|
||||
}
|
||||
|
||||
static void register_deep_sleep()
|
||||
@@ -599,31 +596,112 @@ static int enable_disable(FILE * f,char * nvs_name, struct arg_lit *arg){
|
||||
}
|
||||
return err;
|
||||
}
|
||||
static int do_set_services(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&set_services_args);
|
||||
static int do_configure_wifi(int argc, char **argv){
|
||||
esp_err_t err = ESP_OK;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&wifi_parms_arg);
|
||||
if (nerrors != 0) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
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;
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
nerrors += enable_disable(f,"disable_ps",wifi_parms_arg.disable_power_save);
|
||||
|
||||
if(wifi_parms_arg.scanmode->count>0){
|
||||
if(strcasecmp(wifi_parms_arg.scanmode->sval[0],"Comprehensive") == 0){
|
||||
err = config_set_value(NVS_TYPE_STR, "wifi_smode", "A");
|
||||
}
|
||||
else {
|
||||
err = config_set_value(NVS_TYPE_STR, "wifi_smode", "F");
|
||||
}
|
||||
if(err!=ESP_OK){
|
||||
nerrors++;
|
||||
fprintf(f,"Error setting wifi scan mode to %s. %s\n",wifi_parms_arg.scanmode->sval[0], esp_err_to_name(err));
|
||||
}
|
||||
else {
|
||||
fprintf(f,"Wifi Scan Mode changed to %s\n",wifi_parms_arg.scanmode->sval[0]);
|
||||
}
|
||||
}
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
fflush (f);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
return nerrors;
|
||||
}
|
||||
static int do_set_services(int argc, char **argv)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&set_services_args);
|
||||
if (nerrors != 0) {
|
||||
return 1;
|
||||
}
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
nerrors += enable_disable(f,"enable_airplay",set_services_args.airplay);
|
||||
nerrors += enable_disable(f,"enable_bt_sink",set_services_args.btspeaker);
|
||||
nerrors += enable_disable(f,"telnet_enable",set_services_args.telnet);
|
||||
|
||||
if(set_services_args.telnet->count>0){
|
||||
if(strcasecmp(set_services_args.telnet->sval[0],"Disabled") == 0){
|
||||
err = config_set_value(NVS_TYPE_STR, "telnet_enable", "N");
|
||||
}
|
||||
else if(strcasecmp(set_services_args.telnet->sval[0],"Telnet Only") == 0){
|
||||
err = config_set_value(NVS_TYPE_STR, "telnet_enable", "Y");
|
||||
}
|
||||
else if(strcasecmp(set_services_args.telnet->sval[0],"Telnet and Serial") == 0){
|
||||
err = config_set_value(NVS_TYPE_STR, "telnet_enable", "D");
|
||||
}
|
||||
|
||||
if(err!=ESP_OK){
|
||||
nerrors++;
|
||||
fprintf(f,"Error setting telnet service to %s. %s\n",set_services_args.telnet->sval[0], esp_err_to_name(err));
|
||||
}
|
||||
else {
|
||||
fprintf(f,"Telnet service changed to %s\n",set_services_args.telnet->sval[0]);
|
||||
}
|
||||
}
|
||||
|
||||
#if WITH_TASKS_INFO
|
||||
nerrors += enable_disable(f,"stats",set_services_args.stats);
|
||||
#endif
|
||||
if(!nerrors ){
|
||||
fprintf(f,"Done.\n");
|
||||
}
|
||||
fflush (f);
|
||||
log_send_messaging(nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
return nerrors==0;
|
||||
return nerrors;
|
||||
}
|
||||
|
||||
cJSON * configure_wifi_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
char * p=NULL;
|
||||
if ((p = config_alloc_get(NVS_TYPE_STR, "disable_ps")) != NULL) {
|
||||
cJSON_AddBoolToObject(values,"disable_power_save",strcmp(p,"1") == 0 || strcasecmp(p,"y") == 0);
|
||||
FREE_AND_NULL(p);
|
||||
}
|
||||
if ((p = config_alloc_get(NVS_TYPE_STR, "wifi_smode")) != NULL) {
|
||||
cJSON_AddStringToObject(values,"scanmode",strcasecmp(p,"a") == 0 ?"Comprehensive":"Fast");
|
||||
FREE_AND_NULL(p);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
|
||||
cJSON * set_services_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
char * p=NULL;
|
||||
@@ -636,23 +714,36 @@ cJSON * set_services_cb(){
|
||||
FREE_AND_NULL(p);
|
||||
}
|
||||
if ((p = config_alloc_get(NVS_TYPE_STR, "telnet_enable")) != NULL) {
|
||||
cJSON_AddBoolToObject(values,"telnet",strcasestr("YXD",p)!=NULL);
|
||||
if(strcasestr("YX",p)!=NULL){
|
||||
cJSON_AddStringToObject(values,"telnet","Telnet Only");
|
||||
}
|
||||
else if(strcasestr("D",p)!=NULL){
|
||||
cJSON_AddStringToObject(values,"telnet","Telnet and Serial");
|
||||
}
|
||||
else {
|
||||
cJSON_AddStringToObject(values,"telnet","Disabled");
|
||||
}
|
||||
|
||||
FREE_AND_NULL(p);
|
||||
}
|
||||
#if WITH_TASKS_INFO
|
||||
if((p = config_alloc_get_default(NVS_TYPE_STR, "stats", "n", 0))!=NULL){
|
||||
cJSON_AddBoolToObject(values,"stats",(*p == '1' || *p == 'Y' || *p == 'y')) ;
|
||||
}
|
||||
#endif
|
||||
return values;
|
||||
}
|
||||
|
||||
static void register_set_services(){
|
||||
set_services_args.airplay = arg_lit0(NULL, "AirPlay", "AirPlay");
|
||||
set_services_args.btspeaker = arg_lit0(NULL, "BT_Speaker", "Bluetooth Speaker");
|
||||
set_services_args.telnet= arg_lit0(NULL, "telnet", "Telnet server. Use only for troubleshooting");
|
||||
set_services_args.telnet= arg_str0("t", "telnet","Disabled|Telnet Only|Telnet and Serial","Telnet server. Use only for troubleshooting");
|
||||
#if WITH_TASKS_INFO
|
||||
set_services_args.stats= arg_lit0(NULL, "stats", "System Statistics. Use only for troubleshooting");
|
||||
#endif
|
||||
set_services_args.end=arg_end(2);
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "set_services",
|
||||
.command = CFG_TYPE_SYST("services"),
|
||||
.help = "Services",
|
||||
.argtable = &set_services_args,
|
||||
.hint = NULL,
|
||||
@@ -661,6 +752,21 @@ static void register_set_services(){
|
||||
cmd_to_json_with_cb(&cmd,&set_services_cb);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
static void register_set_wifi_parms(){
|
||||
wifi_parms_arg.scanmode = arg_str0(NULL, "scanmode", "Fast|Comprehensive","Sets the WiFi Scan Mode. Use Comprehensive where more than one AP has the same name on different channels. This will ensure that the AP with the strongest signal is chosen.");
|
||||
wifi_parms_arg.disable_power_save = arg_lit0(NULL, "disable_power_save", "Disable Power Saving. This may help if the wifi connection is unstable.");
|
||||
wifi_parms_arg.end=arg_end(2);
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = CFG_TYPE_SYST("wifi"),
|
||||
.help = "WiFi",
|
||||
.argtable = &wifi_parms_arg,
|
||||
.hint = NULL,
|
||||
.func = &do_configure_wifi,
|
||||
};
|
||||
cmd_to_json_with_cb(&cmd,&configure_wifi_cb);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
/** 'light_sleep' command puts the chip into light sleep mode */
|
||||
|
||||
static struct {
|
||||
@@ -679,22 +785,22 @@ static int light_sleep(int argc, char **argv)
|
||||
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
|
||||
if (light_sleep_args.wakeup_time->count) {
|
||||
uint64_t timeout = 1000ULL * light_sleep_args.wakeup_time->ival[0];
|
||||
log_send_messaging(MESSAGING_INFO, "Enabling timer wakeup, timeout=%lluus", timeout);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "Enabling timer wakeup, timeout=%lluus", timeout);
|
||||
ESP_ERROR_CHECK( esp_sleep_enable_timer_wakeup(timeout) );
|
||||
}
|
||||
int io_count = light_sleep_args.wakeup_gpio_num->count;
|
||||
if (io_count != light_sleep_args.wakeup_gpio_level->count) {
|
||||
log_send_messaging(MESSAGING_INFO, "Should have same number of 'io' and 'io_level' arguments");
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "Should have same number of 'io' and 'io_level' arguments");
|
||||
return 1;
|
||||
}
|
||||
for (int i = 0; i < io_count; ++i) {
|
||||
int io_num = light_sleep_args.wakeup_gpio_num->ival[i];
|
||||
int level = light_sleep_args.wakeup_gpio_level->ival[i];
|
||||
if (level != 0 && level != 1) {
|
||||
log_send_messaging(MESSAGING_ERROR, "Invalid wakeup level: %d", level);
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR, "Invalid wakeup level: %d", level);
|
||||
return 1;
|
||||
}
|
||||
log_send_messaging(MESSAGING_INFO, "Enabling wakeup on GPIO%d, wakeup on %s level",
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "Enabling wakeup on GPIO%d, wakeup on %s level",
|
||||
io_num, level ? "HIGH" : "LOW");
|
||||
|
||||
ESP_ERROR_CHECK( gpio_wakeup_enable(io_num, level ? GPIO_INTR_HIGH_LEVEL : GPIO_INTR_LOW_LEVEL) );
|
||||
@@ -703,7 +809,7 @@ static int light_sleep(int argc, char **argv)
|
||||
ESP_ERROR_CHECK( esp_sleep_enable_gpio_wakeup() );
|
||||
}
|
||||
if (CONFIG_ESP_CONSOLE_UART_NUM <= UART_NUM_1) {
|
||||
log_send_messaging(MESSAGING_INFO, "Enabling UART wakeup (press ENTER to exit light sleep)");
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "Enabling UART wakeup (press ENTER to exit light sleep)");
|
||||
ESP_ERROR_CHECK( uart_set_wakeup_threshold(CONFIG_ESP_CONSOLE_UART_NUM, 3) );
|
||||
ESP_ERROR_CHECK( esp_sleep_enable_uart_wakeup(CONFIG_ESP_CONSOLE_UART_NUM) );
|
||||
}
|
||||
@@ -726,7 +832,7 @@ static int light_sleep(int argc, char **argv)
|
||||
cause_str = "unknown";
|
||||
printf("%d\n", cause);
|
||||
}
|
||||
log_send_messaging(MESSAGING_INFO, "Woke up from: %s", cause_str);
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO, "Woke up from: %s", cause_str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ const char* recovery_prompt = LOG_COLOR_E "recovery-squeezelite-esp32> " LOG_RES
|
||||
|
||||
#define MOUNT_PATH "/data"
|
||||
#define HISTORY_PATH MOUNT_PATH "/history.txt"
|
||||
void run_command(char * line);
|
||||
esp_err_t run_command(char * line);
|
||||
#define ADD_TO_JSON(o,t,n) if (t->n) cJSON_AddStringToObject(o,QUOTE(n),t->n);
|
||||
#define ADD_PARMS_TO_CMD(o,t,n) { cJSON * parms = ParmsToJSON(&t.n->hdr); if(parms) cJSON_AddItemToObject(o,QUOTE(n),parms); }
|
||||
cJSON * cmdList;
|
||||
@@ -99,6 +99,8 @@ cJSON * ParmsToJSON(struct arg_hdr * * argtable){
|
||||
ADD_TO_JSON(entry,table[tabindex],shortopts);
|
||||
cJSON_AddBoolToObject(entry, "checkbox", (table[tabindex]->flag & ARG_HASOPTVALUE)==0 && (table[tabindex]->flag & ARG_HASVALUE)==0);
|
||||
cJSON_AddBoolToObject(entry, "hasvalue", table[tabindex]->flag & ARG_HASVALUE);
|
||||
cJSON_AddNumberToObject(entry,"mincount",table[tabindex]->mincount);
|
||||
cJSON_AddNumberToObject(entry,"maxcount",table[tabindex]->maxcount);
|
||||
cJSON_AddItemToArray(arg_list, entry);
|
||||
tabindex++;
|
||||
}
|
||||
@@ -171,7 +173,7 @@ int arg_parse_msg(int argc, char **argv, struct arg_hdr ** args){
|
||||
if (f != NULL) {
|
||||
arg_print_errors(f, getParmsEnd(args), argv[0]);
|
||||
fflush (f);
|
||||
log_send_messaging(MESSAGING_ERROR,"%s", buf);
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"%s", buf);
|
||||
}
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
@@ -254,7 +256,7 @@ void initialize_console() {
|
||||
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
|
||||
|
||||
/* Initialize the console */
|
||||
esp_console_config_t console_config = { .max_cmdline_args = 22,
|
||||
esp_console_config_t console_config = { .max_cmdline_args = 28,
|
||||
.max_cmdline_length = 600,
|
||||
#if CONFIG_LOG_COLORS
|
||||
.hint_color = atoi(LOG_COLOR_CYAN)
|
||||
@@ -285,7 +287,7 @@ void console_start() {
|
||||
}
|
||||
else {
|
||||
/* Initialize the console */
|
||||
esp_console_config_t console_config = { .max_cmdline_args = 22,
|
||||
esp_console_config_t console_config = { .max_cmdline_args = 28,
|
||||
.max_cmdline_length = 600,
|
||||
#if CONFIG_LOG_COLORS
|
||||
.hint_color = atoi(LOG_COLOR_CYAN)
|
||||
@@ -296,8 +298,10 @@ void console_start() {
|
||||
/* Register commands */
|
||||
esp_console_register_help_command();
|
||||
register_system();
|
||||
register_config_cmd();
|
||||
register_nvs();
|
||||
register_wifi();
|
||||
|
||||
if(!is_recovery_running){
|
||||
register_squeezelite();
|
||||
}
|
||||
@@ -364,7 +368,7 @@ void console_start() {
|
||||
}
|
||||
|
||||
}
|
||||
void run_command(char * line){
|
||||
esp_err_t run_command(char * line){
|
||||
/* Try to run the command */
|
||||
int ret;
|
||||
esp_err_t err = esp_console_run(line, &ret);
|
||||
@@ -373,13 +377,16 @@ void run_command(char * line){
|
||||
ESP_LOGE(TAG,"Unrecognized command: %s", line);
|
||||
} else if (err == ESP_ERR_INVALID_ARG) {
|
||||
// command was empty
|
||||
} else if (err == ESP_OK && ret != ESP_OK) {
|
||||
} else if (err != ESP_OK && ret != ESP_OK) {
|
||||
ESP_LOGW(TAG,"Command returned non-zero error code: 0x%x (%s)", ret,
|
||||
esp_err_to_name(err));
|
||||
esp_err_to_name(err));
|
||||
} else if (err == ESP_OK && ret != ESP_OK) {
|
||||
ESP_LOGW(TAG,"Command returned in error");
|
||||
err = ESP_FAIL;
|
||||
} else if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG,"Internal error: %s", esp_err_to_name(err));
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
static void * console_thread() {
|
||||
if(!is_recovery_running){
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#define CFG_TYPE_HW(a) "cfg-hw-" a
|
||||
#define CFG_TYPE_SYST(a) "cfg-syst-" a
|
||||
#define CFG_TYPE_FW(a) "cfg-fw-" a
|
||||
#define CFG_TYPE_GEN(a) "cfg-gen-" a
|
||||
typedef cJSON * parm_values_fn_t(void);
|
||||
esp_err_t cmd_to_json(const esp_console_cmd_t *cmd);
|
||||
esp_err_t cmd_to_json_with_cb(const esp_console_cmd_t *cmd, parm_values_fn_t parm_values_fn);
|
||||
|
||||
3
components/platform_console/test/CMakeLists.txt
Normal file
3
components/platform_console/test/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS "test_system.c"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES unity tools console json platform_console platform_config )
|
||||
189
components/platform_console/test/test_system.c
Normal file
189
components/platform_console/test/test_system.c
Normal file
@@ -0,0 +1,189 @@
|
||||
/* test_mean.c: Implementation of a testable component.
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include "unity.h"
|
||||
#include "platform_console.h"
|
||||
#include "platform_esp32.h"
|
||||
#include "platform_config.h"
|
||||
#include "string.h"
|
||||
struct arg_lit *arglit;
|
||||
struct arg_int *argint;
|
||||
struct arg_str *argstr;
|
||||
struct arg_end *end;
|
||||
|
||||
extern int is_output_gpio(struct arg_int * gpio, FILE * f, int * gpio_out, bool mandatory);
|
||||
extern void initialize_console();
|
||||
extern esp_err_t run_command(char * line);
|
||||
static char *buf = NULL;
|
||||
static char * s_tmp_line_buf=NULL;
|
||||
static size_t buf_size = 0;
|
||||
static FILE * f;
|
||||
static size_t argc=1;
|
||||
static char ** argv=NULL;
|
||||
static bool config_initialized=false;
|
||||
void init_console(){
|
||||
if(config_initialized) return;
|
||||
initialize_console();
|
||||
config_initialized=true;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void open_mem_stream_file(){
|
||||
f = open_memstream(&buf, &buf_size);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void close_flush_all(void * argtable, int count,bool print){
|
||||
fflush (f);
|
||||
if(print){
|
||||
printf("%s", buf);
|
||||
}
|
||||
fclose(f);
|
||||
free(buf);
|
||||
arg_freetable(argtable,count);
|
||||
free(argv);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
int alloc_split_command_line(char * cmdline){
|
||||
argv = (char **) calloc(22, sizeof(char *));
|
||||
if(!s_tmp_line_buf){
|
||||
s_tmp_line_buf= calloc(strlen(cmdline), 1);
|
||||
}
|
||||
strlcpy(s_tmp_line_buf, cmdline, 22);
|
||||
argc = esp_console_split_argv(s_tmp_line_buf, argv,22);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
int alloc_split_parse_command_line(char * cmdline, void ** args){
|
||||
alloc_split_command_line(cmdline);
|
||||
return arg_parse(argc, argv,args);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Invalid GPIO detected", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test -i 55\n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1,is_output_gpio(argtable[0], f, &out_val, true),"Invalid GPIO not detected");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1,out_val,"GPIO Should be set to -1");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Invalid int gpio: [55] is not a GPIO\n",buf,"Invalid GPIO message wrong");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Input Only GPIO detected", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test -i 35\n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1,is_output_gpio(argtable[0], f, &out_val, true),"Input only GPIO not detected");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1,out_val,"GPIO Should be set to -1");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Invalid int gpio: [35] has input capabilities only\n",buf,"Missing GPIO message wrong");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Valid GPIO Processed", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test -i 33\n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(0,is_output_gpio(argtable[0], f, &out_val, true),"Valid GPIO not recognized");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(33,out_val,"GPIO Should be set to 33");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("",buf,"Valid GPIO shouldn't produce a message");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Missing mandatory GPIO detected", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test \n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1,is_output_gpio(argtable[0], f, &out_val, true),"Missing GPIO not detected");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Missing: int\n",buf,"Missing GPIO parameter message wrong");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1,out_val,"GPIO Should be set to -1");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
}
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Missing mandatory parameter detected", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test \n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1,is_output_gpio(argtable[0], f, &out_val, true),"Missing parameter not detected");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Missing: int\n",buf,"Missing parameter message wrong");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1,out_val,"GPIO Should be set to -1");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
}
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("dac config command", "[config_cmd]")
|
||||
{
|
||||
config_set_value(NVS_TYPE_STR, "dac_config", "");
|
||||
esp_err_t err=run_command("cfg-hw-dac\n");
|
||||
char * nvs_value = config_alloc_get_str("dac_config", NULL,NULL);
|
||||
TEST_ASSERT_NOT_NULL(nvs_value);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK,err,"Running command failed");
|
||||
free(nvs_value);
|
||||
}
|
||||
Reference in New Issue
Block a user