add menu support to lcdproc client (currently hidden behind #ifdef LCDPROC_MENUS) -
patch provided by Andrew Foss
This commit is contained in:
+12
-2
@@ -71,14 +71,24 @@ battery_status(int status)
|
||||
// +--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
battery_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
battery_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
static int first = TRUE;
|
||||
int acstat = 0, battstat = 0, percent = 0;
|
||||
int gauge_wid = lcd_wid - 2;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if (first == TRUE) {
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
sock_send_string (sock, "screen_add B\n");
|
||||
sprintf (buffer, "screen_set B -name {APM stats: %s}\n", get_hostname());
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef BATT_H
|
||||
#define BATT_H
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
int battery_screen (int rep, int display, int * flags_ptr);
|
||||
#else
|
||||
int battery_screen (int rep, int display);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+60
-10
@@ -96,21 +96,31 @@ static char *shortmonths[] = {
|
||||
//+--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
time_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
time_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
char now[20];
|
||||
char day[16], month[16];
|
||||
int xoffs;
|
||||
int days, hour, min, sec;
|
||||
static int first = 1;
|
||||
static int heartbeat = 0;
|
||||
static char colon[] = {':', ' '};
|
||||
time_t thetime;
|
||||
struct tm *rtime;
|
||||
double uptime, idle;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
sock_send_string (sock, "screen_add T\n");
|
||||
sprintf (buffer, "screen_set T -name {Time Screen: %s}\n", get_hostname());
|
||||
@@ -212,19 +222,29 @@ time_screen (int rep, int display)
|
||||
//+--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
clock_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
clock_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
char now[20];
|
||||
char day[16], month[16];
|
||||
int xoffs;
|
||||
static int first = 1;
|
||||
static int heartbeat = 0;
|
||||
static char colon[] = {':', ' '};
|
||||
time_t thetime;
|
||||
struct tm *rtime;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
sock_send_string (sock, "screen_add O\n");
|
||||
sprintf (buffer, "screen_set O -name {Old Clock Screen: %s}\n", get_hostname());
|
||||
@@ -306,17 +326,27 @@ clock_screen (int rep, int display)
|
||||
//+--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
uptime_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
uptime_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
int xoffs;
|
||||
int days, hour, min, sec;
|
||||
double uptime, idle;
|
||||
static int first = 1;
|
||||
static int heartbeat = 0;
|
||||
static char colon[] = {':', ' '};
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
sock_send_string (sock, "screen_add U\n");
|
||||
sprintf (buffer, "screen_set U -name {Uptime Screen: %s}\n", get_hostname());
|
||||
@@ -383,9 +413,12 @@ uptime_screen (int rep, int display)
|
||||
// +--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
big_clock_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
big_clock_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
static int first = 1;
|
||||
time_t thetime;
|
||||
struct tm *rtime;
|
||||
int pos[] = { 1, 4, 8, 11, 15, 18 };
|
||||
@@ -399,9 +432,16 @@ big_clock_screen (int rep, int display)
|
||||
|
||||
// toggle colon display
|
||||
heartbeat ^= 1;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
sock_send_string (sock, "screen_add K\n");
|
||||
sock_send_string (sock, "screen_set K -name {Big Clock Screen} -heartbeat off\n");
|
||||
@@ -460,15 +500,25 @@ big_clock_screen (int rep, int display)
|
||||
//+--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
essential_clock_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
essential_clock_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
static int first = 1;
|
||||
struct tm *rtime;
|
||||
struct timeval ttime;
|
||||
static char colon[] = {':', ' '};
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
sock_send_string (sock, "screen_add E\n");
|
||||
sock_send_string (sock, "screen_set E -name {Essential Clock Screen} -heartbeat off\n");
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
#ifndef CHRONO_H
|
||||
#define CHRONO_H
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
int clock_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 big_clock_screen (int rep, int display, int * flags_ptr);
|
||||
int essential_clock_screen (int rep, int display, int * flags_ptr);
|
||||
#else
|
||||
int clock_screen (int rep, int display);
|
||||
int uptime_screen (int rep, int display);
|
||||
int time_screen (int rep, int display);
|
||||
int big_clock_screen (int rep, int display);
|
||||
int essential_clock_screen (int rep, int display);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+22
-2
@@ -29,11 +29,14 @@
|
||||
// +--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
cpu_screen(int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
cpu_screen(int rep, int display)
|
||||
#endif
|
||||
{
|
||||
#undef CPU_BUF_SIZE
|
||||
#define CPU_BUF_SIZE 4
|
||||
static int first = TRUE;
|
||||
static double cpu[CPU_BUF_SIZE + 1][5]; // last buffer is scratch
|
||||
static int gauge_wid = 0;
|
||||
static int usni_wid = 0;
|
||||
@@ -41,9 +44,16 @@ cpu_screen(int rep, int display)
|
||||
int i, j, n;
|
||||
double value;
|
||||
load_type load;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
sock_send_string(sock, "screen_add C\n");
|
||||
sprintf(buffer, "screen_set C -name {CPU Use: %s}\n", get_hostname());
|
||||
@@ -208,11 +218,14 @@ cpu_screen(int rep, int display)
|
||||
// +--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
cpu_graph_screen(int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
cpu_graph_screen(int rep, int display)
|
||||
#endif
|
||||
{
|
||||
#undef CPU_BUF_SIZE
|
||||
#define CPU_BUF_SIZE 2
|
||||
static int first = TRUE;
|
||||
static double cpu[CPU_BUF_SIZE];
|
||||
static int cpu_past[LCD_MAX_WIDTH];
|
||||
static int gauge_hgt = 0;
|
||||
@@ -220,9 +233,16 @@ cpu_graph_screen(int rep, int display)
|
||||
int i, n = 0;
|
||||
double value ;
|
||||
load_type load;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = FALSE;
|
||||
#endif
|
||||
gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt;
|
||||
|
||||
sock_send_string(sock, "screen_add G\n");
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#ifndef CPU_H
|
||||
#define CPU_H
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
int cpu_screen (int rep, int display, int * flags_ptr);
|
||||
int cpu_graph_screen (int rep, int display, int * flags_ptr);
|
||||
#else
|
||||
int cpu_screen (int rep, int display);
|
||||
int cpu_graph_screen (int rep, int display);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -65,21 +65,31 @@ static char *numnames[MAX_CPUS] = { "one", "two", "three", "four", "five", "six"
|
||||
// CPU screen shows info about percentage of the CPU being used
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
cpu_smp_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
cpu_smp_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
#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
|
||||
load_type load[MAX_CPUS];
|
||||
int numprocs;
|
||||
char buf[256];
|
||||
char *graphsize;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
machine_get_smpload (load, &numprocs);
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef CPU_SMP_H
|
||||
#define CPU_SMP_H
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
int cpu_smp_screen (int rep, int display, int * flags_ptr);
|
||||
#else
|
||||
int cpu_smp_screen (int rep, int display);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+12
-2
@@ -32,7 +32,11 @@
|
||||
//
|
||||
// TODO: Disk screen! Requires virtual pages in the server, though...
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
disk_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
disk_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
static mounts_type mnt[256];
|
||||
static int count = 0;
|
||||
@@ -45,15 +49,21 @@ disk_screen (int rep, int display)
|
||||
} table[256];
|
||||
int i;
|
||||
static int num_disks = 0;
|
||||
static int first = 1; // First line to display, sort of.
|
||||
static int dev_wid = 6;
|
||||
static int gauge_wid = 6;
|
||||
|
||||
#define huge long long int
|
||||
huge size;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
first = FALSE;
|
||||
#endif
|
||||
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);
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef DISK_H
|
||||
#define DISK_H
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
int disk_screen (int rep, int display, int * flags_ptr);
|
||||
#else
|
||||
int disk_screen (int rep, int display);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+13
-3
@@ -26,17 +26,27 @@
|
||||
// +--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
xload_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
xload_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
static int first = 1;
|
||||
static int gauge_hgt = 0;
|
||||
static double loads[LCD_MAX_WIDTH];
|
||||
int loadtop, i;
|
||||
double loadmax = 0, factor;
|
||||
int status = 0;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if (first) { // Only the first time this is ever called...
|
||||
first = 0;
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = FALSE;
|
||||
#endif
|
||||
gauge_hgt = (lcd_hgt > 2) ? (lcd_hgt - 1) : lcd_hgt;
|
||||
memset (loads, '\0', sizeof (double) * LCD_MAX_WIDTH);
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
#define LOAD_MIN 0.5
|
||||
#endif
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
int xload_screen (int rep, int display, int * flags_ptr);
|
||||
#else
|
||||
int xload_screen (int rep, int display);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+156
-14
@@ -45,25 +45,37 @@ static void HelpScreen();
|
||||
static void exit_program(int val);
|
||||
static void main_loop();
|
||||
|
||||
static mode *sequence = NULL;
|
||||
static int islow = -1;
|
||||
|
||||
// 1/8th second is a single time unit...
|
||||
#define TIME_UNIT 125000
|
||||
|
||||
/* list of modes to run */
|
||||
static mode default_sequence[] =
|
||||
#ifdef LCDPROC_MENUS
|
||||
mode sequence[] =
|
||||
{
|
||||
// longname which on off inv timer visible
|
||||
// flags default ACTIVE will run by default
|
||||
// longname which on off inv timer flags
|
||||
{ "CPU", 'C', 1, 2, 0, 0xffff, ACTIVE,}, // [C]PU
|
||||
{ "Memory", 'M', 4, 16, 0, 0xffff, ACTIVE,}, // [M]emory
|
||||
{ "Load", 'X', 64, 128, 1, 0xffff, ACTIVE,}, // [X]-load (load histogram)
|
||||
{ "TimeDate", 'T', 4, 64, 0, 0xffff, ACTIVE,}, // [T]ime/Date
|
||||
{ "About", 'A', 999, 9999, 0, 0xffff, ACTIVE,}, // [A]bout (credits)
|
||||
#else
|
||||
mode *sequence = NULL;
|
||||
|
||||
mode default_sequence[] =
|
||||
{
|
||||
// longname which on off inv timer visible/flags
|
||||
{ "CPU", 'C', 1, 2, 0, 0xffff, 0,}, // [C]PU
|
||||
{ "Memory", 'M', 4, 16, 0, 0xffff, 0,}, // [M]emory
|
||||
{ "Load", 'X', 64, 128, 1, 0xffff, 0,}, // [X]-load (load histogram)
|
||||
{ "TimeDate", 'T', 4, 64, 0, 0xffff, 0,}, // [T]ime/Date
|
||||
{ "About", 'A', 999, 9999, 0, 0xffff, 0,}, // [A]bout (credits)
|
||||
|
||||
{ NULL, 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.
|
||||
#endif
|
||||
{ "SMP-CPU", 'P', 1, 2, 0, 0xffff, 0,}, // CPU_SM[P]
|
||||
{ "OldTime", 'O', 4, 64, 0, 0xffff, 0,}, // [O]ld Timescreen
|
||||
{ "BigClock", 'K', 4, 64, 0, 0xffff, 0,}, // big cloc[K]
|
||||
@@ -76,6 +88,13 @@ static mode default_sequence[] =
|
||||
{ NULL, 0, 0, 0, 0, 0,}, // No more.. all done.
|
||||
};
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
int seqlen = sizeof(sequence) / sizeof(mode);
|
||||
#else
|
||||
int seqlen = sizeof(default_sequence) / sizeof(mode);
|
||||
#endif //LCDPROC_MENUS
|
||||
|
||||
|
||||
// TODO: Config file; not just command line
|
||||
|
||||
const char *get_hostname()
|
||||
@@ -93,6 +112,38 @@ const char *get_sysrelease()
|
||||
return(unamebuf.release);
|
||||
}
|
||||
|
||||
#ifdef LCDPROC_MENUS //set_mode function
|
||||
int set_mode(int shortname, char * longname, int state)
|
||||
{
|
||||
int k;
|
||||
|
||||
/* ignore already selected modes */
|
||||
for (k = 0; (k < seqlen) && (sequence[k].which != 0); k++) {
|
||||
if (((sequence[k].longname != NULL) &&
|
||||
(0 == strcasecmp(longname, sequence[k].longname))) ||
|
||||
(shortname == sequence[k].which)) {
|
||||
if (!state) {
|
||||
sequence[k].flags &= (~ACTIVE & ~INITIALIZED); /* both the active and inititialized bits */
|
||||
sprintf (buffer, "screen_del %c\n", shortname );
|
||||
sock_send_string (sock, buffer);
|
||||
} else
|
||||
sequence[k].flags |= ACTIVE;
|
||||
return 1; //found
|
||||
}
|
||||
}
|
||||
return 0; //not found
|
||||
}
|
||||
|
||||
void clear_modes()
|
||||
{
|
||||
int k;
|
||||
/* ignore already selected modes */
|
||||
for (k = 0; (k < seqlen) && (sequence[k].which != 0); k++) {
|
||||
sequence[k].flags &= (~ACTIVE);
|
||||
}
|
||||
}
|
||||
#endif //LCDPROC_MENUS
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -101,8 +152,6 @@ main(int argc, char **argv)
|
||||
char *server = NULL;
|
||||
int port = LCDPORT;
|
||||
int daemonize = FALSE;
|
||||
/* determine length of default_sequence[] */
|
||||
int seqlen = sizeof(default_sequence) / sizeof(mode);
|
||||
|
||||
/* get uname information */
|
||||
if (uname(&unamebuf) == -1) {
|
||||
@@ -110,6 +159,9 @@ main(int argc, char **argv)
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
// sequence = default_sequence;
|
||||
#else
|
||||
/* allocate sequence */
|
||||
sequence = (mode *) malloc(seqlen * sizeof(mode));
|
||||
if (sequence == NULL) {
|
||||
@@ -122,6 +174,7 @@ main(int argc, char **argv)
|
||||
//sequence[i] = default_sequence[i];
|
||||
memcpy(&sequence[i], &default_sequence[i], sizeof(mode));
|
||||
}
|
||||
#endif //LCDPROC_MENUS
|
||||
|
||||
/* setup error handlers */
|
||||
signal(SIGINT, exit_program); // Ctrl-C
|
||||
@@ -164,6 +217,14 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
/* parse arguments */
|
||||
if (argc > 1 ) //user specified some modes, so clear all defaults
|
||||
clear_modes();
|
||||
for (i = (optind > 0) ? optind : 1; i < argc; i++) {
|
||||
int shortname = (strlen(argv[i]) == 1) ? toupper(argv[i][0]) : '\0';
|
||||
int found = set_mode(shortname, argv[i], 1);
|
||||
#else
|
||||
/* parse arguments */
|
||||
for (i = (optind > 0) ? optind : 1, j = 0; i < argc; i++) {
|
||||
int shortname = (strlen(argv[i]) == 1) ? toupper(argv[i][0]) : '\0';
|
||||
@@ -186,7 +247,7 @@ main(int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* try to find the mode from the mode list */
|
||||
// try to find the mode from the mode list
|
||||
for (k = 0; k < seqlen; k++) {
|
||||
if (((default_sequence[k].longname != NULL) &&
|
||||
(0 == strcasecmp(argv[i], default_sequence[k].longname))) ||
|
||||
@@ -200,7 +261,7 @@ main(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
if (!found) {
|
||||
fprintf(stderr, "Invalid Mode: %c, ignoring\n", argv[i][0]);
|
||||
return(EXIT_FAILURE);
|
||||
@@ -273,13 +334,63 @@ HelpScreen ()
|
||||
void
|
||||
exit_program(int val)
|
||||
{
|
||||
//printf("exit program\n");
|
||||
Quit = 1;
|
||||
sock_close(sock);
|
||||
mode_close();
|
||||
#ifndef LCDPROC_MENUS
|
||||
free(sequence);
|
||||
#endif
|
||||
exit(val);
|
||||
}
|
||||
|
||||
#ifdef LCDPROC_MENUS //menus_init
|
||||
int
|
||||
menus_init ()
|
||||
{
|
||||
int k;
|
||||
|
||||
for (k = 0; sequence[k].which ; k++) {
|
||||
if (sequence[k].longname) {
|
||||
sprintf (buffer, "menu_add_item {} %c checkbox {%s} -value %s\n", sequence[k].which, sequence[k].longname, sequence[k].flags & ACTIVE ? "on" : "off");
|
||||
sock_send_string (sock, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TESTMENUS
|
||||
// # to be entered on escape from test_menu (but overwritten
|
||||
// # 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} 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 {} 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_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_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_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_menu menu {Menu}\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
|
||||
// # 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} 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_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_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_ip -next {test_menu} -prev {test_alpha}\n");
|
||||
sock_send_string (sock, "menu_set_item {test} test_menu_action -next {_close_}\n");
|
||||
#endif //TESTMENUS
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif //LCDPROC_MENUS
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Main program loop...
|
||||
//
|
||||
@@ -332,7 +443,11 @@ main_loop()
|
||||
{
|
||||
if (sequence[j].which == argv[1][0])
|
||||
{
|
||||
#ifdef LCDPROC_MENUS
|
||||
sequence[j].flags |= VISIBLE;
|
||||
#else
|
||||
sequence[j].visible = 1;
|
||||
#endif
|
||||
//debug("Listen %s\n", argv[1]);
|
||||
}
|
||||
}
|
||||
@@ -343,7 +458,11 @@ main_loop()
|
||||
{
|
||||
if (sequence[j].which == argv[1][0])
|
||||
{
|
||||
#ifdef LCDPROC_MENUS
|
||||
sequence[j].flags &= ~VISIBLE;
|
||||
#else
|
||||
sequence[j].visible = 0;
|
||||
#endif
|
||||
//debug("Ignore %s\n", argv[1]);
|
||||
}
|
||||
}
|
||||
@@ -352,9 +471,19 @@ main_loop()
|
||||
{
|
||||
debug("Key %s\n", argv[1]);
|
||||
}
|
||||
#ifdef LCDPROC_MENUS
|
||||
else if (0 == strcmp(argv[0], "menuevent"))
|
||||
{
|
||||
if (argc == 4 && (0 == strcmp(argv[1], "update")))
|
||||
{
|
||||
set_mode(argv[2][0],"", strcmp(argv[3],"off"));
|
||||
}
|
||||
}
|
||||
#else
|
||||
else if (0 == strcmp(argv[0], "menu"))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
else if (0 == strcmp(argv[0], "connect"))
|
||||
{
|
||||
int a;
|
||||
@@ -370,7 +499,14 @@ main_loop()
|
||||
lcd_cellhgt = atoi(argv[++a]);
|
||||
}
|
||||
connected = 1;
|
||||
sock_send_string(sock, "client_set -name LCDproc\n");
|
||||
{
|
||||
char buffer[8192];
|
||||
snprintf(buffer, sizeof(buffer), "client_set -name {LCDproc %s}\n", get_hostname());
|
||||
sock_send_string(sock, buffer);
|
||||
}
|
||||
#ifdef LCDPROC_MENUS
|
||||
menus_init();
|
||||
#endif
|
||||
}
|
||||
else if (0 == strcmp(argv[0], "bye"))
|
||||
{
|
||||
@@ -382,10 +518,10 @@ main_loop()
|
||||
}
|
||||
else
|
||||
{
|
||||
int j;
|
||||
for(j = 0; j < argc; j++)
|
||||
printf("%s ", argv[j]);
|
||||
printf("\n");
|
||||
//int j;
|
||||
//for (j = 0; j < argc; j++)
|
||||
// printf("%s ", argv[j]);
|
||||
//printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,10 +540,16 @@ main_loop()
|
||||
// Update screens...
|
||||
if (connected)
|
||||
{
|
||||
for(i = 0; sequence[i].which > 1; i++)
|
||||
for (i = 0; sequence[i].which > 0; i++)
|
||||
{
|
||||
sequence[i].timer++;
|
||||
#ifdef LCDPROC_MENUS
|
||||
if ((sequence[i].flags & ACTIVE) == 0 )
|
||||
continue;
|
||||
if (sequence[i].flags & VISIBLE)
|
||||
#else
|
||||
if (sequence[i].visible)
|
||||
#endif
|
||||
{
|
||||
if (sequence[i].timer >= sequence[i].on_time)
|
||||
{
|
||||
|
||||
@@ -38,8 +38,16 @@ typedef struct mode
|
||||
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
|
||||
#ifdef LCDPROC_MENUS //struct mode flags
|
||||
int flags; //bit 1 visible, bit 2 selected for display, bit 3 first
|
||||
#else
|
||||
int visible; // Can we be seen right now?
|
||||
#endif //LCDPROC_MENUS
|
||||
} mode;
|
||||
//mode flags
|
||||
#define VISIBLE 0x00000001 //currently visible
|
||||
#define ACTIVE 0x00000002 //selected for display
|
||||
#define INITIALIZED 0x00000004 //replaces the first variable to indicate whether the update screens are initialized
|
||||
|
||||
#define BLINK_ON 0x10
|
||||
#define BLINK_OFF 0x11
|
||||
|
||||
+24
-4
@@ -29,16 +29,26 @@
|
||||
// +--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
mem_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
mem_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
static int first = 1;
|
||||
static int which_title = 0;
|
||||
static int gauge_wid = 0;
|
||||
static int gauge_offs = 0;
|
||||
meminfo_type mem[2];
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
sock_send_string(sock, "screen_add M\n");
|
||||
sprintf(buffer, "screen_set M -name {Memory & Swap: %s}\n", get_hostname());
|
||||
@@ -238,14 +248,24 @@ sort_procs (void *a, void *b)
|
||||
// +--------------------+
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
mem_top_screen (int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
mem_top_screen (int rep, int display)
|
||||
#endif
|
||||
{
|
||||
static int first = 1;
|
||||
LinkedList *procs;
|
||||
int i;
|
||||
#ifdef LCDPROC_MENUS
|
||||
|
||||
if ((*flags_ptr & INITIALIZED) == 0) {
|
||||
*flags_ptr |= INITIALIZED;
|
||||
#else
|
||||
static int first = TRUE;
|
||||
|
||||
if (first) {
|
||||
first = 0;
|
||||
first = FALSE;
|
||||
#endif
|
||||
|
||||
sock_send_string(sock, "screen_add S\n");
|
||||
sprintf(buffer, "screen_set S -name {Top Memory Use: %s}\n", get_hostname());
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#ifndef MEM_H
|
||||
#define MEM_H
|
||||
|
||||
#ifdef LCDPROC_MENUS
|
||||
int mem_screen (int rep, int display, int * flags_ptr);
|
||||
int mem_top_screen (int rep, int display, int * flags_ptr);
|
||||
#else
|
||||
int mem_screen (int rep, int display);
|
||||
int mem_top_screen (int rep, int display);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -81,6 +81,64 @@ update_screen(mode *m, int display)
|
||||
{
|
||||
switch(m->which)
|
||||
{
|
||||
#ifdef LCDPROC_MENUS
|
||||
case 'g':
|
||||
case 'G':
|
||||
status = cpu_graph_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
status = cpu_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'o':
|
||||
case 'O':
|
||||
status = clock_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'k':
|
||||
case 'K':
|
||||
status = big_clock_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
status = mem_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 's':
|
||||
case 'S':
|
||||
status = mem_top_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'u':
|
||||
case 'U':
|
||||
status = uptime_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 't':
|
||||
case 'T':
|
||||
status = time_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
status = disk_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'x':
|
||||
case 'X':
|
||||
status = xload_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'b':
|
||||
case 'B':
|
||||
status = battery_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'a':
|
||||
case 'A':
|
||||
status = credit_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
status = cpu_smp_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
case 'e':
|
||||
case 'E':
|
||||
status = essential_clock_screen(m->timer, display, &(m->flags));
|
||||
break;
|
||||
#else
|
||||
case 'g':
|
||||
case 'G':
|
||||
status = cpu_graph_screen(m->timer, display);
|
||||
@@ -137,6 +195,7 @@ update_screen(mode *m, int display)
|
||||
case 'E':
|
||||
status = essential_clock_screen(m->timer, display);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -164,7 +223,11 @@ update_screen(mode *m, int display)
|
||||
// Credit Screen shows who wrote this...
|
||||
//
|
||||
int
|
||||
#ifdef LCDPROC_MENUS
|
||||
credit_screen(int rep, int display, int * flags_ptr)
|
||||
#else
|
||||
credit_screen(int rep, int display)
|
||||
#endif
|
||||
{
|
||||
static int first = 1;
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@ int mode_init ();
|
||||
void mode_close ();
|
||||
|
||||
int update_screen (mode * m, int display);
|
||||
#ifdef LCDPROC_MENUS
|
||||
int credit_screen (int rep, int display, int * flags_ptr);
|
||||
#else
|
||||
int credit_screen (int rep, int display);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user