diff --git a/README.md b/README.md index f48ba03..8301d01 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,21 @@ Supported fonts (sourced from /usr/share/fonts/truetype/) can render Unicode cha curl 192.168.1.17:9000/api/osd/0?text=Entrée ``` +Empty strings are used to clear the regions: +``` +curl 192.168.1.17:9000/api/osd/1?text= +``` + Specifiers starting with a dollar sign are used to represent real-time statistics: ``` -curl "192.168.1.17:9000/api/osd/1?text=$B C:$C M:$M" +curl "192.168.1.17:9000/api/osd/1?text=$B%20C:$C%20M:$M" ``` +N.B. Spaces have to be escaped with %20 in URL syntaxes -Empty strings are used to clear the regions: +Showing the time and customizing the time format is done this way: ``` -curl 192.168.1.17:9000/api/osd/2?text= +curl 192.168.1.17:9000/api/time?fmt=%25Y/%25m/%25d%20%25H:%25M:%25S +curl 192.168.1.17:9000/api/osd/2?text=$t&posy=120 ``` UTC date and time can be set using Unix timestamps: diff --git a/osd/config.h b/osd/config.h index 568c828..a81056a 100644 --- a/osd/config.h +++ b/osd/config.h @@ -3,6 +3,7 @@ #define DEF_POSX 16 #define DEF_POSY 16 #define DEF_SIZE 32.0f +#define DEF_TIMEFMT "%Y/%m/%d %H:%M:%S" #define MAX_CONN 16 #define MAX_OSD 8 #define PORT "9000" diff --git a/osd/main.c b/osd/main.c index 7917c15..0831caf 100644 --- a/osd/main.c +++ b/osd/main.c @@ -7,6 +7,7 @@ void *io_map; struct osd *osds; +char timefmt[32] = DEF_TIMEFMT; static void fill(char* str) { @@ -78,6 +79,16 @@ static void fill(char* str) strcat(out, m); j += strlen(m); } + else if (str[i + 1] == 't') + { + i++; + char s[64]; + time_t t = time(NULL); + struct tm *tm = gmtime(&t); + strftime(s, 64, timefmt, tm); + strcat(out, s); + j += strlen(s); + } else if (str[i + 1] == 'T') { i++; @@ -192,7 +203,9 @@ void route() for (char *item; (item = extract_pair(&input));) { char *value = item; char *key = extract_key(&value); - if (!strcmp(key, "ts")) { + if (!strcmp(key, "fmt")) + strncpy(timefmt, value, 32); + else if (!strcmp(key, "ts")) { long result = strtol(value, &remain, 10); if (remain == value) continue; t.tv_sec = result; @@ -208,7 +221,7 @@ void route() "Connection: close\r\n" \ "\r\n" \ ); - printf("{\"ts\":%d}", t.tv_sec); + printf("{\"fmt\":\"%s\",\"ts\":%d}", timefmt, t.tv_sec); return; } diff --git a/osd/net.h b/osd/net.h index afd1492..ea884d6 100644 --- a/osd/net.h +++ b/osd/net.h @@ -20,6 +20,7 @@ extern "C" void serve_forever(); char *extract_key(char **pair); char *extract_pair(char **input); + char *request_header(const char *name); void callback(); void route();