use variable gauge_hgt for gauge heights, no purely numeric widget names
This commit is contained in:
+14
-12
@@ -22,7 +22,7 @@
|
||||
// CPU screen shows info about percentage of the CPU being used
|
||||
//
|
||||
// +--------------------+ +--------------------+
|
||||
// |## CPU 51.9%: myh #@| |CPU0[---- ]48.1%@|
|
||||
// |## CPU 51.9%: myh #@| |CPU [---- ]48.1%@|
|
||||
// |Usr 46.0% Nice 0.0%| |U-- S- N I--- |
|
||||
// |Sys 5.9% Idle 48.1%| +--------------------+
|
||||
// |0%-------- 100%|
|
||||
@@ -72,14 +72,14 @@ cpu_screen(int rep, int display)
|
||||
sock_send_string(sock, "widget_set C bar 3 4 0\n");
|
||||
}
|
||||
else {
|
||||
usni_wid = (lcd_wid - 4)/ 4; // 4 gauges + 1 letter for each
|
||||
usni_wid = (lcd_wid - 4) / 4; // 4 gauges + 1 letter for each
|
||||
gauge_wid = lcd_wid - 12; // room between [...]
|
||||
|
||||
sock_send_string(sock, "widget_add C cpu0 string\n");
|
||||
sprintf(buffer, "widget_set C cpu0 1 1 {CPU0[%*s]}\n", gauge_wid, "");
|
||||
sock_send_string(sock, "widget_add C cpu string\n");
|
||||
sprintf(buffer, "widget_set C cpu 1 1 {CPU [%*s]}\n", gauge_wid, "");
|
||||
sock_send_string(sock, buffer);
|
||||
sock_send_string(sock, "widget_add C cpu0% string\n");
|
||||
sprintf(buffer, "widget_set C cpu0%% 1 %d { 0.0%%}\n", lcd_wid - 5);
|
||||
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_send_string(sock, buffer);
|
||||
sock_send_string(sock, "widget_add C usni string\n");
|
||||
sprintf(buffer, "widget_set C usni 1 2 {U%*sS%*sN%*sI%*s}\n",
|
||||
@@ -159,7 +159,7 @@ cpu_screen(int rep, int display)
|
||||
}
|
||||
else { // 2-line display
|
||||
sprintf_percent(tmp, cpu[CPU_BUF_SIZE][4]);
|
||||
sprintf(buffer, "widget_set C cpu0%% %d 1 {%5s}\n", lcd_wid - 5, tmp);
|
||||
sprintf(buffer, "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);
|
||||
@@ -206,6 +206,7 @@ cpu_graph_screen(int rep, int display)
|
||||
static int first = TRUE;
|
||||
static float cpu[CPU_BUF_SIZE];
|
||||
static int cpu_past[LCD_MAX_WIDTH];
|
||||
static int gauge_hgt = 0;
|
||||
|
||||
int i, n = 0;
|
||||
float value ;
|
||||
@@ -213,6 +214,7 @@ cpu_graph_screen(int rep, int display)
|
||||
|
||||
if (first) {
|
||||
first = FALSE;
|
||||
gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt;
|
||||
|
||||
sock_send_string(sock, "screen_add G\n");
|
||||
sprintf(buffer, "screen_set G -name {CPU Graph: %s}\n", get_hostname());
|
||||
@@ -228,9 +230,9 @@ cpu_graph_screen(int rep, int display)
|
||||
sock_send_string(sock, buffer);
|
||||
|
||||
for (i = 1; i <= lcd_wid; i++) {
|
||||
sprintf(buffer, "widget_add G %d vbar\n", i);
|
||||
sprintf(buffer, "widget_add G bar%d vbar\n", i);
|
||||
sock_send_string(sock, buffer);
|
||||
sprintf(buffer, "widget_set G %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;
|
||||
};
|
||||
@@ -255,14 +257,14 @@ cpu_graph_screen(int rep, int display)
|
||||
value /= CPU_BUF_SIZE;
|
||||
|
||||
// Scale result to available height (leave 1st line free when height > 2)
|
||||
n = (int) (value * lcd_cellhgt * ((lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt));
|
||||
n = (int) (value * lcd_cellhgt * gauge_hgt);
|
||||
|
||||
// Shift and update display the graph
|
||||
for (i = 0; i < lcd_wid - 1; i++) {
|
||||
cpu_past[i] = cpu_past[i + 1];
|
||||
|
||||
if (display) {
|
||||
sprintf(buffer, "widget_set G %d %d %d %d\n",
|
||||
sprintf(buffer, "widget_set G bar%d %d %d %d\n",
|
||||
i + 1, i + 1, lcd_hgt, cpu_past[i]);
|
||||
sock_send_string(sock, buffer);
|
||||
}
|
||||
@@ -271,7 +273,7 @@ cpu_graph_screen(int rep, int display)
|
||||
// Save the newest entry and display it
|
||||
cpu_past[lcd_wid - 1] = n;
|
||||
if (display) {
|
||||
sprintf(buffer, "widget_set G %d %d %d %d\n", lcd_wid, lcd_wid, lcd_hgt, n);
|
||||
sprintf(buffer, "widget_set G bar%d %d %d %d\n", lcd_wid, lcd_wid, lcd_hgt, n);
|
||||
sock_send_string(sock, buffer);
|
||||
}
|
||||
|
||||
|
||||
+32
-31
@@ -29,13 +29,15 @@ int
|
||||
xload_screen (int rep, int display)
|
||||
{
|
||||
static int first = 1;
|
||||
static int gauge_hgt = 0;
|
||||
static double loads[LCD_MAX_WIDTH];
|
||||
int n, i;
|
||||
double loadmax = 0, factor, x;
|
||||
int loadtop, i;
|
||||
double loadmax = 0, factor;
|
||||
int status = 0;
|
||||
|
||||
if (first) { // Only the first time this is ever called...
|
||||
first = 0;
|
||||
gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt;
|
||||
memset (loads, '\0', sizeof (double) * LCD_MAX_WIDTH);
|
||||
|
||||
sock_send_string (sock, "screen_add X\n");
|
||||
@@ -43,9 +45,9 @@ xload_screen (int rep, int display)
|
||||
sock_send_string (sock, buffer);
|
||||
// Add the vbars...
|
||||
for (i = 1; i < lcd_wid; i++) {
|
||||
sprintf (tmp, "widget_add X %i vbar\n", i);
|
||||
sprintf (tmp, "widget_add X bar%i vbar\n", i);
|
||||
sock_send_string (sock, tmp);
|
||||
sprintf (tmp, "widget_set X %i %i %i 0\n", i, i, lcd_hgt);
|
||||
sprintf (tmp, "widget_set X bar%i %i %i 0\n", i, i, lcd_hgt);
|
||||
sock_send_string (sock, tmp);
|
||||
}
|
||||
// And add a title...
|
||||
@@ -61,52 +63,51 @@ xload_screen (int rep, int display)
|
||||
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);
|
||||
sprintf (tmp, "widget_set X top %i %i 1\n", lcd_wid, (lcd_hgt + 1 - gauge_hgt));
|
||||
sock_send_string (sock, tmp);
|
||||
}
|
||||
|
||||
for (n = 0; n < (lcd_wid - 2); n++)
|
||||
loads[n] = loads[n + 1];
|
||||
// shift load history
|
||||
for (i = 0; i < (lcd_wid - 2); i++)
|
||||
loads[i] = loads[i + 1];
|
||||
|
||||
// get new load value
|
||||
machine_get_loadavg(&(loads[lcd_wid - 2]));
|
||||
|
||||
for (n = 0; n < lcd_wid - 1; n++)
|
||||
if (loads[n] > loadmax)
|
||||
loadmax = loads[n];
|
||||
// determine max. load from history
|
||||
for (i = 0; i < lcd_wid - 1; i++)
|
||||
loadmax = max(loadmax, loads[i]);
|
||||
|
||||
n = (int) loadmax;
|
||||
if ((double) n < loadmax)
|
||||
n++;
|
||||
// poor man's ceil()
|
||||
loadtop = (int) loadmax;
|
||||
if (loadtop < loadmax)
|
||||
loadtop++;
|
||||
loadtop = max(1, loadtop);
|
||||
|
||||
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);
|
||||
factor = (double) (lcd_cellhgt * gauge_hgt) / (double) loadtop;
|
||||
|
||||
// display load
|
||||
sprintf (tmp, "widget_set X top %i %i %i\n", lcd_wid, (lcd_hgt + 1 - gauge_hgt), loadtop);
|
||||
sock_send_string (sock, tmp);
|
||||
|
||||
factor = (double) (lcd_cellhgt) * ((lcd_hgt <= 2) ? 2.0 : 1.0 * (lcd_hgt-1)) / (double) n;
|
||||
for (i = 0; i < lcd_wid - 1; i++) {
|
||||
double x = loads[i] * 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);
|
||||
sprintf (tmp, "widget_set X bar%i %i %i %i\n", i + 1, i + 1, lcd_hgt, (int) x);
|
||||
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 > 2)
|
||||
sprintf (tmp, "widget_set X title {LOAD %2.2f: %s}\n", loads[lcd_wid - 2], get_hostname());
|
||||
else
|
||||
sprintf (tmp, "widget_set X title 1 1 {%s %2.2f}\n", get_hostname(), loads[lcd_wid - 2]);
|
||||
//if(display) sock_send_string(sock, tmp);
|
||||
sock_send_string (sock, tmp);
|
||||
|
||||
// set return status depending on max & current load
|
||||
status = (loadmax > LOAD_MIN) ? BACKLIGHT_ON : BACKLIGHT_OFF;
|
||||
if (loads[lcd_wid - 2] > LOAD_MAX)
|
||||
status = BLINK_ON;
|
||||
|
||||
return status;
|
||||
} // End xload_screen()
|
||||
|
||||
Reference in New Issue
Block a user