mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 21:17:18 +03:00
command to UI backend wip
This commit is contained in:
@@ -11,13 +11,13 @@
|
||||
#include "cmd_i2ctools.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "esp_console.h"
|
||||
#include "platform_console.h"
|
||||
#include "esp_log.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "platform_config.h"
|
||||
#include "accessors.h"
|
||||
|
||||
#include "trace.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 */
|
||||
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
|
||||
@@ -798,6 +798,8 @@ static void register_i2c_set_display(){
|
||||
.func = &do_i2c_show_display,
|
||||
.argtable = NULL
|
||||
};
|
||||
cmd_to_json(&i2c_set_display);
|
||||
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));
|
||||
}
|
||||
@@ -810,6 +812,7 @@ static void register_i2cdectect(void)
|
||||
.func = &do_i2cdetect_cmd,
|
||||
.argtable = NULL
|
||||
};
|
||||
cmd_to_json(&i2cdetect_cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cdetect_cmd));
|
||||
}
|
||||
|
||||
@@ -826,6 +829,7 @@ static void register_i2cget(void)
|
||||
.func = &do_i2cget_cmd,
|
||||
.argtable = &i2cget_args
|
||||
};
|
||||
cmd_to_json(&i2cget_cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cget_cmd));
|
||||
}
|
||||
|
||||
@@ -843,6 +847,7 @@ static void register_i2cset(void)
|
||||
.func = &do_i2cset_cmd,
|
||||
.argtable = &i2cset_args
|
||||
};
|
||||
cmd_to_json(&i2cset_cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cset_cmd));
|
||||
}
|
||||
|
||||
@@ -860,6 +865,7 @@ static void register_i2cdump(void)
|
||||
.func = &do_i2cdump_cmd,
|
||||
.argtable = &i2cdump_args
|
||||
};
|
||||
cmd_to_json(&i2cdump_cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cdump_cmd));
|
||||
}
|
||||
|
||||
@@ -874,6 +880,7 @@ static void register_i2ccheck(){
|
||||
.func = &do_i2c_check,
|
||||
.argtable = &i2ccheck_args
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
|
||||
@@ -889,9 +896,11 @@ static void register_i2cstop(){
|
||||
.func = &do_i2c_stop,
|
||||
.argtable = &i2cstop_args
|
||||
};
|
||||
cmd_to_json(&i2cconfig_cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cconfig_cmd));
|
||||
}
|
||||
|
||||
|
||||
static void register_i2cconfig(void)
|
||||
{
|
||||
i2cconfig_args.port = arg_int0("p", "port", "<0|1>", "Set the I2C bus port number");
|
||||
@@ -907,6 +916,7 @@ static void register_i2cconfig(void)
|
||||
.func = &do_i2cconfig_cmd,
|
||||
.argtable = &i2cconfig_args
|
||||
};
|
||||
cmd_to_json(&i2cconfig_cmd);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&i2cconfig_cmd));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ extern "C" {
|
||||
#include "cmd_nvs.h"
|
||||
#include "nvs.h"
|
||||
#include "nvs_utilities.h"
|
||||
#include "platform_console.h"
|
||||
|
||||
|
||||
|
||||
@@ -547,6 +548,14 @@ void register_nvs()
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&erase_cmd));
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&erase_namespace_cmd));
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&erase_wifimanager_cmd));
|
||||
cmd_to_json(&list_entries_cmd);
|
||||
cmd_to_json(&set_cmd);
|
||||
cmd_to_json(&get_cmd);
|
||||
cmd_to_json(&erase_cmd);
|
||||
cmd_to_json(&erase_namespace_cmd);
|
||||
cmd_to_json(&erase_wifimanager_cmd);
|
||||
|
||||
|
||||
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include "esp_sleep.h"
|
||||
#include "driver/uart.h" // for the uart driver access
|
||||
#include "messaging.h"
|
||||
#include "platform_console.h"
|
||||
|
||||
|
||||
#ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
|
||||
#define WITH_TASKS_INFO 1
|
||||
@@ -92,6 +94,7 @@ static void register_version()
|
||||
.hint = NULL,
|
||||
.func = &get_version,
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
@@ -228,6 +231,7 @@ static void register_restart()
|
||||
.hint = NULL,
|
||||
.func = &restart,
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
static void register_restart_ota()
|
||||
@@ -238,6 +242,7 @@ static void register_restart_ota()
|
||||
.hint = NULL,
|
||||
.func = &restart_ota,
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
@@ -249,6 +254,7 @@ static void register_factory_boot()
|
||||
.hint = NULL,
|
||||
.func = &restart_factory,
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
/** 'free' command prints available heap memory */
|
||||
@@ -267,6 +273,7 @@ static void register_free()
|
||||
.hint = NULL,
|
||||
.func = &free_mem,
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
@@ -286,6 +293,7 @@ static void register_heap()
|
||||
.hint = NULL,
|
||||
.func = &heap_size,
|
||||
};
|
||||
cmd_to_json(&heap_cmd);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&heap_cmd) );
|
||||
|
||||
}
|
||||
@@ -320,6 +328,7 @@ static void register_tasks()
|
||||
.hint = NULL,
|
||||
.func = &tasks_info,
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
@@ -390,6 +399,7 @@ static void register_deep_sleep()
|
||||
.func = &deep_sleep,
|
||||
.argtable = &deep_sleep_args
|
||||
};
|
||||
cmd_to_json(&cmd);
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
@@ -486,5 +496,6 @@ static void register_light_sleep()
|
||||
.argtable = &light_sleep_args
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
cmd_to_json(&cmd);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "led.h"
|
||||
extern bool bypass_wifi_manager;
|
||||
#define JOIN_TIMEOUT_MS (10000)
|
||||
#include "platform_console.h"
|
||||
|
||||
|
||||
extern EventGroupHandle_t wifi_event_group;
|
||||
extern const int CONNECTED_BIT;
|
||||
@@ -46,6 +48,11 @@ static struct {
|
||||
struct arg_end *end;
|
||||
} join_args;
|
||||
|
||||
|
||||
|
||||
// todo: implement access point config - cmd_to_json(&i2cdetect_cmd);
|
||||
|
||||
|
||||
///** Arguments used by 'join' function */
|
||||
//static struct {
|
||||
// struct arg_int *autoconnect;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "esp_pthread.h"
|
||||
#include "cmd_decl.h"
|
||||
#include "wifi_manager.h"
|
||||
|
||||
#include "trace.h"
|
||||
#include "platform_config.h"
|
||||
#include "telnet.h"
|
||||
|
||||
@@ -53,7 +53,71 @@ 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);
|
||||
|
||||
#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;
|
||||
cJSON * get_cmd_list(){
|
||||
return cmdList;
|
||||
}
|
||||
cJSON * ParmsToJSON(struct arg_hdr * * argtable){
|
||||
if(!argtable) return NULL;
|
||||
cJSON * arg_list = cJSON_CreateArray();
|
||||
struct arg_hdr * *table = (struct arg_hdr * *)argtable;
|
||||
int tabindex = 0;
|
||||
while (!(table[tabindex]->flag & ARG_TERMINATOR))
|
||||
{
|
||||
cJSON * entry = cJSON_CreateObject();
|
||||
ADD_TO_JSON(entry,table[tabindex],datatype);
|
||||
ADD_TO_JSON(entry,table[tabindex],glossary);
|
||||
ADD_TO_JSON(entry,table[tabindex],longopts);
|
||||
ADD_TO_JSON(entry,table[tabindex],shortopts);
|
||||
cJSON_AddBoolToObject(entry, "isoptional", table[tabindex]->flag & ARG_HASOPTVALUE);
|
||||
cJSON_AddBoolToObject(entry, "hasvalue", table[tabindex]->flag & ARG_HASVALUE);
|
||||
cJSON_AddItemToArray(arg_list, entry);
|
||||
tabindex++;
|
||||
}
|
||||
return arg_list;
|
||||
}
|
||||
esp_err_t cmd_to_json(const esp_console_cmd_t *cmd)
|
||||
{
|
||||
if(!cmdList){
|
||||
cmdList=cJSON_CreateObject();
|
||||
}
|
||||
if (cmd->command == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (strchr(cmd->command, ' ') != NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
cJSON * jsoncmd = cJSON_CreateObject();
|
||||
ADD_TO_JSON(jsoncmd,cmd,help);
|
||||
ADD_TO_JSON(jsoncmd,cmd,hint);
|
||||
if(cmd->argtable){
|
||||
cJSON_AddItemToObject(jsoncmd,"argtable",ParmsToJSON(cmd->argtable));
|
||||
}
|
||||
if (cmd->hint) {
|
||||
cJSON_AddStringToObject(jsoncmd, "hint", cmd->hint);
|
||||
}
|
||||
else if (cmd->argtable) {
|
||||
/* Generate hint based on cmd->argtable */
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
if (f != NULL) {
|
||||
arg_print_syntax(f, cmd->argtable, NULL);
|
||||
fclose(f);
|
||||
}
|
||||
cJSON_AddStringToObject(jsoncmd, "hint", buf);
|
||||
free(buf);
|
||||
}
|
||||
char * b=cJSON_Print(jsoncmd);
|
||||
if(b){
|
||||
ESP_LOGI(TAG,"Adding command table %s",b);
|
||||
free(b);
|
||||
}
|
||||
cJSON_AddItemToObject(cmdList, cmd->command,jsoncmd);
|
||||
return ESP_OK;
|
||||
}
|
||||
void process_autoexec(){
|
||||
int i=1;
|
||||
char autoexec_name[21]={0};
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "esp_console.h"
|
||||
#include "cJSON.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
esp_err_t cmd_to_json(const esp_console_cmd_t *cmd);
|
||||
cJSON * get_cmd_list();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user