From 61c3a1058cd4b2909330b8de5a4c7b35b889caf5 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Sun, 26 Jan 2020 01:41:42 -0800 Subject: [PATCH] Update README.md remove config from accessors, nothing to do there --- README.md | 2 +- components/raop/raop_sink.c | 5 +-- components/services/accessors.c | 57 --------------------------- components/services/accessors.h | 1 - components/services/display.c | 69 +++++++++++++++++++++++++++++++++ components/services/display.h | 3 +- 6 files changed, 73 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 28a3422e..e2584a8e 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ The NVS parameter "metadata_config" sets how metadata is displayed for AirPlay a ``` - 'speed' is the scrolling speed in ms (default is 33ms) -- 'format' can contain free text and any of the 3 keywords %artist%, %album%, %title%. Using that format string, the keywords are replaced by their value string is displayed as is. Note that if the plain text following a keyword that happens to be empty during playback will be removed. For example, if you have set format=%artist% - %title% and there is no artist in the metadata then only will be displayed not " - <title>". +- 'format' can contain free text and any of the 3 keywords %artist%, %album%, %title%. Using that format string, the keywords are replaced by their value to build the string to be displayed. Note that the plain text following a keyword that happens to be empty during playback of a track will be removed. For example, if you have set format=%artist% - %title% and there is no artist in the metadata then only <title> will be displayed not " - <title>". ### Vcc GPIO The parameter "Vcc_GPIO" is a comma-separated list of GPIO that will be configured as output with their value set to 1 (Vcc) at boot. Be careful because there is no conflict checks being made wrt which GPIO you're changing, so you might damage your board or create a conflict here. diff --git a/components/raop/raop_sink.c b/components/raop/raop_sink.c index b5c6dfd2..a55d2640 100644 --- a/components/raop/raop_sink.c +++ b/components/raop/raop_sink.c @@ -98,11 +98,8 @@ bool cmd_handler(raop_event_t event, ...) { res = cmd_handler_chain(event, args); break; case RAOP_METADATA: { - int speed; char *artist = va_arg(args, char*), *album = va_arg(args, char*), *title = va_arg(args, char*); - char *string = config_metadata_format(artist, album, title, &speed, 256); - displayer_scroll(string, speed); - free(string); + displayer_metadata(artist, album, title); break; } case RAOP_PROGRESS: { diff --git a/components/services/accessors.c b/components/services/accessors.c index f25f9619..e2e4607b 100644 --- a/components/services/accessors.c +++ b/components/services/accessors.c @@ -58,60 +58,3 @@ const i2c_config_t * config_i2c_get(int * i2c_port) { if(i2c_port) *i2c_port=i2c_system_port; return &i2c; } - -/**************************************************************************************** - * - */ -char *config_metadata_format(char *artist, char *album, char *title, int *speed, int len) { - char *nvs_item, *string = calloc(len + 1, 1), *p; - - nvs_item = config_alloc_get(NVS_TYPE_STR, "metadata_config"); - - if (nvs_item) { - if ((p = strcasestr(nvs_item, "format")) != NULL) { - char token[16], *q; - int space = len; - bool skip = false; - - p = strchr(nvs_item, '='); - - while (p++) { - // find token and copy what's after when reaching last one - if (sscanf(p, "%*[^%%]%%%[^%]%%", token) < 0) { - q = strchr(p, ','); - strncat(string, p, q ? min(q - p, space) : space); - break; - } - - // copy what's before token (be safe) - if ((q = strchr(p, '%')) == NULL) break; - - // skip whatever is after a token if this token is empty - if (!skip) { - strncat(string, p, min(q - p, space)); - space = len - strlen(string); - } - - // then copy token's content - if (strcasestr(q, "artist") && artist) strncat(string, p = artist, space); - else if (strcasestr(q, "album") && album) strncat(string, p = album, space); - else if (strcasestr(q, "title") && title) strncat(string, p = title, space); - space = len - strlen(string); - - // flag to skip the data following an empty field - if (*p) skip = false; - else skip = true; - - // advance to next separator - p = strchr(q + 1, '%'); - } - } else { - string = strdup(title ? title : ""); - } - // get optional scroll speed - if ((p = strcasestr(nvs_item, "speed")) != NULL) sscanf(p, "%*[^=]=%d", speed); - else *speed = 0; - } - - return string; -} diff --git a/components/services/accessors.h b/components/services/accessors.h index 30166a5d..615a8c52 100644 --- a/components/services/accessors.h +++ b/components/services/accessors.h @@ -13,4 +13,3 @@ esp_err_t config_i2c_set(const i2c_config_t * config, int port); const i2c_config_t * config_i2c_get(int * i2c_port); -char * config_metadata_format(char *artist, char *album, char *title, int *speed, int len); \ No newline at end of file diff --git a/components/services/display.c b/components/services/display.c index 25096049..95620986 100644 --- a/components/services/display.c +++ b/components/services/display.c @@ -45,6 +45,7 @@ static EXT_RAM_ATTR struct { enum { DISPLAYER_DISABLED, DISPLAYER_IDLE, DISPLAYER_ACTIVE } state; char string[SCROLLABLE_SIZE + 1]; int offset, boundary; + char *metadata_config; } displayer; static void displayer_task(void *args); @@ -87,6 +88,8 @@ void display_init(char *welcome) { // set lines for "fixed" text mode display->set_font(1, DISPLAY_FONT_TINY, 0); display->set_font(2, DISPLAY_FONT_LARGE, 0); + + displayer.metadata_config = config_alloc_get(NVS_TYPE_STR, "metadata_config"); } if (item) free(item); @@ -122,6 +125,72 @@ static void displayer_task(void *args) { } } +/**************************************************************************************** + * + */ +void displayer_metadata(char *artist, char *album, char *title) { + char *string = displayer.string, *p; + int len = SCROLLABLE_SIZE; + + if (!displayer.metadata_config) { + strncpy(displayer.string, title ? title : "", SCROLLABLE_SIZE); + return; + } + + // format metadata parameters and write them directly + if ((p = strcasestr(displayer.metadata_config, "format")) != NULL) { + char token[16], *q; + int space = len; + bool skip = false; + + displayer.string[0] = '\0'; + p = strchr(displayer.metadata_config, '='); + + while (p++) { + // find token and copy what's after when reaching last one + if (sscanf(p, "%*[^%%]%%%[^%]%%", token) < 0) { + q = strchr(p, ','); + strncat(string, p, q ? min(q - p, space) : space); + break; + } + + // copy what's before token (be safe) + if ((q = strchr(p, '%')) == NULL) break; + + // skip whatever is after a token if this token is empty + if (!skip) { + strncat(string, p, min(q - p, space)); + space = len - strlen(string); + } + + // then copy token's content + if (strcasestr(q, "artist") && artist) strncat(string, p = artist, space); + else if (strcasestr(q, "album") && album) strncat(string, p = album, space); + else if (strcasestr(q, "title") && title) strncat(string, p = title, space); + space = len - strlen(string); + + // flag to skip the data following an empty field + if (*p) skip = false; + else skip = true; + + // advance to next separator + p = strchr(q + 1, '%'); + } + } else { + string = strdup(title ? title : ""); + } + + // get optional scroll speed + if ((p = strcasestr(displayer.metadata_config, "speed")) != NULL) sscanf(p, "%*[^=]=%d", &displayer.speed); + + // just starts displayer directly + xSemaphoreTake(displayer.mutex, portMAX_DELAY); + displayer.offset = 0; + displayer.state = DISPLAYER_ACTIVE; + displayer.boundary = display->stretch(2, displayer.string, SCROLLABLE_SIZE); + xSemaphoreGive(displayer.mutex); +} + /**************************************************************************************** * This is not really thread-safe as displayer_task might be in the middle of line drawing diff --git a/components/services/display.h b/components/services/display.h index c21681ad..1f491244 100644 --- a/components/services/display.h +++ b/components/services/display.h @@ -44,4 +44,5 @@ extern struct display_s { } *display; void displayer_scroll(char *string, int speed); -void displayer_control(enum displayer_cmd_e cmd); \ No newline at end of file +void displayer_control(enum displayer_cmd_e cmd); +void displayer_metadata(char *artist, char *album, char *title); \ No newline at end of file