Update README.md

remove config from accessors, nothing to do there
This commit is contained in:
philippe44
2020-01-26 01:41:42 -08:00
committed by philippe44
parent 0470fddc69
commit 61c3a1058c
6 changed files with 73 additions and 64 deletions

View File

@@ -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 <title> 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.

View File

@@ -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: {

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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

View File

@@ -44,4 +44,5 @@ extern struct display_s {
} *display;
void displayer_scroll(char *string, int speed);
void displayer_control(enum displayer_cmd_e cmd);
void displayer_control(enum displayer_cmd_e cmd);
void displayer_metadata(char *artist, char *album, char *title);