make bigclokc work with <20 char LCDs, 1st preparation for different time formats
This commit is contained in:
+48
-63
@@ -111,8 +111,7 @@ time_screen (int rep, int display, int *flags_ptr)
|
|||||||
*flags_ptr |= INITIALIZED;
|
*flags_ptr |= INITIALIZED;
|
||||||
|
|
||||||
sock_send_string(sock, "screen_add T\n");
|
sock_send_string(sock, "screen_add T\n");
|
||||||
sprintf (buffer, "screen_set T -name {Time Screen: %s}\n", get_hostname());
|
sock_printf(sock, "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 title title\n");
|
||||||
sock_send_string(sock, "widget_add T one string\n");
|
sock_send_string(sock, "widget_add T one string\n");
|
||||||
if (lcd_hgt >= 4) {
|
if (lcd_hgt >= 4) {
|
||||||
@@ -120,13 +119,11 @@ time_screen (int rep, int display, int *flags_ptr)
|
|||||||
sock_send_string(sock, "widget_add T three string\n");
|
sock_send_string(sock, "widget_add T three string\n");
|
||||||
|
|
||||||
// write title bar: OS name, OS version, hostname
|
// 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());
|
get_sysname(), get_sysrelease(), get_hostname());
|
||||||
sock_send_string (sock, buffer);
|
|
||||||
} else {
|
} else {
|
||||||
// write title bar: hostname
|
// write title bar: hostname
|
||||||
sprintf (buffer, "widget_set T title {TIME: %s}\n", get_hostname());
|
sock_printf(sock, "widget_set T title {TIME: %s}\n", get_hostname());
|
||||||
sock_send_string (sock, buffer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,24 +161,21 @@ time_screen (int rep, int display, int *flags_ptr)
|
|||||||
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);
|
days, hour, colon[heartbeat], min, colon[heartbeat], sec);
|
||||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
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)
|
if (display)
|
||||||
sock_send_string (sock, buffer);
|
sock_printf(sock, "widget_set T one 1 2 {%s}\n", tmp);
|
||||||
|
|
||||||
// display the date
|
// display the date
|
||||||
sprintf(tmp, "%s %s %d, %d",
|
sprintf(tmp, "%s %s %d, %d",
|
||||||
day, month, rtime->tm_mday, rtime->tm_year + 1900);
|
day, month, rtime->tm_mday, rtime->tm_year + 1900);
|
||||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
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)
|
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...
|
// 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;
|
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)
|
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
|
else { // 2 line version of the screen
|
||||||
if (lcd_wid >= 20) // 20+x columns
|
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",
|
sprintf(tmp, "%02d.%02d. %s",
|
||||||
rtime->tm_mday, rtime->tm_mon + 1, now);
|
rtime->tm_mday, rtime->tm_mon + 1, now);
|
||||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
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)
|
if (display)
|
||||||
sock_send_string (sock, buffer);
|
sock_printf(sock, "widget_set T one %i 2 {%s}\n", xoffs, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -223,24 +216,20 @@ clock_screen (int rep, int display, int *flags_ptr)
|
|||||||
*flags_ptr |= INITIALIZED;
|
*flags_ptr |= INITIALIZED;
|
||||||
|
|
||||||
sock_send_string(sock, "screen_add O\n");
|
sock_send_string(sock, "screen_add O\n");
|
||||||
sprintf (buffer, "screen_set O -name {Old Clock Screen: %s}\n", get_hostname());
|
sock_printf(sock, "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 title title\n");
|
||||||
sock_send_string(sock, "widget_add O one string\n");
|
sock_send_string(sock, "widget_add O one string\n");
|
||||||
if (lcd_hgt >= 4) {
|
if (lcd_hgt >= 4) {
|
||||||
sock_send_string(sock, "widget_add O two string\n");
|
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 three string\n");
|
||||||
|
|
||||||
sprintf (buffer, "widget_set O title {DATE & TIME}\n");
|
sock_printf(sock, "widget_set O title {DATE & TIME}\n");
|
||||||
sock_send_string (sock, buffer);
|
|
||||||
|
|
||||||
sprintf (tmp, "%s", get_hostname());
|
sprintf (tmp, "%s", get_hostname());
|
||||||
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
|
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_printf(sock, "widget_set O one %i 2 {%s}\n", xoffs, tmp);
|
||||||
sock_send_string (sock, buffer);
|
|
||||||
} else {
|
} else {
|
||||||
sprintf (buffer, "widget_set O title {TIME: %s}\n", get_hostname());
|
sock_printf(sock, "widget_set O title {TIME: %s}\n", get_hostname());
|
||||||
sock_send_string (sock, buffer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,15 +254,13 @@ clock_screen (int rep, int display, int *flags_ptr)
|
|||||||
|
|
||||||
sprintf(tmp, "%s %s", now, day);
|
sprintf(tmp, "%s %s", now, day);
|
||||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
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)
|
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;
|
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)
|
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
|
else { // 2-line version of the screen
|
||||||
if (lcd_wid >= 20) // 20+x columns
|
if (lcd_wid >= 20) // 20+x columns
|
||||||
@@ -283,9 +270,8 @@ clock_screen (int rep, int display, int *flags_ptr)
|
|||||||
sprintf(tmp, "%02d/%02d %s",
|
sprintf(tmp, "%02d/%02d %s",
|
||||||
rtime->tm_mon + 1, rtime->tm_mday, now);
|
rtime->tm_mon + 1, rtime->tm_mday, now);
|
||||||
xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
|
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)
|
if (display)
|
||||||
sock_send_string (sock, buffer);
|
sock_printf(sock, "widget_set O one %i 2 {%s}\n", xoffs, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -314,8 +300,7 @@ uptime_screen (int rep, int display, int *flags_ptr)
|
|||||||
*flags_ptr |= INITIALIZED;
|
*flags_ptr |= INITIALIZED;
|
||||||
|
|
||||||
sock_send_string(sock, "screen_add U\n");
|
sock_send_string(sock, "screen_add U\n");
|
||||||
sprintf (buffer, "screen_set U -name {Uptime Screen: %s}\n", get_hostname());
|
sock_printf(sock, "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, "widget_add U title title\n");
|
||||||
if (lcd_hgt >= 4) {
|
if (lcd_hgt >= 4) {
|
||||||
sock_send_string(sock, "widget_add U one string\n");
|
sock_send_string(sock, "widget_add U one string\n");
|
||||||
@@ -326,18 +311,16 @@ uptime_screen (int rep, int display, int *flags_ptr)
|
|||||||
|
|
||||||
sprintf(tmp, "%s", get_hostname());
|
sprintf(tmp, "%s", get_hostname());
|
||||||
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
|
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_printf(sock, "widget_set U one %i 2 {%s}\n", xoffs, tmp);
|
||||||
sock_send_string (sock, buffer);
|
|
||||||
|
|
||||||
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;
|
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_printf(sock, "widget_set U three %i 4 {%s}\n", xoffs, tmp);
|
||||||
sock_send_string (sock, buffer);
|
|
||||||
} else {
|
} 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_printf(sock, "widget_set U title {%s %s: %s}\n",
|
||||||
sock_send_string (sock, tmp);
|
get_sysname(), get_sysrelease(), get_hostname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,13 +339,13 @@ uptime_screen (int rep, int display, int *flags_ptr)
|
|||||||
sprintf(tmp, "%dd %02d%c%02d%c%02d",
|
sprintf(tmp, "%dd %02d%c%02d%c%02d",
|
||||||
days, hour, colon[heartbeat], min, colon[heartbeat], sec);
|
days, hour, colon[heartbeat], min, colon[heartbeat], sec);
|
||||||
|
|
||||||
|
if (display) {
|
||||||
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
|
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
|
||||||
if (lcd_hgt >= 4)
|
if (lcd_hgt >= 4)
|
||||||
sprintf (buffer, "widget_set U two %d 3 {%s}\n", xoffs, tmp);
|
sock_printf(sock, "widget_set U two %d 3 {%s}\n", xoffs, tmp);
|
||||||
else
|
else
|
||||||
sprintf (buffer, "widget_set U one %d 2 {%s}\n", xoffs, tmp);
|
sock_printf(sock, "widget_set U one %d 2 {%s}\n", xoffs, tmp);
|
||||||
if (display)
|
}
|
||||||
sock_send_string (sock, buffer);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} // End uptime_screen()
|
} // End uptime_screen()
|
||||||
@@ -383,10 +366,12 @@ big_clock_screen (int rep, int display, int *flags_ptr)
|
|||||||
time_t thetime;
|
time_t thetime;
|
||||||
struct tm *rtime;
|
struct tm *rtime;
|
||||||
int pos[] = { 1, 4, 8, 11, 15, 18 };
|
int pos[] = { 1, 4, 8, 11, 15, 18 };
|
||||||
char cmdbuf[64] ;
|
char fulltxt[16];
|
||||||
char fulltxt[16], old_fulltxt[16];
|
static char old_fulltxt[16];
|
||||||
static int heartbeat = 0;
|
static int heartbeat = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
int digits = (lcd_wid >= 20) ? 6 : 4;
|
||||||
|
int xoffs = (lcd_wid + 1 - (pos[digits-1] + 2)) / 2;
|
||||||
|
|
||||||
// toggle colon display
|
// toggle colon display
|
||||||
heartbeat ^= 1;
|
heartbeat ^= 1;
|
||||||
@@ -400,40 +385,40 @@ big_clock_screen (int rep, int display, int *flags_ptr)
|
|||||||
sock_send_string(sock, "widget_add K d1 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 d2 num\n");
|
||||||
sock_send_string(sock, "widget_add K d3 num\n");
|
sock_send_string(sock, "widget_add K d3 num\n");
|
||||||
|
sock_send_string(sock, "widget_add K c0 num\n");
|
||||||
|
|
||||||
|
if (digits > 4) {
|
||||||
sock_send_string(sock, "widget_add K d4 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 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, "widget_add K c1 num\n");
|
||||||
|
}
|
||||||
|
|
||||||
sock_send_string (sock, "widget_set K d0 1 0\n");
|
strcpy(old_fulltxt, " ");
|
||||||
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");
|
|
||||||
|
|
||||||
strcpy(old_fulltxt, "000000");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
time(&thetime);
|
time(&thetime);
|
||||||
rtime = localtime(&thetime);
|
rtime = localtime(&thetime);
|
||||||
|
|
||||||
sprintf (fulltxt, "%02d%02d%02d", rtime->tm_hour, rtime->tm_min, rtime->tm_sec);
|
sprintf(fulltxt, "%02d%02d%02d",
|
||||||
for (j = 0; j < 6; j++) {
|
((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]) {
|
if (fulltxt[j] != old_fulltxt[j]) {
|
||||||
sprintf (cmdbuf, "widget_set K d%d %d %c\n", j, pos[j], fulltxt[j]);
|
sock_printf(sock, "widget_set K d%d %d %c\n", j, xoffs+pos[j], fulltxt[j]);
|
||||||
sock_send_string (sock, cmdbuf);
|
|
||||||
old_fulltxt[j] = fulltxt[j];
|
old_fulltxt[j] = fulltxt[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (heartbeat) { // 10 means: colon
|
if (heartbeat) { // 10 means: colon
|
||||||
sock_send_string (sock, "widget_set K c0 7 10\n");
|
sock_printf(sock, "widget_set K c0 %d 10\n", xoffs + 7);
|
||||||
sock_send_string (sock, "widget_set K c1 14 10\n");
|
if (digits > 4)
|
||||||
|
sock_printf(sock, "widget_set K c1 %d 10\n", xoffs + 14);
|
||||||
}
|
}
|
||||||
else { // kludge: use illegal number to clear colon display
|
else { // kludge: use illegal number to clear colon display
|
||||||
sock_send_string (sock, "widget_set K c0 7 11\n");
|
sock_printf(sock, "widget_set K c0 %d 11\n", xoffs + 7);
|
||||||
sock_send_string (sock, "widget_set K c1 14 11\n");
|
if (digits > 4)
|
||||||
|
sock_printf(sock, "widget_set K c1 %d 11\n", xoffs + 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -472,10 +457,10 @@ mini_clock_screen (int rep, int display, int *flags_ptr)
|
|||||||
time (&thetime);
|
time (&thetime);
|
||||||
rtime = localtime (&thetime);
|
rtime = localtime (&thetime);
|
||||||
|
|
||||||
sprintf(tmp, "%02d%c%02d", rtime->tm_hour, colon[heartbeat & 0x01], rtime->tm_min);
|
sock_printf(sock, "widget_set N one %d %d {%02d%c%02d}\n",
|
||||||
sprintf(buffer, "widget_set N one %d %d {%s}\n",
|
((lcd_wid - 5) / 2) + 1, (lcd_hgt / 2),
|
||||||
((lcd_wid - 5) / 2) + 1, (lcd_hgt / 2), tmp);
|
((TwentyFourHour) ? rtime->tm_hour : (((rtime->tm_hour + 11) % 12) + 1)),
|
||||||
sock_send_string (sock, buffer);
|
colon[heartbeat & 0x01], rtime->tm_min);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} // End mini_clock_screen()
|
} // End mini_clock_screen()
|
||||||
|
|||||||
Reference in New Issue
Block a user