Skip to content

Commit

Permalink
improved locked updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wizmo2 committed Sep 29, 2023
1 parent 07f932a commit e6afaf7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "esp_app_format.h"
#include "tools.h"
#include "messaging.h"
#include "accessors.h"

extern esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t length);
static const char * TAG = "squeezelite_cmd";
Expand Down Expand Up @@ -42,7 +43,6 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {

extern void register_audio_config(void);
extern void register_rotary_config(void);
extern void register_ledvu_config(void);

void register_optional_cmd(void) {
register_rotary_config();
Expand Down
17 changes: 14 additions & 3 deletions components/platform_console/cmd_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ static int do_spdif_cmd(int argc, char **argv){

static int do_rotary_cmd(int argc, char **argv){
rotary_struct_t rotary={ .A = -1, .B = -1, .SW = -1, .longpress = 0, .knobonly=0,.volume_lock=false};

if(is_ledvu_config_locked()) {
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Rotary Encoder Configuration is locked on this platform\n");
return 1;
}

esp_err_t err=ESP_OK;
int nerrors = arg_parse(argc, argv,(void **)&rotary_args);
if (rotary_args.clear->count) {
Expand Down Expand Up @@ -1375,6 +1381,9 @@ static void register_bt_source_config(void){
}

void register_rotary_config(void){
if (!is_rotary_config_locked()){
return;
}
rotary_args.rem = arg_rem("remark","One rotary encoder is supported, quadrature shift with press. Such encoders usually have 2 pins for encoders (A and B), and common C that must be set to ground and an optional SW pin for press. A, B and SW must be pulled up, so automatic pull-up is provided by ESP32, but you can add your own resistors. A bit of filtering on A and B (~470nF) helps for debouncing which is not made by software.\r\nEncoder is normally hard-coded to respectively knob left, right and push on LMS and to volume down/up/play toggle on BT and AirPlay.");
rotary_args.A = arg_int1(NULL,"A","gpio","A/DT gpio");
rotary_args.B = arg_int1(NULL,"B","gpio","B/CLK gpio");
Expand All @@ -1398,6 +1407,9 @@ void register_rotary_config(void){
}

void register_ledvu_config(void){
if (is_ledvu_config_locked()){
return;
}
ledvu_args.type = arg_str0(NULL,"type","WS2812|APA102","Led type (supports one rgb strip to display built in effects and allow remote control through 'dmx' messaging)");
ledvu_args.length = arg_int1(NULL,"length","<1..255>","Strip length (1-255 supported)");
ledvu_args.gpio = arg_int1(NULL,"gpio","<n>","Data pin");
Expand Down Expand Up @@ -1506,9 +1518,8 @@ void register_config_cmd(void){
if(!is_spdif_config_locked()){
register_spdif_config();
}
if (is_ledvu_config_locked()){
register_ledvu_config();
}
register_ledvu_config();

register_optional_cmd();
}

17 changes: 17 additions & 0 deletions components/platform_console/cmd_i2ctools.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ static esp_err_t i2c_master_driver_initialize(const char * cmdname, i2c_config_t

static int do_i2c_set_display(int argc, char **argv)
{
if(is_display_config_locked()) {
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Display Configuration is locked on this platform\n");
return 1;
}
bool bHasi2cConfig = false, bHasSpiConfig=false;
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&i2cdisp_args);
display_config_t config = {
Expand Down Expand Up @@ -445,6 +449,11 @@ static int do_spiconfig_cmd(int argc, char **argv){
.quadwp_io_num = -1,
.quadhd_io_num = -1
};

if(is_spi_config_locked()) {
cmd_send_messaging(argv[0],MESSAGING_ERROR,"SPI Configuration is locked on this platform\n");
return 1;
}
int dc=-1,host = 0;
esp_err_t err=ESP_OK;
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&spiconfig_args);
Expand Down Expand Up @@ -979,6 +988,10 @@ cJSON * i2c_set_display_cb(){
}

static void register_i2c_set_display(){
if (is_display_config_locked()){
return;
}

char * supported_drivers = display_get_supported_drivers();

i2cdisp_args.width = arg_int1("w", "width", "<n>", "Width");
Expand Down Expand Up @@ -1112,6 +1125,10 @@ cJSON * spiconfig_cb(){

static void register_spiconfig(void)
{
if (is_spi_config_locked()){
return;
}

spiconfig_args.clear = arg_lit0(NULL, "clear", "Clear configuration");
spiconfig_args.clk = arg_int0("k", "clk", "<n>", "Clock GPIO");
spiconfig_args.data = arg_int0("d","data", "<n>","Data OUT GPIO");
Expand Down
38 changes: 35 additions & 3 deletions components/services/accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ bool is_spdif_config_locked(){
return false;
}

/****************************************************************************************
*
*/
bool is_ledvu_config_locked(){
#if ( defined CONFIG_LED_VU_CONFIG )
if(strlen(CONFIG_LED_VU_CONFIG) > 0){
Expand All @@ -115,6 +112,41 @@ bool is_ledvu_config_locked(){
return false;
}

bool is_display_config_locked(){
#if ( defined CONFIG_DISPLAY_CONFIG )
if(strlen(CONFIG_DISPLAY_CONFIG) > 0){
return true;
}
#endif
return false;
}

bool is_rotary_config_locked(){
#if ( defined CONFIG_ROTARY_CONFIG )
if(strlen(CONFIG_ROTARY_CONFIG) > 0){
return true;
}
#endif
return false;
}

bool is_spi_config_locked(){
#if ( defined CONFIG_SPI_CONFIG )
if(strlen(CONFIG_SPI_CONFIG) > 0){
return true;
}
#endif
return false;
}

bool is_i2c_config_locked(){
#if ( defined CONFIG_I2C_CONFIG )
if(strlen(CONFIG_I2C_CONFIG) > 0){
return true;
}
#endif
return false;
}

/****************************************************************************************
* Set pin from config string
Expand Down
6 changes: 5 additions & 1 deletion components/services/accessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ const display_config_t * config_display_get();
const eth_config_t * config_eth_get( );
void config_eth_init( eth_config_t * target );
esp_err_t config_display_set(const display_config_t * config);
bool is_display_config_locked();
esp_err_t config_i2c_set(const i2c_config_t * config, int port);
esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char * nvs_name);
esp_err_t config_spi_set(const spi_bus_config_t * config, int host, int dc);
bool is_spi_config_locked();
const i2c_config_t * config_i2c_get(int * i2c_port);
bool is_i2c_config_locked();
const spi_bus_config_t * config_spi_get(spi_host_device_t * spi_host);
const gpio_exp_config_t * config_gpio_exp_get(int index);
void parse_set_GPIO(void (*cb)(int gpio, char *value));
Expand All @@ -123,6 +126,7 @@ bool is_dac_config_locked();
bool are_statistics_enabled();
const rotary_struct_t * config_rotary_get();
esp_err_t config_rotary_set(rotary_struct_t * rotary);
bool is_rotary_config_locked();
const ledvu_struct_t * config_ledvu_get();
esp_err_t config_ledvu_set(ledvu_struct_t * ledvu);
bool is_ledvu_config_locked();
bool is_ledvu_config_locked();

0 comments on commit e6afaf7

Please sign in to comment.