make bigclokc work with <20 char LCDs, 1st preparation for different time formats
This commit is contained in:
+100
-115
@@ -110,37 +110,34 @@ time_screen (int rep, int display, int *flags_ptr)
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
|
||||
sock_send_string (sock, "screen_add T\n");
|
||||
sprintf (buffer, "screen_set T -name {Time Screen: %s}\n", get_hostname());
|
||||
sock_send_string (sock, buffer);
|
||||
sock_send_string (sock, "widget_add T title title\n");
|
||||
sock_send_string (sock, "widget_add T one string\n");
|
||||
sock_send_string(sock, "screen_add T\n");
|
||||
sock_printf(sock, "screen_set T -name {Time Screen: %s}\n", get_hostname());
|
||||
sock_send_string(sock, "widget_add T title title\n");
|
||||
sock_send_string(sock, "widget_add T one string\n");
|
||||
if (lcd_hgt >= 4) {
|
||||
sock_send_string (sock, "widget_add T two string\n");
|
||||
sock_send_string (sock, "widget_add T three string\n");
|
||||
sock_send_string(sock, "widget_add T two string\n");
|
||||
sock_send_string(sock, "widget_add T three string\n");
|
||||
|
||||
// write title bar: OS name, OS version, hostname
|
||||
sprintf (buffer, "widget_set T title {%s %s: %s}\n",
|
||||
sock_printf(sock, "widget_set T title {%s %s: %s}\n",
|
||||
get_sysname(), get_sysrelease(), get_hostname());
|
||||
sock_send_string (sock, buffer);
|
||||
} else {
|
||||
// write title bar: hostname
|
||||
sprintf (buffer, "widget_set T title {TIME: %s}\n", get_hostname());
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set T title {TIME: %s}\n", get_hostname());
|
||||
}
|
||||
}
|
||||
|
||||
// toggle colon display
|
||||
heartbeat ^= 1;
|
||||
|
||||
time (&thetime);
|
||||
rtime = localtime (&thetime);
|
||||
time(&thetime);
|
||||
rtime = localtime(&thetime);
|
||||
|
||||
if (TwentyFourHour) {
|
||||
sprintf (now, "%02d%c%02d%c%02d",
|
||||
sprintf(now, "%02d%c%02d%c%02d",
|
||||
rtime->tm_hour, colon[heartbeat], rtime->tm_min, colon[heartbeat], rtime->tm_sec);
|
||||
} else {
|
||||
sprintf (now, "%02d%c%02d%c%02d%*s",
|
||||
sprintf(now, "%02d%c%02d%c%02d%*s",
|
||||
((rtime->tm_hour + 11) % 12) + 1, colon[heartbeat], rtime->tm_min, colon[heartbeat], rtime->tm_sec,
|
||||
(lcd_wid > 20) ? 2 : 1, (rtime->tm_hour >= 12) ? "pm" : "am");
|
||||
}
|
||||
@@ -158,30 +155,27 @@ time_screen (int rep, int display, int *flags_ptr)
|
||||
sec = ((int) uptime % 60);
|
||||
|
||||
if (lcd_wid >= 20)
|
||||
sprintf (tmp, "Up %3d day%s %02d%c%02d%c%02d",
|
||||
sprintf(tmp, "Up %3d day%s %02d%c%02d%c%02d",
|
||||
days, ((days != 1) ? "s" : ""), hour, colon[heartbeat], min, colon[heartbeat], sec);
|
||||
else
|
||||
sprintf (tmp, "Up %dd %02d%c%02d%c%02d",
|
||||
sprintf(tmp, "Up %dd %02d%c%02d%c%02d",
|
||||
days, hour, colon[heartbeat], min, colon[heartbeat], sec);
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
||||
sprintf (buffer, "widget_set T one 1 2 {%s}\n", tmp);
|
||||
if (display)
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set T one 1 2 {%s}\n", tmp);
|
||||
|
||||
// display the date
|
||||
sprintf (tmp, "%s %s %d, %d",
|
||||
sprintf(tmp, "%s %s %d, %d",
|
||||
day, month, rtime->tm_mday, rtime->tm_year + 1900);
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
||||
sprintf (buffer, "widget_set T two %i 3 {%s}\n", xoffs, tmp);
|
||||
if (display)
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set T two %i 3 {%s}\n", xoffs, tmp);
|
||||
|
||||
// display the time & idle time...
|
||||
sprintf (tmp, "%s %3i%% idle", now, (int) idle);
|
||||
sprintf(tmp, "%s %3i%% idle", now, (int) idle);
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
||||
sprintf (buffer, "widget_set T three %i 4 {%s}\n", xoffs, tmp);
|
||||
if (display)
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set T three %i 4 {%s}\n", xoffs, tmp);
|
||||
}
|
||||
else { // 2 line version of the screen
|
||||
if (lcd_wid >= 20) // 20+x columns
|
||||
@@ -191,9 +185,8 @@ time_screen (int rep, int display, int *flags_ptr)
|
||||
sprintf(tmp, "%02d.%02d. %s",
|
||||
rtime->tm_mday, rtime->tm_mon + 1, now);
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
||||
sprintf(buffer, "widget_set T one %i 2 {%s}\n", xoffs, tmp);
|
||||
if (display)
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set T one %i 2 {%s}\n", xoffs, tmp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -222,25 +215,21 @@ clock_screen (int rep, int display, int *flags_ptr)
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
|
||||
sock_send_string (sock, "screen_add O\n");
|
||||
sprintf (buffer, "screen_set O -name {Old Clock Screen: %s}\n", get_hostname());
|
||||
sock_send_string (sock, buffer);
|
||||
sock_send_string (sock, "widget_add O title title\n");
|
||||
sock_send_string (sock, "widget_add O one string\n");
|
||||
sock_send_string(sock, "screen_add O\n");
|
||||
sock_printf(sock, "screen_set O -name {Old Clock Screen: %s}\n", get_hostname());
|
||||
sock_send_string(sock, "widget_add O title title\n");
|
||||
sock_send_string(sock, "widget_add O one string\n");
|
||||
if (lcd_hgt >= 4) {
|
||||
sock_send_string (sock, "widget_add O two string\n");
|
||||
sock_send_string (sock, "widget_add O three string\n");
|
||||
sock_send_string(sock, "widget_add O two string\n");
|
||||
sock_send_string(sock, "widget_add O three string\n");
|
||||
|
||||
sprintf (buffer, "widget_set O title {DATE & TIME}\n");
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set O title {DATE & TIME}\n");
|
||||
|
||||
sprintf (tmp, "%s", get_hostname());
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
|
||||
sprintf (buffer, "widget_set O one %i 2 {%s}\n", xoffs, tmp);
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set O one %i 2 {%s}\n", xoffs, tmp);
|
||||
} else {
|
||||
sprintf (buffer, "widget_set O title {TIME: %s}\n", get_hostname());
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set O title {TIME: %s}\n", get_hostname());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,10 +240,10 @@ clock_screen (int rep, int display, int *flags_ptr)
|
||||
rtime = localtime (&thetime);
|
||||
|
||||
if (TwentyFourHour) {
|
||||
sprintf (now, "%02d%c%02d%c%02d",
|
||||
sprintf(now, "%02d%c%02d%c%02d",
|
||||
rtime->tm_hour, colon[heartbeat], rtime->tm_min, colon[heartbeat], rtime->tm_sec);
|
||||
} else {
|
||||
sprintf (now, "%02d%c%02d%c%02d%*s",
|
||||
sprintf(now, "%02d%c%02d%c%02d%*s",
|
||||
((rtime->tm_hour + 11) % 12) + 1, colon[heartbeat], rtime->tm_min, colon[heartbeat], rtime->tm_sec,
|
||||
(lcd_wid > 20) ? 2 : 1, (rtime->tm_hour >= 12) ? "pm" : "am");
|
||||
}
|
||||
@@ -263,29 +252,26 @@ clock_screen (int rep, int display, int *flags_ptr)
|
||||
char *day = days[rtime->tm_wday];
|
||||
char *month = months[rtime->tm_mon];
|
||||
|
||||
sprintf (tmp, "%s %s", now, day);
|
||||
sprintf(tmp, "%s %s", now, day);
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
||||
sprintf (buffer, "widget_set O two %i 3 {%s}\n", xoffs, tmp);
|
||||
if (display)
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set O two %i 3 {%s}\n", xoffs, tmp);
|
||||
|
||||
sprintf (tmp, "%s %d, %d", month, rtime->tm_mday, rtime->tm_year + 1900);
|
||||
sprintf(tmp, "%s %d, %d", month, rtime->tm_mday, rtime->tm_year + 1900);
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
||||
sprintf (buffer, "widget_set O three %i 4 {%s}\n", xoffs, tmp);
|
||||
if (display)
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set O three %i 4 {%s}\n", xoffs, tmp);
|
||||
}
|
||||
else { // 2-line version of the screen
|
||||
if (lcd_wid >= 20) // 20+x columns
|
||||
sprintf (tmp, "%d-%02d-%02d %s",
|
||||
sprintf(tmp, "%d-%02d-%02d %s",
|
||||
rtime->tm_year + 1900, rtime->tm_mon + 1, rtime->tm_mday, now);
|
||||
else // <20 columns
|
||||
sprintf (tmp, "%02d/%02d %s",
|
||||
sprintf(tmp, "%02d/%02d %s",
|
||||
rtime->tm_mon + 1, rtime->tm_mday, now);
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
||||
sprintf(buffer, "widget_set O one %i 2 {%s}\n", xoffs, tmp);
|
||||
if (display)
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set O one %i 2 {%s}\n", xoffs, tmp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -313,31 +299,28 @@ uptime_screen (int rep, int display, int *flags_ptr)
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
|
||||
sock_send_string (sock, "screen_add U\n");
|
||||
sprintf (buffer, "screen_set U -name {Uptime Screen: %s}\n", get_hostname());
|
||||
sock_send_string (sock, buffer);
|
||||
sock_send_string (sock, "widget_add U title title\n");
|
||||
sock_send_string(sock, "screen_add U\n");
|
||||
sock_printf(sock, "screen_set U -name {Uptime Screen: %s}\n", get_hostname());
|
||||
sock_send_string(sock, "widget_add U title title\n");
|
||||
if (lcd_hgt >= 4) {
|
||||
sock_send_string (sock, "widget_add U one string\n");
|
||||
sock_send_string (sock, "widget_add U two string\n");
|
||||
sock_send_string (sock, "widget_add U three string\n");
|
||||
sock_send_string(sock, "widget_add U one string\n");
|
||||
sock_send_string(sock, "widget_add U two string\n");
|
||||
sock_send_string(sock, "widget_add U three string\n");
|
||||
|
||||
sock_send_string (sock, "widget_set U title {SYSTEM UPTIME}\n");
|
||||
sock_send_string(sock, "widget_set U title {SYSTEM UPTIME}\n");
|
||||
|
||||
sprintf (tmp, "%s", get_hostname());
|
||||
sprintf(tmp, "%s", get_hostname());
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
|
||||
sprintf (buffer, "widget_set U one %i 2 {%s}\n", xoffs, tmp);
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set U one %i 2 {%s}\n", xoffs, tmp);
|
||||
|
||||
sprintf (tmp, "%s %s", get_sysname(), get_sysrelease());
|
||||
sprintf(tmp, "%s %s", get_sysname(), get_sysrelease());
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
|
||||
sprintf (buffer, "widget_set U three %i 4 {%s}\n", xoffs, tmp);
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set U three %i 4 {%s}\n", xoffs, tmp);
|
||||
} else {
|
||||
sock_send_string (sock, "widget_add U one string\n");
|
||||
sock_send_string(sock, "widget_add U one string\n");
|
||||
|
||||
sprintf (tmp, "widget_set U title {%s %s: %s}\n", get_sysname(), get_sysrelease(), get_hostname());
|
||||
sock_send_string (sock, tmp);
|
||||
sock_printf(sock, "widget_set U title {%s %s: %s}\n",
|
||||
get_sysname(), get_sysrelease(), get_hostname());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,19 +333,19 @@ uptime_screen (int rep, int display, int *flags_ptr)
|
||||
min = (((int) uptime % 86400) % 3600) / 60;
|
||||
sec = ((int) uptime % 60);
|
||||
if (lcd_wid >= 20)
|
||||
sprintf (tmp, "%d day%s %02d%c%02d%c%02d",
|
||||
sprintf(tmp, "%d day%s %02d%c%02d%c%02d",
|
||||
days, ((days != 1) ? "s" : ""), hour, colon[heartbeat], min, colon[heartbeat], sec);
|
||||
else
|
||||
sprintf (tmp, "%dd %02d%c%02d%c%02d",
|
||||
sprintf(tmp, "%dd %02d%c%02d%c%02d",
|
||||
days, hour, colon[heartbeat], min, colon[heartbeat], sec);
|
||||
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
|
||||
if (lcd_hgt >= 4)
|
||||
sprintf (buffer, "widget_set U two %d 3 {%s}\n", xoffs, tmp);
|
||||
else
|
||||
sprintf (buffer, "widget_set U one %d 2 {%s}\n", xoffs, tmp);
|
||||
if (display)
|
||||
sock_send_string (sock, buffer);
|
||||
if (display) {
|
||||
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
|
||||
if (lcd_hgt >= 4)
|
||||
sock_printf(sock, "widget_set U two %d 3 {%s}\n", xoffs, tmp);
|
||||
else
|
||||
sock_printf(sock, "widget_set U one %d 2 {%s}\n", xoffs, tmp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
} // End uptime_screen()
|
||||
@@ -383,57 +366,59 @@ big_clock_screen (int rep, int display, int *flags_ptr)
|
||||
time_t thetime;
|
||||
struct tm *rtime;
|
||||
int pos[] = { 1, 4, 8, 11, 15, 18 };
|
||||
char cmdbuf[64] ;
|
||||
char fulltxt[16], old_fulltxt[16];
|
||||
char fulltxt[16];
|
||||
static char old_fulltxt[16];
|
||||
static int heartbeat = 0;
|
||||
int j = 0;
|
||||
|
||||
int digits = (lcd_wid >= 20) ? 6 : 4;
|
||||
int xoffs = (lcd_wid + 1 - (pos[digits-1] + 2)) / 2;
|
||||
|
||||
// toggle colon display
|
||||
heartbeat ^= 1;
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
|
||||
sock_send_string (sock, "screen_add K\n");
|
||||
sock_send_string (sock, "screen_set K -name {Big Clock Screen} -heartbeat off\n");
|
||||
sock_send_string (sock, "widget_add K d0 num\n");
|
||||
sock_send_string (sock, "widget_add K d1 num\n");
|
||||
sock_send_string (sock, "widget_add K d2 num\n");
|
||||
sock_send_string (sock, "widget_add K d3 num\n");
|
||||
sock_send_string (sock, "widget_add K d4 num\n");
|
||||
sock_send_string (sock, "widget_add K d5 num\n");
|
||||
sock_send_string (sock, "widget_add K c0 num\n");
|
||||
sock_send_string (sock, "widget_add K c1 num\n");
|
||||
sock_send_string(sock, "screen_add K\n");
|
||||
sock_send_string(sock, "screen_set K -name {Big Clock Screen} -heartbeat off\n");
|
||||
sock_send_string(sock, "widget_add K d0 num\n");
|
||||
sock_send_string(sock, "widget_add K d1 num\n");
|
||||
sock_send_string(sock, "widget_add K d2 num\n");
|
||||
sock_send_string(sock, "widget_add K d3 num\n");
|
||||
sock_send_string(sock, "widget_add K c0 num\n");
|
||||
|
||||
sock_send_string (sock, "widget_set K d0 1 0\n");
|
||||
sock_send_string (sock, "widget_set K d1 4 0\n");
|
||||
sock_send_string (sock, "widget_set K d2 8 0\n");
|
||||
sock_send_string (sock, "widget_set K d3 11 0\n");
|
||||
sock_send_string (sock, "widget_set K d4 15 0\n");
|
||||
sock_send_string (sock, "widget_set K d5 18 0\n");
|
||||
if (digits > 4) {
|
||||
sock_send_string(sock, "widget_add K d4 num\n");
|
||||
sock_send_string(sock, "widget_add K d5 num\n");
|
||||
sock_send_string(sock, "widget_add K c1 num\n");
|
||||
}
|
||||
|
||||
strcpy(old_fulltxt, "000000");
|
||||
strcpy(old_fulltxt, " ");
|
||||
}
|
||||
|
||||
time (&thetime);
|
||||
rtime = localtime (&thetime);
|
||||
time(&thetime);
|
||||
rtime = localtime(&thetime);
|
||||
|
||||
sprintf (fulltxt, "%02d%02d%02d", rtime->tm_hour, rtime->tm_min, rtime->tm_sec);
|
||||
for (j = 0; j < 6; j++) {
|
||||
sprintf(fulltxt, "%02d%02d%02d",
|
||||
((TwentyFourHour) ? rtime->tm_hour : (((rtime->tm_hour + 11) % 12) + 1)),
|
||||
rtime->tm_min, rtime->tm_sec);
|
||||
|
||||
for (j = 0; j < digits; j++) {
|
||||
if (fulltxt[j] != old_fulltxt[j]) {
|
||||
sprintf (cmdbuf, "widget_set K d%d %d %c\n", j, pos[j], fulltxt[j]);
|
||||
sock_send_string (sock, cmdbuf);
|
||||
sock_printf(sock, "widget_set K d%d %d %c\n", j, xoffs+pos[j], fulltxt[j]);
|
||||
old_fulltxt[j] = fulltxt[j];
|
||||
}
|
||||
}
|
||||
|
||||
if (heartbeat) { // 10 means: colon
|
||||
sock_send_string (sock, "widget_set K c0 7 10\n");
|
||||
sock_send_string (sock, "widget_set K c1 14 10\n");
|
||||
sock_printf(sock, "widget_set K c0 %d 10\n", xoffs + 7);
|
||||
if (digits > 4)
|
||||
sock_printf(sock, "widget_set K c1 %d 10\n", xoffs + 14);
|
||||
}
|
||||
else { // kludge: use illegal number to clear colon display
|
||||
sock_send_string (sock, "widget_set K c0 7 11\n");
|
||||
sock_send_string (sock, "widget_set K c1 14 11\n");
|
||||
sock_printf(sock, "widget_set K c0 %d 11\n", xoffs + 7);
|
||||
if (digits > 4)
|
||||
sock_printf(sock, "widget_set K c1 %d 11\n", xoffs + 14);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -464,18 +449,18 @@ mini_clock_screen (int rep, int display, int *flags_ptr)
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
|
||||
sock_send_string (sock, "screen_add N\n");
|
||||
sock_send_string (sock, "screen_set N -name {Essential Clock Screen} -heartbeat off\n");
|
||||
sock_send_string (sock, "widget_add N one string\n");
|
||||
sock_send_string(sock, "screen_add N\n");
|
||||
sock_send_string(sock, "screen_set N -name {Essential Clock Screen} -heartbeat off\n");
|
||||
sock_send_string(sock, "widget_add N one string\n");
|
||||
}
|
||||
|
||||
time (&thetime);
|
||||
rtime = localtime (&thetime);
|
||||
|
||||
sprintf(tmp, "%02d%c%02d", rtime->tm_hour, colon[heartbeat & 0x01], rtime->tm_min);
|
||||
sprintf(buffer, "widget_set N one %d %d {%s}\n",
|
||||
((lcd_wid - 5) / 2) + 1, (lcd_hgt / 2), tmp);
|
||||
sock_send_string (sock, buffer);
|
||||
sock_printf(sock, "widget_set N one %d %d {%02d%c%02d}\n",
|
||||
((lcd_wid - 5) / 2) + 1, (lcd_hgt / 2),
|
||||
((TwentyFourHour) ? rtime->tm_hour : (((rtime->tm_hour + 11) % 12) + 1)),
|
||||
colon[heartbeat & 0x01], rtime->tm_min);
|
||||
|
||||
return 0;
|
||||
} // End mini_clock_screen()
|
||||
|
||||
Reference in New Issue
Block a user