mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 21:17:18 +03:00
buttons extension + config memory leak & external allocation
This commit is contained in:
@@ -69,7 +69,7 @@ void config_set_entry_changed_flag(cJSON * entry, cJSON_bool flag);
|
|||||||
void * pval = config_alloc_get(nt, key);\
|
void * pval = config_alloc_get(nt, key);\
|
||||||
if(pval!=NULL){ *value = *(t * )pval; free(pval); return ESP_OK; }\
|
if(pval!=NULL){ *value = *(t * )pval; free(pval); return ESP_OK; }\
|
||||||
return ESP_FAIL;}
|
return ESP_FAIL;}
|
||||||
#ifdef RECOVERY_APPLICATION
|
#if RECOVERY_APPLICATION==0
|
||||||
static void * malloc_fn(size_t sz){
|
static void * malloc_fn(size_t sz){
|
||||||
|
|
||||||
void * ptr = heap_caps_malloc(sz, MALLOC_CAP_SPIRAM);
|
void * ptr = heap_caps_malloc(sz, MALLOC_CAP_SPIRAM);
|
||||||
@@ -80,7 +80,7 @@ static void * malloc_fn(size_t sz){
|
|||||||
}
|
}
|
||||||
static void * free_fn(void * ptr){
|
static void * free_fn(void * ptr){
|
||||||
if(ptr!=NULL){
|
if(ptr!=NULL){
|
||||||
free(ptr);
|
heap_caps_free(ptr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ESP_LOGW(TAG,"free_fn: Cannot free null pointer!");
|
ESP_LOGW(TAG,"free_fn: Cannot free null pointer!");
|
||||||
@@ -92,7 +92,7 @@ void init_cJSON(){
|
|||||||
static cJSON_Hooks hooks;
|
static cJSON_Hooks hooks;
|
||||||
// initialize cJSON hooks it uses SPIRAM memory
|
// initialize cJSON hooks it uses SPIRAM memory
|
||||||
// as opposed to IRAM
|
// as opposed to IRAM
|
||||||
#ifndef RECOVERY_APPLICATION
|
#if RECOVERY_APPLICATION==0
|
||||||
// In squeezelite mode, allocate memory from PSRAM. Otherwise allocate from internal RAM
|
// In squeezelite mode, allocate memory from PSRAM. Otherwise allocate from internal RAM
|
||||||
// as recovery will lock flash access when erasing FLASH or writing to OTA partition.
|
// as recovery will lock flash access when erasing FLASH or writing to OTA partition.
|
||||||
hooks.malloc_fn=&malloc_fn;
|
hooks.malloc_fn=&malloc_fn;
|
||||||
@@ -228,6 +228,8 @@ cJSON * config_set_value_safe(nvs_type_t nvs_type, const char *key, void * value
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ESP_LOGD(TAG, "Config not changed. ");
|
ESP_LOGD(TAG, "Config not changed. ");
|
||||||
|
cJSON_Delete(entry);
|
||||||
|
entry = existing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -697,7 +699,6 @@ esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, void * value){
|
|||||||
else {
|
else {
|
||||||
ESP_LOGV(TAG,"config_set_value completed");
|
ESP_LOGV(TAG,"config_set_value completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
config_unlock();
|
config_unlock();
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ static int n_buttons = 0;
|
|||||||
#define DEBOUNCE 50
|
#define DEBOUNCE 50
|
||||||
|
|
||||||
static EXT_RAM_ATTR struct button_s {
|
static EXT_RAM_ATTR struct button_s {
|
||||||
void *id;
|
void *client;
|
||||||
int gpio;
|
int gpio;
|
||||||
int debounce;
|
int debounce;
|
||||||
button_handler handler;
|
button_handler handler;
|
||||||
@@ -123,18 +123,18 @@ static void buttons_task(void* arg) {
|
|||||||
if (event == BUTTON_RELEASED) {
|
if (event == BUTTON_RELEASED) {
|
||||||
// early release of a long-press button, send press/release
|
// early release of a long-press button, send press/release
|
||||||
if (!button.shifting) {
|
if (!button.shifting) {
|
||||||
(*button.handler)(button.id, BUTTON_PRESSED, press, false);
|
(*button.handler)(button.client, BUTTON_PRESSED, press, false);
|
||||||
(*button.handler)(button.id, BUTTON_RELEASED, press, false);
|
(*button.handler)(button.client, BUTTON_RELEASED, press, false);
|
||||||
}
|
}
|
||||||
// button is a copy, so need to go to real context
|
// button is a copy, so need to go to real context
|
||||||
button.self->shifting = false;
|
button.self->shifting = false;
|
||||||
} else if (!button.shifting) {
|
} else if (!button.shifting) {
|
||||||
// normal long press and not shifting so don't discard
|
// normal long press and not shifting so don't discard
|
||||||
(*button.handler)(button.id, BUTTON_PRESSED, press, true);
|
(*button.handler)(button.client, BUTTON_PRESSED, press, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// normal press/release of a button or release of a long-press button
|
// normal press/release of a button or release of a long-press button
|
||||||
if (!button.shifting) (*button.handler)(button.id, event, press, button.long_press);
|
if (!button.shifting) (*button.handler)(button.client, event, press, button.long_press);
|
||||||
// button is a copy, so need to go to real context
|
// button is a copy, so need to go to real context
|
||||||
button.self->shifting = false;
|
button.self->shifting = false;
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ void dummy_handler(void *id, button_event_e event, button_press_e press) {
|
|||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
* Create buttons
|
* Create buttons
|
||||||
*/
|
*/
|
||||||
void button_create(void *id, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio) {
|
void button_create(void *client, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio) {
|
||||||
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__ ((aligned (4)));
|
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__ ((aligned (4)));
|
||||||
static EXT_RAM_ATTR StackType_t xStack[BUTTON_STACK_SIZE] __attribute__ ((aligned (4)));
|
static EXT_RAM_ATTR StackType_t xStack[BUTTON_STACK_SIZE] __attribute__ ((aligned (4)));
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ void button_create(void *id, int gpio, int type, bool pull, int debounce, button
|
|||||||
memset(buttons + n_buttons, 0, sizeof(struct button_s));
|
memset(buttons + n_buttons, 0, sizeof(struct button_s));
|
||||||
|
|
||||||
// set mandatory parameters
|
// set mandatory parameters
|
||||||
buttons[n_buttons].id = id;
|
buttons[n_buttons].client = client;
|
||||||
buttons[n_buttons].gpio = gpio;
|
buttons[n_buttons].gpio = gpio;
|
||||||
buttons[n_buttons].debounce = debounce ? debounce: DEBOUNCE;
|
buttons[n_buttons].debounce = debounce ? debounce: DEBOUNCE;
|
||||||
buttons[n_buttons].handler = handler;
|
buttons[n_buttons].handler = handler;
|
||||||
@@ -214,3 +214,53 @@ void button_create(void *id, int gpio, int type, bool pull, int debounce, button
|
|||||||
|
|
||||||
n_buttons++;
|
n_buttons++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************
|
||||||
|
* Get stored id
|
||||||
|
*/
|
||||||
|
void button_get_client(int gpio) {
|
||||||
|
for (int i = 0; i < n_buttons; i++) {
|
||||||
|
if (buttons[i].gpio == gpio) return buttons[i].client;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************
|
||||||
|
* Update buttons
|
||||||
|
*/
|
||||||
|
void *button_remap(void *client, int gpio, button_handler handler, int long_press, int shifter_gpio) {
|
||||||
|
int i;
|
||||||
|
struct button_s *button = NULL;
|
||||||
|
void *prev_client;
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "remapping GPIO %u, long press %u shifter %u", gpio, long_press, shifter_gpio);
|
||||||
|
|
||||||
|
// find button
|
||||||
|
for (i = 0; i < n_buttons; i++) {
|
||||||
|
if (buttons[i].gpio == gpio) {
|
||||||
|
button = buttons + i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// huh
|
||||||
|
if (!button) return NULL;
|
||||||
|
|
||||||
|
prev_client = button->client;
|
||||||
|
button->client = client;
|
||||||
|
button->handler = handler;
|
||||||
|
button->long_press = long_press;
|
||||||
|
button->shifter_gpio = shifter_gpio;
|
||||||
|
|
||||||
|
// find our shifter (if any)
|
||||||
|
for (i = 0; shifter_gpio != -1 && i < n_buttons; i++) {
|
||||||
|
if (buttons[i].gpio == shifter_gpio) {
|
||||||
|
button->shifter = buttons + i;
|
||||||
|
// a shifter must have a long-press handler
|
||||||
|
if (!buttons[i].long_press) buttons[i].long_press = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return prev_client;
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,4 +33,6 @@ set shifter_gpio to -1 for no shift
|
|||||||
NOTE: shifter buttons *must* be created before shiftee
|
NOTE: shifter buttons *must* be created before shiftee
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void button_create(void *id, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio);
|
void button_create(void *client, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio);
|
||||||
|
void *button_remap(void *client, int gpio, button_handler handler, int long_press, int shifter_gpio);
|
||||||
|
void button_get_client(int gpio);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ void services_init(void) {
|
|||||||
if ((p = strcasestr(nvs_item, "sda")) != NULL) sda = atoi(strchr(p, '=') + 1);
|
if ((p = strcasestr(nvs_item, "sda")) != NULL) sda = atoi(strchr(p, '=') + 1);
|
||||||
if ((p = strcasestr(nvs_item, "speed")) != NULL) i2c_speed = atoi(strchr(p, '=') + 1);
|
if ((p = strcasestr(nvs_item, "speed")) != NULL) i2c_speed = atoi(strchr(p, '=') + 1);
|
||||||
if ((p = strcasestr(nvs_item, "port")) != NULL) i2c_system_port = atoi(strchr(p, '=') + 1);
|
if ((p = strcasestr(nvs_item, "port")) != NULL) i2c_system_port = atoi(strchr(p, '=') + 1);
|
||||||
|
free(nvs_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SQUEEZEAMP
|
#ifdef CONFIG_SQUEEZEAMP
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<sha>799ae4860f9c009ac25c2ec35eb4070c5f474659</sha>
|
<sha>799ae4860f9c009ac25c2ec35eb4070c5f474659</sha>
|
||||||
<email>philippe_44@outlook.com</email>
|
<email>philippe_44@outlook.com</email>
|
||||||
<desc lang="EN">SqueezeESP32 additional player id (100)</desc>
|
<desc lang="EN">SqueezeESP32 additional player id (100)</desc>
|
||||||
<url>http://github.com/sle118/squeezelite-esp32/raw/master/plugin/SqueezeESP32/SqueezeESP32.zip</url>
|
<url>http://github.com/sle118/squeezelite-esp32/raw/master/plugin/SqueezeESP32.zip</url>
|
||||||
<title lang="EN">SqueezeESP32</title>
|
<title lang="EN">SqueezeESP32</title>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
Reference in New Issue
Block a user