More formatting changes, new tags file.

This commit is contained in:
William Ferrell
2000-04-03 22:13:57 +00:00
parent 0d703c5864
commit 6a115b4446
64 changed files with 8950 additions and 8950 deletions
+121 -121
View File
@@ -18,47 +18,47 @@ static int get_batt_stat (int *acstat, int *battstat, int *battflag, int *percen
static int
get_batt_stat (int *acstat, int *battstat, int *battflag, int *percent)
{
char str[64];
char str[64];
if (!batt_fd)
batt_fd = open ("/proc/apm", O_RDONLY);
if (batt_fd <= 0)
return -1;
if (!batt_fd)
batt_fd = open ("/proc/apm", O_RDONLY);
if (batt_fd <= 0)
return -1;
if (lseek (batt_fd, 0, 0) != 0)
return -1;
if (lseek (batt_fd, 0, 0) != 0)
return -1;
if (read (batt_fd, str, sizeof (str) - 1) < 0)
return -1;
if (read (batt_fd, str, sizeof (str) - 1) < 0)
return -1;
if (3 > sscanf (str + 13, "0x%x 0x%x 0x%x %d", acstat, battstat, battflag, percent))
return -1;
if (3 > sscanf (str + 13, "0x%x 0x%x 0x%x %d", acstat, battstat, battflag, percent))
return -1;
return 0;
return 0;
}
int
batt_init ()
{
static int first = 1;
static int first = 1;
if (first) {
first = 0;
sock_send_string (sock, "screen_add B\n");
}
if (first) {
first = 0;
sock_send_string (sock, "screen_add B\n");
}
return 0;
return 0;
}
int
batt_close ()
{
if (batt_fd)
close (batt_fd);
batt_fd = 0;
if (batt_fd)
close (batt_fd);
batt_fd = 0;
return 0;
return 0;
}
////////////////////////////////////////////////////////////////////////
@@ -74,116 +74,116 @@ batt_close ()
int
battery_screen (int rep, int display)
{
static int first = 1;
static int first = 1;
int acstat = 0, battstat = 0, battflag = 0, percent = 0;
int acstat = 0, battstat = 0, battflag = 0, percent = 0;
if (first) {
first = 0;
if (first) {
first = 0;
sprintf (buffer, "screen_set B -name {APM stats: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add B title title\n");
sprintf (tmp, "widget_set B title {LCDPROC %s}\n", version);
sock_send_string (sock, tmp);
sock_send_string (sock, "widget_add B one string\n");
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add B two string\n");
sock_send_string (sock, "widget_add B three string\n");
sock_send_string (sock, "widget_add B gauge hbar\n");
sock_send_string (sock, "widget_set B one 1 2 {AC: Unknown}\n");
sock_send_string (sock, "widget_set B two 1 3 {Batt: Unknown}\n");
sock_send_string (sock, "widget_set B three 1 4 {E F}\n");
sock_send_string (sock, "widget_set B gauge 2 4 0\n");
}
}
// Only run once every 16 frames...
//if(rep&0x0f) return 0;
sprintf (buffer, "screen_set B -name {APM stats: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add B title title\n");
sprintf (tmp, "widget_set B title {LCDPROC %s}\n", version);
sock_send_string (sock, tmp);
sock_send_string (sock, "widget_add B one string\n");
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add B two string\n");
sock_send_string (sock, "widget_add B three string\n");
sock_send_string (sock, "widget_add B gauge hbar\n");
sock_send_string (sock, "widget_set B one 1 2 {AC: Unknown}\n");
sock_send_string (sock, "widget_set B two 1 3 {Batt: Unknown}\n");
sock_send_string (sock, "widget_set B three 1 4 {E F}\n");
sock_send_string (sock, "widget_set B gauge 2 4 0\n");
}
}
// Only run once every 16 frames...
//if(rep&0x0f) return 0;
get_batt_stat (&acstat, &battstat, &battflag, &percent);
get_batt_stat (&acstat, &battstat, &battflag, &percent);
if (percent >= 0)
sprintf (buffer, "%i%%", percent);
else
sprintf (buffer, "??%%");
sprintf (tmp, "widget_set B title {Batt: %s: %s}\n", buffer, host);
if (percent >= 0)
sprintf (buffer, "%i%%", percent);
else
sprintf (buffer, "??%%");
sprintf (tmp, "widget_set B title {Batt: %s: %s}\n", buffer, host);
if (display)
sock_send_string (sock, tmp);
if (display)
sock_send_string (sock, tmp);
if (lcd_hgt >= 4) // 4-line version of the screen
{
sprintf (tmp, "widget_set B one 1 2 {");
switch (acstat) {
case 0:
sprintf (tmp + strlen (tmp), "AC: Off}\n");
break;
case 1:
sprintf (tmp + strlen (tmp), "AC: On}\n");
break;
case 2:
sprintf (tmp + strlen (tmp), "AC: Backup}\n");
break;
default:
sprintf (tmp + strlen (tmp), "AC: Unknown}\n");
break;
}
if (lcd_hgt >= 4) // 4-line version of the screen
{
sprintf (tmp, "widget_set B one 1 2 {");
switch (acstat) {
case 0:
sprintf (tmp + strlen (tmp), "AC: Off}\n");
break;
case 1:
sprintf (tmp + strlen (tmp), "AC: On}\n");
break;
case 2:
sprintf (tmp + strlen (tmp), "AC: Backup}\n");
break;
default:
sprintf (tmp + strlen (tmp), "AC: Unknown}\n");
break;
}
if (display)
sock_send_string (sock, tmp);
if (display)
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set B two 1 3 {");
if (battflag == 0xff) {
sprintf (tmp + strlen (tmp), "Battery Stat Unknown");
} else {
sprintf (tmp + strlen (tmp), "Batt:");
if (battflag & 1)
sprintf (tmp + strlen (tmp), " High");
if (battflag & 2)
sprintf (tmp + strlen (tmp), " Low");
if (battflag & 4)
sprintf (tmp + strlen (tmp), " Critical");
if (battflag & 8 || battstat == 3)
sprintf (tmp + strlen (tmp), " Charging");
if (battflag & 128)
sprintf (tmp + strlen (tmp), " (NONE)");
}
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set B two 1 3 {");
if (battflag == 0xff) {
sprintf (tmp + strlen (tmp), "Battery Stat Unknown");
} else {
sprintf (tmp + strlen (tmp), "Batt:");
if (battflag & 1)
sprintf (tmp + strlen (tmp), " High");
if (battflag & 2)
sprintf (tmp + strlen (tmp), " Low");
if (battflag & 4)
sprintf (tmp + strlen (tmp), " Critical");
if (battflag & 8 || battstat == 3)
sprintf (tmp + strlen (tmp), " Charging");
if (battflag & 128)
sprintf (tmp + strlen (tmp), " (NONE)");
}
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
if (percent > 0) {
sprintf (tmp, "widget_set B gauge 2 4 %i\n", (percent * ((lcd_wid - 2) * lcd_cellwid) / 100));
if (display)
sock_send_string (sock, tmp);
}
} // end if(lcd_hgt >= 4)
else // two-line version of the screen
{
sprintf (tmp, "widget_set B one 1 2 {");
if (acstat == 1)
sprintf (tmp + strlen (tmp), "AC, ");
if (percent > 0) {
sprintf (tmp, "widget_set B gauge 2 4 %i\n", (percent * ((lcd_wid - 2) * lcd_cellwid) / 100));
if (display)
sock_send_string (sock, tmp);
}
} // end if(lcd_hgt >= 4)
else // two-line version of the screen
{
sprintf (tmp, "widget_set B one 1 2 {");
if (acstat == 1)
sprintf (tmp + strlen (tmp), "AC, ");
if (battflag == 0xff) {
sprintf (tmp + strlen (tmp), "No battery???");
} else {
sprintf (tmp + strlen (tmp), "Batt:");
if (battflag & 1)
sprintf (tmp + strlen (tmp), " High");
if (battflag & 2)
sprintf (tmp + strlen (tmp), " Low");
if (battflag & 4)
sprintf (tmp + strlen (tmp), " Critical");
if (battflag & 8 || battstat == 3)
sprintf (tmp + strlen (tmp), " Charging");
if (battflag & 128)
sprintf (tmp + strlen (tmp), " (NONE)");
}
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
if (battflag == 0xff) {
sprintf (tmp + strlen (tmp), "No battery???");
} else {
sprintf (tmp + strlen (tmp), "Batt:");
if (battflag & 1)
sprintf (tmp + strlen (tmp), " High");
if (battflag & 2)
sprintf (tmp + strlen (tmp), " Low");
if (battflag & 4)
sprintf (tmp + strlen (tmp), " Critical");
if (battflag & 8 || battstat == 3)
sprintf (tmp + strlen (tmp), " Charging");
if (battflag & 128)
sprintf (tmp + strlen (tmp), " (NONE)");
}
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
}
}
return 0;
return 0;
}
+361 -361
View File
@@ -23,106 +23,106 @@ static double get_uptime (double *up, double *idle);
static double
get_uptime (double *up, double *idle)
{
double uptime;
double uptime;
reread (uptime_fd, "get_uptime:");
sscanf (buffer, "%lf %lf", &uptime, idle);
reread (uptime_fd, "get_uptime:");
sscanf (buffer, "%lf %lf", &uptime, idle);
*up = uptime;
*up = uptime;
return uptime;
return uptime;
}
// A couple of tables for later use...
static char *days[] = {
"Sunday, ",
"Monday, ",
"Tuesday, ",
"Wednesday,",
"Thursday, ",
"Friday, ",
"Saturday, ",
"Sunday, ",
"Monday, ",
"Tuesday, ",
"Wednesday,",
"Thursday, ",
"Friday, ",
"Saturday, ",
};
static char *shortdays[] = {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
};
static char *months[] = {
" January",
" February",
" March",
" April",
" May",
" June",
" July",
" August",
"September",
" October",
" November",
" December",
" January",
" February",
" March",
" April",
" May",
" June",
" July",
" August",
"September",
" October",
" November",
" December",
};
static char *shortmonths[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
};
int
chrono_init ()
{
struct utsname *unamebuf;
struct utsname *unamebuf;
if (!uptime_fd) {
unamebuf = (struct utsname *) malloc (sizeof (struct utsname));
uptime_fd = open ("/proc/uptime", O_RDONLY);
if (!uptime_fd) {
unamebuf = (struct utsname *) malloc (sizeof (struct utsname));
uptime_fd = open ("/proc/uptime", O_RDONLY);
#if 0
kversion_fd = open ("/proc/sys/kernel/osrelease", O_RDONLY);
kversion_fd = open ("/proc/sys/kernel/osrelease", O_RDONLY);
reread (kversion_fd, "main:");
sscanf (buffer, "%s", kver);
reread (kversion_fd, "main:");
sscanf (buffer, "%s", kver);
close (kversion_fd);
close (kversion_fd);
# endif
/* Get OS name and version from uname() */
if (uname (unamebuf) != 0) {
perror ("Error calling uname:");
}
strcpy (kver, unamebuf->release);
strcpy (sysname, unamebuf->sysname);
/* Get OS name and version from uname() */
if (uname (unamebuf) != 0) {
perror ("Error calling uname:");
}
strcpy (kver, unamebuf->release);
strcpy (sysname, unamebuf->sysname);
free (unamebuf);
free (unamebuf);
}
}
return 0;
return 0;
}
int
chrono_close ()
{
if (uptime_fd)
close (uptime_fd);
if (uptime_fd)
close (uptime_fd);
uptime_fd = 0;
uptime_fd = 0;
return 0;
return 0;
}
//////////////////////////////////////////////////////////////////////
@@ -139,133 +139,133 @@ chrono_close ()
int
time_screen (int rep, int display)
{
char hr[8], min[8], sec[8], ampm[8];
char day[16], month[16];
static int first = 1;
static int colons = 0;
time_t thetime;
struct tm *rtime;
double uptime, idle;
int i = 0;
char colon;
char hr[8], min[8], sec[8], ampm[8];
char day[16], month[16];
static int first = 1;
static int colons = 0;
time_t thetime;
struct tm *rtime;
double uptime, idle;
int i = 0;
char colon;
if (first) {
first = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add T\n");
sprintf (buffer, "screen_set T -name {Time Screen: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add T title title\n");
sock_send_string (sock, "widget_set T title {Time Screen}\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");
} else {
sprintf (buffer, "widget_set T title {TIME: %s}\n", host);
sock_send_string (sock, buffer);
}
}
sock_send_string (sock, "screen_add T\n");
sprintf (buffer, "screen_set T -name {Time Screen: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add T title title\n");
sock_send_string (sock, "widget_set T title {Time Screen}\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");
} else {
sprintf (buffer, "widget_set T title {TIME: %s}\n", host);
sock_send_string (sock, buffer);
}
}
if (colons)
colon = ':';
else
colon = ' ';
if (colons)
colon = ':';
else
colon = ' ';
time (&thetime);
rtime = localtime (&thetime);
time (&thetime);
rtime = localtime (&thetime);
if (TwentyFourHour) {
sprintf (hr, "%02d", rtime->tm_hour);
} else {
if (rtime->tm_hour > 12) {
i = 1;
sprintf (hr, "%02d", (rtime->tm_hour - 12));
} else if (rtime->tm_hour == 0) {
i = 0;
sprintf (hr, "12");
} else {
i = 0;
sprintf (hr, "%02d", rtime->tm_hour);
}
}
if (rtime->tm_hour >= 12)
sprintf (ampm, "%s", "P");
else
sprintf (ampm, "%s", "A");
if (TwentyFourHour) {
sprintf (hr, "%02d", rtime->tm_hour);
} else {
if (rtime->tm_hour > 12) {
i = 1;
sprintf (hr, "%02d", (rtime->tm_hour - 12));
} else if (rtime->tm_hour == 0) {
i = 0;
sprintf (hr, "12");
} else {
i = 0;
sprintf (hr, "%02d", rtime->tm_hour);
}
}
if (rtime->tm_hour >= 12)
sprintf (ampm, "%s", "P");
else
sprintf (ampm, "%s", "A");
sprintf (min, "%02d", rtime->tm_min);
sprintf (sec, "%02d", rtime->tm_sec);
sprintf (min, "%02d", rtime->tm_min);
sprintf (sec, "%02d", rtime->tm_sec);
strcpy (day, shortdays[rtime->tm_wday]);
strcpy (month, shortmonths[rtime->tm_mon]);
strcpy (day, shortdays[rtime->tm_wday]);
strcpy (month, shortmonths[rtime->tm_mon]);
///////////////////// Write the title bar (os name and version)
///////////////////// Write the title bar (os name and version)
if (lcd_hgt >= 4) {
sprintf (tmp, "widget_set T title {");
sprintf (tmp + strlen (tmp), "%s %s: %s}\n", sysname, kver, host);
if (display)
sock_send_string (sock, tmp);
}
/////////////////////// Display the time...
if (lcd_hgt >= 4) {
get_uptime (&uptime, &idle);
idle = (idle * 100) / uptime;
if (lcd_hgt >= 4) {
sprintf (tmp, "widget_set T title {");
sprintf (tmp + strlen (tmp), "%s %s: %s}\n", sysname, kver, host);
if (display)
sock_send_string (sock, tmp);
}
/////////////////////// Display the time...
if (lcd_hgt >= 4) {
get_uptime (&uptime, &idle);
idle = (idle * 100) / uptime;
if (TwentyFourHour)
sprintf (tmp, "%s%c%s%c%s %2i%% idle", hr, colon, min, colon, sec, (int) idle);
else
sprintf (tmp, "%s%c%s%c%s%s %2i%% idle", hr, colon, min, colon, sec, ampm, (int) idle);
// Center the output line...
i = ((lcd_wid - strlen (tmp)) / 2) + 1;
sprintf (buffer, "widget_set T three %i 4 {%s}\n", i, tmp);
if (display)
sock_send_string (sock, buffer);
if (TwentyFourHour)
sprintf (tmp, "%s%c%s%c%s %2i%% idle", hr, colon, min, colon, sec, (int) idle);
else
sprintf (tmp, "%s%c%s%c%s%s %2i%% idle", hr, colon, min, colon, sec, ampm, (int) idle);
// Center the output line...
i = ((lcd_wid - strlen (tmp)) / 2) + 1;
sprintf (buffer, "widget_set T three %i 4 {%s}\n", i, tmp);
if (display)
sock_send_string (sock, buffer);
sprintf (tmp, "%s %s %d, %d", day, month, rtime->tm_mday, (rtime->tm_year + 1900));
sprintf (buffer, "widget_set T two 3 3 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
sprintf (tmp, "%s %s %d, %d", day, month, rtime->tm_mday, (rtime->tm_year + 1900));
sprintf (buffer, "widget_set T two 3 3 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
/////////////////////// Display the uptime...
i = (int) uptime / 86400;
sprintf (day, "Up %d day%s,", i, (i != 1 ? "s" : ""));
i = ((int) uptime % 86400) / 60 / 60;
sprintf (hr, "%02i", i);
i = (((int) uptime % 86400) % 3600) / 60;
sprintf (min, "%02i", i);
i = ((int) uptime % 60);
sprintf (sec, "%02i", i);
if (colons)
sprintf (tmp, "%s %s:%s:%s", day, hr, min, sec);
else
sprintf (tmp, "%s %s %s %s", day, hr, min, sec);
//// Center this line automatically...
//i = ((lcd_wid - strlen(tmp)) / 2) + 1;
sprintf (buffer, "widget_set T one 1 2 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
/////////////////////// Display the uptime...
i = (int) uptime / 86400;
sprintf (day, "Up %d day%s,", i, (i != 1 ? "s" : ""));
i = ((int) uptime % 86400) / 60 / 60;
sprintf (hr, "%02i", i);
i = (((int) uptime % 86400) % 3600) / 60;
sprintf (min, "%02i", i);
i = ((int) uptime % 60);
sprintf (sec, "%02i", i);
if (colons)
sprintf (tmp, "%s %s:%s:%s", day, hr, min, sec);
else
sprintf (tmp, "%s %s %s %s", day, hr, min, sec);
//// Center this line automatically...
//i = ((lcd_wid - strlen(tmp)) / 2) + 1;
sprintf (buffer, "widget_set T one 1 2 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
} else // 20x2 version of the screen
{
sprintf (tmp, "widget_set T one 1 2 {");
if (lcd_wid >= 20)
sprintf (tmp + strlen (tmp), "%d-%02d-%02d ", rtime->tm_year + 1900, rtime->tm_mon + 1, rtime->tm_mday);
else // 16x2 version...
sprintf (tmp + strlen (tmp), "%02d/%02d ", rtime->tm_mon + 1, rtime->tm_mday);
sprintf (tmp + strlen (tmp), "%s%c%s%c%s", hr, colon, min, colon, sec);
if (!TwentyFourHour)
sprintf (tmp + strlen (tmp), "%s", ampm);
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
}
} else // 20x2 version of the screen
{
sprintf (tmp, "widget_set T one 1 2 {");
if (lcd_wid >= 20)
sprintf (tmp + strlen (tmp), "%d-%02d-%02d ", rtime->tm_year + 1900, rtime->tm_mon + 1, rtime->tm_mday);
else // 16x2 version...
sprintf (tmp + strlen (tmp), "%02d/%02d ", rtime->tm_mon + 1, rtime->tm_mday);
sprintf (tmp + strlen (tmp), "%s%c%s%c%s", hr, colon, min, colon, sec);
if (!TwentyFourHour)
sprintf (tmp + strlen (tmp), "%s", ampm);
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
}
colons = colons ^ 1;
colons = colons ^ 1;
return 0;
} // End time_screen()
return 0;
} // End time_screen()
//////////////////////////////////////////////////////////////////////
// Clock Screen displays current time and date...
@@ -273,103 +273,103 @@ time_screen (int rep, int display)
int
clock_screen (int rep, int display)
{
char hr[8], min[8], sec[8], ampm[8];
char day[16], month[16];
static int first = 1;
static int colons = 0;
time_t thetime;
struct tm *rtime;
int i = 0;
char colon;
char hr[8], min[8], sec[8], ampm[8];
char day[16], month[16];
static int first = 1;
static int colons = 0;
time_t thetime;
struct tm *rtime;
int i = 0;
char colon;
if (lcd_hgt < 4)
return 0;
if (lcd_hgt < 4)
return 0;
if (first) {
first = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add O\n");
sprintf (buffer, "screen_set O -name {Clock Screen: %s}\n", host);
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");
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_set O title {DATE & TIME}\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 one 3 2 {%s}\n", host);
sock_send_string (sock, buffer);
} else {
sprintf (buffer, "widget_set O title {TIME: %s}\n", host);
sock_send_string (sock, buffer);
}
}
sock_send_string (sock, "screen_add O\n");
sprintf (buffer, "screen_set O -name {Clock Screen: %s}\n", host);
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");
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_set O title {DATE & TIME}\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 one 3 2 {%s}\n", host);
sock_send_string (sock, buffer);
} else {
sprintf (buffer, "widget_set O title {TIME: %s}\n", host);
sock_send_string (sock, buffer);
}
}
if (colons)
colon = ':';
else
colon = ' ';
if (colons)
colon = ':';
else
colon = ' ';
time (&thetime);
rtime = localtime (&thetime);
time (&thetime);
rtime = localtime (&thetime);
strcpy (day, days[rtime->tm_wday]);
strcpy (day, days[rtime->tm_wday]);
if (TwentyFourHour) {
sprintf (hr, "%02d", rtime->tm_hour);
} else {
if (rtime->tm_hour > 12) {
i = 1;
sprintf (hr, "%02d", (rtime->tm_hour - 12));
} else {
i = 0;
sprintf (hr, "%02d", rtime->tm_hour);
}
}
if (rtime->tm_hour == 12)
i = 1;
sprintf (min, "%02d", rtime->tm_min);
sprintf (sec, "%02d", rtime->tm_sec);
if (i == 1) {
sprintf (ampm, "%s", "P");
} else {
sprintf (ampm, "%s", "A");
}
strcpy (month, months[rtime->tm_mon]);
if (TwentyFourHour) {
sprintf (hr, "%02d", rtime->tm_hour);
} else {
if (rtime->tm_hour > 12) {
i = 1;
sprintf (hr, "%02d", (rtime->tm_hour - 12));
} else {
i = 0;
sprintf (hr, "%02d", rtime->tm_hour);
}
}
if (rtime->tm_hour == 12)
i = 1;
sprintf (min, "%02d", rtime->tm_min);
sprintf (sec, "%02d", rtime->tm_sec);
if (i == 1) {
sprintf (ampm, "%s", "P");
} else {
sprintf (ampm, "%s", "A");
}
strcpy (month, months[rtime->tm_mon]);
if (lcd_hgt >= 4) // 4-line version of the screen
{
sprintf (tmp, "widget_set O two 1 3 {");
if (TwentyFourHour)
sprintf (tmp + strlen (tmp), "%s%c%s%c%s %s", hr, colon, min, colon, sec, day);
else
sprintf (tmp + strlen (tmp), "%s%c%s%c%s%s %s", hr, colon, min, colon, sec, ampm, day);
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
if (lcd_hgt >= 4) // 4-line version of the screen
{
sprintf (tmp, "widget_set O two 1 3 {");
if (TwentyFourHour)
sprintf (tmp + strlen (tmp), "%s%c%s%c%s %s", hr, colon, min, colon, sec, day);
else
sprintf (tmp + strlen (tmp), "%s%c%s%c%s%s %s", hr, colon, min, colon, sec, ampm, day);
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set O three 2 4 {");
sprintf (tmp + strlen (tmp), "%s %d, %d", month, rtime->tm_mday, (rtime->tm_year + 1900));
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
} // end if(lcd_hgt >= 4)
else // 20x2 version of the screen
{
sprintf (tmp, "widget_set O one 1 2 {");
sprintf (tmp + strlen (tmp), "%d-%02d-%02d ", rtime->tm_year + 1900, rtime->tm_mon + 1, rtime->tm_mday);
sprintf (tmp + strlen (tmp), "%s%c%s%c%s", hr, colon, min, colon, sec);
if (!TwentyFourHour)
sprintf (tmp + strlen (tmp), "%s", ampm);
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
}
sprintf (tmp, "widget_set O three 2 4 {");
sprintf (tmp + strlen (tmp), "%s %d, %d", month, rtime->tm_mday, (rtime->tm_year + 1900));
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
} // end if(lcd_hgt >= 4)
else // 20x2 version of the screen
{
sprintf (tmp, "widget_set O one 1 2 {");
sprintf (tmp + strlen (tmp), "%d-%02d-%02d ", rtime->tm_year + 1900, rtime->tm_mon + 1, rtime->tm_mday);
sprintf (tmp + strlen (tmp), "%s%c%s%c%s", hr, colon, min, colon, sec);
if (!TwentyFourHour)
sprintf (tmp + strlen (tmp), "%s", ampm);
sprintf (tmp + strlen (tmp), "}\n");
if (display)
sock_send_string (sock, tmp);
}
colons = colons ^ 1;
colons = colons ^ 1;
return 0;
} // End clock_screen()
return 0;
} // End clock_screen()
////////////////////////////////////////////////////////////////////
// Uptime Screen shows info about system uptime and OS version
@@ -377,65 +377,65 @@ clock_screen (int rep, int display)
int
uptime_screen (int rep, int display)
{
int i;
char date[16], hour[8], min[8], sec[8];
double uptime, idle;
static int first = 1;
static int colons = 0;
char colon;
int i;
char date[16], hour[8], min[8], sec[8];
double uptime, idle;
static int first = 1;
static int colons = 0;
char colon;
if (first) {
first = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add U\n");
sprintf (buffer, "screen_set U -name {Uptime Screen: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add U title title\n");
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_set U title {SYSTEM UPTIME}\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, "screen_add U\n");
sprintf (buffer, "screen_set U -name {Uptime Screen: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add U title title\n");
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_set U title {SYSTEM UPTIME}\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");
sprintf (buffer, "widget_set U one 3 2 {%s}\n", host);
sock_send_string (sock, buffer);
sprintf (tmp, "widget_set U three 5 4 {%s %s}\n", sysname, kver);
sock_send_string (sock, tmp);
} else {
sprintf (tmp, "widget_set U title {%s %s: %s}\n", sysname, kver, host);
sock_send_string (sock, tmp);
sock_send_string (sock, "widget_add U one string\n");
}
}
sprintf (buffer, "widget_set U one 3 2 {%s}\n", host);
sock_send_string (sock, buffer);
sprintf (tmp, "widget_set U three 5 4 {%s %s}\n", sysname, kver);
sock_send_string (sock, tmp);
} else {
sprintf (tmp, "widget_set U title {%s %s: %s}\n", sysname, kver, host);
sock_send_string (sock, tmp);
sock_send_string (sock, "widget_add U one string\n");
}
}
if (colons)
colon = ':';
else
colon = ' ';
if (colons)
colon = ':';
else
colon = ' ';
get_uptime (&uptime, &idle);
i = (int) uptime / 86400;
sprintf (date, "%d day%s,", i, (i != 1 ? "s" : ""));
i = ((int) uptime % 86400) / 60 / 60;
sprintf (hour, "%02i", i);
i = (((int) uptime % 86400) % 3600) / 60;
sprintf (min, "%02i", i);
i = ((int) uptime % 60);
sprintf (sec, "%02i", i);
sprintf (tmp, "%s %s%c%s%c%s", date, hour, colon, min, colon, sec);
i = ((20 - strlen (tmp)) / 2) + 1;
get_uptime (&uptime, &idle);
i = (int) uptime / 86400;
sprintf (date, "%d day%s,", i, (i != 1 ? "s" : ""));
i = ((int) uptime % 86400) / 60 / 60;
sprintf (hour, "%02i", i);
i = (((int) uptime % 86400) % 3600) / 60;
sprintf (min, "%02i", i);
i = ((int) uptime % 60);
sprintf (sec, "%02i", i);
sprintf (tmp, "%s %s%c%s%c%s", date, hour, colon, min, colon, sec);
i = ((20 - strlen (tmp)) / 2) + 1;
if (lcd_hgt >= 4)
sprintf (buffer, "widget_set U two %i 3 {%s}\n", i, tmp);
else
sprintf (buffer, "widget_set U one %i 2 {%s}\n", i, tmp);
if (display)
sock_send_string (sock, buffer);
if (lcd_hgt >= 4)
sprintf (buffer, "widget_set U two %i 3 {%s}\n", i, tmp);
else
sprintf (buffer, "widget_set U one %i 2 {%s}\n", i, tmp);
if (display)
sock_send_string (sock, buffer);
colons = colons ^ 1;
colons = colons ^ 1;
return 0;
} // End uptime_screen()
return 0;
} // End uptime_screen()
//////////////////////////////////////////////////////////////////////
// Big Clock Screen displays current time...
@@ -452,61 +452,61 @@ uptime_screen (int rep, int display)
int
big_clock_screen (int rep, int display)
{
static int first = 1;
static int colons = 0;
time_t thetime;
struct tm *rtime;
int pos[] = { 1, 4, 8, 11, 15, 18 };
// int i=0;
static int first = 1;
static int colons = 0;
time_t thetime;
struct tm *rtime;
int pos[] = { 1, 4, 8, 11, 15, 18 };
// int i=0;
char fulltxt[16], old_fulltxt[16];
int j = 0;
char fulltxt[16], old_fulltxt[16];
int j = 0;
if (lcd_hgt < 4)
return 0;
if (lcd_hgt < 4)
return 0;
if (first) {
first = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add K\n");
sock_send_string (sock, "screen_set K -name {Big Clock Screen}\n");
sock_send_string (sock, "widget_del K heartbeat\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, "screen_add K\n");
sock_send_string (sock, "screen_set K -name {Big Clock Screen}\n");
sock_send_string (sock, "widget_del K heartbeat\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 one string\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");
old_fulltxt[0] = '0';
old_fulltxt[1] = '0';
old_fulltxt[2] = '0';
old_fulltxt[3] = '0';
old_fulltxt[4] = '0';
old_fulltxt[5] = '0';
old_fulltxt[6] = 0;
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");
old_fulltxt[0] = '0';
old_fulltxt[1] = '0';
old_fulltxt[2] = '0';
old_fulltxt[3] = '0';
old_fulltxt[4] = '0';
old_fulltxt[5] = '0';
old_fulltxt[6] = 0;
// sock_send_string(sock, "widget_set K one 1 4 {000000}\n");
}
}
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++) {
if (fulltxt[j] != old_fulltxt[j]) {
sprintf (tmp + strlen (tmp), "widget_set K d%d %d %c\n", j, pos[j], fulltxt[j]);
old_fulltxt[j] = fulltxt[j];
}
}
sprintf (fulltxt, "%02d%02d%02d", rtime->tm_hour, rtime->tm_min, rtime->tm_sec);
for (j = 0; j < 6; j++) {
if (fulltxt[j] != old_fulltxt[j]) {
sprintf (tmp + strlen (tmp), "widget_set K d%d %d %c\n", j, pos[j], fulltxt[j]);
old_fulltxt[j] = fulltxt[j];
}
}
if (display)
sock_send_string (sock, tmp);
if (display)
sock_send_string (sock, tmp);
return 0;
} // End big_clock_screen()
return 0;
} // End big_clock_screen()
+266 -266
View File
@@ -12,7 +12,7 @@
#include "cpu.h"
struct load {
unsigned long total, user, system, nice, idle;
unsigned long total, user, system, nice, idle;
};
int load_fd = 0;
@@ -21,43 +21,43 @@ static void get_load (struct load *result);
static void
get_load (struct load *result)
{
static struct load last_load = { 0, 0, 0, 0, 0 };
struct load curr_load;
static struct load last_load = { 0, 0, 0, 0, 0 };
struct load curr_load;
reread (load_fd, "get_load:");
sscanf (buffer, "%*s %lu %lu %lu %lu\n", &curr_load.user, &curr_load.nice, &curr_load.system, &curr_load.idle);
curr_load.total = curr_load.user + curr_load.nice + curr_load.system + curr_load.idle;
result->total = curr_load.total - last_load.total;
result->user = curr_load.user - last_load.user;
result->nice = curr_load.nice - last_load.nice;
result->system = curr_load.system - last_load.system;
result->idle = curr_load.idle - last_load.idle;
last_load.total = curr_load.total;
last_load.user = curr_load.user;
last_load.nice = curr_load.nice;
last_load.system = curr_load.system;
last_load.idle = curr_load.idle;
reread (load_fd, "get_load:");
sscanf (buffer, "%*s %lu %lu %lu %lu\n", &curr_load.user, &curr_load.nice, &curr_load.system, &curr_load.idle);
curr_load.total = curr_load.user + curr_load.nice + curr_load.system + curr_load.idle;
result->total = curr_load.total - last_load.total;
result->user = curr_load.user - last_load.user;
result->nice = curr_load.nice - last_load.nice;
result->system = curr_load.system - last_load.system;
result->idle = curr_load.idle - last_load.idle;
last_load.total = curr_load.total;
last_load.user = curr_load.user;
last_load.nice = curr_load.nice;
last_load.system = curr_load.system;
last_load.idle = curr_load.idle;
}
int
cpu_init ()
{
if (!load_fd) {
load_fd = open ("/proc/stat", O_RDONLY);
}
if (!load_fd) {
load_fd = open ("/proc/stat", O_RDONLY);
}
return 0;
return 0;
}
int
cpu_close ()
{
if (load_fd)
close (load_fd);
if (load_fd)
close (load_fd);
load_fd = 0;
load_fd = 0;
return 0;
return 0;
}
//////////////////////////////////////////////////////////////////////////
@@ -68,193 +68,193 @@ cpu_screen (int rep, int display)
{
#undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 4
int i, j, n;
static int first = 1;
float value;
static float cpu[CPU_BUF_SIZE + 1][5]; // last buffer is scratch
struct load load;
int i, j, n;
static int first = 1;
float value;
static float cpu[CPU_BUF_SIZE + 1][5]; // last buffer is scratch
struct load load;
if (first) {
first = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add C\n");
sprintf (buffer, "screen_set C -name {CPU Use: %s}\n", host);
sock_send_string (sock, buffer);
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add C title title\n");
sock_send_string (sock, "widget_set C title {CPU LOAD}\n");
sock_send_string (sock, "widget_add C one string\n");
sock_send_string (sock, "widget_set C one 1 2 {0 1 Sys 0.0%}\n");
sock_send_string (sock, "widget_add C two string\n");
sock_send_string (sock, "widget_add C three string\n");
sock_send_string (sock, "widget_set C one 1 2 {Usr 0.0% Nice 0.0%}\n");
sock_send_string (sock, "widget_set C two 1 3 {Sys 0.0% Idle 0.0%}\n");
sock_send_string (sock, "widget_set C three 1 4 {0% 100%}\n");
sock_send_string (sock, "widget_add C usr string\n");
sock_send_string (sock, "widget_add C nice string\n");
sock_send_string (sock, "widget_add C idle string\n");
sock_send_string (sock, "widget_add C sys string\n");
sock_send_string (sock, "widget_add C bar hbar\n");
sock_send_string (sock, "widget_set C bar 3 4 0\n");
} else {
sock_send_string (sock, "widget_add C cpu0 string\n");
if (lcd_wid >= 20)
sock_send_string (sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n");
else
sock_send_string (sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n");
sock_send_string (sock, "widget_add C cpu0% string\n");
sprintf (buffer, "widget_set C cpu0%% 1 %i { 0.0%%}\n", lcd_wid - 4);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add C usni string\n");
sock_send_string (sock, "widget_set C usni 1 2 { U S N I}\n");
sock_send_string (sock, "widget_add C usr hbar\n");
sock_send_string (sock, "widget_add C sys hbar\n");
sock_send_string (sock, "widget_add C nice hbar\n");
sock_send_string (sock, "widget_add C idle hbar\n");
sock_send_string (sock, "widget_add C total hbar\n");
sock_send_string (sock, "widget_set C total 6 1 0\n");
}
sock_send_string (sock, "screen_add C\n");
sprintf (buffer, "screen_set C -name {CPU Use: %s}\n", host);
sock_send_string (sock, buffer);
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add C title title\n");
sock_send_string (sock, "widget_set C title {CPU LOAD}\n");
sock_send_string (sock, "widget_add C one string\n");
sock_send_string (sock, "widget_set C one 1 2 {0 1 Sys 0.0%}\n");
sock_send_string (sock, "widget_add C two string\n");
sock_send_string (sock, "widget_add C three string\n");
sock_send_string (sock, "widget_set C one 1 2 {Usr 0.0% Nice 0.0%}\n");
sock_send_string (sock, "widget_set C two 1 3 {Sys 0.0% Idle 0.0%}\n");
sock_send_string (sock, "widget_set C three 1 4 {0% 100%}\n");
sock_send_string (sock, "widget_add C usr string\n");
sock_send_string (sock, "widget_add C nice string\n");
sock_send_string (sock, "widget_add C idle string\n");
sock_send_string (sock, "widget_add C sys string\n");
sock_send_string (sock, "widget_add C bar hbar\n");
sock_send_string (sock, "widget_set C bar 3 4 0\n");
} else {
sock_send_string (sock, "widget_add C cpu0 string\n");
if (lcd_wid >= 20)
sock_send_string (sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n");
else
sock_send_string (sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n");
sock_send_string (sock, "widget_add C cpu0% string\n");
sprintf (buffer, "widget_set C cpu0%% 1 %i { 0.0%%}\n", lcd_wid - 4);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add C usni string\n");
sock_send_string (sock, "widget_set C usni 1 2 { U S N I}\n");
sock_send_string (sock, "widget_add C usr hbar\n");
sock_send_string (sock, "widget_add C sys hbar\n");
sock_send_string (sock, "widget_add C nice hbar\n");
sock_send_string (sock, "widget_add C idle hbar\n");
sock_send_string (sock, "widget_add C total hbar\n");
sock_send_string (sock, "widget_set C total 6 1 0\n");
}
return 0;
}
//else return 0;
return 0;
}
//else return 0;
get_load (&load);
get_load (&load);
// Shift values over by one
for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
for (j = 0; j < 5; j++)
cpu[i][j] = cpu[i + 1][j];
// Shift values over by one
for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
for (j = 0; j < 5; j++)
cpu[i][j] = cpu[i + 1][j];
// Read new data
cpu[CPU_BUF_SIZE - 1][0] = ((float) load.user / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE - 1][1] = ((float) load.system / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE - 1][2] = ((float) load.nice / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE - 1][3] = ((float) load.idle / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE - 1][4] = (((float) load.user + (float) load.system + (float) load.nice) / (float) load.total) * 100.0;
// Read new data
cpu[CPU_BUF_SIZE - 1][0] = ((float) load.user / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE - 1][1] = ((float) load.system / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE - 1][2] = ((float) load.nice / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE - 1][3] = ((float) load.idle / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE - 1][4] = (((float) load.user + (float) load.system + (float) load.nice) / (float) load.total) * 100.0;
// Only clear on first display...
if (!rep) {
/*
// Make all the same, if this is the first time...
for(i=0; i<CPU_BUF_SIZE-1; i++)
for(j=0; j<5; j++)
cpu[i][j] = cpu[CPU_BUF_SIZE-1][j];
*/
}
// Average values for final result
for (i = 0; i < 5; i++) {
value = 0;
for (j = 0; j < CPU_BUF_SIZE; j++) {
value += cpu[j][i];
}
value /= CPU_BUF_SIZE;
cpu[CPU_BUF_SIZE][i] = value;
}
// Only clear on first display...
if (!rep) {
/*
// Make all the same, if this is the first time...
for(i=0; i<CPU_BUF_SIZE-1; i++)
for(j=0; j<5; j++)
cpu[i][j] = cpu[CPU_BUF_SIZE-1][j];
*/
}
// Average values for final result
for (i = 0; i < 5; i++) {
value = 0;
for (j = 0; j < CPU_BUF_SIZE; j++) {
value += cpu[j][i];
}
value /= CPU_BUF_SIZE;
cpu[CPU_BUF_SIZE][i] = value;
}
if (lcd_hgt >= 4) {
value = cpu[CPU_BUF_SIZE][4];
n = (int) (value * 70.0);
if (value >= 99.9) {
sprintf (tmp, "100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C title {CPU %s: %s}\n", tmp, host);
if (display)
sock_send_string (sock, buffer);
if (lcd_hgt >= 4) {
value = cpu[CPU_BUF_SIZE][4];
n = (int) (value * 70.0);
if (value >= 99.9) {
sprintf (tmp, "100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C title {CPU %s: %s}\n", tmp, host);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][0];
if (value >= 99.9) {
sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C usr 5 2 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][0];
if (value >= 99.9) {
sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C usr 5 2 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][1];
if (value >= 99.9) {
sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C sys 5 3 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][1];
if (value >= 99.9) {
sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C sys 5 3 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][2];
if (value >= 99.9) {
sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C nice 16 2 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][2];
if (value >= 99.9) {
sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C nice 16 2 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][3];
if (value >= 99.9) {
sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C idle 16 3 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][3];
if (value >= 99.9) {
sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C idle 16 3 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][4];
n = (int) (value * (lcd_cellwid * 14) / 100.0);
sprintf (buffer, "widget_set C bar 3 4 %i\n", n);
if (display)
sock_send_string (sock, buffer);
} // end if(lcd_hgt >= 4)
else // 20x2 version
{
value = cpu[CPU_BUF_SIZE][4];
if (value >= 99.9) {
sprintf (tmp, "100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C cpu0%% %i 1 {%s}\n", lcd_wid - 4, tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][4];
n = (int) (value * (lcd_cellwid * 14) / 100.0);
sprintf (buffer, "widget_set C bar 3 4 %i\n", n);
if (display)
sock_send_string (sock, buffer);
} // end if(lcd_hgt >= 4)
else // 20x2 version
{
value = cpu[CPU_BUF_SIZE][4];
if (value >= 99.9) {
sprintf (tmp, "100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C cpu0%% %i 1 {%s}\n", lcd_wid - 4, tmp);
if (display)
sock_send_string (sock, buffer);
n = (float) (value * lcd_cellwid * (float) (lcd_wid - 11)) / 100.0;
sprintf (buffer, "widget_set C total 6 1 %i\n", n);
if (display)
sock_send_string (sock, buffer);
n = (float) (value * lcd_cellwid * (float) (lcd_wid - 11)) / 100.0;
sprintf (buffer, "widget_set C total 6 1 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][0];
n = (float) (value * lcd_cellwid * 4.0) / 100.0;
sprintf (buffer, "widget_set C usr 1 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][0];
n = (float) (value * lcd_cellwid * 4.0) / 100.0;
sprintf (buffer, "widget_set C usr 1 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][1];
n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C sys 7 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][1];
n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C sys 7 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][2];
n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C nice 12 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][2];
n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C nice 12 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][3];
n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C idle 17 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][3];
n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C idle 17 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
}
}
return 0;
} // End cpu_screen()
return 0;
} // End cpu_screen()
//////////////////////////////////////////////////////////////////////////
// Cpu Graph Screen shows a quick-moving histogram of CPU use.
@@ -262,95 +262,95 @@ cpu_screen (int rep, int display)
int
cpu_graph_screen (int rep, int display)
{
int i, j, n = 0;
static int first = 1;
float value, maxload;
int i, j, n = 0;
static int first = 1;
float value, maxload;
#undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 2
static float cpu[CPU_BUF_SIZE + 1]; // last buffer is scratch
static int cpu_past[LCD_MAX_WIDTH];
struct load load;
int status = 0;
static float cpu[CPU_BUF_SIZE + 1]; // last buffer is scratch
static int cpu_past[LCD_MAX_WIDTH];
struct load load;
int status = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add G\n");
sprintf (buffer, "screen_set G -name {CPU Graph: %s}\n", host);
sock_send_string (sock, buffer);
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add G title title\n");
sprintf (buffer, "widget_set G title {CPU: %s}\n", host);
} else {
sock_send_string (sock, "widget_add G title string\n");
sprintf (buffer, "widget_set G title 1 1 {CPU: %s}\n", host);
}
sock_send_string (sock, buffer);
if (first) {
first = 0;
sock_send_string (sock, "screen_add G\n");
sprintf (buffer, "screen_set G -name {CPU Graph: %s}\n", host);
sock_send_string (sock, buffer);
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add G title title\n");
sprintf (buffer, "widget_set G title {CPU: %s}\n", host);
} else {
sock_send_string (sock, "widget_add G title string\n");
sprintf (buffer, "widget_set G title 1 1 {CPU: %s}\n", host);
}
sock_send_string (sock, buffer);
for (i = 1; i <= lcd_wid; i++) {
sprintf (tmp, "widget_add G %i vbar\n", i);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set G %i %i %i 0\n", i, i, lcd_hgt);
sock_send_string (sock, tmp);
}
}
for (i = 1; i <= lcd_wid; i++) {
sprintf (tmp, "widget_add G %i vbar\n", i);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set G %i %i %i 0\n", i, i, lcd_hgt);
sock_send_string (sock, tmp);
}
}
get_load (&load);
get_load (&load);
// Shift values over by one
for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
cpu[i] = cpu[i + 1];
// Shift values over by one
for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
cpu[i] = cpu[i + 1];
// Read new data
cpu[CPU_BUF_SIZE - 1] = ((float) load.user + (float) load.system + (float) load.nice) / (float) load.total;
// Read new data
cpu[CPU_BUF_SIZE - 1] = ((float) load.user + (float) load.system + (float) load.nice) / (float) load.total;
// Only clear on first display...
if (!rep) {
/*
// Make all the same, if this is the first time...
for(i=0; i<CPU_BUF_SIZE-1; i++)
cpu[i] = cpu[CPU_BUF_SIZE-1];
*/
}
// Average values for final result
value = 0;
for (j = 0; j < CPU_BUF_SIZE; j++) {
value += cpu[j];
}
value /= (float) CPU_BUF_SIZE;
cpu[CPU_BUF_SIZE] = value;
// Only clear on first display...
if (!rep) {
/*
// Make all the same, if this is the first time...
for(i=0; i<CPU_BUF_SIZE-1; i++)
cpu[i] = cpu[CPU_BUF_SIZE-1];
*/
}
// Average values for final result
value = 0;
for (j = 0; j < CPU_BUF_SIZE; j++) {
value += cpu[j];
}
value /= (float) CPU_BUF_SIZE;
cpu[CPU_BUF_SIZE] = value;
maxload = 0;
for (i = 0; i < lcd_wid - 1; i++) {
cpu_past[i] = cpu_past[i + 1];
maxload = 0;
for (i = 0; i < lcd_wid - 1; i++) {
cpu_past[i] = cpu_past[i + 1];
j = cpu_past[i];
sprintf (tmp, "widget_set G %i %i %i %i\n", i + 1, i + 1, lcd_hgt, j);
if (display)
sock_send_string (sock, tmp);
j = cpu_past[i];
sprintf (tmp, "widget_set G %i %i %i %i\n", i + 1, i + 1, lcd_hgt, j);
if (display)
sock_send_string (sock, tmp);
if (cpu_past[i] > maxload)
maxload = cpu_past[i];
}
if (cpu_past[i] > maxload)
maxload = cpu_past[i];
}
value = cpu[CPU_BUF_SIZE];
if (lcd_hgt > 2)
n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt - 1));
else
n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt));
value = cpu[CPU_BUF_SIZE];
if (lcd_hgt > 2)
n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt - 1));
else
n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt));
cpu_past[lcd_wid - 1] = n;
sprintf (tmp, "widget_set G %i %i %i %i\n", lcd_wid, lcd_wid, lcd_hgt, n);
if (display)
sock_send_string (sock, tmp);
cpu_past[lcd_wid - 1] = n;
sprintf (tmp, "widget_set G %i %i %i %i\n", lcd_wid, lcd_wid, lcd_hgt, n);
if (display)
sock_send_string (sock, tmp);
if (n > maxload)
maxload = n;
if (n > maxload)
maxload = n;
if (cpu_past[lcd_wid - 1] > 0)
status = BACKLIGHT_ON;
if (maxload < 1)
status = BACKLIGHT_OFF;
if (cpu_past[lcd_wid - 1] > 0)
status = BACKLIGHT_ON;
if (maxload < 1)
status = BACKLIGHT_OFF;
// return status;
return 0;
} // End cpu_graph_screen()
return 0;
} // End cpu_graph_screen()
+119 -119
View File
@@ -59,7 +59,7 @@
#define MAX_CPUS 8
struct load {
unsigned long total, user, system, nice, idle;
unsigned long total, user, system, nice, idle;
};
static int load_fd = 0;
@@ -69,62 +69,62 @@ static char *numnames[MAX_CPUS] = { "one", "two", "three", "four", "five", "six"
static void
get_load (struct load *result, int *numcpus)
{
char *token;
static struct load last_load[MAX_CPUS];
struct load curr_load[MAX_CPUS];
char *token;
static struct load last_load[MAX_CPUS];
struct load curr_load[MAX_CPUS];
*numcpus = 0;
*numcpus = 0;
reread (load_fd, "get_load");
reread (load_fd, "get_load");
// Look for lines starting with "cpu0", "cpu1", etc.
// Look for lines starting with "cpu0", "cpu1", etc.
token = strtok (buffer, "\n");
while (token) {
if (token[0] == 'c') {
if (isdigit (token[3])) {
sscanf (token, "%*s %lu %lu %lu %lu", &curr_load[*numcpus].user, &curr_load[*numcpus].nice, &curr_load[*numcpus].system, &curr_load[*numcpus].idle);
token = strtok (buffer, "\n");
while (token) {
if (token[0] == 'c') {
if (isdigit (token[3])) {
sscanf (token, "%*s %lu %lu %lu %lu", &curr_load[*numcpus].user, &curr_load[*numcpus].nice, &curr_load[*numcpus].system, &curr_load[*numcpus].idle);
curr_load[*numcpus].total = curr_load[*numcpus].user + curr_load[*numcpus].nice + curr_load[*numcpus].system + curr_load[*numcpus].idle;
result[*numcpus].total = curr_load[*numcpus].total - last_load[*numcpus].total;
result[*numcpus].user = curr_load[*numcpus].user - last_load[*numcpus].user;
result[*numcpus].nice = curr_load[*numcpus].nice - last_load[*numcpus].nice;
result[*numcpus].system = curr_load[*numcpus].system - last_load[*numcpus].system;
result[*numcpus].idle = curr_load[*numcpus].idle - last_load[*numcpus].idle;
last_load[*numcpus].total = curr_load[*numcpus].total;
last_load[*numcpus].user = curr_load[*numcpus].user;
last_load[*numcpus].nice = curr_load[*numcpus].nice;
last_load[*numcpus].system = curr_load[*numcpus].system;
last_load[*numcpus].idle = curr_load[*numcpus].idle;
curr_load[*numcpus].total = curr_load[*numcpus].user + curr_load[*numcpus].nice + curr_load[*numcpus].system + curr_load[*numcpus].idle;
result[*numcpus].total = curr_load[*numcpus].total - last_load[*numcpus].total;
result[*numcpus].user = curr_load[*numcpus].user - last_load[*numcpus].user;
result[*numcpus].nice = curr_load[*numcpus].nice - last_load[*numcpus].nice;
result[*numcpus].system = curr_load[*numcpus].system - last_load[*numcpus].system;
result[*numcpus].idle = curr_load[*numcpus].idle - last_load[*numcpus].idle;
last_load[*numcpus].total = curr_load[*numcpus].total;
last_load[*numcpus].user = curr_load[*numcpus].user;
last_load[*numcpus].nice = curr_load[*numcpus].nice;
last_load[*numcpus].system = curr_load[*numcpus].system;
last_load[*numcpus].idle = curr_load[*numcpus].idle;
(*numcpus)++;
}
} else {
break;
}
token = strtok (NULL, "\n");
}
(*numcpus)++;
}
} else {
break;
}
token = strtok (NULL, "\n");
}
}
int
cpu_smp_init ()
{
if (!load_fd) {
load_fd = open ("/proc/stat", O_RDONLY);
}
if (!load_fd) {
load_fd = open ("/proc/stat", O_RDONLY);
}
return 0;
return 0;
}
int
cpu_smp_close ()
{
if (load_fd)
close (load_fd);
if (load_fd)
close (load_fd);
load_fd = 0;
load_fd = 0;
return 0;
return 0;
}
//////////////////////////////////////////////////////////////////////////
@@ -135,105 +135,105 @@ cpu_smp_screen (int rep, int display)
{
#undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 4
int i, j, n, z;
static int first = 1;
float value;
static float cpu[MAX_CPUS][CPU_BUF_SIZE + 1][5]; // last buffer is scratch
struct load load[MAX_CPUS];
int numprocs;
char buf[256];
char *graphsize;
int i, j, n, z;
static int first = 1;
float value;
static float cpu[MAX_CPUS][CPU_BUF_SIZE + 1][5]; // last buffer is scratch
struct load load[MAX_CPUS];
int numprocs;
char buf[256];
char *graphsize;
if (first) {
first = 0;
if (first) {
first = 0;
get_load (load, &numprocs);
get_load (load, &numprocs);
sock_send_string (sock, "screen_add P\n");
sock_send_string (sock, "widget_del P heartbeat\n");
sock_send_string (sock, "screen_add P\n");
sock_send_string (sock, "widget_del P heartbeat\n");
sprintf (buffer, "screen_set P -name {CPU Use: %s}\n", host);
sock_send_string (sock, buffer);
sprintf (buffer, "screen_set P -name {CPU Use: %s}\n", host);
sock_send_string (sock, buffer);
graphsize = calloc (sizeof (char), lcd_wid);
if (numprocs > lcd_hgt) {
for (i = 0; i < lcd_wid / 2 - 6; i++) {
graphsize[i] = ' ';
}
} else {
for (i = 0; i < lcd_wid - 6; i++) {
graphsize[i] = ' ';
}
}
graphsize = calloc (sizeof (char), lcd_wid);
if (numprocs > lcd_hgt) {
for (i = 0; i < lcd_wid / 2 - 6; i++) {
graphsize[i] = ' ';
}
} else {
for (i = 0; i < lcd_wid - 6; i++) {
graphsize[i] = ' ';
}
}
for (i = 0; i < numprocs; i++) {
if (i + 1 > lcd_hgt * 2)
break;
for (i = 0; i < numprocs; i++) {
if (i + 1 > lcd_hgt * 2)
break;
sprintf (buf, "widget_add P %s_title string\n", numnames[i]);
sock_send_string (sock, buf);
sprintf (buf, "widget_add P %s_title string\n", numnames[i]);
sock_send_string (sock, buf);
if (numprocs > lcd_hgt) {
sprintf (buf, "widget_set P %s_title %d %d \"CPU%d[%s]\"\n", numnames[i], i % 2 * lcd_wid / 2 + 1, i / 2 + 1, i, graphsize);
} else {
sprintf (buf, "widget_set P %s_title 1 %d \"CPU%d[%s]\"\n", numnames[i], i + 1, i, graphsize);
}
sock_send_string (sock, buf);
if (numprocs > lcd_hgt) {
sprintf (buf, "widget_set P %s_title %d %d \"CPU%d[%s]\"\n", numnames[i], i % 2 * lcd_wid / 2 + 1, i / 2 + 1, i, graphsize);
} else {
sprintf (buf, "widget_set P %s_title 1 %d \"CPU%d[%s]\"\n", numnames[i], i + 1, i, graphsize);
}
sock_send_string (sock, buf);
sprintf (buf, "widget_add P %s_bar hbar\n", numnames[i]);
sock_send_string (sock, buf);
}
sprintf (buf, "widget_add P %s_bar hbar\n", numnames[i]);
sock_send_string (sock, buf);
}
free (graphsize);
free (graphsize);
return 0;
}
return 0;
}
get_load (load, &numprocs);
get_load (load, &numprocs);
for (z = 0; z < numprocs; z++) {
for (z = 0; z < numprocs; z++) {
// Shift values over by one
for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
for (j = 4; j < 5; j++)
cpu[z][i][j] = cpu[z][i + 1][j];
// Shift values over by one
for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
for (j = 4; j < 5; j++)
cpu[z][i][j] = cpu[z][i + 1][j];
if (load[z].total == 0) {
continue;
}
// Read new data
#if 0 // we're only using 4 right now
cpu[z][CPU_BUF_SIZE - 1][0] = ((float) load[z].user / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][1] = ((float) load[z].system / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][2] = ((float) load[z].nice / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][3] = ((float) load[z].idle / (float) load[z].total) * 100.0;
if (load[z].total == 0) {
continue;
}
// Read new data
#if 0 // we're only using 4 right now
cpu[z][CPU_BUF_SIZE - 1][0] = ((float) load[z].user / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][1] = ((float) load[z].system / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][2] = ((float) load[z].nice / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][3] = ((float) load[z].idle / (float) load[z].total) * 100.0;
#endif
cpu[z][CPU_BUF_SIZE - 1][4] = (((float) load[z].user + (float) load[z].system + (float) load[z].nice) / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][4] = (((float) load[z].user + (float) load[z].system + (float) load[z].nice) / (float) load[z].total) * 100.0;
// Average values for final result
for (i = 4; i < 5; i++) {
value = 0;
for (j = 0; j < CPU_BUF_SIZE; j++) {
value += cpu[z][j][i];
}
value /= CPU_BUF_SIZE;
cpu[z][CPU_BUF_SIZE][i] = value;
}
// Average values for final result
for (i = 4; i < 5; i++) {
value = 0;
for (j = 0; j < CPU_BUF_SIZE; j++) {
value += cpu[z][j][i];
}
value /= CPU_BUF_SIZE;
cpu[z][CPU_BUF_SIZE][i] = value;
}
value = cpu[z][CPU_BUF_SIZE][4];
value = cpu[z][CPU_BUF_SIZE][4];
if (numprocs > lcd_hgt) {
n = (float) (value * lcd_cellwid * ((float) lcd_wid / 2.f - 6.f)) / 100.f + .5f;
sprintf (buf, "widget_set P %s_bar %d %d %d\n", numnames[z], z % 2 * lcd_wid / 2 + 6, z / 2 + 1, n);
} else {
n = (float) (value * lcd_cellwid * ((float) lcd_wid - 6.f)) / 100.f + .5f;
sprintf (buf, "widget_set P %s_bar 6 %d %d\n", numnames[z], z + 1, n);
}
sock_send_string (sock, buf);
if (numprocs > lcd_hgt) {
n = (float) (value * lcd_cellwid * ((float) lcd_wid / 2.f - 6.f)) / 100.f + .5f;
sprintf (buf, "widget_set P %s_bar %d %d %d\n", numnames[z], z % 2 * lcd_wid / 2 + 6, z / 2 + 1, n);
} else {
n = (float) (value * lcd_cellwid * ((float) lcd_wid - 6.f)) / 100.f + .5f;
sprintf (buf, "widget_set P %s_bar 6 %d %d\n", numnames[z], z + 1, n);
}
sock_send_string (sock, buf);
if (z + 1 > lcd_hgt * 2)
break;
}
if (z + 1 > lcd_hgt * 2)
break;
}
return 0;
} // End cpu_screen()
return 0;
} // End cpu_screen()
+138 -138
View File
@@ -36,79 +36,79 @@
FILE *mtab_fd;
typedef struct mounts {
char dev[256], type[64], mpoint[256];
long bsize, blocks, bfree, files, ffree;
char dev[256], type[64], mpoint[256];
long bsize, blocks, bfree, files, ffree;
} mounts;
static int
get_fs (mounts fs[])
{
#ifdef STAT_STATVFS
struct statvfs fsinfo;
struct statvfs fsinfo;
#else
struct statfs fsinfo;
struct statfs fsinfo;
#endif
char line[256];
int x = 0, y;
char line[256];
int x = 0, y;
mtab_fd = fopen ("/etc/mtab", "r");
mtab_fd = fopen ("/etc/mtab", "r");
// Get rid of old, unmounted filesystems...
memset (fs, 0, sizeof (mounts) * 256);
// Get rid of old, unmounted filesystems...
memset (fs, 0, sizeof (mounts) * 256);
while (x < 256) {
if (fgets (line, 256, mtab_fd) == NULL) {
fclose (mtab_fd);
return x;
}
while (x < 256) {
if (fgets (line, 256, mtab_fd) == NULL) {
fclose (mtab_fd);
return x;
}
sscanf (line, "%s %s %s", fs[x].dev, fs[x].mpoint, fs[x].type);
sscanf (line, "%s %s %s", fs[x].dev, fs[x].mpoint, fs[x].type);
if (strcmp (fs[x].type, "proc")
if (strcmp (fs[x].type, "proc")
#ifndef STAT_NFS
&& strcmp (fs[x].type, "nfs")
&& strcmp (fs[x].type, "nfs")
#endif
#ifndef STAT_SMBFS
&& strcmp (fs[x].type, "smbfs")
&& strcmp (fs[x].type, "smbfs")
#endif
) {
) {
#ifdef STAT_STATVFS
y = statvfs (fs[x].mpoint, &fsinfo);
y = statvfs (fs[x].mpoint, &fsinfo);
#elif STAT_STATFS2_BSIZE
y = statfs (fs[x].mpoint, &fsinfo);
y = statfs (fs[x].mpoint, &fsinfo);
#elif STAT_STATFS4
y = statfs (fs[x].mpoint, &fsinfo, sizeof (fsinfo), 0);
y = statfs (fs[x].mpoint, &fsinfo, sizeof (fsinfo), 0);
#else
#error "statfs for this system noy yet supported"
#endif
fs[x].blocks = fsinfo.f_blocks;
if (fs[x].blocks > 0) {
fs[x].bsize = fsinfo.f_bsize;
fs[x].bfree = fsinfo.f_bfree;
fs[x].files = fsinfo.f_files;
fs[x].ffree = fsinfo.f_ffree;
x++;
}
}
}
fs[x].blocks = fsinfo.f_blocks;
if (fs[x].blocks > 0) {
fs[x].bsize = fsinfo.f_bsize;
fs[x].bfree = fsinfo.f_bfree;
fs[x].files = fsinfo.f_files;
fs[x].ffree = fsinfo.f_ffree;
x++;
}
}
}
fclose (mtab_fd);
return x;
fclose (mtab_fd);
return x;
}
int
disk_init ()
{
return 0;
return 0;
}
int
disk_close ()
{
return 0;
return 0;
}
///////////////////////////////////////////////////////////////////////////
@@ -122,123 +122,123 @@ disk_close ()
int
disk_screen (int rep, int display)
{
static mounts mnt[256];
static int count = 0;
static mounts mnt[256];
static int count = 0;
// Holds info to display (avoid recalculating it)
struct disp {
char dev[8];
char cap[8];
int full;
} table[256];
int i;
static int num_disks = 0;
static int first = 1; // First line to display, sort of.
// Holds info to display (avoid recalculating it)
struct disp {
char dev[8];
char cap[8];
int full;
} table[256];
int i;
static int num_disks = 0;
static int first = 1; // First line to display, sort of.
#define huge long long int
huge size;
huge size;
if (first) {
first = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add D\n");
sprintf (buffer, "screen_set D -name {Disk Use: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add D title title\n");
sprintf (buffer, "widget_set D title {DISKS: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add D f frame\n");
//sock_send_string(sock, "widget_set D f 1 2 20 4 20 3 v 8\n");
sprintf (buffer, "widget_set D f 1 2 %i %i %i %i v 12\n", lcd_wid, lcd_hgt, lcd_wid, lcd_hgt - 1);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add D err1 string\n");
sock_send_string (sock, "widget_add D err2 string\n");
sock_send_string (sock, "widget_set D err1 5 2 { Reading }\n");
sock_send_string (sock, "widget_set D err2 5 3 {Filesystems}\n");
}
// Grab disk stats on first display, and fill "table".
// Get rid of old, unmounted filesystems...
memset (table, 0, sizeof (struct disp) * 256);
sock_send_string (sock, "screen_add D\n");
sprintf (buffer, "screen_set D -name {Disk Use: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add D title title\n");
sprintf (buffer, "widget_set D title {DISKS: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add D f frame\n");
//sock_send_string(sock, "widget_set D f 1 2 20 4 20 3 v 8\n");
sprintf (buffer, "widget_set D f 1 2 %i %i %i %i v 12\n", lcd_wid, lcd_hgt, lcd_wid, lcd_hgt - 1);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add D err1 string\n");
sock_send_string (sock, "widget_add D err2 string\n");
sock_send_string (sock, "widget_set D err1 5 2 { Reading }\n");
sock_send_string (sock, "widget_set D err2 5 3 {Filesystems}\n");
}
// Grab disk stats on first display, and fill "table".
// Get rid of old, unmounted filesystems...
memset (table, 0, sizeof (struct disp) * 256);
count = get_fs (mnt);
first = 0;
count = get_fs (mnt);
first = 0;
// Fill the display structure...
if (count) {
sock_send_string (sock, "widget_set D err1 30 5 .\n");
sock_send_string (sock, "widget_set D err2 30 5 .\n");
for (i = 0; i < count; i++) {
if (strlen (mnt[i].mpoint) > 6) {
sprintf (table[i].dev, "%c%s", ELLIPSIS, (mnt[i].mpoint) + (strlen (mnt[i].mpoint) - 5));
} else {
sprintf (table[i].dev, "%s", mnt[i].mpoint);
}
// Fill the display structure...
if (count) {
sock_send_string (sock, "widget_set D err1 30 5 .\n");
sock_send_string (sock, "widget_set D err2 30 5 .\n");
for (i = 0; i < count; i++) {
if (strlen (mnt[i].mpoint) > 6) {
sprintf (table[i].dev, "%c%s", ELLIPSIS, (mnt[i].mpoint) + (strlen (mnt[i].mpoint) - 5));
} else {
sprintf (table[i].dev, "%s", mnt[i].mpoint);
}
//table[i].full = (lcd.cellwid * 4)
table[i].full = (huge) (lcd_cellwid * 4)
* (huge) (mnt[i].blocks - mnt[i].bfree)
/ (huge) mnt[i].blocks;
//table[i].full = (lcd.cellwid * 4)
table[i].full = (huge) (lcd_cellwid * 4)
* (huge) (mnt[i].blocks - mnt[i].bfree)
/ (huge) mnt[i].blocks;
size = (huge) mnt[i].bsize * (huge) mnt[i].blocks;
memset (table[i].cap, 0, 8);
size = (huge) mnt[i].bsize * (huge) mnt[i].blocks;
memset (table[i].cap, 0, 8);
// Kilobytes
if (size > 0 && size < (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fk", (double) (size) / 1024.0);
// Megabytes
else if (size >= (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fM", (float) (size / (huge) 1024) / 1024.0);
// Gigabytes
else if (size >= (huge) 1000 * (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fG", (float) (size / ((huge) 1024 * (huge) 1024)) / 1024.0);
// Terabytes
else if (size >= (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fT", (float) (size / ((huge) 1024 * (huge) 1024 * (huge) 1024)) / 1024.0);
// Kilobytes
if (size > 0 && size < (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fk", (double) (size) / 1024.0);
// Megabytes
else if (size >= (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fM", (float) (size / (huge) 1024) / 1024.0);
// Gigabytes
else if (size >= (huge) 1000 * (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fG", (float) (size / ((huge) 1024 * (huge) 1024)) / 1024.0);
// Terabytes
else if (size >= (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fT", (float) (size / ((huge) 1024 * (huge) 1024 * (huge) 1024)) / 1024.0);
// PectaBytes -- Yeah! I want some!
else if (size >= (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fP", (float) (size / ((huge) 1024 * (huge) 1024 * (huge) 1024 * (huge) 1024)) / 1024.0);
// PectaBytes -- Yeah! I want some!
else if (size >= (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000)
sprintf (table[i].cap, "%3.1fP", (float) (size / ((huge) 1024 * (huge) 1024 * (huge) 1024 * (huge) 1024)) / 1024.0);
}
}
}
}
if (!count) {
sock_send_string (sock, "widget_set D err1 1 2 {Error Retrieving}\n");
sock_send_string (sock, "widget_set D err2 1 3 {Filesystem Stats}\n");
return 0;
}
// Display stuff... (show for two seconds, then scroll once per
// second, then hold at the end for two seconds)
sprintf (buffer, "widget_set D f 1 2 %i %i %i %i v 12\n", lcd_wid, lcd_hgt, lcd_wid, count);
sock_send_string (sock, buffer);
//sprintf(tmp, "widget_set D f 1 2 20 4 20 %i v 8\n", count);
//sock_send_string(sock, tmp);
for (i = 0; i < count; i++) {
if (table[i].dev[0] == 0)
continue;
if (i >= num_disks) // Make sure we have enough lines...
{
sprintf (tmp, "widget_add D s%i string -in f\n", i);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_add D h%i hbar -in f\n", i);
sock_send_string (sock, tmp);
if (!count) {
sock_send_string (sock, "widget_set D err1 1 2 {Error Retrieving}\n");
sock_send_string (sock, "widget_set D err2 1 3 {Filesystem Stats}\n");
return 0;
}
// Display stuff... (show for two seconds, then scroll once per
// second, then hold at the end for two seconds)
sprintf (buffer, "widget_set D f 1 2 %i %i %i %i v 12\n", lcd_wid, lcd_hgt, lcd_wid, count);
sock_send_string (sock, buffer);
//sprintf(tmp, "widget_set D f 1 2 20 4 20 %i v 8\n", count);
//sock_send_string(sock, tmp);
for (i = 0; i < count; i++) {
if (table[i].dev[0] == 0)
continue;
if (i >= num_disks) // Make sure we have enough lines...
{
sprintf (tmp, "widget_add D s%i string -in f\n", i);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_add D h%i hbar -in f\n", i);
sock_send_string (sock, tmp);
}
sprintf (tmp, "widget_set D s%i 1 %i {%-6s %6s E F}\n", i, i + 1, table[i].dev, table[i].cap);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set D h%i 16 %i %i\n", i, i + 1, table[i].full);
sock_send_string (sock, tmp);
}
}
sprintf (tmp, "widget_set D s%i 1 %i {%-6s %6s E F}\n", i, i + 1, table[i].dev, table[i].cap);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set D h%i 16 %i %i\n", i, i + 1, table[i].full);
sock_send_string (sock, tmp);
}
// Now remove extra widgets...
for (; i < num_disks; i++) {
sprintf (tmp, "widget_del D s%i\n", i);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_del D h%i\n", i);
sock_send_string (sock, tmp);
}
// Now remove extra widgets...
for (; i < num_disks; i++) {
sprintf (tmp, "widget_del D s%i\n", i);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_del D h%i\n", i);
sock_send_string (sock, tmp);
}
num_disks = count;
num_disks = count;
#undef huge
@@ -248,5 +248,5 @@ disk_screen (int rep, int display)
// /dos/c 2.1G E----F
// /stuff 4.3G E----F
*/
return 0;
return 0;
}
+87 -87
View File
@@ -17,31 +17,31 @@ static double get_loadavg (void);
static double
get_loadavg (void)
{
double load;
double load;
reread (loadavg_fd, "get_load:");
sscanf (buffer, "%lf", &load);
return load;
reread (loadavg_fd, "get_load:");
sscanf (buffer, "%lf", &load);
return load;
}
int
load_init ()
{
if (!loadavg_fd)
loadavg_fd = open ("/proc/loadavg", O_RDONLY);
if (!loadavg_fd)
loadavg_fd = open ("/proc/loadavg", O_RDONLY);
return 0;
return 0;
}
int
load_close ()
{
if (loadavg_fd)
close (loadavg_fd);
if (loadavg_fd)
close (loadavg_fd);
loadavg_fd = 0;
loadavg_fd = 0;
return 0;
return 0;
}
///////////////////////////////////////////////////////////////////////////
@@ -51,89 +51,89 @@ load_close ()
int
xload_screen (int rep, int display)
{
static int first = 1;
static float loads[LCD_MAX_WIDTH];
int n, i;
float loadmax = 0, factor, x;
int status = 0;
static int first = 1;
static float loads[LCD_MAX_WIDTH];
int n, i;
float loadmax = 0, factor, x;
int status = 0;
if (first) // Only the first time this is ever called...
{
first = 0;
memset (loads, 0, sizeof (float) * LCD_MAX_WIDTH);
if (first) // Only the first time this is ever called...
{
first = 0;
memset (loads, 0, sizeof (float) * LCD_MAX_WIDTH);
sock_send_string (sock, "screen_add X\n");
sprintf (buffer, "screen_set X -name {X-Load: %s}\n", host);
sock_send_string (sock, buffer);
// Add the vbars...
for (i = 1; i < lcd_wid; i++) {
sprintf (tmp, "widget_add X %i vbar\n", i);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set X %i %i %i 0\n", i, i, lcd_hgt);
sock_send_string (sock, tmp);
}
// And add a title...
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add X title title\n");
sock_send_string (sock, "widget_set X title {LOAD }\n");
} else {
sock_send_string (sock, "widget_add X title string\n");
sock_send_string (sock, "widget_set X title 1 1 {LOAD}\n");
sock_send_string (sock, "widget_del X heartbeat\n");
}
sock_send_string (sock, "widget_add X zero string\n");
sock_send_string (sock, "widget_add X top string\n");
sprintf (tmp, "widget_set X zero %i %i 0\n", lcd_wid, lcd_hgt);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set X top %i %i 1\n", lcd_wid, (lcd_hgt == 2) ? 1 : 2);
sock_send_string (sock, tmp);
}
sock_send_string (sock, "screen_add X\n");
sprintf (buffer, "screen_set X -name {X-Load: %s}\n", host);
sock_send_string (sock, buffer);
// Add the vbars...
for (i = 1; i < lcd_wid; i++) {
sprintf (tmp, "widget_add X %i vbar\n", i);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set X %i %i %i 0\n", i, i, lcd_hgt);
sock_send_string (sock, tmp);
}
// And add a title...
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add X title title\n");
sock_send_string (sock, "widget_set X title {LOAD }\n");
} else {
sock_send_string (sock, "widget_add X title string\n");
sock_send_string (sock, "widget_set X title 1 1 {LOAD}\n");
sock_send_string (sock, "widget_del X heartbeat\n");
}
sock_send_string (sock, "widget_add X zero string\n");
sock_send_string (sock, "widget_add X top string\n");
sprintf (tmp, "widget_set X zero %i %i 0\n", lcd_wid, lcd_hgt);
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set X top %i %i 1\n", lcd_wid, (lcd_hgt == 2) ? 1 : 2);
sock_send_string (sock, tmp);
}
for (n = 0; n < (lcd_wid - 2); n++)
loads[n] = loads[n + 1];
loads[lcd_wid - 2] = get_loadavg ();
for (n = 0; n < (lcd_wid - 2); n++)
loads[n] = loads[n + 1];
loads[lcd_wid - 2] = get_loadavg ();
for (n = 0; n < lcd_wid - 1; n++)
if (loads[n] > loadmax)
loadmax = loads[n];
for (n = 0; n < lcd_wid - 1; n++)
if (loads[n] > loadmax)
loadmax = loads[n];
n = (int) loadmax;
if ((float) n < loadmax) {
n++;
}
sprintf (tmp, "widget_set X top %i %i %i\n", lcd_wid, (lcd_hgt == 2) ? 1 : 2, n);
//if(display) sock_send_string(sock, tmp);
sock_send_string (sock, tmp);
n = (int) loadmax;
if ((float) n < loadmax) {
n++;
}
sprintf (tmp, "widget_set X top %i %i %i\n", lcd_wid, (lcd_hgt == 2) ? 1 : 2, n);
//if(display) sock_send_string(sock, tmp);
sock_send_string (sock, tmp);
if (loadmax < 1.0)
factor = (float) (lcd_cellhgt) * ((lcd_hgt == 2) ? 2.0 : 3.0);
else
factor = (float) (lcd_cellhgt) * ((lcd_hgt == 2) ? 2.0 : 3.0) / (float) n;
if (loadmax < 1.0)
factor = (float) (lcd_cellhgt) * ((lcd_hgt == 2) ? 2.0 : 3.0);
else
factor = (float) (lcd_cellhgt) * ((lcd_hgt == 2) ? 2.0 : 3.0) / (float) n;
for (n = 0; n < lcd_wid - 1; n++) {
x = (loads[n] * factor);
for (n = 0; n < lcd_wid - 1; n++) {
x = (loads[n] * factor);
sprintf (tmp, "widget_set X %i %i %i %i\n", n + 1, n + 1, lcd_hgt, (int) x);
//if(display) sock_send_string(sock, tmp);
sock_send_string (sock, tmp);
}
sprintf (tmp, "widget_set X %i %i %i %i\n", n + 1, n + 1, lcd_hgt, (int) x);
//if(display) sock_send_string(sock, tmp);
sock_send_string (sock, tmp);
}
if (loadmax < LOAD_MIN) {
status = BACKLIGHT_OFF;
}
if (loadmax > LOAD_MIN) {
status = BACKLIGHT_ON;
}
if (loads[lcd_wid - 2] > LOAD_MAX) {
status = BLINK_ON;
}
// And now the title...
if (lcd_hgt >= 4)
sprintf (tmp, "widget_set X title {LOAD %2.2f: %s}\n", loads[lcd_wid - 2], host);
else
sprintf (tmp, "widget_set X title 1 1 {%s %2.2f}\n", host, loads[lcd_wid - 2]);
//if(display) sock_send_string(sock, tmp);
sock_send_string (sock, tmp);
if (loadmax < LOAD_MIN) {
status = BACKLIGHT_OFF;
}
if (loadmax > LOAD_MIN) {
status = BACKLIGHT_ON;
}
if (loads[lcd_wid - 2] > LOAD_MAX) {
status = BLINK_ON;
}
// And now the title...
if (lcd_hgt >= 4)
sprintf (tmp, "widget_set X title {LOAD %2.2f: %s}\n", loads[lcd_wid - 2], host);
else
sprintf (tmp, "widget_set X title 1 1 {%s %2.2f}\n", host, loads[lcd_wid - 2]);
//if(display) sock_send_string(sock, tmp);
sock_send_string (sock, tmp);
return status;
} // End xload_screen()
return status;
} // End xload_screen()
+238 -238
View File
@@ -47,24 +47,24 @@ void main_loop (mode * sequence);
// Contains a list of modes to run
mode default_sequence[] = {
// which on off inv timer/visible
{'C', 1, 2, 0, 0xffff, 0,}, // [C]PU
{'M', 4, 16, 0, 0xffff, 0,}, // [M]emory
{'X', 64, 128, 1, 0xffff, 0,}, // [X]-load (load histogram)
{'T', 4, 64, 0, 0xffff, 0,}, // [T]ime/Date
{'A', 999, 9999, 0, 0xffff, 0,}, // [A]bout (credits)
{'C', 1, 2, 0, 0xffff, 0,}, // [C]PU
{'M', 4, 16, 0, 0xffff, 0,}, // [M]emory
{'X', 64, 128, 1, 0xffff, 0,}, // [X]-load (load histogram)
{'T', 4, 64, 0, 0xffff, 0,}, // [T]ime/Date
{'A', 999, 9999, 0, 0xffff, 0,}, // [A]bout (credits)
{1, 0, 0, 0, 0, 0,}, // Modes after this line will not be run by default...
// ... all non-default modes must be in here!
// ... they will not show up otherwise.
{'P', 1, 2, 0, 0xffff, 0,}, // [O]ld Timescreen
{'O', 4, 64, 0, 0xffff, 0,}, // [O]ld Timescreen
{'K', 4, 64, 0, 0xffff, 0,}, // big cloc[K]
{'U', 4, 128, 0, 0xffff, 0,}, // Old [U]ptime Screen
{'B', 32, 256, 1, 0xffff, 0,}, // [B]attery Status
{'G', 1, 2, 0, 0xffff, 0,}, // Cpu histogram [G]raph
{'S', 16, 256, 1, 0xffff, 0,}, // [S]ize of biggest programs
{'D', 256, 256, 1, 0xffff, 0,}, // [D]isk stats
{0, 0, 0, 0, 0,}, // No more.. all done.
{1, 0, 0, 0, 0, 0,}, // Modes after this line will not be run by default...
// ... all non-default modes must be in here!
// ... they will not show up otherwise.
{'P', 1, 2, 0, 0xffff, 0,}, // [O]ld Timescreen
{'O', 4, 64, 0, 0xffff, 0,}, // [O]ld Timescreen
{'K', 4, 64, 0, 0xffff, 0,}, // big cloc[K]
{'U', 4, 128, 0, 0xffff, 0,}, // Old [U]ptime Screen
{'B', 32, 256, 1, 0xffff, 0,}, // [B]attery Status
{'G', 1, 2, 0, 0xffff, 0,}, // Cpu histogram [G]raph
{'S', 16, 256, 1, 0xffff, 0,}, // [S]ize of biggest programs
{'D', 256, 256, 1, 0xffff, 0,}, // [D]isk stats
{0, 0, 0, 0, 0,}, // No more.. all done.
};
// TODO: Clean up main()... It is still way too big.
@@ -74,123 +74,123 @@ mode default_sequence[] = {
int
main (int argc, char **argv)
{
mode sequence[MAX_SEQUENCE];
char cfgfile[256] = "/etc/lcdproc.cf";
char server[256] = "localhost";
int port = LCDPORT;
int i, j, k;
int tmp;
mode sequence[MAX_SEQUENCE];
char cfgfile[256] = "/etc/lcdproc.cf";
char server[256] = "localhost";
int port = LCDPORT;
int i, j, k;
int tmp;
memset (sequence, 0, sizeof (mode) * MAX_SEQUENCE);
memset (sequence, 0, sizeof (mode) * MAX_SEQUENCE);
// Ctrl-C will cause a clean exit...
signal (SIGINT, exit_program);
// and "kill"...
signal (SIGTERM, exit_program);
// and "kill -HUP" (hangup)...
signal (SIGHUP, exit_program);
// and just in case, "kill -KILL" (which cannot be trapped; but oh well)
signal (SIGKILL, exit_program);
// Ctrl-C will cause a clean exit...
signal (SIGINT, exit_program);
// and "kill"...
signal (SIGTERM, exit_program);
// and "kill -HUP" (hangup)...
signal (SIGHUP, exit_program);
// and just in case, "kill -KILL" (which cannot be trapped; but oh well)
signal (SIGKILL, exit_program);
// Command line
memcpy (sequence, default_sequence, sizeof (default_sequence));
for (i = 1, j = 0; i < argc; i++) {
if (argv[i][0] == '-')
switch (argv[i][1]) {
// s is for server
case 'S':
case 's':
if (argc < i + 1)
HelpScreen ();
strcpy (server, argv[++i]);
break;
// p is for port
case 'P':
case 'p':
if (argc < i + 1)
HelpScreen ();
port = atoi (argv[++i]);
if (port < 1 && port > 0xffff)
fprintf (stderr, "Warning: Port %i outside of standard range\n", port);
break;
// Command line
memcpy (sequence, default_sequence, sizeof (default_sequence));
for (i = 1, j = 0; i < argc; i++) {
if (argv[i][0] == '-')
switch (argv[i][1]) {
// s is for server
case 'S':
case 's':
if (argc < i + 1)
HelpScreen ();
strcpy (server, argv[++i]);
break;
// p is for port
case 'P':
case 'p':
if (argc < i + 1)
HelpScreen ();
port = atoi (argv[++i]);
if (port < 1 && port > 0xffff)
fprintf (stderr, "Warning: Port %i outside of standard range\n", port);
break;
// otherwise... Get help!
default:
HelpScreen ();
break;
}
// Parse command line here... read the man page.
else if (strlen (argv[i]) == 1) {
// Grab the mode letter...
sequence[j].which = argv[i][0];
// otherwise... Get help!
default:
HelpScreen ();
break;
}
// Parse command line here... read the man page.
else if (strlen (argv[i]) == 1) {
// Grab the mode letter...
sequence[j].which = argv[i][0];
// If we have just a letter with no numbers...
// Set the defaults...
for (tmp = 0, k = 0; default_sequence[k].which; k++) {
if (toupper (sequence[j].which) == default_sequence[k].which) {
memcpy (&sequence[j], &default_sequence[k], sizeof (mode));
tmp = 1;
break;
}
}
if (!tmp) {
printf ("Invalid Mode: %c\n", argv[i][0]);
exit (0);
}
// If we have just a letter with no numbers...
// Set the defaults...
for (tmp = 0, k = 0; default_sequence[k].which; k++) {
if (toupper (sequence[j].which) == default_sequence[k].which) {
memcpy (&sequence[j], &default_sequence[k], sizeof (mode));
tmp = 1;
break;
}
}
if (!tmp) {
printf ("Invalid Mode: %c\n", argv[i][0]);
exit (0);
}
j++;
// Set the last element to 0...
memset (sequence + j, 0, sizeof (mode));
} // End if(strlen(argv == 1))
else {
// A multicharacter parameter by itself
// is assumed to be a config file..
strcpy (cfgfile, argv[i]);
printf ("Ignoring config file: %s\n", cfgfile);
}
}
j++;
// Set the last element to 0...
memset (sequence + j, 0, sizeof (mode));
} // End if(strlen(argv == 1))
else {
// A multicharacter parameter by itself
// is assumed to be a config file..
strcpy (cfgfile, argv[i]);
printf ("Ignoring config file: %s\n", cfgfile);
}
}
// Connect to the server...
usleep (500000); // wait for the server to start up
sock = sock_connect (server, port);
if (sock <= 0) {
printf ("Error connecting to server %s on port %i.\n", server, port);
return 0;
}
sock_send_string (sock, "hello\n");
usleep (500000); // wait for the server to say hi.
// Connect to the server...
usleep (500000); // wait for the server to start up
sock = sock_connect (server, port);
if (sock <= 0) {
printf ("Error connecting to server %s on port %i.\n", server, port);
return 0;
}
sock_send_string (sock, "hello\n");
usleep (500000); // wait for the server to say hi.
// We grab the real values below, from the "connect" line.
lcd_wid = 20;
lcd_hgt = 4;
lcd_cellwid = 5;
lcd_cellhgt = 8;
// We grab the real values below, from the "connect" line.
lcd_wid = 20;
lcd_hgt = 4;
lcd_cellwid = 5;
lcd_cellhgt = 8;
// Init the status gatherers...
mode_init (sequence);
// Init the status gatherers...
mode_init (sequence);
// And spew stuff!
main_loop (sequence);
// And spew stuff!
main_loop (sequence);
// Clean up
exit_program (0);
return 0;
// Clean up
exit_program (0);
return 0;
}
void
HelpScreen ()
{
printf ("LCDproc, %s\n", version);
printf ("Usage: lcdproc [-s server] [-p port] [modelist]\n");
printf ("\tOptions in []'s are optional.\n");
printf ("\tmodelist is \"mode [mode mode ...]\"\n");
printf ("\tMode letters: \t[C]pu [G]raph [T]ime [M]emory [X]load [D]isk [B]attery\n\t\t\tproc_[S]izes [O]ld_time big_cloc[K] [U]ptime CPU_SM[P]\n\t\t\t[A]bout\n");
printf ("\n");
printf ("\tUse \"man lcdproc\" for more info.\n");
printf ("Example:\n");
printf ("\tlcdproc -s my.lcdproc.server.com C M X -p 13666\n");
printf ("\n");
exit (0);
printf ("LCDproc, %s\n", version);
printf ("Usage: lcdproc [-s server] [-p port] [modelist]\n");
printf ("\tOptions in []'s are optional.\n");
printf ("\tmodelist is \"mode [mode mode ...]\"\n");
printf ("\tMode letters: \t[C]pu [G]raph [T]ime [M]emory [X]load [D]isk [B]attery\n\t\t\tproc_[S]izes [O]ld_time big_cloc[K] [U]ptime CPU_SM[P]\n\t\t\t[A]bout\n");
printf ("\n");
printf ("\tUse \"man lcdproc\" for more info.\n");
printf ("Example:\n");
printf ("\tlcdproc -s my.lcdproc.server.com C M X -p 13666\n");
printf ("\n");
exit (0);
}
///////////////////////////////////////////////////////////////////
@@ -199,10 +199,10 @@ HelpScreen ()
void
exit_program (int val)
{
Quit = 1;
sock_close (sock);
mode_close ();
exit (0);
Quit = 1;
sock_close (sock);
mode_close ();
exit (0);
}
///////////////////////////////////////////////////////////////////
@@ -211,126 +211,126 @@ exit_program (int val)
void
main_loop (mode * sequence)
{
int i = 0, j;
//int status=0;
char buf[8192];
char *argv[256];
int argc, newtoken;
int len;
int i = 0, j;
//int status=0;
char buf[8192];
char *argv[256];
int argc, newtoken;
int len;
// Main loop
// Run whatever screen we want, then wait. Woo-hoo!
while (!Quit) {
// Check for server input...
len = sock_recv (sock, buf, 8000);
// Main loop
// Run whatever screen we want, then wait. Woo-hoo!
while (!Quit) {
// Check for server input...
len = sock_recv (sock, buf, 8000);
// Handle server input...
while (len > 0) {
// Now split the string into tokens...
//for(i=0; i<argc; i++) argv[i]=NULL; // Get rid of old tokens
argc = 0;
newtoken = 1;
for (i = 0; i < len; i++) {
if (buf[i]) // For regular letters, keep tokenizing...
{
switch (buf[i]) {
case ' ':
newtoken = 1;
buf[i] = 0;
break;
case '\n':
buf[i] = 0;
default:
if (newtoken) {
argv[argc] = buf + i;
argc++;
}
newtoken = 0;
break;
}
} else // If we've got a zero, it's the end of a string...
{
if (argc > 0) {
//printf("%s %s\n", argv[0], argv[1]);
if (0 == strcmp (argv[0], "listen")) {
for (j = 0; sequence[j].which; j++) {
if (sequence[j].which == argv[1][0]) {
sequence[j].visible = 1;
//debug("Listen %s\n", argv[1]);
// Handle server input...
while (len > 0) {
// Now split the string into tokens...
//for(i=0; i<argc; i++) argv[i]=NULL; // Get rid of old tokens
argc = 0;
newtoken = 1;
for (i = 0; i < len; i++) {
if (buf[i]) // For regular letters, keep tokenizing...
{
switch (buf[i]) {
case ' ':
newtoken = 1;
buf[i] = 0;
break;
case '\n':
buf[i] = 0;
default:
if (newtoken) {
argv[argc] = buf + i;
argc++;
}
newtoken = 0;
break;
}
} else // If we've got a zero, it's the end of a string...
{
if (argc > 0) {
//printf("%s %s\n", argv[0], argv[1]);
if (0 == strcmp (argv[0], "listen")) {
for (j = 0; sequence[j].which; j++) {
if (sequence[j].which == argv[1][0]) {
sequence[j].visible = 1;
//debug("Listen %s\n", argv[1]);
}
}
} else if (0 == strcmp (argv[0], "ignore")) {
for (j = 0; sequence[j].which; j++) {
if (sequence[j].which == argv[1][0]) {
sequence[j].visible = 0;
//debug("Ignore %s\n", argv[1]);
}
}
} else if (0 == strcmp (argv[0], "key")) {
debug ("Key %s\n", argv[1]);
} else if (0 == strcmp (argv[0], "menu")) {
} else if (0 == strcmp (argv[0], "connect")) {
int a;
for (a = 1; a < argc; a++) {
if (0 == strcmp (argv[a], "wid"))
lcd_wid = atoi (argv[++a]);
else if (0 == strcmp (argv[a], "hgt"))
lcd_hgt = atoi (argv[++a]);
else if (0 == strcmp (argv[a], "cellwid"))
lcd_cellwid = atoi (argv[++a]);
else if (0 == strcmp (argv[a], "cellhgt"))
lcd_cellhgt = atoi (argv[++a]);
}
sock_send_string (sock, "client_set -name LCDproc\n");
} else if (0 == strcmp (argv[0], "bye")) {
//printf("Exiting LCDproc\n");
exit_program (0);
} else {
int j;
for (j = 0; j < argc; j++)
printf ("%s ", argv[j]);
printf ("\n");
}
}
argc = 0;
newtoken = 1;
}
}
}
} else if (0 == strcmp (argv[0], "ignore")) {
for (j = 0; sequence[j].which; j++) {
if (sequence[j].which == argv[1][0]) {
sequence[j].visible = 0;
//debug("Ignore %s\n", argv[1]);
len = sock_recv (sock, buf, 8000);
//debug("\n");
}
// Gather stats...
// Update screens...
for (i = 0; sequence[i].which > 1; i++) {
sequence[i].timer++;
if (sequence[i].visible) {
if (sequence[i].timer >= sequence[i].on_time) {
sequence[i].timer = 0;
// Now, update the screen...
update_screen (sequence + i, 1);
}
} else {
if (sequence[i].show_invisible) {
if (sequence[i].timer >= sequence[i].off_time) {
sequence[i].timer = 0;
// Now, update the screen...
update_screen (sequence + i, 1);
}
} else {
if (sequence[i].timer >= sequence[i].off_time) {
sequence[i].timer = 0;
// Now, update the screen...
update_screen (sequence + i, 0);
}
}
}
}
} else if (0 == strcmp (argv[0], "key")) {
debug ("Key %s\n", argv[1]);
} else if (0 == strcmp (argv[0], "menu")) {
} else if (0 == strcmp (argv[0], "connect")) {
int a;
for (a = 1; a < argc; a++) {
if (0 == strcmp (argv[a], "wid"))
lcd_wid = atoi (argv[++a]);
else if (0 == strcmp (argv[a], "hgt"))
lcd_hgt = atoi (argv[++a]);
else if (0 == strcmp (argv[a], "cellwid"))
lcd_cellwid = atoi (argv[++a]);
else if (0 == strcmp (argv[a], "cellhgt"))
lcd_cellhgt = atoi (argv[++a]);
}
sock_send_string (sock, "client_set -name LCDproc\n");
} else if (0 == strcmp (argv[0], "bye")) {
//printf("Exiting LCDproc\n");
exit_program (0);
} else {
int j;
for (j = 0; j < argc; j++)
printf ("%s ", argv[j]);
printf ("\n");
}
}
}
argc = 0;
newtoken = 1;
}
}
len = sock_recv (sock, buf, 8000);
//debug("\n");
}
// Gather stats...
// Update screens...
for (i = 0; sequence[i].which > 1; i++) {
sequence[i].timer++;
if (sequence[i].visible) {
if (sequence[i].timer >= sequence[i].on_time) {
sequence[i].timer = 0;
// Now, update the screen...
update_screen (sequence + i, 1);
}
} else {
if (sequence[i].show_invisible) {
if (sequence[i].timer >= sequence[i].off_time) {
sequence[i].timer = 0;
// Now, update the screen...
update_screen (sequence + i, 1);
}
} else {
if (sequence[i].timer >= sequence[i].off_time) {
sequence[i].timer = 0;
// Now, update the screen...
update_screen (sequence + i, 0);
}
}
}
}
// Now sleep...
usleep (TIME_UNIT);
// Now sleep...
usleep (TIME_UNIT);
/* Old stuff
timer=0;
@@ -398,5 +398,5 @@ main_loop (mode * sequence)
i++;
if(sequence[i].which < 2) i=0;
*/
}
}
}
+6 -6
View File
@@ -12,12 +12,12 @@ extern int lcd_cellwid;
extern int lcd_cellhgt;
typedef struct mode {
char which; // Which screen is it?
int on_time; // How often to update while visible?
int off_time; // How often to get stats while not visible?
int show_invisible; // Send stats while not visible?
int timer; // Time since last update
int visible; // Can we be seen right now?
char which; // Which screen is it?
int on_time; // How often to update while visible?
int off_time; // How often to get stats while not visible?
int show_invisible; // Send stats while not visible?
int timer; // Time since last update
int visible; // Can we be seen right now?
} mode;
#define BLINK_ON 0x10
+305 -305
View File
@@ -16,7 +16,7 @@
#include "mem.h"
struct meminfo {
int total, cache, buffers, free, shared;
int total, cache, buffers, free, shared;
};
int meminfo_fd = 0;
@@ -28,35 +28,35 @@ get_mem_info (struct meminfo *result)
{
// int i, res; char *bufptr;
reread (meminfo_fd, "get_meminfo:");
result[0].total = getentry ("MemTotal:", buffer);
result[0].free = getentry ("MemFree:", buffer);
result[0].shared = getentry ("MemShared:", buffer);
result[0].buffers = getentry ("Buffers:", buffer);
result[0].cache = getentry ("Cached:", buffer);
result[1].total = getentry ("SwapTotal:", buffer);
result[1].free = getentry ("SwapFree:", buffer);
reread (meminfo_fd, "get_meminfo:");
result[0].total = getentry ("MemTotal:", buffer);
result[0].free = getentry ("MemFree:", buffer);
result[0].shared = getentry ("MemShared:", buffer);
result[0].buffers = getentry ("Buffers:", buffer);
result[0].cache = getentry ("Cached:", buffer);
result[1].total = getentry ("SwapTotal:", buffer);
result[1].free = getentry ("SwapFree:", buffer);
}
int
mem_init ()
{
if (!meminfo_fd) {
meminfo_fd = open ("/proc/meminfo", O_RDONLY);
}
if (!meminfo_fd) {
meminfo_fd = open ("/proc/meminfo", O_RDONLY);
}
return 0;
return 0;
}
int
mem_close ()
{
if (meminfo_fd)
meminfo_fd = open ("/proc/meminfo", O_RDONLY);
if (meminfo_fd)
meminfo_fd = open ("/proc/meminfo", O_RDONLY);
meminfo_fd = 0;
meminfo_fd = 0;
return 0;
return 0;
}
/////////////////////////////////////////////////////////////////////////
@@ -65,343 +65,343 @@ mem_close ()
int
mem_screen (int rep, int display)
{
int n;
struct meminfo mem[2];
static int first = 1;
static int which_title = 0;
float value;
int n;
struct meminfo mem[2];
static int first = 1;
static int which_title = 0;
float value;
if (first) {
first = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add M\n");
sprintf (buffer, "screen_set M -name {Memory & Swap: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "screen_add M\n");
sprintf (buffer, "screen_set M -name {Memory & Swap: %s}\n", host);
sock_send_string (sock, buffer);
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add M title title\n");
sock_send_string (sock, "widget_set M title { MEM -==- SWAP}\n");
sock_send_string (sock, "widget_add M totl string\n");
sock_send_string (sock, "widget_add M used string\n");
sock_send_string (sock, "widget_set M totl 9 2 Totl\n");
sock_send_string (sock, "widget_set M used 9 3 Free\n");
sock_send_string (sock, "widget_add M EF string\n");
sock_send_string (sock, "widget_set M EF 1 4 {E F E F}\n");
sock_send_string (sock, "widget_add M memused string\n");
sock_send_string (sock, "widget_add M swapused string\n");
//sock_send_string(sock, "widget_set M memgauge 2 4 0\n");
//sock_send_string(sock, "widget_set M swapgauge 13 4 0\n");
} else {
sock_send_string (sock, "widget_add M m string\n");
sock_send_string (sock, "widget_add M s string\n");
if (lcd_wid >= 20) {
sock_send_string (sock, "widget_set M m 1 1 {M [ ]}\n");
sock_send_string (sock, "widget_set M s 1 2 {S [ ]}\n");
} else {
sock_send_string (sock, "widget_set M m 1 1 {M [ ]}\n");
sock_send_string (sock, "widget_set M s 1 2 {S [ ]}\n");
}
sock_send_string (sock, "widget_add M mem% string\n");
sock_send_string (sock, "widget_add M swap% string\n");
sock_send_string (sock, "widget_set M mem% 16 1 { 0.0%}\n");
sock_send_string (sock, "widget_set M swap% 16 2 { 0.0%}\n");
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add M title title\n");
sock_send_string (sock, "widget_set M title { MEM -==- SWAP}\n");
sock_send_string (sock, "widget_add M totl string\n");
sock_send_string (sock, "widget_add M used string\n");
sock_send_string (sock, "widget_set M totl 9 2 Totl\n");
sock_send_string (sock, "widget_set M used 9 3 Free\n");
sock_send_string (sock, "widget_add M EF string\n");
sock_send_string (sock, "widget_set M EF 1 4 {E F E F}\n");
sock_send_string (sock, "widget_add M memused string\n");
sock_send_string (sock, "widget_add M swapused string\n");
//sock_send_string(sock, "widget_set M memgauge 2 4 0\n");
//sock_send_string(sock, "widget_set M swapgauge 13 4 0\n");
} else {
sock_send_string (sock, "widget_add M m string\n");
sock_send_string (sock, "widget_add M s string\n");
if (lcd_wid >= 20) {
sock_send_string (sock, "widget_set M m 1 1 {M [ ]}\n");
sock_send_string (sock, "widget_set M s 1 2 {S [ ]}\n");
} else {
sock_send_string (sock, "widget_set M m 1 1 {M [ ]}\n");
sock_send_string (sock, "widget_set M s 1 2 {S [ ]}\n");
}
sock_send_string (sock, "widget_add M mem% string\n");
sock_send_string (sock, "widget_add M swap% string\n");
sock_send_string (sock, "widget_set M mem% 16 1 { 0.0%}\n");
sock_send_string (sock, "widget_set M swap% 16 2 { 0.0%}\n");
//sock_send_string(sock, "widget_set M memgauge 8 1 0\n");
//sock_send_string(sock, "widget_set M swapgauge 8 2 0\n");
}
//sock_send_string(sock, "widget_set M memgauge 8 1 0\n");
//sock_send_string(sock, "widget_set M swapgauge 8 2 0\n");
}
sock_send_string (sock, "widget_add M memtotl string\n");
sock_send_string (sock, "widget_add M swaptotl string\n");
sock_send_string (sock, "widget_add M memtotl string\n");
sock_send_string (sock, "widget_add M swaptotl string\n");
sock_send_string (sock, "widget_add M memgauge hbar\n");
sock_send_string (sock, "widget_add M swapgauge hbar\n");
sock_send_string (sock, "widget_add M memgauge hbar\n");
sock_send_string (sock, "widget_add M swapgauge hbar\n");
//sock_send_string(sock, "\n");
}
//sock_send_string(sock, "\n");
}
get_mem_info (mem);
get_mem_info (mem);
// flip the title back and forth...
if (lcd_hgt >= 4) {
if (which_title & 4) {
sprintf (buffer, "widget_set M title {%s}\n", host);
sock_send_string (sock, buffer);
} else
sock_send_string (sock, "widget_set M title { MEM -==- SWAP}\n");
which_title = (which_title + 1) & 7;
// flip the title back and forth...
if (lcd_hgt >= 4) {
if (which_title & 4) {
sprintf (buffer, "widget_set M title {%s}\n", host);
sock_send_string (sock, buffer);
} else
sock_send_string (sock, "widget_set M title { MEM -==- SWAP}\n");
which_title = (which_title + 1) & 7;
// Total memory
sprintf (tmp, "widget_set M memtotl 1 2 {%6dk}\n", mem[0].total);
if (display)
sock_send_string (sock, tmp);
// Total memory
sprintf (tmp, "widget_set M memtotl 1 2 {%6dk}\n", mem[0].total);
if (display)
sock_send_string (sock, tmp);
// Free memory (plus buffers and cache)
sprintf (tmp, "widget_set M memused 1 3 {%6dk}\n", mem[0].free + mem[0].buffers + mem[0].cache);
if (display)
sock_send_string (sock, tmp);
// Free memory (plus buffers and cache)
sprintf (tmp, "widget_set M memused 1 3 {%6dk}\n", mem[0].free + mem[0].buffers + mem[0].cache);
if (display)
sock_send_string (sock, tmp);
// Total swap
sprintf (tmp, "widget_set M swaptotl 14 2 {%6dk}\n", mem[1].total);
if (display)
sock_send_string (sock, tmp);
// Total swap
sprintf (tmp, "widget_set M swaptotl 14 2 {%6dk}\n", mem[1].total);
if (display)
sock_send_string (sock, tmp);
// Free swap
sprintf (tmp, "widget_set M swapused 14 3 {%6dk}\n", mem[1].free);
if (display)
sock_send_string (sock, tmp);
// Free swap
sprintf (tmp, "widget_set M swapused 14 3 {%6dk}\n", mem[1].free);
if (display)
sock_send_string (sock, tmp);
// Free memory graph
n = (int) (35.0 - ((float) mem[0].free + (float) mem[0].buffers + (float) mem[0].cache)
/ (float) mem[0].total * 35.0);
sprintf (tmp, "widget_set M memgauge 2 4 %i\n", n);
if (display)
sock_send_string (sock, tmp);
// Free memory graph
n = (int) (35.0 - ((float) mem[0].free + (float) mem[0].buffers + (float) mem[0].cache)
/ (float) mem[0].total * 35.0);
sprintf (tmp, "widget_set M memgauge 2 4 %i\n", n);
if (display)
sock_send_string (sock, tmp);
// Free swap graph
n = (int) (35.0 - (float) mem[1].free / (float) mem[1].total * 35.0);
sprintf (tmp, "widget_set M swapgauge 13 4 %i\n", n);
if (display)
sock_send_string (sock, tmp);
} else {
// Total memory
sprintf (tmp, "widget_set M memtotl 2 1 {%4dM}\n", (int) (mem[0].total / 1024.0));
if (display)
sock_send_string (sock, tmp);
// Free swap graph
n = (int) (35.0 - (float) mem[1].free / (float) mem[1].total * 35.0);
sprintf (tmp, "widget_set M swapgauge 13 4 %i\n", n);
if (display)
sock_send_string (sock, tmp);
} else {
// Total memory
sprintf (tmp, "widget_set M memtotl 2 1 {%4dM}\n", (int) (mem[0].total / 1024.0));
if (display)
sock_send_string (sock, tmp);
// Total swap
sprintf (tmp, "widget_set M swaptotl 2 2 {%4dM}\n", (int) (mem[1].total / 1024.0));
if (display)
sock_send_string (sock, tmp);
// Total swap
sprintf (tmp, "widget_set M swaptotl 2 2 {%4dM}\n", (int) (mem[1].total / 1024.0));
if (display)
sock_send_string (sock, tmp);
// Free memory graph
value = ((float) mem[0].free + (float) mem[0].buffers + (float) mem[0].cache)
/ (float) mem[0].total;
value = 1.0 - value;
n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value));
sprintf (tmp, "widget_set M memgauge 8 1 %i\n", n);
if (display)
sock_send_string (sock, tmp);
// Free memory graph
value = ((float) mem[0].free + (float) mem[0].buffers + (float) mem[0].cache)
/ (float) mem[0].total;
value = 1.0 - value;
n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value));
sprintf (tmp, "widget_set M memgauge 8 1 %i\n", n);
if (display)
sock_send_string (sock, tmp);
value *= 100.0;
if (value >= 99.9) {
sprintf (buffer, "100%%");
} else {
sprintf (buffer, "%4.1f%%", value);
}
sprintf (tmp, "widget_set M mem%% %i 1 {%s}\n", lcd_wid - 4, buffer);
if (display)
sock_send_string (sock, tmp);
value *= 100.0;
if (value >= 99.9) {
sprintf (buffer, "100%%");
} else {
sprintf (buffer, "%4.1f%%", value);
}
sprintf (tmp, "widget_set M mem%% %i 1 {%s}\n", lcd_wid - 4, buffer);
if (display)
sock_send_string (sock, tmp);
// Free swap graph
value = ((float) mem[1].free / (float) mem[1].total);
value = 1.0 - value;
n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value));
sprintf (tmp, "widget_set M swapgauge 8 2 %i\n", n);
if (display)
sock_send_string (sock, tmp);
// Free swap graph
value = ((float) mem[1].free / (float) mem[1].total);
value = 1.0 - value;
n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value));
sprintf (tmp, "widget_set M swapgauge 8 2 %i\n", n);
if (display)
sock_send_string (sock, tmp);
value *= 100.0;
if (value >= 99.9) {
sprintf (buffer, "100%%");
} else {
sprintf (buffer, "%4.1f%%", value);
}
sprintf (tmp, "widget_set M swap%% %i 2 {%s}\n", lcd_wid - 4, buffer);
if (display)
sock_send_string (sock, tmp);
value *= 100.0;
if (value >= 99.9) {
sprintf (buffer, "100%%");
} else {
sprintf (buffer, "%4.1f%%", value);
}
sprintf (tmp, "widget_set M swap%% %i 2 {%s}\n", lcd_wid - 4, buffer);
if (display)
sock_send_string (sock, tmp);
}
}
return 0;
} // End mem_screen()
return 0;
} // End mem_screen()
typedef struct proc_mem_info {
char name[16]; // Is this really long enough?
// Size isn't used any more...
// Totl stores the "size" of the program now...
int size, totl;
int number;
char name[16]; // Is this really long enough?
// Size isn't used any more...
// Totl stores the "size" of the program now...
int size, totl;
int number;
} proc_mem_info;
static int
sort_procs (void *a, void *b)
{
proc_mem_info *one, *two;
proc_mem_info *one, *two;
if (!a)
return 0;
if (!b)
return 0;
if (!a)
return 0;
if (!b)
return 0;
one = (proc_mem_info *) a;
two = (proc_mem_info *) b;
one = (proc_mem_info *) a;
two = (proc_mem_info *) b;
return (two->totl > one->totl);
return (two->totl > one->totl);
}
int
mem_top_screen (int rep, int display)
{
// Much of this code was ripped from "gmemusage"
char buf[128];
// Much of this code was ripped from "gmemusage"
char buf[128];
DIR *proc;
FILE *StatusFile;
struct dirent *procdir;
DIR *proc;
FILE *StatusFile;
struct dirent *procdir;
char procName[16];
int
procSize, procRSS, procData, procStk, procExe;
const char
*NameLine = "Name:", *VmSizeLine = "VmSize:", *VmRSSLine = "VmRSS", *VmDataLine = "VmData", *VmStkLine = "VmStk", *VmExeLine = "VmExe";
const int
NameLineLen = strlen (NameLine), VmSizeLineLen = strlen (VmSizeLine), VmDataLineLen = strlen (VmDataLine), VmStkLineLen = strlen (VmStkLine), VmExeLineLen = strlen (VmExeLine), VmRSSLineLen = strlen (VmRSSLine);
char procName[16];
int
procSize, procRSS, procData, procStk, procExe;
const char
*NameLine = "Name:", *VmSizeLine = "VmSize:", *VmRSSLine = "VmRSS", *VmDataLine = "VmData", *VmStkLine = "VmStk", *VmExeLine = "VmExe";
const int
NameLineLen = strlen (NameLine), VmSizeLineLen = strlen (VmSizeLine), VmDataLineLen = strlen (VmDataLine), VmStkLineLen = strlen (VmStkLine), VmExeLineLen = strlen (VmExeLine), VmRSSLineLen = strlen (VmRSSLine);
int threshold = 400, unique;
int i;
proc_mem_info *p;
LL *procs;
static int first = 1;
int threshold = 400, unique;
int i;
proc_mem_info *p;
LL *procs;
static int first = 1;
if (first) {
first = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add S\n");
sprintf (buffer, "screen_set S -name {Top Memory Use: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add S title title\n");
sprintf (buffer, "widget_set S title {TOP MEM: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add S f frame\n");
if (lcd_hgt >= 4)
sock_send_string (sock, "widget_set S f 1 2 20 4 20 5 v 8\n");
else
sock_send_string (sock, "widget_set S f 1 2 20 2 20 5 v 16\n");
for (i = 1; i <= 5; i++) {
sprintf (buffer, "widget_add S %i string -in f\n", i);
sock_send_string (sock, buffer);
}
sock_send_string (sock, "widget_set S 1 1 1 Checking...\n");
}
sock_send_string (sock, "screen_add S\n");
sprintf (buffer, "screen_set S -name {Top Memory Use: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add S title title\n");
sprintf (buffer, "widget_set S title {TOP MEM: %s}\n", host);
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add S f frame\n");
if (lcd_hgt >= 4)
sock_send_string (sock, "widget_set S f 1 2 20 4 20 5 v 8\n");
else
sock_send_string (sock, "widget_set S f 1 2 20 2 20 5 v 16\n");
for (i = 1; i <= 5; i++) {
sprintf (buffer, "widget_add S %i string -in f\n", i);
sock_send_string (sock, buffer);
}
sock_send_string (sock, "widget_set S 1 1 1 Checking...\n");
}
procs = LL_new ();
if (!procs) {
fprintf (stderr, "mem_top_screen: Error allocating list\n");
return -1;
}
procs = LL_new ();
if (!procs) {
fprintf (stderr, "mem_top_screen: Error allocating list\n");
return -1;
}
if ((proc = opendir ("/proc")) == NULL) {
fprintf (stderr, "mem_top_screen: unable to open /proc");
perror ("");
return -1;
}
if ((proc = opendir ("/proc")) == NULL) {
fprintf (stderr, "mem_top_screen: unable to open /proc");
perror ("");
return -1;
}
while ((procdir = readdir (proc))) {
if (!index ("1234567890", procdir->d_name[0])) {
continue;
}
sprintf (buf, "/proc/%s/status", procdir->d_name);
if ((StatusFile = fopen (buf, "r")) == NULL) {
// Not a serious error; process has finished before we could
// examine it:
//fprintf ( stderr , "mem_top_screen: cannot open %s for reading" ,
// buf ) ;
//perror ( "" ) ;
continue;
}
procRSS = procSize = procData = procStk = procExe = 0;
while (fgets (buf, sizeof (buf), StatusFile)) {
if (!strncmp (buf, NameLine, NameLineLen)) {
/* Name: procName */
sscanf (buf, "%*s %s", procName);
} else if (!strncmp (buf, VmSizeLine, VmSizeLineLen)) {
/* VmSize: procSize kB */
sscanf (buf, "%*s %d", &procSize);
} else if (!strncmp (buf, VmRSSLine, VmRSSLineLen)) {
/* VmRSS: procRSS kB */
sscanf (buf, "%*s %d", &procRSS);
} else if (!strncmp (buf, VmDataLine, VmDataLineLen)) {
/* VmData: procData kB */
sscanf (buf, "%*s %d", &procData);
} else if (!strncmp (buf, VmStkLine, VmStkLineLen)) {
/* VmStk: procStk kB */
sscanf (buf, "%*s %d", &procStk);
} else if (!strncmp (buf, VmExeLine, VmExeLineLen)) {
/* VmExe: procExe kB */
sscanf (buf, "%*s %d", &procExe);
}
}
fclose (StatusFile);
if (procSize > threshold) {
// Figure out if it's sharing any memory...
unique = 1;
LL_Rewind (procs);
do {
p = LL_Get (procs);
if (p) {
if (0 == strcmp (p->name, procName)) {
unique = 0;
p->number++;
p->totl += procData + procStk + procExe;
}
}
} while (LL_Next (procs) == 0);
while ((procdir = readdir (proc))) {
if (!index ("1234567890", procdir->d_name[0])) {
continue;
}
sprintf (buf, "/proc/%s/status", procdir->d_name);
if ((StatusFile = fopen (buf, "r")) == NULL) {
// Not a serious error; process has finished before we could
// examine it:
//fprintf ( stderr , "mem_top_screen: cannot open %s for reading" ,
// buf ) ;
//perror ( "" ) ;
continue;
}
procRSS = procSize = procData = procStk = procExe = 0;
while (fgets (buf, sizeof (buf), StatusFile)) {
if (!strncmp (buf, NameLine, NameLineLen)) {
/* Name: procName */
sscanf (buf, "%*s %s", procName);
} else if (!strncmp (buf, VmSizeLine, VmSizeLineLen)) {
/* VmSize: procSize kB */
sscanf (buf, "%*s %d", &procSize);
} else if (!strncmp (buf, VmRSSLine, VmRSSLineLen)) {
/* VmRSS: procRSS kB */
sscanf (buf, "%*s %d", &procRSS);
} else if (!strncmp (buf, VmDataLine, VmDataLineLen)) {
/* VmData: procData kB */
sscanf (buf, "%*s %d", &procData);
} else if (!strncmp (buf, VmStkLine, VmStkLineLen)) {
/* VmStk: procStk kB */
sscanf (buf, "%*s %d", &procStk);
} else if (!strncmp (buf, VmExeLine, VmExeLineLen)) {
/* VmExe: procExe kB */
sscanf (buf, "%*s %d", &procExe);
}
}
fclose (StatusFile);
if (procSize > threshold) {
// Figure out if it's sharing any memory...
unique = 1;
LL_Rewind (procs);
do {
p = LL_Get (procs);
if (p) {
if (0 == strcmp (p->name, procName)) {
unique = 0;
p->number++;
p->totl += procData + procStk + procExe;
}
}
} while (LL_Next (procs) == 0);
// If this is the first one by this name...
if (unique) {
p = malloc (sizeof (proc_mem_info));
if (!p) {
fprintf (stderr, "mem_top_screen: Error allocating process entry\n");
goto end; // Ack! I hate goto's!
}
strcpy (p->name, procName);
p->size = procSize;
p->totl = procData + procStk + procExe;
p->number = 1;
// TODO: Check for errors here?
LL_Push (procs, (void *) p);
}
}
// If this is the first one by this name...
if (unique) {
p = malloc (sizeof (proc_mem_info));
if (!p) {
fprintf (stderr, "mem_top_screen: Error allocating process entry\n");
goto end; // Ack! I hate goto's!
}
strcpy (p->name, procName);
p->size = procSize;
p->totl = procData + procStk + procExe;
p->number = 1;
// TODO: Check for errors here?
LL_Push (procs, (void *) p);
}
}
}
closedir (proc);
}
closedir (proc);
// Now, print some info...
LL_Rewind (procs);
LL_Sort (procs, sort_procs);
LL_Rewind (procs);
for (i = 1; i <= 5; i++) {
p = LL_Get (procs);
if (p) {
//printf("Mem hog: %s: %ik\n", p->name, p->size);
if (p->number > 1)
sprintf (buffer, "widget_set S %i 1 %i {%i%6ik %s(%i)}\n", i, i, i, p->totl, p->name, p->number);
else
sprintf (buffer, "widget_set S %i 1 %i {%i%6ik %s}\n", i, i, i, p->totl, p->name);
if (display)
sock_send_string (sock, buffer);
} else {
//printf("Mem hog: none?\n");
sprintf (buffer, "widget_set S %i 1 %i {}\n", i, i);
if (display)
sock_send_string (sock, buffer);
}
// Now, print some info...
LL_Rewind (procs);
LL_Sort (procs, sort_procs);
LL_Rewind (procs);
for (i = 1; i <= 5; i++) {
p = LL_Get (procs);
if (p) {
//printf("Mem hog: %s: %ik\n", p->name, p->size);
if (p->number > 1)
sprintf (buffer, "widget_set S %i 1 %i {%i%6ik %s(%i)}\n", i, i, i, p->totl, p->name, p->number);
else
sprintf (buffer, "widget_set S %i 1 %i {%i%6ik %s}\n", i, i, i, p->totl, p->name);
if (display)
sock_send_string (sock, buffer);
} else {
//printf("Mem hog: none?\n");
sprintf (buffer, "widget_set S %i 1 %i {}\n", i, i);
if (display)
sock_send_string (sock, buffer);
}
LL_Next (procs);
}
LL_Next (procs);
}
end: // Ack! I hate using labels!
// Now clean it all up...
LL_Rewind (procs);
do {
p = (proc_mem_info *) LL_Get (procs);
if (p) {
//printf("Proc: %6ik %s\n", p->size, p->name);
free (p);
}
} while (LL_Next (procs) == 0);
LL_Destroy (procs);
end: // Ack! I hate using labels!
// Now clean it all up...
LL_Rewind (procs);
do {
p = (proc_mem_info *) LL_Get (procs);
if (p) {
//printf("Proc: %6ik %s\n", p->size, p->name);
free (p);
}
} while (LL_Next (procs) == 0);
LL_Destroy (procs);
return 0;
return 0;
} // End mem_top_screen()
} // End mem_top_screen()
+200 -200
View File
@@ -42,211 +42,211 @@ int getentry (const char *tag, const char *bufptr);
int
mode_init (mode * sequence)
{
int i;
struct utsname Uname;
int i;
struct utsname Uname;
// Grab the host name
if (0 > uname (&Uname)) {
perror ("Can't get hostname");
strcpy (host, "host");
} else {
strncpy (host, Uname.nodename, 15);
host[16] = 0;
if (index (host, '.')) // truncate at the first dot
*(index (host, '.')) = '\0';
for (i = 0; i < 16; i++)
if (host[i] == '\n')
host[i] = 0;
}
// Grab the host name
if (0 > uname (&Uname)) {
perror ("Can't get hostname");
strcpy (host, "host");
} else {
strncpy (host, Uname.nodename, 15);
host[16] = 0;
if (index (host, '.')) // truncate at the first dot
*(index (host, '.')) = '\0';
for (i = 0; i < 16; i++)
if (host[i] == '\n')
host[i] = 0;
}
// Init all the modescreens we need
for (i = 0; sequence[i].which > 1; i++) {
switch (sequence[i].which) {
case 'g':
case 'G': // cpu_graph_screen
cpu_init ();
break;
case 'c':
case 'C': // cpu_screen
cpu_init ();
break;
case 'o':
case 'O': // clock_screen
chrono_init ();
break;
case 'k':
case 'K': // big_clock_screen
chrono_init ();
break;
case 'm':
case 'M': // mem_screen
mem_init ();
break;
case 's':
case 'S': // mem_info_screen
mem_init ();
break;
case 'u':
case 'U': // uptime_screen
chrono_init ();
break;
case 't':
case 'T': // time_screen
chrono_init ();
break;
case 'd':
case 'D': // disk_screen
disk_init ();
break;
case 'x':
case 'X': // xload_screen
load_init ();
break;
case 'b':
case 'B': // battery_screen
batt_init ();
break;
case 'a':
case 'A': // credit_screen
break;
case 'p':
case 'P': // cpu_smp_screen
cpu_smp_init ();
break;
default:
break;
}
}
// Init all the modescreens we need
for (i = 0; sequence[i].which > 1; i++) {
switch (sequence[i].which) {
case 'g':
case 'G': // cpu_graph_screen
cpu_init ();
break;
case 'c':
case 'C': // cpu_screen
cpu_init ();
break;
case 'o':
case 'O': // clock_screen
chrono_init ();
break;
case 'k':
case 'K': // big_clock_screen
chrono_init ();
break;
case 'm':
case 'M': // mem_screen
mem_init ();
break;
case 's':
case 'S': // mem_info_screen
mem_init ();
break;
case 'u':
case 'U': // uptime_screen
chrono_init ();
break;
case 't':
case 'T': // time_screen
chrono_init ();
break;
case 'd':
case 'D': // disk_screen
disk_init ();
break;
case 'x':
case 'X': // xload_screen
load_init ();
break;
case 'b':
case 'B': // battery_screen
batt_init ();
break;
case 'a':
case 'A': // credit_screen
break;
case 'p':
case 'P': // cpu_smp_screen
cpu_smp_init ();
break;
default:
break;
}
}
return 0;
return 0;
}
void
mode_close ()
{
batt_close ();
chrono_close ();
cpu_close ();
disk_close ();
load_close ();
mem_close ();
cpu_smp_close ();
batt_close ();
chrono_close ();
cpu_close ();
disk_close ();
load_close ();
mem_close ();
cpu_smp_close ();
}
int
update_screen (mode * m, int display)
{
static int status = -1;
int old_status = status;
static int status = -1;
int old_status = status;
if (m) {
switch (m->which) {
case 'g':
case 'G':
status = cpu_graph_screen (m->timer, display);
break;
case 'c':
case 'C':
status = cpu_screen (m->timer, display);
break;
case 'o':
case 'O':
status = clock_screen (m->timer, display);
break;
case 'k':
case 'K':
status = big_clock_screen (m->timer, display);
break;
case 'm':
case 'M':
status = mem_screen (m->timer, display);
break;
case 's':
case 'S':
status = mem_top_screen (m->timer, display);
break;
case 'u':
case 'U':
status = uptime_screen (m->timer, display);
break;
case 't':
case 'T':
status = time_screen (m->timer, display);
break;
case 'd':
case 'D':
status = disk_screen (m->timer, display);
break;
case 'x':
case 'X':
status = xload_screen (m->timer, display);
break;
case 'b':
case 'B':
status = battery_screen (m->timer, display);
break;
case 'a':
case 'A':
status = credit_screen (m->timer, display);
break;
case 'p':
case 'P':
status = cpu_smp_screen (m->timer, display);
break;
default:
break;
}
/* Debugging tool...
if(display)
{
printf("Displayed Mode %c\n", m->which);
}
*/
}
if (m) {
switch (m->which) {
case 'g':
case 'G':
status = cpu_graph_screen (m->timer, display);
break;
case 'c':
case 'C':
status = cpu_screen (m->timer, display);
break;
case 'o':
case 'O':
status = clock_screen (m->timer, display);
break;
case 'k':
case 'K':
status = big_clock_screen (m->timer, display);
break;
case 'm':
case 'M':
status = mem_screen (m->timer, display);
break;
case 's':
case 'S':
status = mem_top_screen (m->timer, display);
break;
case 'u':
case 'U':
status = uptime_screen (m->timer, display);
break;
case 't':
case 'T':
status = time_screen (m->timer, display);
break;
case 'd':
case 'D':
status = disk_screen (m->timer, display);
break;
case 'x':
case 'X':
status = xload_screen (m->timer, display);
break;
case 'b':
case 'B':
status = battery_screen (m->timer, display);
break;
case 'a':
case 'A':
status = credit_screen (m->timer, display);
break;
case 'p':
case 'P':
status = cpu_smp_screen (m->timer, display);
break;
default:
break;
}
/* Debugging tool...
if(display)
{
printf("Displayed Mode %c\n", m->which);
}
*/
}
if (status != old_status) {
if (status == BACKLIGHT_OFF) {
sock_send_string (sock, "backlight off\n");
}
if (status == BACKLIGHT_ON) {
sock_send_string (sock, "backlight on\n");
}
if (status == BLINK_ON) {
sock_send_string (sock, "backlight blink\n");
}
}
return status;
if (status != old_status) {
if (status == BACKLIGHT_OFF) {
sock_send_string (sock, "backlight off\n");
}
if (status == BACKLIGHT_ON) {
sock_send_string (sock, "backlight on\n");
}
if (status == BLINK_ON) {
sock_send_string (sock, "backlight blink\n");
}
}
return status;
}
void
reread (int f, char *errmsg)
{
if (lseek (f, 0L, 0) == 0 && read (f, buffer, sizeof (buffer) - 1) > 0)
return;
perror (errmsg);
exit (1);
if (lseek (f, 0L, 0) == 0 && read (f, buffer, sizeof (buffer) - 1) > 0)
return;
perror (errmsg);
exit (1);
}
int
getentry (const char *tag, const char *bufptr)
{
char *tail;
int retval, len = strlen (tag);
char *tail;
int retval, len = strlen (tag);
while (bufptr) {
if (*bufptr == '\n')
bufptr++;
if (!strncmp (tag, bufptr, len)) {
retval = strtol (bufptr + len, &tail, 10);
if (tail == bufptr + len)
return -1;
else
return retval;
}
bufptr = strchr (bufptr, '\n');
}
return -1;
while (bufptr) {
if (*bufptr == '\n')
bufptr++;
if (!strncmp (tag, bufptr, len)) {
retval = strtol (bufptr + len, &tail, 10);
if (tail == bufptr + len)
return -1;
else
return retval;
}
bufptr = strchr (bufptr, '\n');
}
return -1;
}
///////////////////////////////////////////////////////////////////////////
@@ -263,28 +263,28 @@ char tmp[1024];
int
credit_screen (int rep, int display)
{
static int first = 1;
static int first = 1;
if (first) {
first = 0;
if (first) {
first = 0;
sock_send_string (sock, "screen_add A\n");
sock_send_string (sock, "screen_set A -name {Credits for LCDproc}\n");
sock_send_string (sock, "widget_add A title title\n");
sprintf (tmp, "widget_set A title {LCDPROC %s}\n", version);
sock_send_string (sock, tmp);
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add A one string\n");
sock_send_string (sock, "widget_add A two string\n");
sock_send_string (sock, "widget_add A three string\n");
sock_send_string (sock, "widget_set A one 1 2 { for Linux }\n");
sock_send_string (sock, "widget_set A two 1 3 { by William Ferrell}\n");
sock_send_string (sock, "widget_set A three 1 4 { and Scott Scriven}\n");
} else {
sock_send_string (sock, "widget_add A text scroller\n");
sock_send_string (sock, "widget_set A text 1 2 20 2 v 8 { for Linux by William Ferrell and Scott Scriven}\n");
}
}
sock_send_string (sock, "screen_add A\n");
sock_send_string (sock, "screen_set A -name {Credits for LCDproc}\n");
sock_send_string (sock, "widget_add A title title\n");
sprintf (tmp, "widget_set A title {LCDPROC %s}\n", version);
sock_send_string (sock, tmp);
if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add A one string\n");
sock_send_string (sock, "widget_add A two string\n");
sock_send_string (sock, "widget_add A three string\n");
sock_send_string (sock, "widget_set A one 1 2 { for Linux }\n");
sock_send_string (sock, "widget_set A two 1 3 { by William Ferrell}\n");
sock_send_string (sock, "widget_set A three 1 4 { and Scott Scriven}\n");
} else {
sock_send_string (sock, "widget_add A text scroller\n");
sock_send_string (sock, "widget_set A text 1 2 20 2 v 8 { for Linux by William Ferrell and Scott Scriven}\n");
}
}
return 0;
} // End credit_screen()
return 0;
} // End credit_screen()