#include #include #include #include #include #include #include #include #include #include #include "main.h" #include "lcd.h" #include "mode.h" //#include "lock.h" #include "sockets.h" // TODO: Commenting... Everything! char version[] = "v0.3.4"; char build_date[] = "1998-06-20"; int Quit = 0; /* Mode List: See below... (default_sequence[]) */ typedef struct mode { char which; int num_times; int delay_time; } mode; void HelpScreen(); void exit_program(int val); void main_loop(mode *sequence); #define MAX_SEQUENCE 256 // 1/8th second is a single time unit... #define TIME_UNIT 125000 // Contains a list of modes to run mode default_sequence[] = { { 'C', 32, 1, },// [C]PU { 'M', 8, 4, },// [M]emory { 'X', 1, 32, },// [X]-load (load histogram) { 'T', 8, 4, },// [T]ime/Date { 'D', 32, 1, },// [D]isk stats { 'A', 1, 16, },// [A]bout (credits) { 1 , 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. { 'O', 8, 4, },// [O]ld Timescreen { 'U', 8, 4, },// Old [U]ptime Screen { 'B', 32, 1, },// [B]attery Status { 'G', 32, 1, },// Cpu histogram [G]raph { 0, 0, 0, },// No more.. all done. }; // TODO: Clean up main()... It is still way too big. // TODO: Socket language, client handling... // TODO: Config file; not just command line int main(int argc, char **argv) { char device[256] = "/dev/lcd"; char cfgfile[256] = "/etc/lcdproc.cf"; mode sequence[MAX_SEQUENCE]; char driver[256] = "MtxOrb"; int i, j, k; int already_running = 0; int contrast = 140; int tmp; memset(sequence, 0, sizeof(mode) * MAX_SEQUENCE); // Ctrl-C will cause a clean exit... signal(SIGINT, exit_program); // and "kill"... signal(SIGTERM, exit_program); // and "kill -HUP" (hangup)... signal(SIGHUP, exit_program); // and just in case, "kill -KILL" (which cannot be trapped; but oh well) signal(SIGKILL, exit_program); // Check to see if we are already running... // already_running = CheckForLock(); already_running = PingLCDport(); if(already_running < 0) { printf("Error checking for another LCDproc.\n"); return -1; } // Communicate with the previously running LCDproc if(already_running > 0) { // "already_running" holds the pid of the LCDproc we want to talk to... // Do the command line ("lcd pet status", or "lcd contrast 50") // And stuff... // ...Then exit printf("Detected another LCDproc. (%i) Exiting...\n", already_running); // Remove me ^^^^ return 0; } tmp = StartSocketServer(); if (tmp <= 0) { printf("Error starting socket server.\n"); return 0; } // Command line memcpy(sequence, default_sequence, sizeof(default_sequence)); for(i=1, j=0; i