small refactoring of lcdproc client: get rid of global variables tmp & buffer

This commit is contained in:
marschap
2006-10-15 20:48:13 +00:00
parent 7811b491db
commit 8fb54a71ff
20 changed files with 240 additions and 339 deletions
+1
View File
@@ -8,6 +8,7 @@ Key:
v.0.5dev (ongoing development) v.0.5dev (ongoing development)
* fix switching on/off the Load screen in lcdproc client using the menu * fix switching on/off the Load screen in lcdproc client using the menu
* refactor adv_bignum: support height > 4, loadable chars with offset * refactor adv_bignum: support height > 4, loadable chars with offset
* ged rid of global variables buffer & tmp in lcdproc client
v.0.5.1 v.0.5.1
+ config file support in lcdproc client (Andrew Foss) + config file support in lcdproc client (Andrew Foss)
+33 -43
View File
@@ -71,7 +71,7 @@ battery_status(int status)
// +--------------------+ // +--------------------+
// //
int int
battery_screen (int rep, int display, int *flags_ptr) battery_screen(int rep, int display, int *flags_ptr)
{ {
int acstat = 0, battstat = 0, percent = 0; int acstat = 0, battstat = 0, percent = 0;
int gauge_wid = lcd_wid - 2; int gauge_wid = lcd_wid - 2;
@@ -79,23 +79,20 @@ battery_screen (int rep, int display, int *flags_ptr)
if ((*flags_ptr & INITIALIZED) == 0) { if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED; *flags_ptr |= INITIALIZED;
sock_send_string (sock, "screen_add B\n"); sock_send_string(sock, "screen_add B\n");
sprintf (buffer, "screen_set B -name {APM stats: %s}\n", get_hostname()); sock_printf(sock, "screen_set B -name {APM stats: %s}\n", get_hostname());
sock_send_string (sock, buffer); sock_send_string(sock, "widget_add B title title\n");
sock_send_string (sock, "widget_add B title title\n"); sock_printf(sock, "widget_set B title {LCDPROC %s}\n", version);
sprintf (buffer, "widget_set B title {LCDPROC %s}\n", version); sock_send_string(sock, "widget_add B one string\n");
sock_send_string (sock, buffer);
sock_send_string (sock, "widget_add B one string\n");
if (lcd_hgt >= 4) { if (lcd_hgt >= 4) {
sock_send_string (sock, "widget_add B two string\n"); 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 three string\n");
sock_send_string (sock, "widget_add B gauge hbar\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 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 two 1 3 {Batt: Unknown}\n");
sprintf(buffer, "widget_set B three 1 4 {E%*sF}\n", gauge_wid, ""); sock_printf(sock, "widget_set B three 1 4 {E%*sF}\n", gauge_wid, "");
sock_send_string (sock, buffer); sock_send_string(sock, "widget_set B gauge 2 4 0\n");
sock_send_string (sock, "widget_set B gauge 2 4 0\n");
} }
} }
// Only run once every 16 frames... // Only run once every 16 frames...
@@ -103,36 +100,29 @@ battery_screen (int rep, int display, int *flags_ptr)
machine_get_battstat(&acstat, &battstat, &percent); machine_get_battstat(&acstat, &battstat, &percent);
if (percent >= 0) if (display) {
sprintf(tmp, "%d%%", percent); char tmp[20];
else
sprintf(tmp, "??%%");
sprintf(buffer, "widget_set B title {%s: %s: %s}\n",
(acstat == LCDP_AC_ON && battstat == LCDP_BATT_ABSENT) ? "AC" : "Batt",
tmp, get_hostname());
if (display)
sock_send_string (sock, buffer);
if (lcd_hgt >= 4) { // 4-line version of the screen if (percent >= 0)
sprintf(buffer, "widget_set B one 1 2 {AC: %s}\n", ac_status(acstat)); sprintf(tmp, "%d%%", percent);
if (display) else
sock_send_string (sock, buffer); sprintf(tmp, "??%%");
sock_printf(sock, "widget_set B title {%s: %s: %s}\n",
(acstat == LCDP_AC_ON && battstat == LCDP_BATT_ABSENT) ? "AC" : "Batt",
tmp, get_hostname());
sprintf(buffer, "widget_set B two 1 3 {Batt: %s}\n", battery_status(battstat)); if (lcd_hgt >= 4) { // 4-line version of the screen
if (display) sock_printf(sock, "widget_set B one 1 2 {AC: %s}\n", ac_status(acstat));
sock_send_string(sock, buffer); sock_printf(sock, "widget_set B two 1 3 {Batt: %s}\n", battery_status(battstat));
if (percent > 0)
if (percent > 0) { sock_printf(sock, "widget_set B gauge 2 4 %d\n",
sprintf(buffer, "widget_set B gauge 2 4 %d\n", (percent * gauge_wid * lcd_cellwid) / 100); (percent * gauge_wid * lcd_cellwid) / 100);
if (display) }
sock_send_string(sock, buffer); else { // two-line version of the screen
sock_printf(sock, "widget_set B one 1 2 {%sBatt: %s}\n",
(acstat == LCDP_AC_ON) ? "AC, " : "",
battery_status(battstat));
} }
}
else { // two-line version of the screen
sprintf(buffer, "widget_set B one 1 2 {%sBatt: %s}\n",
(acstat == LCDP_AC_ON) ? "AC, " : "", battery_status(battstat));
if (display)
sock_send_string(sock, buffer);
} }
return 0; return 0;
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef BATT_H #ifndef BATT_H
#define BATT_H #define BATT_H
int battery_screen (int rep, int display, int *flags_ptr); int battery_screen(int rep, int display, int *flags_ptr);
#endif #endif
+14 -11
View File
@@ -48,7 +48,7 @@ static char *tickTime(char *time, int heartbeat);
//+--------------------+ //+--------------------+
// //
int int
time_screen (int rep, int display, int *flags_ptr) time_screen(int rep, int display, int *flags_ptr)
{ {
char now[40]; char now[40];
char today[40]; char today[40];
@@ -99,6 +99,7 @@ time_screen (int rep, int display, int *flags_ptr)
if (lcd_hgt >= 4) { if (lcd_hgt >= 4) {
machine_get_uptime(&uptime, &idle); machine_get_uptime(&uptime, &idle);
char tmp[40]; // should be large enough
// display the uptime... // display the uptime...
days = (int) uptime / 86400; days = (int) uptime / 86400;
@@ -148,7 +149,7 @@ time_screen (int rep, int display, int *flags_ptr)
//+--------------------+ //+--------------------+
// //
int int
clock_screen (int rep, int display, int *flags_ptr) clock_screen(int rep, int display, int *flags_ptr)
{ {
char now[40]; char now[40];
char today[40]; char today[40];
@@ -160,6 +161,8 @@ clock_screen (int rep, int display, int *flags_ptr)
struct tm *rtime; struct tm *rtime;
if ((*flags_ptr & INITIALIZED) == 0) { if ((*flags_ptr & INITIALIZED) == 0) {
char tmp[257]; // should be large enough for host name
*flags_ptr |= INITIALIZED; *flags_ptr |= INITIALIZED;
/* get config values */ /* get config values */
@@ -176,7 +179,7 @@ clock_screen (int rep, int display, int *flags_ptr)
sock_printf(sock, "widget_set O title {DATE & TIME}\n"); sock_printf(sock, "widget_set O title {DATE & TIME}\n");
sprintf (tmp, "%s", get_hostname()); sprintf(tmp, "%s", get_hostname());
xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1; xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
sock_printf(sock, "widget_set O one %i 2 {%s}\n", xoffs, tmp); sock_printf(sock, "widget_set O one %i 2 {%s}\n", xoffs, tmp);
} else { } else {
@@ -187,15 +190,14 @@ clock_screen (int rep, int display, int *flags_ptr)
// toggle colon display // toggle colon display
heartbeat ^= 1; heartbeat ^= 1;
time (&thetime); time(&thetime);
rtime = localtime (&thetime); rtime = localtime(&thetime);
if (strftime(today, sizeof(today), dateFormat, rtime) == 0) if (strftime(today, sizeof(today), dateFormat, rtime) == 0)
*today = '\0'; *today = '\0';
if (strftime(now, sizeof(now), timeFormat, rtime) == 0) if (strftime(now, sizeof(now), timeFormat, rtime) == 0)
*now = '\0'; *now = '\0';
tickTime(now, heartbeat); tickTime(now, heartbeat);
fprintf(stderr, "now: %s\ttoday: %s\n", now, today);
if (lcd_hgt >= 4) { // 4-line version of the screen if (lcd_hgt >= 4) { // 4-line version of the screen
xoffs = (lcd_wid > strlen(today)) ? ((lcd_wid - strlen(today)) / 2) + 1 : 1; xoffs = (lcd_wid > strlen(today)) ? ((lcd_wid - strlen(today)) / 2) + 1 : 1;
@@ -227,12 +229,13 @@ fprintf(stderr, "now: %s\ttoday: %s\n", now, today);
//+--------------------+ //+--------------------+
// //
int int
uptime_screen (int rep, int display, int *flags_ptr) uptime_screen(int rep, int display, int *flags_ptr)
{ {
int xoffs; int xoffs;
int days, hour, min, sec; int days, hour, min, sec;
double uptime, idle; double uptime, idle;
static int heartbeat = 0; static int heartbeat = 0;
char tmp[257]; // should be large enough for host name
if ((*flags_ptr & INITIALIZED) == 0) { if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED; *flags_ptr |= INITIALIZED;
@@ -298,7 +301,7 @@ uptime_screen (int rep, int display, int *flags_ptr)
// +--------------------+ // +--------------------+
// //
int int
big_clock_screen (int rep, int display, int *flags_ptr) big_clock_screen(int rep, int display, int *flags_ptr)
{ {
time_t thetime; time_t thetime;
struct tm *rtime; struct tm *rtime;
@@ -374,7 +377,7 @@ big_clock_screen (int rep, int display, int *flags_ptr)
//+--------------------+ //+--------------------+
// //
int int
mini_clock_screen (int rep, int display, int *flags_ptr) mini_clock_screen(int rep, int display, int *flags_ptr)
{ {
char now[40]; char now[40];
time_t thetime; time_t thetime;
@@ -397,8 +400,8 @@ mini_clock_screen (int rep, int display, int *flags_ptr)
sock_send_string(sock, "widget_add N one string\n"); sock_send_string(sock, "widget_add N one string\n");
} }
time (&thetime); time(&thetime);
rtime = localtime (&thetime); rtime = localtime(&thetime);
if (strftime(now, sizeof(now), timeFormat, rtime) == 0) if (strftime(now, sizeof(now), timeFormat, rtime) == 0)
*now = '\0'; *now = '\0';
+5 -5
View File
@@ -1,10 +1,10 @@
#ifndef CHRONO_H #ifndef CHRONO_H
#define CHRONO_H #define CHRONO_H
int clock_screen (int rep, int display, int *flags_ptr); int clock_screen(int rep, int display, int *flags_ptr);
int uptime_screen (int rep, int display, int *flags_ptr); int uptime_screen(int rep, int display, int *flags_ptr);
int time_screen (int rep, int display, int *flags_ptr); int time_screen(int rep, int display, int *flags_ptr);
int big_clock_screen (int rep, int display, int *flags_ptr); int big_clock_screen(int rep, int display, int *flags_ptr);
int mini_clock_screen (int rep, int display, int *flags_ptr); int mini_clock_screen(int rep, int display, int *flags_ptr);
#endif #endif
+31 -54
View File
@@ -40,13 +40,13 @@ cpu_screen(int rep, int display, int *flags_ptr)
int i, j, n; int i, j, n;
double value; double value;
load_type load; load_type load;
char tmp[25]; // should be large enough
if ((*flags_ptr & INITIALIZED) == 0) { if ((*flags_ptr & INITIALIZED) == 0) {
*flags_ptr |= INITIALIZED; *flags_ptr |= INITIALIZED;
sock_send_string(sock, "screen_add C\n"); sock_send_string(sock, "screen_add C\n");
sprintf(buffer, "screen_set C -name {CPU Use: %s}\n", get_hostname()); sock_printf(sock, "screen_set C -name {CPU Use: %s}\n", get_hostname());
sock_send_string(sock, buffer);
if (lcd_hgt >= 4) { if (lcd_hgt >= 4) {
gauge_wid = lcd_wid - 6; // room between 0%...100% gauge_wid = lcd_wid - 6; // room between 0%...100%
@@ -55,14 +55,11 @@ cpu_screen(int rep, int display, int *flags_ptr)
sock_send_string(sock, "widget_add C one string\n"); sock_send_string(sock, "widget_add C one string\n");
sock_send_string(sock, "widget_add C two string\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_add C three string\n");
sprintf(buffer, "widget_set C one 1 2 {%-*s%-*s}\n", sock_printf(sock, "widget_set C one 1 2 {%-*s%-*s}\n",
lcd_wid / 2, "Usr", lcd_wid / 2, "Nice"); lcd_wid / 2, "Usr", lcd_wid / 2, "Nice");
sock_send_string(sock, buffer); sock_printf(sock, "widget_set C two 1 3 {%-*s%-*s}\n",
sprintf(buffer, "widget_set C two 1 3 {%-*s%-*s}\n", lcd_wid / 2, "Sys", lcd_wid / 2, "Idle");
lcd_wid / 2, "Sys", lcd_wid / 2, "Idle"); sock_printf(sock, "widget_set C three 1 4 {0%%%*s100%%}\n", gauge_wid, "");
sock_send_string(sock, buffer);
sprintf(buffer, "widget_set C three 1 4 {0%%%*s100%%}\n", gauge_wid, "");
sock_send_string(sock, buffer);
sock_send_string(sock, "widget_add C usr string\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 nice string\n");
sock_send_string(sock, "widget_add C idle string\n"); sock_send_string(sock, "widget_add C idle string\n");
@@ -75,15 +72,12 @@ cpu_screen(int rep, int display, int *flags_ptr)
gauge_wid = lcd_wid - 12; // room between [...] gauge_wid = lcd_wid - 12; // room between [...]
sock_send_string(sock, "widget_add C cpu string\n"); sock_send_string(sock, "widget_add C cpu string\n");
sprintf(buffer, "widget_set C cpu 1 1 {CPU [%*s]}\n", gauge_wid, ""); sock_printf(sock, "widget_set C cpu 1 1 {CPU [%*s]}\n", gauge_wid, "");
sock_send_string(sock, buffer);
sock_send_string(sock, "widget_add C cpu% string\n"); sock_send_string(sock, "widget_add C cpu% string\n");
sprintf(buffer, "widget_set C cpu%% 1 %d { 0.0%%}\n", lcd_wid - 5); sock_printf(sock, "widget_set C cpu%% 1 %d { 0.0%%}\n", lcd_wid - 5);
sock_send_string(sock, buffer);
sock_send_string(sock, "widget_add C usni string\n"); sock_send_string(sock, "widget_add C usni string\n");
sprintf(buffer, "widget_set C usni 1 2 {U%*sS%*sN%*sI%*s}\n", sock_printf(sock, "widget_set C usni 1 2 {U%*sS%*sN%*sI%*s}\n",
usni_wid, "", usni_wid, "", usni_wid, "", usni_wid, ""); usni_wid, "", usni_wid, "", usni_wid, "", usni_wid, "");
sock_send_string(sock, buffer);
sock_send_string(sock, "widget_add C usr hbar\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 sys hbar\n");
sock_send_string(sock, "widget_add C nice hbar\n"); sock_send_string(sock, "widget_add C nice hbar\n");
@@ -142,53 +136,41 @@ cpu_screen(int rep, int display, int *flags_ptr)
if (lcd_hgt >= 4) { // 4-line display if (lcd_hgt >= 4) { // 4-line display
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][4]); sprintf_percent(tmp, cpu[CPU_BUF_SIZE][4]);
sprintf(buffer, "widget_set C title {CPU %5s: %s}\n", tmp, get_hostname()); sock_printf(sock, "widget_set C title {CPU %5s: %s}\n", tmp, get_hostname());
sock_send_string(sock, buffer);
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][0]); sprintf_percent(tmp, cpu[CPU_BUF_SIZE][0]);
sprintf(buffer, "widget_set C usr %i 2 {%5s}\n", (lcd_wid / 2) - 5, tmp); sock_printf(sock, "widget_set C usr %i 2 {%5s}\n", (lcd_wid / 2) - 5, tmp);
sock_send_string(sock, buffer);
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][1]); sprintf_percent(tmp, cpu[CPU_BUF_SIZE][1]);
sprintf(buffer, "widget_set C sys %i 3 {%5s}\n", (lcd_wid / 2) - 5, tmp); sock_printf(sock, "widget_set C sys %i 3 {%5s}\n", (lcd_wid / 2) - 5, tmp);
sock_send_string(sock, buffer);
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][2]); sprintf_percent(tmp, cpu[CPU_BUF_SIZE][2]);
sprintf(buffer, "widget_set C nice %i 2 {%5s}\n", lcd_wid - 4, tmp); sock_printf(sock, "widget_set C nice %i 2 {%5s}\n", lcd_wid - 4, tmp);
sock_send_string(sock, buffer);
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][3]); sprintf_percent(tmp, cpu[CPU_BUF_SIZE][3]);
sprintf(buffer, "widget_set C idle %i 3 {%5s}\n", lcd_wid - 4, tmp); sock_printf(sock, "widget_set C idle %i 3 {%5s}\n", lcd_wid - 4, tmp);
sock_send_string(sock, buffer);
n = (int) ((cpu[CPU_BUF_SIZE][4] * lcd_cellwid * gauge_wid) / 100.0); n = (int) ((cpu[CPU_BUF_SIZE][4] * lcd_cellwid * gauge_wid) / 100.0);
sprintf(buffer, "widget_set C bar 3 4 %d\n", n); sock_printf(sock, "widget_set C bar 3 4 %d\n", n);
sock_send_string(sock, buffer);
} }
else { // 2-line display else { // 2-line display
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][4]); sprintf_percent(tmp, cpu[CPU_BUF_SIZE][4]);
sprintf(buffer, "widget_set C cpu%% %d 1 {%5s}\n", lcd_wid - 5, tmp); sock_printf(sock, "widget_set C cpu%% %d 1 {%5s}\n", lcd_wid - 5, tmp);
sock_send_string(sock, buffer);
n = (int) ((cpu[CPU_BUF_SIZE][4] * lcd_cellwid * gauge_wid) / 100.0); n = (int) ((cpu[CPU_BUF_SIZE][4] * lcd_cellwid * gauge_wid) / 100.0);
sprintf(buffer, "widget_set C total 6 1 %d\n", n); sock_printf(sock, "widget_set C total 6 1 %d\n", n);
sock_send_string(sock, buffer);
n = (int) ((cpu[CPU_BUF_SIZE][0] * lcd_cellwid * usni_wid) / 100.0); n = (int) ((cpu[CPU_BUF_SIZE][0] * lcd_cellwid * usni_wid) / 100.0);
sprintf(buffer, "widget_set C usr %d 2 %d\n", 0 * (usni_wid + 1) + 2, n); sock_printf(sock, "widget_set C usr %d 2 %d\n", 0 * (usni_wid + 1) + 2, n);
sock_send_string(sock, buffer);
n = (int) ((cpu[CPU_BUF_SIZE][1] * lcd_cellwid * usni_wid) / 100.0); n = (int) ((cpu[CPU_BUF_SIZE][1] * lcd_cellwid * usni_wid) / 100.0);
sprintf(buffer, "widget_set C sys %d 2 %d\n", 1 * (usni_wid + 1) + 2, n); sock_printf(sock, "widget_set C sys %d 2 %d\n", 1 * (usni_wid + 1) + 2, n);
sock_send_string(sock, buffer);
n = (int) ((cpu[CPU_BUF_SIZE][2] * lcd_cellwid * usni_wid) / 100.0); n = (int) ((cpu[CPU_BUF_SIZE][2] * lcd_cellwid * usni_wid) / 100.0);
sprintf(buffer, "widget_set C nice %d 2 %d\n", 2 * (usni_wid + 1) + 2, n); sock_printf(sock, "widget_set C nice %d 2 %d\n", 2 * (usni_wid + 1) + 2, n);
sock_send_string(sock, buffer);
n = (int) ((cpu[CPU_BUF_SIZE][3] * lcd_cellwid * usni_wid) / 100.0); n = (int) ((cpu[CPU_BUF_SIZE][3] * lcd_cellwid * usni_wid) / 100.0);
sprintf(buffer, "widget_set C idle %d 2 %d\n", 3 * (usni_wid + 1) + 2, n); sock_printf(sock, "widget_set C idle %d 2 %d\n", 3 * (usni_wid + 1) + 2, n);
sock_send_string(sock, buffer);
} }
return(0); return(0);
@@ -225,23 +207,20 @@ cpu_graph_screen(int rep, int display, int *flags_ptr)
gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt; gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt;
sock_send_string(sock, "screen_add G\n"); sock_send_string(sock, "screen_add G\n");
sprintf(buffer, "screen_set G -name {CPU Graph: %s}\n", get_hostname()); sock_printf(sock, "screen_set G -name {CPU Graph: %s}\n", get_hostname());
sock_send_string(sock, buffer);
if (lcd_hgt >= 4) { if (lcd_hgt >= 4) {
sock_send_string(sock, "widget_add G title title\n"); sock_send_string(sock, "widget_add G title title\n");
sprintf(buffer, "widget_set G title {CPU: %s}\n", get_hostname()); sock_printf(sock, "widget_set G title {CPU: %s}\n", get_hostname());
} }
else { else {
sock_send_string(sock, "widget_add G title string\n"); sock_send_string(sock, "widget_add G title string\n");
sprintf(buffer, "widget_set G title 1 1 {CPU: %s}\n", get_hostname()); sock_printf(sock, "widget_set G title 1 1 {CPU: %s}\n", get_hostname());
} }
sock_send_string(sock, buffer);
for (i = 1; i <= lcd_wid; i++) { for (i = 1; i <= lcd_wid; i++) {
sprintf(buffer, "widget_add G bar%d vbar\n", i); sock_printf(sock, "widget_add G bar%d vbar\n", i);
sock_send_string(sock, buffer); sock_printf(sock, "widget_set G bar%d %d %d 0\n", i, i, lcd_hgt);
sprintf(buffer, "widget_set G bar%d %d %d 0\n", i, i, lcd_hgt);
sock_send_string(sock, buffer);
cpu_past[i-1] = 0; cpu_past[i-1] = 0;
}; };
@@ -274,17 +253,15 @@ cpu_graph_screen(int rep, int display, int *flags_ptr)
cpu_past[i] = cpu_past[i + 1]; cpu_past[i] = cpu_past[i + 1];
if (display) { if (display) {
sprintf(buffer, "widget_set G bar%d %d %d %d\n", sock_printf(sock, "widget_set G bar%d %d %d %d\n",
i + 1, i + 1, lcd_hgt, cpu_past[i]); i + 1, i + 1, lcd_hgt, cpu_past[i]);
sock_send_string(sock, buffer);
} }
} }
// Save the newest entry and display it // Save the newest entry and display it
cpu_past[lcd_wid - 1] = n; cpu_past[lcd_wid - 1] = n;
if (display) { if (display) {
sprintf(buffer, "widget_set G bar%d %d %d %d\n", lcd_wid, lcd_wid, lcd_hgt, n); sock_printf(sock, "widget_set G bar%d %d %d %d\n", lcd_wid, lcd_wid, lcd_hgt, n);
sock_send_string(sock, buffer);
} }
return(0); return(0);
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef CPU_H #ifndef CPU_H
#define CPU_H #define CPU_H
int cpu_screen (int rep, int display, int *flags_ptr); int cpu_screen(int rep, int display, int *flags_ptr);
int cpu_graph_screen (int rep, int display, int *flags_ptr); int cpu_graph_screen(int rep, int display, int *flags_ptr);
#endif #endif
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef CPU_SMP_H #ifndef CPU_SMP_H
#define CPU_SMP_H #define CPU_SMP_H
int cpu_smp_screen (int rep, int display, int *flags_ptr); int cpu_smp_screen(int rep, int display, int *flags_ptr);
#endif #endif
+31 -43
View File
@@ -32,7 +32,7 @@
// //
// TODO: Disk screen! Requires virtual pages in the server, though... // TODO: Disk screen! Requires virtual pages in the server, though...
int int
disk_screen (int rep, int display, int *flags_ptr) disk_screen(int rep, int display, int *flags_ptr)
{ {
static mounts_type mnt[256]; static mounts_type mnt[256];
static int count = 0; static int count = 0;
@@ -57,19 +57,16 @@ disk_screen (int rep, int display, int *flags_ptr)
dev_wid = (lcd_wid >= 20) ? (lcd_wid - 8) / 2 : (lcd_wid / 2) - 1; dev_wid = (lcd_wid >= 20) ? (lcd_wid - 8) / 2 : (lcd_wid / 2) - 1;
gauge_wid = (lcd_wid >= 20) ? (lcd_wid - dev_wid - 10) : (lcd_wid - dev_wid - 3); gauge_wid = (lcd_wid >= 20) ? (lcd_wid - dev_wid - 10) : (lcd_wid - dev_wid - 3);
sock_send_string (sock, "screen_add D\n"); sock_send_string(sock, "screen_add D\n");
sprintf (buffer, "screen_set D -name {Disk Use: %s}\n", get_hostname()); sock_printf(sock, "screen_set D -name {Disk Use: %s}\n", get_hostname());
sock_send_string (sock, buffer); sock_send_string(sock, "widget_add D title title\n");
sock_send_string (sock, "widget_add D title title\n"); sock_printf(sock, "widget_set D title {DISKS: %s}\n", get_hostname());
sprintf (buffer, "widget_set D title {DISKS: %s}\n", get_hostname()); sock_send_string(sock, "widget_add D f frame\n");
sock_send_string (sock, buffer); sock_printf(sock, "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, "widget_add D f frame\n"); sock_send_string(sock, "widget_add D err1 string\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, "widget_add D err2 string\n");
sock_send_string (sock, buffer); sock_send_string(sock, "widget_set D err1 5 2 { Reading }\n");
sock_send_string (sock, "widget_add D err1 string\n"); sock_send_string(sock, "widget_set D err2 5 3 {Filesystems}\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". // Grab disk stats on first display, and fill "table".
// Get rid of old, unmounted filesystems... // Get rid of old, unmounted filesystems...
@@ -78,68 +75,59 @@ disk_screen (int rep, int display, int *flags_ptr)
// Fill the display structure... // Fill the display structure...
if (count) { if (count) {
sock_send_string (sock, "widget_set D err1 30 5 .\n"); sock_send_string(sock, "widget_set D err1 30 5 .\n");
sock_send_string (sock, "widget_set D err2 30 5 .\n"); sock_send_string(sock, "widget_set D err2 30 5 .\n");
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (strlen(mnt[i].mpoint) > dev_wid) if (strlen(mnt[i].mpoint) > dev_wid)
sprintf (table[i].dev, "-%s", (mnt[i].mpoint) + (strlen(mnt[i].mpoint) - (dev_wid - 1))); sprintf(table[i].dev, "-%s", (mnt[i].mpoint) + (strlen(mnt[i].mpoint) - (dev_wid - 1)));
else else
sprintf (table[i].dev, "%s", mnt[i].mpoint); sprintf(table[i].dev, "%s", mnt[i].mpoint);
table[i].full = (huge) (lcd_cellwid * gauge_wid) table[i].full = (huge) (lcd_cellwid * gauge_wid)
* (huge) (mnt[i].blocks - mnt[i].bfree) * (huge) (mnt[i].blocks - mnt[i].bfree)
/ (huge) mnt[i].blocks; / (huge) mnt[i].blocks;
size = (huge) mnt[i].bsize * (huge) mnt[i].blocks; size = (huge) mnt[i].bsize * (huge) mnt[i].blocks;
memset (table[i].cap, '\0', 8); memset(table[i].cap, '\0', 8);
sprintf_memory(table[i].cap, (double) size, 1); sprintf_memory(table[i].cap, (double) size, 1);
} }
} }
else { else {
sock_send_string (sock, "widget_set D err1 1 2 {Error Retrieving}\n"); 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"); sock_send_string(sock, "widget_set D err2 1 3 {Filesystem Stats}\n");
return 0; return 0;
} }
// Display stuff... (show for two seconds, then scroll once per // Display stuff... (show for two seconds, then scroll once per
// second, then hold at the end for two seconds) // 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_printf(sock, "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++) { for (i = 0; i < count; i++) {
char tmp[lcd_wid+1]; // should be large enough
if (table[i].dev[0] == '\0') if (table[i].dev[0] == '\0')
continue; continue;
if (i >= num_disks) { // Make sure we have enough lines... if (i >= num_disks) { // Make sure we have enough lines...
sprintf (tmp, "widget_add D s%i string -in f\n", i); sock_printf(sock, "widget_add D s%i string -in f\n", i);
sock_send_string (sock, tmp); sock_printf(sock, "widget_add D h%i hbar -in f\n", i);
sprintf (tmp, "widget_add D h%i hbar -in f\n", i);
sock_send_string (sock, tmp);
} }
if (lcd_wid >= 20) { // 20+x columns if (lcd_wid >= 20) { // 20+x columns
sprintf (tmp, "%-*s %6s E%*sF", dev_wid, table[i].dev, table[i].cap, gauge_wid, ""); sprintf(tmp, "%-*s %6s E%*sF", dev_wid, table[i].dev, table[i].cap, gauge_wid, "");
sprintf (buffer, "widget_set D s%i 1 %i {%s}\n", i, i + 1, tmp); sock_printf(sock, "widget_set D s%i 1 %i {%s}\n", i, i + 1, tmp);
sock_send_string (sock, buffer); sock_printf(sock, "widget_set D h%i %i %i %i\n", i, 10 + dev_wid, i + 1, table[i].full);
sprintf (buffer, "widget_set D h%i %i %i %i\n", i, 10 + dev_wid, i + 1, table[i].full);
sock_send_string (sock, buffer);
} }
else { // < 20 columns else { // < 20 columns
sprintf (tmp, "%-*s E%*sF", dev_wid, table[i].dev, gauge_wid, ""); sprintf(tmp, "%-*s E%*sF", dev_wid, table[i].dev, gauge_wid, "");
sprintf (buffer, "widget_set D s%i 1 %i {%s}\n", i, i + 1, tmp); sock_printf(sock, "widget_set D s%i 1 %i {%s}\n", i, i + 1, tmp);
sock_send_string (sock, buffer); sock_printf(sock, "widget_set D h%i %i %i %i\n", i, 3 + dev_wid, i + 1, table[i].full);
sprintf (buffer, "widget_set D h%i %i %i %i\n", i, 3 + dev_wid, i + 1, table[i].full);
sock_send_string (sock, buffer);
} }
} }
// Now remove extra widgets... // Now remove extra widgets...
for ( ; i < num_disks; i++) { for ( ; i < num_disks; i++) {
sprintf (tmp, "widget_del D s%i\n", i); sock_printf(sock, "widget_del D s%i\n", i);
sock_send_string (sock, tmp); sock_printf(sock, "widget_del D h%i\n", i);
sprintf (tmp, "widget_del D h%i\n", i);
sock_send_string (sock, tmp);
} }
num_disks = count; num_disks = count;
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef DISK_H #ifndef DISK_H
#define DISK_H #define DISK_H
int disk_screen (int rep, int display, int *flags_ptr); int disk_screen(int rep, int display, int *flags_ptr);
#endif #endif
+8 -12
View File
@@ -53,10 +53,8 @@ eyebox_screen(char display, int init)
load_type load; load_type load;
if (init == 0) { if (init == 0) {
sprintf(buffer, "widget_add %c eyebo_cpu string\n", display); sock_printf(sock, "widget_add %c eyebo_cpu string\n", display);
sock_send_string(sock, buffer); sock_printf(sock, "widget_add %c eyebo_mem string\n", display);
sprintf(buffer, "widget_add %c eyebo_mem string\n", display);
sock_send_string(sock, buffer);
return(0); return(0);
} }
@@ -100,8 +98,8 @@ eyebox_screen(char display, int init)
* b = Level * b = Level
*/ */
sprintf(buffer, "widget_set %c eyebo_cpu 1 2 {/xB%d%d}\n", display, 2,(int)(cpu[CPU_BUF_SIZE][4]/10)); sock_printf(sock, "widget_set %c eyebo_cpu 1 2 {/xB%d%d}\n",
sock_send_string(sock, buffer); display, 2,(int)(cpu[CPU_BUF_SIZE][4]/10));
/* /*
* /xBab = Use Bas * /xBab = Use Bas
@@ -111,8 +109,7 @@ eyebox_screen(char display, int init)
value = 1.0 - (double) (mem[0].free + mem[0].buffers + mem[0].cache) value = 1.0 - (double) (mem[0].free + mem[0].buffers + mem[0].cache)
/ (double) mem[0].total; / (double) mem[0].total;
sprintf(buffer, "widget_set %c eyebo_mem 1 3 {/xB%d%d}\n", display, 1, (int) (value * 10)) ; sock_printf(sock, "widget_set %c eyebo_mem 1 3 {/xB%d%d}\n", display, 1, (int) (value * 10)) ;
sock_send_string(sock, buffer);
return 0; return 0;
} // End mem_screen() } // End mem_screen()
@@ -132,9 +129,8 @@ void eyebox_clear(void){
sock_send_string(sock, "widget_set OFF text 1 2 {Reseting Leds...}\n"); sock_send_string(sock, "widget_set OFF text 1 2 {Reseting Leds...}\n");
sock_send_string(sock, "widget_set OFF about 5 4 {EyeBO by NeZetiC}\n"); sock_send_string(sock, "widget_set OFF about 5 4 {EyeBO by NeZetiC}\n");
sprintf(buffer, "widget_set OFF cpu 1 2 {/xB%d%d}\n", 2, 0); sock_printf(sock, "widget_set OFF cpu 1 2 {/xB%d%d}\n", 2, 0);
sock_send_string(sock, buffer); sock_printf(sock, "widget_set OFF mem 1 3 {/xB%d%d}\n", 1, 0);
sprintf(buffer, "widget_set OFF mem 1 3 {/xB%d%d}\n", 1, 0);
sock_send_string(sock, buffer);
usleep(2000000); /* Wait last order execution */ usleep(2000000); /* Wait last order execution */
} }
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef CTRL_H #ifndef CTRL_H
#define CTRL_H #define CTRL_H
int eyebox_screen (char display, int init); int eyebox_screen(char display, int init);
void eyebox_clear(void); void eyebox_clear(void);
#endif #endif
+7 -7
View File
@@ -16,7 +16,7 @@
#define MAX_INTERFACES 3 /* max number of interfaces in multi-interface mode */ #define MAX_INTERFACES 3 /* max number of interfaces in multi-interface mode */
int iface_screen (int rep, int display, int *flags_ptr); int iface_screen(int rep, int display, int *flags_ptr);
IfaceInfo iface[MAX_INTERFACES]; /* interface info */ IfaceInfo iface[MAX_INTERFACES]; /* interface info */
/************************/ /************************/
@@ -24,28 +24,28 @@ IfaceInfo iface[MAX_INTERFACES]; /* interface info */
/************************/ /************************/
/* read interface stats from /proc/net/dev */ /* read interface stats from /proc/net/dev */
int get_iface_stats (IfaceInfo *interface); int get_iface_stats(IfaceInfo *interface);
/* send initial commands to server to add the speed screen */ /* send initial commands to server to add the speed screen */
void initialize_speed_screen (void); void initialize_speed_screen(void);
/* send initial commands to server to add the transfer screen */ /* send initial commands to server to add the transfer screen */
void initialize_transfer_screen(void); void initialize_transfer_screen(void);
/* format the time in ASCII */ /* format the time in ASCII */
void get_time_string (char *buff, time_t last_online); void get_time_string(char *buff, time_t last_online);
/* format value, scaling value and adding proper suffixes */ /* format value, scaling value and adding proper suffixes */
void format_value (char *buff, double value, char *unit); void format_value(char *buff, double value, char *unit);
/* format value, scaling value and adding proper suffixes (for multi-interface /* format value, scaling value and adding proper suffixes (for multi-interface
* mode) */ * mode) */
void format_value_multi_interface(char *buff, double value, char *unit); void format_value_multi_interface(char *buff, double value, char *unit);
/* actualize widgets values in speed screen */ /* actualize widgets values in speed screen */
void actualize_speed_screen (IfaceInfo *iface, unsigned int interval, int index); void actualize_speed_screen(IfaceInfo *iface, unsigned int interval, int index);
/* actualize widgets values in transfer screen */ /* actualize widgets values in transfer screen */
void actualize_transfer_screen (IfaceInfo *iface, int index); void actualize_transfer_screen(IfaceInfo *iface, int index);
#endif #endif
+19 -27
View File
@@ -27,7 +27,7 @@
// +--------------------+ // +--------------------+
// //
int int
xload_screen (int rep, int display, int *flags_ptr) xload_screen(int rep, int display, int *flags_ptr)
{ {
static int gauge_hgt = 0; static int gauge_hgt = 0;
static double loads[LCD_MAX_WIDTH]; static double loads[LCD_MAX_WIDTH];
@@ -45,33 +45,28 @@ xload_screen (int rep, int display, int *flags_ptr)
highLoad = config_get_float("Load", "HighLoad", 0, LOAD_MAX); highLoad = config_get_float("Load", "HighLoad", 0, LOAD_MAX);
gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt; gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt;
memset (loads, '\0', sizeof (double) * LCD_MAX_WIDTH); memset(loads, '\0', sizeof(double) * LCD_MAX_WIDTH);
sock_send_string (sock, "screen_add L\n"); sock_send_string(sock, "screen_add L\n");
sprintf (buffer, "screen_set L -name {Load: %s}\n", get_hostname()); sock_printf(sock, "screen_set L -name {Load: %s}\n", get_hostname());
sock_send_string (sock, buffer);
// Add the vbars... // Add the vbars...
for (i = 1; i < lcd_wid; i++) { for (i = 1; i < lcd_wid; i++) {
sprintf (tmp, "widget_add L bar%i vbar\n", i); sock_printf(sock, "widget_add L bar%i vbar\n", i);
sock_send_string (sock, tmp); sock_printf(sock, "widget_set L bar%i %i %i 0\n", i, i, lcd_hgt);
sprintf (tmp, "widget_set L bar%i %i %i 0\n", i, i, lcd_hgt);
sock_send_string (sock, tmp);
} }
// And add a title... // And add a title...
if (lcd_hgt > 2) { if (lcd_hgt > 2) {
sock_send_string (sock, "widget_add L title title\n"); sock_send_string(sock, "widget_add L title title\n");
sock_send_string (sock, "widget_set L title {LOAD }\n"); sock_send_string(sock, "widget_set L title {LOAD }\n");
} else { } else {
sock_send_string (sock, "widget_add L title string\n"); sock_send_string(sock, "widget_add L title string\n");
sock_send_string (sock, "widget_set L title 1 1 {LOAD}\n"); sock_send_string(sock, "widget_set L title 1 1 {LOAD}\n");
sock_send_string (sock, "screen_set L -heartbeat off\n"); sock_send_string(sock, "screen_set L -heartbeat off\n");
} }
sock_send_string (sock, "widget_add L zero string\n"); sock_send_string(sock, "widget_add L zero string\n");
sock_send_string (sock, "widget_add L top string\n"); sock_send_string(sock, "widget_add L top string\n");
sprintf (tmp, "widget_set L zero %i %i 0\n", lcd_wid, lcd_hgt); sock_printf(sock, "widget_set L zero %i %i 0\n", lcd_wid, lcd_hgt);
sock_send_string (sock, tmp); sock_printf(sock, "widget_set L top %i %i 1\n", lcd_wid, (lcd_hgt + 1 - gauge_hgt));
sprintf (tmp, "widget_set L top %i %i 1\n", lcd_wid, (lcd_hgt + 1 - gauge_hgt));
sock_send_string (sock, tmp);
} }
// shift load history // shift load history
@@ -94,22 +89,19 @@ xload_screen (int rep, int display, int *flags_ptr)
factor = (double) (lcd_cellhgt * gauge_hgt) / (double) loadtop; factor = (double) (lcd_cellhgt * gauge_hgt) / (double) loadtop;
// display load // display load
sprintf (tmp, "widget_set L top %i %i %i\n", lcd_wid, (lcd_hgt + 1 - gauge_hgt), loadtop); sock_printf(sock, "widget_set L top %i %i %i\n", lcd_wid, (lcd_hgt + 1 - gauge_hgt), loadtop);
sock_send_string (sock, tmp);
for (i = 0; i < lcd_wid - 1; i++) { for (i = 0; i < lcd_wid - 1; i++) {
double x = loads[i] * factor; double x = loads[i] * factor;
sprintf (tmp, "widget_set L bar%i %i %i %i\n", i + 1, i + 1, lcd_hgt, (int) x); sock_printf(sock, "widget_set L bar%i %i %i %i\n", i + 1, i + 1, lcd_hgt, (int) x);
sock_send_string (sock, tmp);
} }
// And now the title... // And now the title...
if (lcd_hgt > 2) if (lcd_hgt > 2)
sprintf (tmp, "widget_set L title {LOAD %2.2f: %s}\n", loads[lcd_wid - 2], get_hostname()); sock_printf(sock, "widget_set L title {LOAD %2.2f: %s}\n", loads[lcd_wid - 2], get_hostname());
else else
sprintf (tmp, "widget_set L title 1 1 {%s %2.2f}\n", get_hostname(), loads[lcd_wid - 2]); sock_printf(sock, "widget_set L title 1 1 {%s %2.2f}\n", get_hostname(), loads[lcd_wid - 2]);
sock_send_string (sock, tmp);
// set return status depending on max & current load // set return status depending on max & current load
if (lowLoad < highLoad) { if (lowLoad < highLoad) {
+1 -1
View File
@@ -8,6 +8,6 @@
#define LOAD_MIN 0.05 #define LOAD_MIN 0.05
#endif #endif
int xload_screen (int rep, int display, int *flags_ptr); int xload_screen(int rep, int display, int *flags_ptr);
#endif #endif
+23 -24
View File
@@ -466,42 +466,41 @@ menus_init ()
for (k = 0; sequence[k].which ; k++) { for (k = 0; sequence[k].which ; k++) {
if (sequence[k].longname) { if (sequence[k].longname) {
sprintf (buffer, "menu_add_item {} %c checkbox {%s} -value %s\n", sock_printf(sock, "menu_add_item {} %c checkbox {%s} -value %s\n",
sequence[k].which, sequence[k].longname, sequence[k].which, sequence[k].longname,
(sequence[k].flags & ACTIVE) ? "on" : "off"); (sequence[k].flags & ACTIVE) ? "on" : "off");
sock_send_string (sock, buffer);
} }
} }
#ifdef LCDPROC_CLIENT_TESTMENUS #ifdef LCDPROC_CLIENT_TESTMENUS
// # to be entered on escape from test_menu (but overwritten // # to be entered on escape from test_menu (but overwritten
// # for test_{checkbox,ring} // # for test_{checkbox,ring}
sock_send_string (sock, "menu_add_item {} ask menu {Leave menus?} -is_hidden true\n"); sock_send_string(sock, "menu_add_item {} ask menu {Leave menus?} -is_hidden true\n");
sock_send_string (sock, "menu_add_item {ask} ask_yes action {Yes} -next _quit_\n"); sock_send_string(sock, "menu_add_item {ask} ask_yes action {Yes} -next _quit_\n");
sock_send_string (sock, "menu_add_item {ask} ask_no action {No} -next _close_\n"); sock_send_string(sock, "menu_add_item {ask} ask_no action {No} -next _close_\n");
sock_send_string (sock, "menu_add_item {} test menu {Test}\n"); sock_send_string(sock, "menu_add_item {} test menu {Test}\n");
sock_send_string (sock, "menu_add_item {test} test_action action {Action}\n"); sock_send_string(sock, "menu_add_item {test} test_action action {Action}\n");
sock_send_string (sock, "menu_add_item {test} test_checkbox checkbox {Checkbox}\n"); sock_send_string(sock, "menu_add_item {test} test_checkbox checkbox {Checkbox}\n");
sock_send_string (sock, "menu_add_item {test} test_ring ring {Ring} -strings {one\ttwo\tthree}\n"); sock_send_string(sock, "menu_add_item {test} test_ring ring {Ring} -strings {one\ttwo\tthree}\n");
sock_send_string (sock, "menu_add_item {test} test_slider slider {Slider} -mintext < -maxtext > -value 50\n"); sock_send_string(sock, "menu_add_item {test} test_slider slider {Slider} -mintext < -maxtext > -value 50\n");
sock_send_string (sock, "menu_add_item {test} test_numeric numeric {Numeric} -value 42\n"); sock_send_string(sock, "menu_add_item {test} test_numeric numeric {Numeric} -value 42\n");
sock_send_string (sock, "menu_add_item {test} test_alpha alpha {Alpha} -value abc\n"); sock_send_string(sock, "menu_add_item {test} test_alpha alpha {Alpha} -value abc\n");
sock_send_string (sock, "menu_add_item {test} test_ip ip {IP} -v6 false -value 192.168.1.1\n"); sock_send_string(sock, "menu_add_item {test} test_ip ip {IP} -v6 false -value 192.168.1.1\n");
sock_send_string (sock, "menu_add_item {test} test_menu menu {Menu}\n"); sock_send_string(sock, "menu_add_item {test} test_menu menu {Menu}\n");
sock_send_string (sock, "menu_add_item {test_menu} test_menu_action action {Submenu's action}\n"); sock_send_string(sock, "menu_add_item {test_menu} test_menu_action action {Submenu's action}\n");
// # no successor for menus. Since test_checkbox and test_ring have their // # no successor for menus. Since test_checkbox and test_ring have their
// # own predecessors defined the "ask" rule will not work for them // # own predecessors defined the "ask" rule will not work for them
sock_send_string (sock, "menu_set_item {} test -prev {ask}\n"); sock_send_string(sock, "menu_set_item {} test -prev {ask}\n");
sock_send_string (sock, "menu_set_item {test} test_action -next {test_checkbox}\n"); sock_send_string(sock, "menu_set_item {test} test_action -next {test_checkbox}\n");
sock_send_string (sock, "menu_set_item {test} test_checkbox -next {test_ring} -prev test_action\n"); sock_send_string(sock, "menu_set_item {test} test_checkbox -next {test_ring} -prev test_action\n");
sock_send_string (sock, "menu_set_item {test} test_ring -next {test_slider} -prev {test_checkbox}\n"); sock_send_string(sock, "menu_set_item {test} test_ring -next {test_slider} -prev {test_checkbox}\n");
sock_send_string (sock, "menu_set_item {test} test_slider -next {test_numeric} -prev {test_ring}\n"); sock_send_string(sock, "menu_set_item {test} test_slider -next {test_numeric} -prev {test_ring}\n");
sock_send_string (sock, "menu_set_item {test} test_numeric -next {test_alpha} -prev {test_slider}\n"); sock_send_string(sock, "menu_set_item {test} test_numeric -next {test_alpha} -prev {test_slider}\n");
sock_send_string (sock, "menu_set_item {test} test_alpha -next {test_ip} -prev {test_numeric}\n"); sock_send_string(sock, "menu_set_item {test} test_alpha -next {test_ip} -prev {test_numeric}\n");
sock_send_string (sock, "menu_set_item {test} test_ip -next {test_menu} -prev {test_alpha}\n"); sock_send_string(sock, "menu_set_item {test} test_ip -next {test_menu} -prev {test_alpha}\n");
sock_send_string (sock, "menu_set_item {test} test_menu_action -next {_close_}\n"); sock_send_string(sock, "menu_set_item {test} test_menu_action -next {_close_}\n");
#endif //LCDPROC_CLIENT_TESTMENUS #endif //LCDPROC_CLIENT_TESTMENUS
return 0; return 0;
+52 -71
View File
@@ -29,7 +29,7 @@
// +--------------------+ // +--------------------+
// //
int int
mem_screen (int rep, int display, int *flags_ptr) mem_screen(int rep, int display, int *flags_ptr)
{ {
static int which_title = 0; static int which_title = 0;
static int gauge_wid = 0; static int gauge_wid = 0;
@@ -40,8 +40,7 @@ mem_screen (int rep, int display, int *flags_ptr)
*flags_ptr |= INITIALIZED; *flags_ptr |= INITIALIZED;
sock_send_string(sock, "screen_add M\n"); sock_send_string(sock, "screen_add M\n");
sprintf(buffer, "screen_set M -name {Memory & Swap: %s}\n", get_hostname()); sock_printf(sock, "screen_set M -name {Memory & Swap: %s}\n", get_hostname());
sock_send_string(sock, buffer);
if (lcd_hgt >= 4) { if (lcd_hgt >= 4) {
gauge_wid = (lcd_wid >= 18) gauge_wid = (lcd_wid >= 18)
@@ -52,17 +51,13 @@ mem_screen (int rep, int display, int *flags_ptr)
sock_send_string(sock, "widget_set M title { MEM -==- SWAP}\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 totl string\n");
sock_send_string(sock, "widget_add M used string\n"); sock_send_string(sock, "widget_add M used string\n");
sprintf(buffer, "widget_set M totl %i 2 Totl\n", lcd_wid/2 - 1); sock_printf(sock, "widget_set M totl %i 2 Totl\n", lcd_wid/2 - 1);
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M used %i 3 Free\n", lcd_wid/2 - 1);
sprintf(buffer, "widget_set M used %i 3 Free\n", lcd_wid/2 - 1);
sock_send_string(sock, buffer);
sock_send_string(sock, "widget_add M EFmem string\n"); sock_send_string(sock, "widget_add M EFmem string\n");
sprintf(buffer, "widget_set M EFmem 1 4 {E%*sF}\n", gauge_wid, ""); sock_printf(sock, "widget_set M EFmem 1 4 {E%*sF}\n", gauge_wid, "");
sock_send_string(sock, buffer);
sock_send_string(sock, "widget_add M EFswap string\n"); sock_send_string(sock, "widget_add M EFswap string\n");
sprintf(buffer, "widget_set M EFswap %i 4 {E%*sF}\n", sock_printf(sock, "widget_set M EFswap %i 4 {E%*sF}\n",
lcd_wid - gauge_wid - 1, gauge_wid, ""); lcd_wid - gauge_wid - 1, gauge_wid, "");
sock_send_string(sock, buffer);
sock_send_string(sock, "widget_add M memused string\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_add M swapused string\n");
} else { } else {
@@ -72,12 +67,10 @@ mem_screen (int rep, int display, int *flags_ptr)
sock_send_string(sock, "widget_add M m string\n"); sock_send_string(sock, "widget_add M m string\n");
sock_send_string(sock, "widget_add M s string\n"); sock_send_string(sock, "widget_add M s string\n");
if (gauge_wid > 0) { if (gauge_wid > 0) {
sprintf(buffer, "widget_set M m 1 1 {M%*s[%*s]}\n", sock_printf(sock, "widget_set M m 1 1 {M%*s[%*s]}\n",
gauge_offs - 3, "", gauge_wid, ""); gauge_offs - 3, "", gauge_wid, "");
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M s 1 2 {S%*s[%*s]}\n",
sprintf(buffer, "widget_set M s 1 2 {S%*s[%*s]}\n",
gauge_offs - 3, "", gauge_wid, ""); gauge_offs - 3, "", gauge_wid, "");
sock_send_string(sock, buffer);
} }
else { else {
sock_send_string(sock, "widget_set M m 1 1 {M }\n"); sock_send_string(sock, "widget_set M m 1 1 {M }\n");
@@ -97,37 +90,34 @@ mem_screen (int rep, int display, int *flags_ptr)
machine_get_meminfo(mem); machine_get_meminfo(mem);
if (lcd_hgt >= 4) { if (lcd_hgt >= 4) {
char tmp[12]; // should be sufficient
// flip the title back and forth... (every 4 updates) // flip the title back and forth... (every 4 updates)
if (which_title & 4) { if (which_title & 4) {
sprintf(buffer, "widget_set M title {%s}\n", get_hostname()); sock_printf(sock, "widget_set M title {%s}\n", get_hostname());
sock_send_string(sock, buffer);
} else } else
sock_send_string(sock, "widget_set M title { MEM -==- SWAP}\n"); sock_send_string(sock, "widget_set M title { MEM -==- SWAP}\n");
which_title = (which_title + 1) & 7; which_title = (which_title + 1) & 7;
// Total memory // Total memory
sprintf_memory(tmp, mem[0].total * 1024, 1); sprintf_memory(tmp, mem[0].total * 1024, 1);
sprintf(buffer, "widget_set M memtotl 1 2 {%7s}\n", tmp);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M memtotl 1 2 {%7s}\n", tmp);
// Free memory (plus buffers and cache) // Free memory (plus buffers and cache)
sprintf_memory(tmp, (mem[0].free + mem[0].buffers + mem[0].cache) * 1024, 1); sprintf_memory(tmp, (mem[0].free + mem[0].buffers + mem[0].cache) * 1024, 1);
sprintf(buffer, "widget_set M memused 1 3 {%7s}\n", tmp);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M memused 1 3 {%7s}\n", tmp);
// Total swap // Total swap
sprintf_memory(tmp, mem[1].total * 1024, 1); sprintf_memory(tmp, mem[1].total * 1024, 1);
sprintf(buffer, "widget_set M swaptotl %i 2 {%7s}\n", lcd_wid - 7, tmp);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M swaptotl %i 2 {%7s}\n", lcd_wid - 7, tmp);
// Free swap // Free swap
sprintf_memory(tmp, mem[1].free * 1024, 1); sprintf_memory(tmp, mem[1].free * 1024, 1);
sprintf(buffer, "widget_set M swapused %i 3 {%7s}\n", lcd_wid - 7, tmp);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M swapused %i 3 {%7s}\n", lcd_wid - 7, tmp);
if (gauge_wid > 0) { if (gauge_wid > 0) {
// Free memory graph // Free memory graph
@@ -136,10 +126,9 @@ mem_screen (int rep, int display, int *flags_ptr)
/ (double) mem[0].total; / (double) mem[0].total;
//printf(".0f", val) only prints the integer part //printf(".0f", val) only prints the integer part
sprintf(buffer, "widget_set M memgauge 2 4 %.0f\n",
lcd_cellwid * gauge_wid * value);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M memgauge 2 4 %.0f\n",
lcd_cellwid * gauge_wid * value);
} }
// Free swap graph // Free swap graph
@@ -147,25 +136,24 @@ mem_screen (int rep, int display, int *flags_ptr)
double value = 1.0 - ((double) mem[1].free / (double) mem[1].total); double value = 1.0 - ((double) mem[1].free / (double) mem[1].total);
//printf(".0f", val) only prints the integer part //printf(".0f", val) only prints the integer part
sprintf(buffer, "widget_set M swapgauge %i 4 %.0f\n",
lcd_wid - gauge_wid, lcd_cellwid * gauge_wid * value);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M swapgauge %i 4 %.0f\n",
lcd_wid - gauge_wid, lcd_cellwid * gauge_wid * value);
} }
} }
} }
else { else {
char tmp[12]; // should be sufficient
// Total memory // Total memory
sprintf_memory(tmp, mem[0].total * 1024, 1); sprintf_memory(tmp, mem[0].total * 1024, 1);
sprintf(buffer, "widget_set M memtotl 3 1 {%6s}\n", tmp);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M memtotl 3 1 {%6s}\n", tmp);
// Total swap // Total swap
sprintf_memory(tmp, mem[1].total * 1024, 1); sprintf_memory(tmp, mem[1].total * 1024, 1);
sprintf(buffer, "widget_set M swaptotl 3 2 {%6s}\n", tmp);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M swaptotl 3 2 {%6s}\n", tmp);
// Free memory graph // Free memory graph
strcpy(tmp, "N/A"); strcpy(tmp, "N/A");
@@ -175,17 +163,15 @@ mem_screen (int rep, int display, int *flags_ptr)
if (gauge_wid > 0) { if (gauge_wid > 0) {
//printf(".0f", val) only prints the integer part //printf(".0f", val) only prints the integer part
sprintf(buffer, "widget_set M memgauge %i 1 %.0f\n",
gauge_offs, lcd_cellwid * gauge_wid * value);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M memgauge %i 1 %.0f\n",
gauge_offs, lcd_cellwid * gauge_wid * value);
} }
sprintf_percent(tmp, value * 100); sprintf_percent(tmp, value * 100);
} }
sprintf(buffer, "widget_set M mem%% %i 1 {%5s}\n", lcd_wid - 5, tmp);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M mem%% %i 1 {%5s}\n", lcd_wid - 5, tmp);
// Free swap graph // Free swap graph
strcpy(tmp, "N/A"); strcpy(tmp, "N/A");
@@ -194,17 +180,15 @@ mem_screen (int rep, int display, int *flags_ptr)
if (gauge_wid > 0) { if (gauge_wid > 0) {
//printf(".0f", val) only prints the integer part //printf(".0f", val) only prints the integer part
sprintf(buffer, "widget_set M swapgauge %i 2 %.0f\n",
gauge_offs, lcd_cellwid * gauge_wid * value);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M swapgauge %i 2 %.0f\n",
gauge_offs, lcd_cellwid * gauge_wid * value);
} }
sprintf_percent(tmp, value * 100); sprintf_percent(tmp, value * 100);
} }
sprintf(buffer, "widget_set M swap%% %i 2 {%5s}\n", lcd_wid - 5, tmp);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set M swap%% %i 2 {%5s}\n", lcd_wid - 5, tmp);
} }
return 0; return 0;
@@ -212,7 +196,7 @@ mem_screen (int rep, int display, int *flags_ptr)
static int static int
sort_procs (void *a, void *b) sort_procs(void *a, void *b)
{ {
procinfo_type *one, *two; procinfo_type *one, *two;
@@ -237,7 +221,7 @@ sort_procs (void *a, void *b)
// +--------------------+ // +--------------------+
// //
int int
mem_top_screen (int rep, int display, int *flags_ptr) mem_top_screen(int rep, int display, int *flags_ptr)
{ {
LinkedList *procs; LinkedList *procs;
int i; int i;
@@ -246,31 +230,27 @@ mem_top_screen (int rep, int display, int *flags_ptr)
*flags_ptr |= INITIALIZED; *flags_ptr |= INITIALIZED;
sock_send_string(sock, "screen_add S\n"); sock_send_string(sock, "screen_add S\n");
sprintf(buffer, "screen_set S -name {Top Memory Use: %s}\n", get_hostname()); sock_printf(sock, "screen_set S -name {Top Memory Use: %s}\n", get_hostname());
sock_send_string(sock, buffer);
sock_send_string(sock, "widget_add S title title\n"); sock_send_string(sock, "widget_add S title title\n");
sprintf(buffer, "widget_set S title {TOP MEM: %s}\n", get_hostname()); sock_printf(sock, "widget_set S title {TOP MEM: %s}\n", get_hostname());
sock_send_string(sock, buffer);
// frame from (2nd line, left) to (last line, right) // frame from (2nd line, left) to (last line, right)
sock_send_string(sock, "widget_add S f frame\n"); sock_send_string(sock, "widget_add S f frame\n");
sprintf(buffer, "widget_set S f 1 2 %i %i %i 5 v %i\n", sock_printf(sock, "widget_set S f 1 2 %i %i %i 5 v %i\n",
lcd_wid, lcd_hgt, lcd_wid, lcd_wid, lcd_hgt, lcd_wid,
// scroll rate: 1 line every X ticks (= 1/8 sec) // scroll rate: 1 line every X ticks (= 1/8 sec)
((lcd_hgt >= 4) ? 8 : 12)); ((lcd_hgt >= 4) ? 8 : 12));
sock_send_string(sock, buffer);
// frame contents // frame contents
for (i = 1; i <= 5; i++) { for (i = 1; i <= 5; i++) {
sprintf(buffer, "widget_add S %i string -in f\n", i); sock_printf(sock, "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, "widget_set S 1 1 1 Checking...\n");
} }
procs = LL_new(); procs = LL_new();
if (procs == NULL) { if (procs == NULL) {
fprintf (stderr, "mem_top_screen: Error allocating list\n"); fprintf(stderr, "mem_top_screen: Error allocating list\n");
return -1; return -1;
} }
@@ -289,22 +269,23 @@ mem_top_screen (int rep, int display, int *flags_ptr)
sprintf_memory(mem, (double) p->totl * 1024, 1); sprintf_memory(mem, (double) p->totl * 1024, 1);
//printf("Mem hog: %s: %s\n", p->name, mem); //printf("Mem hog: %s: %s\n", p->name, mem);
if (p->number > 1) if (display) {
sprintf(tmp, "%i %5s %s(%i)", i, mem, p->name, p->number); if (p->number > 1)
else sock_printf(sock, "widget_set S %i 1 %i {%i %5s %s(%i)}\n",
sprintf(tmp, "%i %5s %s", i, mem, p->name); i, i, i, mem, p->name, p->number);
sprintf(buffer, "widget_set S %i 1 %i {%s}\n", i, i, tmp); else
if (display) sock_printf(sock, "widget_set S %i 1 %i {%i %5s %s}\n",
sock_send_string(sock, buffer); i, i, i, mem, p->name);
} else { }
}
else {
//printf("Mem hog: none?\n"); //printf("Mem hog: none?\n");
//sprintf(buffer, "widget_set S %i 1 %i {}\n", i, i); //sprintf(buffer, "widget_set S %i 1 %i {}\n", i, i);
sprintf(buffer, "widget_set S %i 1 %i { }\n", i, i);
if (display) if (display)
sock_send_string(sock, buffer); sock_printf(sock, "widget_set S %i 1 %i { }\n", i, i);
} }
LL_Next (procs); LL_Next(procs);
} }
// Now clean it all up... // Now clean it all up...
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef MEM_H #ifndef MEM_H
#define MEM_H #define MEM_H
int mem_screen (int rep, int display, int *flags_ptr); int mem_screen(int rep, int display, int *flags_ptr);
int mem_top_screen (int rep, int display, int *flags_ptr); int mem_top_screen(int rep, int display, int *flags_ptr);
#endif #endif
+2 -26
View File
@@ -25,22 +25,10 @@
// TODO: Clean this up... Support multiple display sizes.. // TODO: Clean this up... Support multiple display sizes..
char *tmp = NULL;
char *buffer = NULL;
int int
mode_init() mode_init()
{ {
if ((buffer = malloc(1024)) == NULL) {
perror("malloc buffer");
return(0);
}
if ((tmp = malloc(1024)) == NULL) {
perror("malloc tmp");
return(0);
}
machine_init(); machine_init();
return(0); return(0);
@@ -50,16 +38,6 @@ void
mode_close() mode_close()
{ {
machine_close(); machine_close();
if (tmp != NULL) {
free(tmp);
tmp = NULL;
}
if (buffer != NULL) {
free(buffer);
buffer = NULL;
}
} }
int int
@@ -112,8 +90,7 @@ credit_screen(int rep, int display, int *flags_ptr)
sock_send_string(sock, "screen_add A\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, "screen_set A -name {Credits for LCDproc}\n");
sock_send_string(sock, "widget_add A title title\n"); sock_send_string(sock, "widget_add A title title\n");
sprintf(buffer, "widget_set A title {LCDPROC %s}\n", version); sock_printf(sock, "widget_set A title {LCDPROC %s}\n", version);
sock_send_string(sock, buffer);
if (lcd_hgt >= 4) if (lcd_hgt >= 4)
{ {
sock_send_string(sock, "widget_add A one string\n"); sock_send_string(sock, "widget_add A one string\n");
@@ -126,8 +103,7 @@ credit_screen(int rep, int display, int *flags_ptr)
else else
{ {
sock_send_string(sock, "widget_add A text scroller\n"); sock_send_string(sock, "widget_add A text scroller\n");
sprintf(buffer, "widget_set A text 1 2 %d 2 h 8 { for Linux & *BSD by William Ferrell, Scott Scriven}\n", lcd_wid); sock_printf(sock, "widget_set A text 1 2 %d 2 h 8 { for Linux & *BSD by William Ferrell, Scott Scriven}\n", lcd_wid);
sock_send_string(sock, buffer);
} }
} }
+5 -7
View File
@@ -3,14 +3,12 @@
#include "main.h" #include "main.h"
//TODO: get rid of these global variables!
extern char *tmp;
extern char *buffer;
int mode_init (); int mode_init();
void mode_close (); void mode_close();
int update_screen (mode * m, int display); int update_screen(mode * m, int display);
int credit_screen (int rep, int display, int *flags_ptr);
int credit_screen(int rep, int display, int *flags_ptr);
#endif #endif