mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 21:17:18 +03:00
json button mapping config
This commit is contained in:
38
.cproject
38
.cproject
@@ -489,18 +489,48 @@
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cygwin.base.58932738;cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.1067614858;cdt.managedbuild.tool.gnu.c.compiler.cygwin.base.1865841553;cdt.managedbuild.tool.gnu.c.compiler.input.cygwin.1383814557">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291.395881736;cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291.395881736.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1907231332;cdt.managedbuild.tool.gnu.cpp.compiler.input.604467026">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291;cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1722031516;cdt.managedbuild.tool.gnu.cpp.compiler.input.2073997022">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291;cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291.;cdt.managedbuild.tool.gnu.cross.c.compiler.1302011176;cdt.managedbuild.tool.gnu.c.compiler.input.539301587">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cygwin.base.58932738;cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.1067614858;cdt.managedbuild.tool.gnu.cpp.compiler.cygwin.base.410547198;cdt.managedbuild.tool.gnu.cpp.compiler.input.cygwin.1499974240">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291.395881736;cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291.395881736.;cdt.managedbuild.tool.gnu.cross.c.compiler.824219909;cdt.managedbuild.tool.gnu.c.compiler.input.644208200">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707;cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707.;cdt.managedbuild.tool.gnu.c.compiler.cygwin.base.211315976;cdt.managedbuild.tool.gnu.c.compiler.input.cygwin.857914729">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.1943329896;cdt.managedbuild.toolchain.gnu.cross.base.1943329896.30011915;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1749746745;cdt.managedbuild.tool.gnu.cpp.compiler.input.1914005798">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
@@ -519,13 +549,7 @@
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291.395881736;cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291.395881736.;cdt.managedbuild.tool.gnu.cross.c.compiler.824219909;cdt.managedbuild.tool.gnu.c.compiler.input.644208200">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
</scannerConfigBuildInfo>
|
||||
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291;cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1722031516;cdt.managedbuild.tool.gnu.cpp.compiler.input.2073997022">
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707;cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707.;cdt.managedbuild.tool.gnu.cpp.compiler.cygwin.base.145410566;cdt.managedbuild.tool.gnu.cpp.compiler.input.cygwin.1181636367">
|
||||
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -66,3 +66,4 @@ libs/
|
||||
/cdump.cmd
|
||||
/_*
|
||||
sdkconfig
|
||||
squeezelite-esp32-jsonblob.zip
|
||||
|
||||
@@ -92,3 +92,25 @@ environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348/PROJECT_
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348/PROJECT_VER/value=custom
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348/append=true
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348/appendContributed=true
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/BATCH_BUILD/delimiter=;
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/BATCH_BUILD/operation=append
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/BATCH_BUILD/value=1
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/IDF_PATH/delimiter=;
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/IDF_PATH/operation=replace
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/IDF_PATH/value=c\:/msys32/opt/esp-idf
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/PATH/delimiter=;
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/PATH/operation=replace
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/PATH/value=C\:\\msys32\\usr\\bin;C\:\\msys32\\mingw32\\bin;C\:\\msys32\\opt\\xtensa-esp32-elf\\bin;C\:\\Python27
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/append=true
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738.859326707/appendContributed=false
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/BATCH_BUILD/delimiter=;
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/BATCH_BUILD/operation=append
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/BATCH_BUILD/value=1
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/IDF_PATH/delimiter=;
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/IDF_PATH/operation=replace
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/IDF_PATH/value=c\:/msys32/opt/esp-idf
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/PATH/delimiter=;
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/PATH/operation=replace
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/PATH/value=C\:\\msys32\\usr\\bin;C\:\\msys32\\mingw32\\bin;C\:\\msys32\\opt\\xtensa-esp32-elf\\bin;C\:\\Python27
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/append=true
|
||||
environment/project/cdt.managedbuild.toolchain.gnu.cygwin.base.58932738/appendContributed=false
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
idf_component_register(SRCS "led.c"
|
||||
idf_component_register(SRCS "led.c" "audio_controls.c" "buttons.c" "services.c" "monitor.c"INCLUDE_DIRS
|
||||
INCLUDE_DIRS . ../tools/
|
||||
|
||||
)
|
||||
|
||||
@@ -24,11 +24,17 @@
|
||||
#include <unistd.h>
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
#include "cJSON.h"
|
||||
#include "buttons.h"
|
||||
#include "audio_controls.h"
|
||||
// BEWARE: the actions below need to stay aligned with the corresponding enum to properly support json parsing
|
||||
static const char * actrls_action_s[ ] = { "ACTRLS_VOLUP","ACTRLS_VOLDOWN","ACTRLS_TOGGLE","ACTRLS_PLAY",
|
||||
"ACTRLS_PAUSE","ACTRLS_STOP","ACTRLS_REW","ACTRLS_FWD","ACTRLS_PREV","ACTRLS_NEXT",
|
||||
"BCTRLS_PUSH", "BCTRLS_UP","BCTRLS_DOWN","BCTRLS_LEFT","BCTRLS_RIGHT", ""} ;
|
||||
|
||||
|
||||
static const char * TAG = "audio controls";
|
||||
|
||||
static actrls_config_t *json_config;
|
||||
static actrls_t default_controls, current_controls;
|
||||
|
||||
static void control_handler(void *id, button_event_e event, button_press_e press, bool long_press) {
|
||||
@@ -86,10 +92,143 @@ void down(void *id, button_event_e event, button_press_e press, bool longpress)
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void actrls_init(int n, const actrls_config_t *config) {
|
||||
esp_err_t actrls_init(int n, const actrls_config_t *config) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
button_create((void*) (config + i), config[i].gpio, config[i].type, config[i].pull, control_handler, config[i].long_press, config[i].shifter_gpio);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
actrls_action_e actrls_parse_action_json(const char * name){
|
||||
|
||||
for(int i=0;actrls_action_s[i][0]!='\0' && i<ACTRLS_MAX;i++){
|
||||
if(!strcmp(actrls_action_s[i], name)){
|
||||
return (actrls_action_e) i;
|
||||
}
|
||||
}
|
||||
return ACTRLS_NONE;
|
||||
}
|
||||
esp_err_t actrls_parse_config_map(const cJSON * member, actrls_config_t *cur_config){
|
||||
const actrls_config_map_t * map=NULL;
|
||||
esp_err_t err=ESP_OK;
|
||||
char *config_pointer = (char*) cur_config;
|
||||
cJSON *button_action;
|
||||
|
||||
char * string = cJSON_Print(member);
|
||||
ESP_LOGD(TAG, "Processing structure member json : %s", string);
|
||||
free(string);
|
||||
|
||||
for(int i = 0;!map && actrls_config_map[i].type!=ACTRLS_MAP_END ;i++){
|
||||
if(!strcmp(member->string, actrls_config_map[i].member)){
|
||||
map = &actrls_config_map[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(!map){
|
||||
ESP_LOGE(TAG,"Unknown structure member [%s]", member->string?member->string:"");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG,
|
||||
"Found map type %d at structure offset %u",
|
||||
map->type, map->offset);
|
||||
void *value = (config_pointer + map->offset);
|
||||
switch (map->type) {
|
||||
case ACTRLS_MAP_TYPE:
|
||||
if (member->child != NULL) {
|
||||
*(int*) value =
|
||||
!strcmp(member->child->string,
|
||||
"BUTTON_LOW") ?
|
||||
BUTTON_LOW : BUTTON_HIGH;
|
||||
} else {
|
||||
ESP_LOGE(TAG,
|
||||
"Button type value expected string value of BUTTON_LOW or BUTTON_HIGH, none found");
|
||||
}
|
||||
break;
|
||||
case ACTRLS_MAP_INT:
|
||||
*(int*) value = member->valueint;
|
||||
break;
|
||||
case ACTRLS_MAP_BOOL:
|
||||
*(bool*) value = cJSON_IsTrue(member);
|
||||
break;
|
||||
case ACTRLS_MAP_ACTION:
|
||||
button_action= cJSON_GetObjectItemCaseSensitive(
|
||||
member, "pressed");
|
||||
if (button_action != NULL) {
|
||||
((actrls_action_e*) value)[0] =
|
||||
actrls_parse_action_json(
|
||||
button_action->string);
|
||||
}
|
||||
button_action = cJSON_GetObjectItemCaseSensitive(
|
||||
member, "released");
|
||||
if (button_action != NULL) {
|
||||
((actrls_action_e*) value)[1] =
|
||||
actrls_parse_action_json(
|
||||
button_action->string);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (err == ESP_OK) {
|
||||
button_create((void*) cur_config, cur_config->gpio,
|
||||
cur_config->type, cur_config->pull,
|
||||
control_handler, cur_config->long_press,
|
||||
cur_config->shifter_gpio);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
esp_err_t actrls_init_json(const char *config) {
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
actrls_config_t *cur_config;
|
||||
|
||||
cJSON *buttons = cJSON_Parse(config);
|
||||
if (buttons != NULL) {
|
||||
if (cJSON_IsArray(buttons)) {
|
||||
int member_count = 0;
|
||||
const cJSON *button;
|
||||
const cJSON *member;
|
||||
cJSON_ArrayForEach(button, buttons)
|
||||
{
|
||||
member_count++;
|
||||
}
|
||||
ESP_LOGD(TAG, "config contains %u button definitions",
|
||||
member_count);
|
||||
if (member_count == 0) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
json_config = malloc(sizeof(actrls_config_t) * member_count);
|
||||
memset(json_config, 0x00, sizeof(actrls_config_t) * member_count);
|
||||
cur_config = json_config;
|
||||
|
||||
cJSON_ArrayForEach(button, buttons)
|
||||
{
|
||||
esp_err_t loc_err = ESP_OK;
|
||||
cJSON_ArrayForEach(member, button)
|
||||
{
|
||||
actrls_parse_config_map(member, cur_config);
|
||||
err = err == ESP_OK ? loc_err : err;
|
||||
}
|
||||
cur_config++;
|
||||
}
|
||||
}
|
||||
|
||||
cJSON_Delete(buttons);
|
||||
} else {
|
||||
err = ESP_FAIL;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
|
||||
@@ -26,6 +26,12 @@ typedef enum { ACTRLS_NONE = -1, ACTRLS_VOLUP, ACTRLS_VOLDOWN, ACTRLS_TOGGLE, A
|
||||
BCTRLS_PUSH, BCTRLS_UP, BCTRLS_DOWN, BCTRLS_LEFT, BCTRLS_RIGHT,
|
||||
ACTRLS_MAX
|
||||
} actrls_action_e;
|
||||
typedef enum {
|
||||
ACTRLS_MAP_INT, ACTRLS_MAP_BOOL, ACTRLS_MAP_ACTION,ACTRLS_MAP_TYPE,ACTRLS_MAP_END
|
||||
} actrls_action_map_element_type_e;
|
||||
|
||||
|
||||
|
||||
typedef void (*actrls_handler)(void);
|
||||
typedef actrls_handler actrls_t[ACTRLS_MAX - ACTRLS_NONE - 1];
|
||||
typedef struct {
|
||||
@@ -37,7 +43,30 @@ typedef struct {
|
||||
actrls_action_e normal[2], longpress[2], shifted[2], longshifted[2]; // [0] keypressed, [1] keyreleased
|
||||
} actrls_config_t;
|
||||
|
||||
void actrls_init(int n, const actrls_config_t *config);
|
||||
|
||||
|
||||
typedef struct {
|
||||
char * member;
|
||||
uint32_t offset;
|
||||
actrls_action_map_element_type_e type;
|
||||
} actrls_config_map_t;
|
||||
|
||||
static const actrls_config_map_t actrls_config_map[] =
|
||||
{
|
||||
{"gpio", offsetof(actrls_config_t,gpio), ACTRLS_MAP_INT},
|
||||
{"type", offsetof(actrls_config_t,type),ACTRLS_MAP_TYPE},
|
||||
{"pull", offsetof(actrls_config_t,pull),ACTRLS_MAP_BOOL},
|
||||
{"long_press", offsetof(actrls_config_t,long_press),ACTRLS_MAP_INT},
|
||||
{"shifter_gpio", offsetof(actrls_config_t,shifter_gpio),ACTRLS_MAP_INT},
|
||||
{"normal", offsetof(actrls_config_t,normal), ACTRLS_MAP_ACTION},
|
||||
{"longpress", offsetof(actrls_config_t,longpress), ACTRLS_MAP_ACTION},
|
||||
{"longshifted", offsetof(actrls_config_t,longshifted), ACTRLS_MAP_ACTION},
|
||||
{"", 0,ACTRLS_MAP_END}
|
||||
};
|
||||
|
||||
|
||||
esp_err_t actrls_init(int n, const actrls_config_t *config);
|
||||
esp_err_t actrls_init_json(const char * config);
|
||||
void actrls_set_default(const actrls_t controls);
|
||||
void actrls_set(const actrls_t controls);
|
||||
void actrls_unset(void);
|
||||
|
||||
@@ -32,14 +32,18 @@ static struct {
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
static void battery_callback(TimerHandle_t xTimer) {
|
||||
|
||||
battery.sum += adc1_get_raw(ADC1_CHANNEL_7) / 4095. * (10+174)/10. * 1.1;
|
||||
if (++battery.count == 30) {
|
||||
battery.avg = battery.sum / battery.count;
|
||||
battery.sum = battery.count = 0;
|
||||
ESP_LOGI(TAG, "Voltage %.2fV", battery.avg);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
|
||||
Binary file not shown.
@@ -48,6 +48,11 @@
|
||||
#include "config.h"
|
||||
#include "audio_controls.h"
|
||||
|
||||
// todo: this should be moved to the build scripts definitions
|
||||
static const char * actrls_brd1 = "[{\"gpio\":4,\"type\":\"BUTTON_LOW\",\"pull\":true,\"long_press\":1000,\"shifter_gpio\":-1,\"normal\":{\"pressed\":\"ACTRLS_VOLUP\",\"released\":\"ACTRLS_NONE\"},\"longpress\":{\"pressed\":\"ACTRLS_PREV\",\"released\":\"ACTRLS_NONE\"},\"shifted\":{\"pressed\":\"ACTRLS_NONE\",\"released\":\"ACTRLS_NONE\"},\"longshifted\":{\"pressed\":\"ACTRLS_NONE\",\"released\":\"ACTRLS_NONE\"}},{\"gpio\":5,\"type\":\"BUTTON_LOW\",\"pull\":true,\"long_press\":1000,\"shifter_gpio\":4,\"normal\":{\"pressed\":\"ACTRLS_VOLDOWN\",\"released\":\"ACTRLS_NONE\"},\"longpress\":{\"pressed\":\"ACTRLS_NEXT\",\"released\":\"ACTRLS_NONE\"},\"shifted\":{\"pressed\":\"ACTRLS_TOGGLE\",\"released\":\"ACTRLS_NONE\"},\"longshifted\":{\"pressed\":\"ACTRLS_NEXT\",\"released\":\"ACTRLS_NONE\"}}]";
|
||||
static const char * actrls_brd2 ="[{\"gpio\":21,\"type\":\"BUTTON_LOW\",\"pull\":true,\"long_press\":1000,\"shifter_gpio\":-1,\"normal\":{\"pressed\":\"ACTRLS_TOGGLE\",\"released\":\"ACTRLS_NONE\"},\"longpress\":{\"pressed\":\"ACTRLS_STOP\",\"released\":\"ACTRLS_NONE\"},\"shifted\":{\"pressed\":\"ACTRLS_NONE\",\"released\":\"ACTRLS_NONE\"},\"longshifted\":{\"pressed\":\"ACTRLS_NONE\",\"released\":\"ACTRLS_NONE\"}},{\"gpio\":18,\"type\":\"BUTTON_LOW\",\"pull\":true,\"long_press\":1000,\"shifter_gpio\":21,\"normal\":{\"pressed\":\"ACTRLS_VOLUP\",\"released\":\"ACTRLS_NONE\"},\"longpress\":{\"pressed\":\"ACTRLS_NONE\",\"released\":\"ACTRLS_NONE\"},\"shifted\":{\"pressed\":\"ACTRLS_NEXT\",\"released\":\"ACTRLS_NONE\"},\"longshifted\":{\"pressed\":\"ACTRLS_FWD\",\"released\":\"ACTRLS_PLAY\"}},{\"gpio\":19,\"type\":\"BUTTON_LOW\",\"pull\":true,\"long_press\":1000,\"shifter_gpio\":21,\"normal\":{\"pressed\":\"ACTRLS_VOLDOWN\",\"released\":\"ACTRLS_NONE\"},\"longpress\":{\"pressed\":\"ACTRLS_NONE\",\"released\":\"ACTRLS_NONE\"},\"shifted\":{\"pressed\":\"ACTRLS_PREV\",\"released\":\"ACTRLS_NONE\"},\"longshifted\":{\"pressed\":\"ACTRLS_REW\",\"released\":\"ACTRLS_PLAY\"}}]";
|
||||
|
||||
|
||||
extern bool enable_bt_sink;
|
||||
extern bool enable_airplay;
|
||||
extern bool jack_mutes_amp;
|
||||
@@ -78,26 +83,6 @@ extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end");
|
||||
|
||||
extern void services_init(void);
|
||||
|
||||
static const actrls_config_t board_1[] = {
|
||||
// normal long shifted long shifted
|
||||
{ 4, BUTTON_LOW, true, 1000, -1, {ACTRLS_VOLUP, ACTRLS_NONE}, {ACTRLS_PREV, ACTRLS_NONE}, {ACTRLS_NONE, ACTRLS_NONE}, {ACTRLS_NONE, ACTRLS_NONE} },
|
||||
{ 5, BUTTON_LOW, true, 1000, 4, {ACTRLS_VOLDOWN, ACTRLS_NONE}, {ACTRLS_NEXT, ACTRLS_NONE}, {ACTRLS_TOGGLE, ACTRLS_NONE}, {BCTRLS_DOWN, ACTRLS_NONE} },
|
||||
};
|
||||
|
||||
static const actrls_config_t board_2[] = {
|
||||
// normal long shifted long shifted
|
||||
{ 21, BUTTON_LOW, true, 1000, -1, {ACTRLS_TOGGLE, ACTRLS_NONE}, {ACTRLS_STOP, ACTRLS_NONE}, {ACTRLS_NONE, ACTRLS_NONE}, {ACTRLS_NONE, ACTRLS_NONE} },
|
||||
{ 18, BUTTON_LOW, true, 1000, 21, {ACTRLS_VOLUP, ACTRLS_NONE}, {ACTRLS_NONE, ACTRLS_NONE}, {ACTRLS_NEXT, ACTRLS_NONE}, {ACTRLS_FWD, ACTRLS_PLAY} },
|
||||
{ 19, BUTTON_LOW, true, 1000, 21, {ACTRLS_VOLDOWN, ACTRLS_NONE}, {ACTRLS_NONE, ACTRLS_NONE}, {ACTRLS_PREV, ACTRLS_NONE}, {ACTRLS_REW, ACTRLS_PLAY} },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
int n;
|
||||
const actrls_config_t *config;
|
||||
} board_configs[] = {
|
||||
{ 2, board_1 },
|
||||
{ 3, board_2 },
|
||||
};
|
||||
|
||||
/* brief this is an exemple of a callback that you can setup in your own app to get notified of wifi manager event */
|
||||
void cb_connection_got_ip(void *pvParameter){
|
||||
@@ -308,8 +293,14 @@ void register_default_nvs(){
|
||||
ESP_LOGD(TAG,"Registering default value for key %s, value %s", "bypass_wm", "0");
|
||||
config_set_default(NVS_TYPE_STR, "bypass_wm", "0", 0);
|
||||
|
||||
ESP_LOGD(TAG,"Registering default value for key %s, value %s", "test_num", "0");
|
||||
ESP_LOGD(TAG,"Registering Audio control board type %s, value %s","actrls_brd1",actrls_brd1);
|
||||
config_set_default(NVS_TYPE_STR, "actrls_brd1", actrls_brd1, 0);
|
||||
|
||||
ESP_LOGD(TAG,"Registering Audio control board type %s, value %s","actrls_brd2", actrls_brd1);
|
||||
config_set_default(NVS_TYPE_STR, "actrls_brd2", actrls_brd2, 0);
|
||||
|
||||
ESP_LOGD(TAG,"Registering Defalt Audio control board type %s, value ","actrls_brd");
|
||||
config_set_default(NVS_TYPE_STR, "actrls_brd", "", 0);
|
||||
|
||||
char number_buffer[101] = {};
|
||||
snprintf(number_buffer,sizeof(number_buffer)-1,"%u",OTA_FLASH_ERASE_BLOCK);
|
||||
@@ -402,11 +393,20 @@ void app_main()
|
||||
ESP_LOGD(TAG,"Configuring Red led");
|
||||
led_config(LED_RED, LED_RED_GPIO, 0);
|
||||
|
||||
char *board_index = config_alloc_get_default(NVS_TYPE_STR, "board_index", NULL, 0);
|
||||
if (board_index) {
|
||||
ESP_LOGD(TAG,"Initializing audio control buttons index %u", atoi(board_index));
|
||||
actrls_init(board_configs[atoi(board_index)].n, (actrls_config_t*) board_configs[atoi(board_index)].config);
|
||||
free(board_index);
|
||||
char *actrls_brd = config_alloc_get_default(NVS_TYPE_STR, "actrls_brd", NULL, 0);
|
||||
if (actrls_brd) {
|
||||
if(actrls_brd[0] !='\0'){
|
||||
ESP_LOGD(TAG,"Initializing audio control buttons board type %s", actrls_brd);
|
||||
char *actrls_brd_json = config_alloc_get_default(NVS_TYPE_STR, actrls_brd, NULL, 0);
|
||||
if(actrls_brd_json){
|
||||
actrls_init_json(actrls_brd_json);
|
||||
free(actrls_brd_json);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG,"Audio controls board type %s could not be found",actrls_brd);
|
||||
}
|
||||
}
|
||||
free(actrls_brd);
|
||||
}
|
||||
|
||||
/* start the wifi manager */
|
||||
|
||||
Reference in New Issue
Block a user