Removed lcddriver.c (doesn't do anything, isn't in any makefiles, etc.).

Passed *every* piece of source in this project through indent. I'm setting
things up with ctags soon and am actually going to *gasp* use a nice
programming environment to continue development in. :)
This commit is contained in:
William Ferrell
2000-03-30 20:20:41 +00:00
parent 2222adcfbe
commit f5a5e9653b
88 changed files with 8207 additions and 8723 deletions
+1 -1
View File
@@ -73,8 +73,8 @@
/* Define the package version */ /* Define the package version */
#undef VERSION #undef VERSION
/* Leave that blank line there!! Autoheader needs it. /* Leave that blank line there!! Autoheader needs it.
If you're adding to this file, keep in mind: If you're adding to this file, keep in mind:
The entries are in sort -df order: alphabetical, case insensitive, The entries are in sort -df order: alphabetical, case insensitive,
+126 -120
View File
@@ -14,48 +14,51 @@
int batt_fd = 0; int batt_fd = 0;
static int get_batt_stat(int *acstat, int *battstat, static int get_batt_stat (int *acstat, int *battstat, int *battflag, int *percent);
int *battflag, int *percent);
static int get_batt_stat(int *acstat, int *battstat, static int
int *battflag, int *percent) get_batt_stat (int *acstat, int *battstat, int *battflag, int *percent)
{ {
char str[64]; char str[64];
if(!batt_fd)
batt_fd = open("/proc/apm", O_RDONLY);
if(batt_fd <= 0) return -1;
if(lseek(batt_fd, 0, 0) != 0) return -1; if (!batt_fd)
batt_fd = open ("/proc/apm", O_RDONLY);
if (batt_fd <= 0)
return -1;
if(read(batt_fd, str, sizeof(str)-1) < 0) return -1; if (lseek (batt_fd, 0, 0) != 0)
return -1;
if(3 > sscanf(str+13, "0x%x 0x%x 0x%x %d",
acstat, battstat, battflag, percent)) if (read (batt_fd, str, sizeof (str) - 1) < 0)
return -1; return -1;
if (3 > sscanf (str + 13, "0x%x 0x%x 0x%x %d", acstat, battstat, battflag, percent))
return -1;
return 0;
return 0;
} }
int batt_init() int
batt_init ()
{ {
static int first = 1; static int first = 1;
if(first) if (first) {
{
first = 0; first = 0;
sock_send_string(sock, "screen_add B\n"); sock_send_string (sock, "screen_add B\n");
} }
return 0; return 0;
} }
int batt_close() int
batt_close ()
{ {
if(batt_fd) close(batt_fd); if (batt_fd)
close (batt_fd);
batt_fd = 0; batt_fd = 0;
return 0; return 0;
@@ -72,122 +75,125 @@ int batt_close()
//Batt: Low (Charging) //Batt: Low (Charging)
//E------------------F //E------------------F
int battery_screen(int rep, int display) int
battery_screen (int rep, int display)
{ {
static int first=1; static int first = 1;
int acstat=0, battstat=0, battflag=0, percent=0; int acstat = 0, battstat = 0, battflag = 0, percent = 0;
if(first)
{ if (first) {
first = 0; first = 0;
sprintf(buffer, "screen_set B -name {APM stats: %s}\n", host); sprintf (buffer, "screen_set B -name {APM stats: %s}\n", host);
sock_send_string(sock, buffer); 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");
sprintf(tmp, "widget_set B title {LCDPROC %s}\n", version); sprintf (tmp, "widget_set B title {LCDPROC %s}\n", version);
sock_send_string(sock, tmp); sock_send_string (sock, tmp);
sock_send_string(sock, "widget_add B one string\n"); 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, sock_send_string (sock, "widget_set B two 1 3 {Batt: Unknown}\n");
"widget_set B one 1 2 {AC: Unknown}\n"); sock_send_string (sock, "widget_set B three 1 4 {E F}\n");
sock_send_string(sock, sock_send_string (sock, "widget_set B gauge 2 4 0\n");
"widget_set B two 1 3 {Batt: Unknown}\n");
sock_send_string(sock,
"widget_set B three 1 4 {E F}\n");
sock_send_string(sock, "widget_set B gauge 2 4 0\n");
} }
} }
// Only run once every 16 frames... // Only run once every 16 frames...
//if(rep&0x0f) return 0; //if(rep&0x0f) return 0;
get_batt_stat(&acstat, &battstat, &battflag, &percent); get_batt_stat (&acstat, &battstat, &battflag, &percent);
if(percent >= 0) sprintf(buffer, "%i%%", percent); if (percent >= 0)
else sprintf(buffer, "??%%"); sprintf (buffer, "%i%%", percent);
sprintf(tmp, "widget_set B title {Batt: %s: %s}\n", buffer, host); else
sprintf (buffer, "??%%");
if(display) sock_send_string(sock, tmp); sprintf (tmp, "widget_set B title {Batt: %s: %s}\n", buffer, host);
if(lcd_hgt >= 4) // 4-line version of the screen if (display)
sock_send_string (sock, tmp);
if (lcd_hgt >= 4) // 4-line version of the screen
{ {
sprintf(tmp, "widget_set B one 1 2 {"); sprintf (tmp, "widget_set B one 1 2 {");
switch(acstat) switch (acstat) {
{ case 0:
case 0: sprintf(tmp+strlen(tmp), "AC: Off}\n"); sprintf (tmp + strlen (tmp), "AC: Off}\n");
break; break;
case 1: sprintf(tmp+strlen(tmp), "AC: On}\n"); case 1:
break; sprintf (tmp + strlen (tmp), "AC: On}\n");
case 2: sprintf(tmp+strlen(tmp), "AC: Backup}\n"); break;
break; case 2:
default: sprintf(tmp+strlen(tmp), "AC: Unknown}\n"); sprintf (tmp + strlen (tmp), "AC: Backup}\n");
break; break;
default:
sprintf (tmp + strlen (tmp), "AC: Unknown}\n");
break;
} }
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
sprintf(tmp, "widget_set B two 1 3 {");
if(battflag == 0xff)
{
sprintf(tmp+strlen(tmp), "Battery Stat Unknown");
}
else
{
sprintf(tmp+strlen(tmp), "Batt:");
if(battflag & 1) sprintf(tmp+strlen(tmp), " High");
if(battflag & 2) sprintf(tmp+strlen(tmp), " Low");
if(battflag & 4) sprintf(tmp+strlen(tmp), " Critical");
if(battflag & 8
||battstat == 3) sprintf(tmp+strlen(tmp), " Charging");
if(battflag & 128) sprintf(tmp+strlen(tmp), " (NONE)");
}
sprintf(tmp+strlen(tmp), "}\n");
if(display) sock_send_string(sock, tmp);
if(percent > 0) sprintf (tmp, "widget_set B two 1 3 {");
{ if (battflag == 0xff) {
sprintf(tmp, "widget_set B gauge 2 4 %i\n", sprintf (tmp + strlen (tmp), "Battery Stat Unknown");
(percent * ((lcd_wid-2)*lcd_cellwid)/100)); } else {
if(display) sock_send_string(sock, tmp); sprintf (tmp + strlen (tmp), "Batt:");
if (battflag & 1)
sprintf (tmp + strlen (tmp), " High");
if (battflag & 2)
sprintf (tmp + strlen (tmp), " Low");
if (battflag & 4)
sprintf (tmp + strlen (tmp), " Critical");
if (battflag & 8 || battstat == 3)
sprintf (tmp + strlen (tmp), " Charging");
if (battflag & 128)
sprintf (tmp + strlen (tmp), " (NONE)");
} }
} // end if(lcd_hgt >= 4) sprintf (tmp + strlen (tmp), "}\n");
else // two-line version of the screen if (display)
sock_send_string (sock, tmp);
if (percent > 0) {
sprintf (tmp, "widget_set B gauge 2 4 %i\n", (percent * ((lcd_wid - 2) * lcd_cellwid) / 100));
if (display)
sock_send_string (sock, tmp);
}
} // end if(lcd_hgt >= 4)
else // two-line version of the screen
{ {
sprintf(tmp, "widget_set B one 1 2 {"); sprintf (tmp, "widget_set B one 1 2 {");
if(acstat == 1) if (acstat == 1)
sprintf(tmp+strlen(tmp), "AC, "); sprintf (tmp + strlen (tmp), "AC, ");
if(battflag == 0xff) if (battflag == 0xff) {
{ sprintf (tmp + strlen (tmp), "No battery???");
sprintf(tmp+strlen(tmp), "No battery???"); } else {
sprintf (tmp + strlen (tmp), "Batt:");
if (battflag & 1)
sprintf (tmp + strlen (tmp), " High");
if (battflag & 2)
sprintf (tmp + strlen (tmp), " Low");
if (battflag & 4)
sprintf (tmp + strlen (tmp), " Critical");
if (battflag & 8 || battstat == 3)
sprintf (tmp + strlen (tmp), " Charging");
if (battflag & 128)
sprintf (tmp + strlen (tmp), " (NONE)");
} }
else sprintf (tmp + strlen (tmp), "}\n");
{ if (display)
sprintf(tmp+strlen(tmp), "Batt:"); sock_send_string (sock, tmp);
if(battflag & 1) sprintf(tmp+strlen(tmp), " High");
if(battflag & 2) sprintf(tmp+strlen(tmp), " Low");
if(battflag & 4) sprintf(tmp+strlen(tmp), " Critical");
if(battflag & 8
||battstat == 3) sprintf(tmp+strlen(tmp), " Charging");
if(battflag & 128) sprintf(tmp+strlen(tmp), " (NONE)");
}
sprintf(tmp+strlen(tmp), "}\n");
if(display) sock_send_string(sock, tmp);
} }
return 0; return 0;
} }
+3 -3
View File
@@ -1,10 +1,10 @@
#ifndef BATT_H #ifndef BATT_H
#define BATT_H #define BATT_H
int batt_init(); int batt_init ();
int batt_close(); int batt_close ();
int battery_screen(int rep, int display); int battery_screen (int rep, int display);
#endif #endif
+320 -341
View File
@@ -12,118 +12,120 @@
#include "mode.h" #include "mode.h"
#include "chrono.h" #include "chrono.h"
int TwentyFourHour=1; int TwentyFourHour = 1;
int uptime_fd = 0; int uptime_fd = 0;
static char kver[SYS_NMLN]; static char kver[SYS_NMLN];
static char sysname[SYS_NMLN]; static char sysname[SYS_NMLN];
static double get_uptime(double *up, double *idle); static double get_uptime (double *up, double *idle);
static double get_uptime(double *up, double *idle) static double
get_uptime (double *up, double *idle)
{ {
double uptime; double uptime;
reread(uptime_fd, "get_uptime:"); reread (uptime_fd, "get_uptime:");
sscanf(buffer, "%lf %lf", &uptime, idle); sscanf (buffer, "%lf %lf", &uptime, idle);
*up = uptime; *up = uptime;
return uptime; return uptime;
} }
// A couple of tables for later use... // A couple of tables for later use...
static char *days[] = { static char *days[] = {
"Sunday, ", "Sunday, ",
"Monday, ", "Monday, ",
"Tuesday, ", "Tuesday, ",
"Wednesday,", "Wednesday,",
"Thursday, ", "Thursday, ",
"Friday, ", "Friday, ",
"Saturday, ", "Saturday, ",
}; };
static char *shortdays[] = { static char *shortdays[] = {
"Sun", "Sun",
"Mon", "Mon",
"Tue", "Tue",
"Wed", "Wed",
"Thu", "Thu",
"Fri", "Fri",
"Sat", "Sat",
}; };
static char *months[] = { static char *months[] = {
" January", " January",
" February", " February",
" March", " March",
" April", " April",
" May", " May",
" June", " June",
" July", " July",
" August", " August",
"September", "September",
" October", " October",
" November", " November",
" December", " December",
}; };
static char *shortmonths[] = { static char *shortmonths[] = {
"Jan", "Jan",
"Feb", "Feb",
"Mar", "Mar",
"Apr", "Apr",
"May", "May",
"Jun", "Jun",
"Jul", "Jul",
"Aug", "Aug",
"Sep", "Sep",
"Oct", "Oct",
"Nov", "Nov",
"Dec", "Dec",
}; };
int chrono_init() int
chrono_init ()
{ {
struct utsname *unamebuf; struct utsname *unamebuf;
if(!uptime_fd) if (!uptime_fd) {
{ unamebuf = (struct utsname *) malloc (sizeof (struct utsname));
unamebuf = (struct utsname *) malloc( sizeof(struct utsname) ); uptime_fd = open ("/proc/uptime", O_RDONLY);
uptime_fd = open("/proc/uptime",O_RDONLY);
#if 0 #if 0
kversion_fd = open("/proc/sys/kernel/osrelease",O_RDONLY); kversion_fd = open ("/proc/sys/kernel/osrelease", O_RDONLY);
reread(kversion_fd, "main:"); reread (kversion_fd, "main:");
sscanf(buffer, "%s", kver); sscanf (buffer, "%s", kver);
close(kversion_fd); close (kversion_fd);
# endif # endif
/* Get OS name and version from uname() */ /* Get OS name and version from uname() */
if( uname( unamebuf ) != 0 ) { if (uname (unamebuf) != 0) {
perror( "Error calling uname:" ); perror ("Error calling uname:");
} }
strcpy( kver, unamebuf->release ); strcpy (kver, unamebuf->release);
strcpy( sysname, unamebuf->sysname ); strcpy (sysname, unamebuf->sysname);
free(unamebuf); free (unamebuf);
} }
return 0; return 0;
} }
int chrono_close() int
chrono_close ()
{ {
if(uptime_fd) if (uptime_fd)
close(uptime_fd); close (uptime_fd);
uptime_fd = 0; uptime_fd = 0;
@@ -143,7 +145,8 @@ int chrono_close()
//+--------------------+ //+--------------------+
// //
int time_screen(int rep, int display) int
time_screen (int rep, int display)
{ {
char hr[8], min[8], sec[8], ampm[8]; char hr[8], min[8], sec[8], ampm[8];
char day[16], month[16]; char day[16], month[16];
@@ -156,157 +159,146 @@ int time_screen(int rep, int display)
char colon; char colon;
if(first) if (first) {
{
first = 0; first = 0;
sock_send_string(sock, "screen_add T\n"); sock_send_string (sock, "screen_add T\n");
sprintf(buffer, "screen_set T -name {Time Screen: %s}\n", host); sprintf (buffer, "screen_set T -name {Time Screen: %s}\n", host);
sock_send_string(sock, buffer); sock_send_string (sock, buffer);
sock_send_string(sock, "widget_add T title title\n"); sock_send_string (sock, "widget_add T title title\n");
sock_send_string(sock, "widget_set T title {Time Screen}\n"); sock_send_string (sock, "widget_set T title {Time Screen}\n");
sock_send_string(sock, "widget_add T one string\n"); sock_send_string (sock, "widget_add T one string\n");
if(lcd_hgt >= 4) if (lcd_hgt >= 4) {
{ sock_send_string (sock, "widget_add T two string\n");
sock_send_string(sock, "widget_add T two string\n"); sock_send_string (sock, "widget_add T three string\n");
sock_send_string(sock, "widget_add T three string\n"); } else {
} sprintf (buffer, "widget_set T title {TIME: %s}\n", host);
else sock_send_string (sock, buffer);
{
sprintf(buffer, "widget_set T title {TIME: %s}\n", host);
sock_send_string(sock, buffer);
} }
} }
if(colons) if (colons)
colon = ':'; colon = ':';
else else
colon = ' '; colon = ' ';
time(&thetime); time (&thetime);
rtime = localtime(&thetime); rtime = localtime (&thetime);
if(TwentyFourHour) if (TwentyFourHour) {
{ sprintf (hr, "%02d", rtime->tm_hour);
sprintf(hr, "%02d", rtime->tm_hour); } else {
if (rtime->tm_hour > 12) {
i = 1;
sprintf (hr, "%02d", (rtime->tm_hour - 12));
} else if (rtime->tm_hour == 0) {
i = 0;
sprintf (hr, "12");
} else {
i = 0;
sprintf (hr, "%02d", rtime->tm_hour);
}
} }
if (rtime->tm_hour >= 12)
sprintf (ampm, "%s", "P");
else else
{ sprintf (ampm, "%s", "A");
if (rtime->tm_hour > 12)
{ sprintf (min, "%02d", rtime->tm_min);
i = 1; sprintf(hr, "%02d", (rtime->tm_hour - 12)); sprintf (sec, "%02d", rtime->tm_sec);
}
else if(rtime->tm_hour == 0)
{ strcpy (day, shortdays[rtime->tm_wday]);
i = 0; sprintf(hr, "12"); strcpy (month, shortmonths[rtime->tm_mon]);
}
else
{
i = 0; sprintf(hr, "%02d", rtime->tm_hour);
}
}
if(rtime->tm_hour >= 12) sprintf(ampm, "%s", "P");
else sprintf(ampm, "%s", "A");
sprintf(min, "%02d", rtime->tm_min);
sprintf(sec, "%02d", rtime->tm_sec);
strcpy(day, shortdays[rtime->tm_wday]);
strcpy(month, shortmonths[rtime->tm_mon]);
///////////////////// Write the title bar (os name and version) ///////////////////// Write the title bar (os name and version)
if(lcd_hgt >= 4) if (lcd_hgt >= 4) {
{ sprintf (tmp, "widget_set T title {");
sprintf(tmp, "widget_set T title {"); sprintf (tmp + strlen (tmp), "%s %s: %s}\n", sysname, kver, host);
sprintf(tmp+strlen(tmp), "%s %s: %s}\n", if (display)
sysname, kver, host); sock_send_string (sock, tmp);
if(display) sock_send_string(sock, tmp);
} }
/////////////////////// Display the time... /////////////////////// Display the time...
if(lcd_hgt >= 4) if (lcd_hgt >= 4) {
{ get_uptime (&uptime, &idle);
get_uptime(&uptime, &idle);
idle = (idle * 100) / uptime; idle = (idle * 100) / uptime;
if(TwentyFourHour) if (TwentyFourHour)
sprintf(tmp, "%s%c%s%c%s %2i%% idle", sprintf (tmp, "%s%c%s%c%s %2i%% idle", hr, colon, min, colon, sec, (int) idle);
hr, colon, min, colon, sec, (int)idle);
else else
sprintf(tmp, "%s%c%s%c%s%s %2i%% idle", sprintf (tmp, "%s%c%s%c%s%s %2i%% idle", hr, colon, min, colon, sec, ampm, (int) idle);
hr, colon, min, colon, sec, ampm, (int)idle);
// Center the output line... // Center the output line...
i = ((lcd_wid - strlen(tmp)) / 2) + 1; i = ((lcd_wid - strlen (tmp)) / 2) + 1;
sprintf(buffer, "widget_set T three %i 4 {%s}\n", i, tmp); sprintf (buffer, "widget_set T three %i 4 {%s}\n", i, tmp);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
sprintf(tmp, "%s %s %d, %d", day, month, sprintf (tmp, "%s %s %d, %d", day, month, rtime->tm_mday, (rtime->tm_year + 1900));
rtime->tm_mday, (rtime->tm_year + 1900)); sprintf (buffer, "widget_set T two 3 3 {%s}\n", tmp);
sprintf(buffer, "widget_set T two 3 3 {%s}\n", tmp); if (display)
if(display) sock_send_string(sock, buffer); sock_send_string (sock, buffer);
/////////////////////// Display the uptime... /////////////////////// Display the uptime...
i = (int)uptime / 86400; i = (int) uptime / 86400;
sprintf(day, "Up %d day%s,", i, (i != 1 ? "s" : "")); sprintf (day, "Up %d day%s,", i, (i != 1 ? "s" : ""));
i = ((int)uptime % 86400) / 60 / 60; i = ((int) uptime % 86400) / 60 / 60;
sprintf(hr, "%02i",i); sprintf (hr, "%02i", i);
i = (((int)uptime % 86400) % 3600) / 60; i = (((int) uptime % 86400) % 3600) / 60;
sprintf(min, "%02i",i); sprintf (min, "%02i", i);
i = ((int)uptime % 60); i = ((int) uptime % 60);
sprintf(sec, "%02i",i); sprintf (sec, "%02i", i);
if (colons) if (colons)
sprintf(tmp, "%s %s:%s:%s", day, hr, min, sec); sprintf (tmp, "%s %s:%s:%s", day, hr, min, sec);
else else
sprintf(tmp, "%s %s %s %s", day, hr, min, sec); sprintf (tmp, "%s %s %s %s", day, hr, min, sec);
//// Center this line automatically... //// Center this line automatically...
//i = ((lcd_wid - strlen(tmp)) / 2) + 1; //i = ((lcd_wid - strlen(tmp)) / 2) + 1;
sprintf(buffer, "widget_set T one 1 2 {%s}\n", tmp); sprintf (buffer, "widget_set T one 1 2 {%s}\n", tmp);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
} } else // 20x2 version of the screen
else // 20x2 version of the screen
{ {
sprintf(tmp, "widget_set T one 1 2 {"); sprintf (tmp, "widget_set T one 1 2 {");
if(lcd_wid >= 20) if (lcd_wid >= 20)
sprintf(tmp+strlen(tmp), "%d-%02d-%02d ", sprintf (tmp + strlen (tmp), "%d-%02d-%02d ", rtime->tm_year + 1900, rtime->tm_mon + 1, rtime->tm_mday);
rtime->tm_year+1900, rtime->tm_mon+1, rtime->tm_mday); else // 16x2 version...
else // 16x2 version... sprintf (tmp + strlen (tmp), "%02d/%02d ", rtime->tm_mon + 1, rtime->tm_mday);
sprintf(tmp+strlen(tmp), "%02d/%02d ", sprintf (tmp + strlen (tmp), "%s%c%s%c%s", hr, colon, min, colon, sec);
rtime->tm_mon+1, rtime->tm_mday); if (!TwentyFourHour)
sprintf(tmp+strlen(tmp), "%s%c%s%c%s", hr, colon, min, colon, sec); sprintf (tmp + strlen (tmp), "%s", ampm);
if(! TwentyFourHour) sprintf (tmp + strlen (tmp), "}\n");
sprintf(tmp+strlen(tmp), "%s", ampm); if (display)
sprintf(tmp+strlen(tmp), "}\n"); sock_send_string (sock, tmp);
if(display) sock_send_string(sock, tmp);
} }
colons = colons ^ 1; colons = colons ^ 1;
return 0; return 0;
} // End time_screen() } // End time_screen()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Clock Screen displays current time and date... // Clock Screen displays current time and date...
// //
int clock_screen(int rep, int display) int
clock_screen (int rep, int display)
{ {
char hr[8], min[8], sec[8], ampm[8]; char hr[8], min[8], sec[8], ampm[8];
char day[16], month[16]; char day[16], month[16];
@@ -314,114 +306,108 @@ int clock_screen(int rep, int display)
static int colons = 0; static int colons = 0;
time_t thetime; time_t thetime;
struct tm *rtime; struct tm *rtime;
int i=0; int i = 0;
char colon; char colon;
if(lcd_hgt < 4) return 0; if (lcd_hgt < 4)
return 0;
if(first)
{ if (first) {
first = 0; first = 0;
sock_send_string(sock, "screen_add O\n"); sock_send_string (sock, "screen_add O\n");
sprintf(buffer, "screen_set O -name {Clock Screen: %s}\n", host); sprintf (buffer, "screen_set O -name {Clock Screen: %s}\n", host);
sock_send_string(sock, buffer); sock_send_string (sock, buffer);
sock_send_string(sock, "widget_add O title title\n"); sock_send_string (sock, "widget_add O title title\n");
sock_send_string(sock, "widget_add O one string\n"); sock_send_string (sock, "widget_add O one string\n");
if(lcd_hgt >= 4) if (lcd_hgt >= 4) {
{ sock_send_string (sock, "widget_set O title {DATE & TIME}\n");
sock_send_string(sock, "widget_set O title {DATE & TIME}\n"); sock_send_string (sock, "widget_add O two string\n");
sock_send_string(sock, "widget_add O two string\n"); sock_send_string (sock, "widget_add O three string\n");
sock_send_string(sock, "widget_add O three string\n"); sprintf (buffer, "widget_set O one 3 2 {%s}\n", host);
sprintf(buffer, "widget_set O one 3 2 {%s}\n", host); sock_send_string (sock, buffer);
sock_send_string(sock, buffer); } else {
} sprintf (buffer, "widget_set O title {TIME: %s}\n", host);
else sock_send_string (sock, buffer);
{
sprintf(buffer, "widget_set O title {TIME: %s}\n", host);
sock_send_string(sock, buffer);
} }
} }
if(colons)
if (colons)
colon = ':'; colon = ':';
else else
colon = ' '; colon = ' ';
time(&thetime);
rtime = localtime(&thetime);
strcpy(day, days[rtime->tm_wday]); time (&thetime);
rtime = localtime (&thetime);
if(TwentyFourHour) strcpy (day, days[rtime->tm_wday]);
{
sprintf(hr, "%02d", rtime->tm_hour); if (TwentyFourHour) {
sprintf (hr, "%02d", rtime->tm_hour);
} else {
if (rtime->tm_hour > 12) {
i = 1;
sprintf (hr, "%02d", (rtime->tm_hour - 12));
} else {
i = 0;
sprintf (hr, "%02d", rtime->tm_hour);
}
} }
else if (rtime->tm_hour == 12)
{ i = 1;
if (rtime->tm_hour > 12) sprintf (min, "%02d", rtime->tm_min);
{ sprintf (sec, "%02d", rtime->tm_sec);
i = 1; sprintf(hr, "%02d", (rtime->tm_hour - 12)); if (i == 1) {
} sprintf (ampm, "%s", "P");
else } else {
{ sprintf (ampm, "%s", "A");
i = 0; sprintf(hr, "%02d", rtime->tm_hour);
}
} }
if(rtime->tm_hour == 12) i=1; strcpy (month, months[rtime->tm_mon]);
sprintf(min, "%02d", rtime->tm_min);
sprintf(sec, "%02d", rtime->tm_sec);
if (i == 1) { sprintf(ampm, "%s", "P"); }
else { sprintf(ampm, "%s", "A"); }
strcpy(month, months[rtime->tm_mon]);
if(lcd_hgt >= 4) // 4-line version of the screen if (lcd_hgt >= 4) // 4-line version of the screen
{ {
sprintf(tmp, "widget_set O two 1 3 {"); sprintf (tmp, "widget_set O two 1 3 {");
if(TwentyFourHour) if (TwentyFourHour)
sprintf(tmp+strlen(tmp), "%s%c%s%c%s %s", sprintf (tmp + strlen (tmp), "%s%c%s%c%s %s", hr, colon, min, colon, sec, day);
hr, colon, min, colon, sec, day);
else else
sprintf(tmp+strlen(tmp), "%s%c%s%c%s%s %s", sprintf (tmp + strlen (tmp), "%s%c%s%c%s%s %s", hr, colon, min, colon, sec, ampm, day);
hr, colon, min, colon, sec, ampm, day); sprintf (tmp + strlen (tmp), "}\n");
sprintf(tmp+strlen(tmp), "}\n"); if (display)
if(display) sock_send_string(sock, tmp); sock_send_string (sock, tmp);
sprintf(tmp, "widget_set O three 2 4 {"); sprintf (tmp, "widget_set O three 2 4 {");
sprintf(tmp+strlen(tmp), sprintf (tmp + strlen (tmp), "%s %d, %d", month, rtime->tm_mday, (rtime->tm_year + 1900));
"%s %d, %d", sprintf (tmp + strlen (tmp), "}\n");
month, if (display)
rtime->tm_mday, sock_send_string (sock, tmp);
(rtime->tm_year + 1900)); } // end if(lcd_hgt >= 4)
sprintf(tmp+strlen(tmp), "}\n"); else // 20x2 version of the screen
if(display) sock_send_string(sock, tmp);
} // end if(lcd_hgt >= 4)
else // 20x2 version of the screen
{ {
sprintf(tmp, "widget_set O one 1 2 {"); sprintf (tmp, "widget_set O one 1 2 {");
sprintf(tmp+strlen(tmp), "%d-%02d-%02d ", sprintf (tmp + strlen (tmp), "%d-%02d-%02d ", rtime->tm_year + 1900, rtime->tm_mon + 1, rtime->tm_mday);
rtime->tm_year+1900, rtime->tm_mon+1, rtime->tm_mday); sprintf (tmp + strlen (tmp), "%s%c%s%c%s", hr, colon, min, colon, sec);
sprintf(tmp+strlen(tmp), "%s%c%s%c%s", hr, colon, min, colon, sec); if (!TwentyFourHour)
if(! TwentyFourHour) sprintf (tmp + strlen (tmp), "%s", ampm);
sprintf(tmp+strlen(tmp), "%s", ampm); sprintf (tmp + strlen (tmp), "}\n");
sprintf(tmp+strlen(tmp), "}\n"); if (display)
if(display) sock_send_string(sock, tmp); sock_send_string (sock, tmp);
} }
colons = colons ^ 1; colons = colons ^ 1;
return 0; return 0;
} // End clock_screen() } // End clock_screen()
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Uptime Screen shows info about system uptime and OS version // Uptime Screen shows info about system uptime and OS version
// //
int uptime_screen(int rep, int display) int
uptime_screen (int rep, int display)
{ {
int i; int i;
char date[16], hour[8], min[8], sec[8]; char date[16], hour[8], min[8], sec[8];
@@ -430,62 +416,58 @@ int uptime_screen(int rep, int display)
static int colons = 0; static int colons = 0;
char colon; char colon;
if(first) if (first) {
{
first = 0; first = 0;
sock_send_string(sock, "screen_add U\n"); sock_send_string (sock, "screen_add U\n");
sprintf(buffer, "screen_set U -name {Uptime Screen: %s}\n", host); sprintf (buffer, "screen_set U -name {Uptime Screen: %s}\n", host);
sock_send_string(sock, buffer); sock_send_string (sock, buffer);
sock_send_string(sock, "widget_add U title title\n"); sock_send_string (sock, "widget_add U title title\n");
if(lcd_hgt >= 4) if (lcd_hgt >= 4) {
{ sock_send_string (sock, "widget_set U title {SYSTEM UPTIME}\n");
sock_send_string(sock, "widget_set U title {SYSTEM UPTIME}\n"); sock_send_string (sock, "widget_add U one string\n");
sock_send_string(sock, "widget_add U one string\n"); sock_send_string (sock, "widget_add U two string\n");
sock_send_string(sock, "widget_add U two string\n"); sock_send_string (sock, "widget_add U three string\n");
sock_send_string(sock, "widget_add U three string\n");
sprintf(buffer, "widget_set U one 3 2 {%s}\n", host); sprintf (buffer, "widget_set U one 3 2 {%s}\n", host);
sock_send_string(sock, buffer); sock_send_string (sock, buffer);
sprintf(tmp, "widget_set U three 5 4 {%s %s}\n", sysname, kver); sprintf (tmp, "widget_set U three 5 4 {%s %s}\n", sysname, kver);
sock_send_string(sock, tmp); sock_send_string (sock, tmp);
} } else {
else sprintf (tmp, "widget_set U title {%s %s: %s}\n", sysname, kver, host);
{ sock_send_string (sock, tmp);
sprintf(tmp, "widget_set U title {%s %s: %s}\n", sock_send_string (sock, "widget_add U one string\n");
sysname, kver, host);
sock_send_string(sock, tmp);
sock_send_string(sock, "widget_add U one string\n");
} }
} }
if(colons) if (colons)
colon = ':'; colon = ':';
else else
colon = ' '; colon = ' ';
get_uptime(&uptime, &idle);
i = (int)uptime / 86400;
sprintf(date, "%d day%s,", i, (i != 1 ? "s" : ""));
i = ((int)uptime % 86400) / 60 / 60;
sprintf(hour, "%02i",i);
i = (((int)uptime % 86400) % 3600) / 60;
sprintf(min, "%02i",i);
i = ((int)uptime % 60);
sprintf(sec, "%02i",i);
sprintf(tmp, "%s %s%c%s%c%s", date, hour, colon, min, colon, sec);
i = ((20 - strlen(tmp)) / 2) + 1;
if(lcd_hgt >= 4) get_uptime (&uptime, &idle);
sprintf(buffer, "widget_set U two %i 3 {%s}\n", i, tmp); i = (int) uptime / 86400;
sprintf (date, "%d day%s,", i, (i != 1 ? "s" : ""));
i = ((int) uptime % 86400) / 60 / 60;
sprintf (hour, "%02i", i);
i = (((int) uptime % 86400) % 3600) / 60;
sprintf (min, "%02i", i);
i = ((int) uptime % 60);
sprintf (sec, "%02i", i);
sprintf (tmp, "%s %s%c%s%c%s", date, hour, colon, min, colon, sec);
i = ((20 - strlen (tmp)) / 2) + 1;
if (lcd_hgt >= 4)
sprintf (buffer, "widget_set U two %i 3 {%s}\n", i, tmp);
else else
sprintf(buffer, "widget_set U one %i 2 {%s}\n", i, tmp); sprintf (buffer, "widget_set U one %i 2 {%s}\n", i, tmp);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
colons = colons ^ 1; colons = colons ^ 1;
return 0; return 0;
} // End uptime_screen() } // End uptime_screen()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@@ -500,67 +482,64 @@ int uptime_screen(int rep, int display)
//|111555 444222 111333| //|111555 444222 111333|
//+--------------------+ //+--------------------+
// //
int big_clock_screen(int rep, int display) int
big_clock_screen (int rep, int display)
{ {
static int first = 1; static int first = 1;
static int colons = 0; static int colons = 0;
time_t thetime; time_t thetime;
struct tm *rtime; struct tm *rtime;
int pos[]={1,4,8,11,15,18}; int pos[] = { 1, 4, 8, 11, 15, 18 };
// int i=0; // int i=0;
char fulltxt[16], old_fulltxt[16]; char fulltxt[16], old_fulltxt[16];
int j=0; int j = 0;
if(lcd_hgt < 4) return 0; if (lcd_hgt < 4)
return 0;
if(first)
{ if (first) {
first = 0; first = 0;
sock_send_string(sock, "screen_add K\n"); sock_send_string (sock, "screen_add K\n");
sock_send_string(sock, "screen_set K -name {Big Clock Screen}\n"); sock_send_string (sock, "screen_set K -name {Big Clock Screen}\n");
sock_send_string(sock, "widget_del K heartbeat\n"); sock_send_string (sock, "widget_del K heartbeat\n");
sock_send_string(sock, "widget_add K d0 num\n"); sock_send_string (sock, "widget_add K d0 num\n");
sock_send_string(sock, "widget_add K d1 num\n"); sock_send_string (sock, "widget_add K d1 num\n");
sock_send_string(sock, "widget_add K d2 num\n"); sock_send_string (sock, "widget_add K d2 num\n");
sock_send_string(sock, "widget_add K d3 num\n"); sock_send_string (sock, "widget_add K d3 num\n");
sock_send_string(sock, "widget_add K d4 num\n"); sock_send_string (sock, "widget_add K d4 num\n");
sock_send_string(sock, "widget_add K d5 num\n"); sock_send_string (sock, "widget_add K d5 num\n");
// sock_send_string(sock, "widget_add K one string\n"); // sock_send_string(sock, "widget_add K one string\n");
sock_send_string(sock, "widget_set K d0 1 0\n"); sock_send_string (sock, "widget_set K d0 1 0\n");
sock_send_string(sock, "widget_set K d1 4 0\n"); sock_send_string (sock, "widget_set K d1 4 0\n");
sock_send_string(sock, "widget_set K d2 8 0\n"); sock_send_string (sock, "widget_set K d2 8 0\n");
sock_send_string(sock, "widget_set K d3 11 0\n"); sock_send_string (sock, "widget_set K d3 11 0\n");
sock_send_string(sock, "widget_set K d4 15 0\n"); sock_send_string (sock, "widget_set K d4 15 0\n");
sock_send_string(sock, "widget_set K d5 18 0\n"); sock_send_string (sock, "widget_set K d5 18 0\n");
old_fulltxt[0]='0'; old_fulltxt[0] = '0';
old_fulltxt[1]='0'; old_fulltxt[1] = '0';
old_fulltxt[2]='0'; old_fulltxt[2] = '0';
old_fulltxt[3]='0'; old_fulltxt[3] = '0';
old_fulltxt[4]='0'; old_fulltxt[4] = '0';
old_fulltxt[5]='0'; old_fulltxt[5] = '0';
old_fulltxt[6]=0; old_fulltxt[6] = 0;
// sock_send_string(sock, "widget_set K one 1 4 {000000}\n"); // sock_send_string(sock, "widget_set K one 1 4 {000000}\n");
} }
time(&thetime); time (&thetime);
rtime = localtime(&thetime); rtime = localtime (&thetime);
sprintf(fulltxt, "%02d%02d%02d", sprintf (fulltxt, "%02d%02d%02d", rtime->tm_hour, rtime->tm_min, rtime->tm_sec);
rtime->tm_hour, rtime->tm_min, rtime->tm_sec); for (j = 0; j < 6; j++) {
for(j=0;j<6;j++){ if (fulltxt[j] != old_fulltxt[j]) {
if (fulltxt[j]!=old_fulltxt[j]){ sprintf (tmp + strlen (tmp), "widget_set K d%d %d %c\n", j, pos[j], fulltxt[j]);
sprintf(tmp+strlen(tmp), "widget_set K d%d %d %c\n", old_fulltxt[j] = fulltxt[j];
j, pos[j], fulltxt[j]);
old_fulltxt[j]=fulltxt[j];
} }
} }
if(display) if (display)
sock_send_string(sock, tmp); sock_send_string (sock, tmp);
return 0; return 0;
} // End big_clock_screen() } // End big_clock_screen()
+6 -6
View File
@@ -1,12 +1,12 @@
#ifndef CHRONO_H #ifndef CHRONO_H
#define CHRONO_H #define CHRONO_H
int chrono_init(); int chrono_init ();
int chrono_close(); int chrono_close ();
int clock_screen(int rep, int display); int clock_screen (int rep, int display);
int uptime_screen(int rep, int display); int uptime_screen (int rep, int display);
int time_screen(int rep, int display); int time_screen (int rep, int display);
int big_clock_screen(int rep, int display); int big_clock_screen (int rep, int display);
#endif #endif
+240 -233
View File
@@ -11,57 +11,55 @@
#include "mode.h" #include "mode.h"
#include "cpu.h" #include "cpu.h"
struct load { unsigned long total, user, system, nice, idle; }; struct load {
unsigned long total, user, system, nice, idle;
};
int load_fd = 0; int load_fd = 0;
static void get_load(struct load * result); static void get_load (struct load *result);
static void get_load(struct load * result) static void
get_load (struct load *result)
{ {
static struct load last_load = { 0, 0, 0, 0, 0 }; struct load curr_load; static struct load last_load = { 0, 0, 0, 0, 0 };
struct load curr_load;
reread(load_fd, "get_load:"); reread (load_fd, "get_load:");
sscanf(buffer, "%*s %lu %lu %lu %lu\n", sscanf (buffer, "%*s %lu %lu %lu %lu\n", &curr_load.user, &curr_load.nice, &curr_load.system, &curr_load.idle);
&curr_load.user, curr_load.total = curr_load.user + curr_load.nice + curr_load.system + curr_load.idle;
&curr_load.nice, result->total = curr_load.total - last_load.total;
&curr_load.system, result->user = curr_load.user - last_load.user;
&curr_load.idle); result->nice = curr_load.nice - last_load.nice;
curr_load.total = curr_load.user result->system = curr_load.system - last_load.system;
+ curr_load.nice result->idle = curr_load.idle - last_load.idle;
+ curr_load.system last_load.total = curr_load.total;
+ curr_load.idle; last_load.user = curr_load.user;
result->total = curr_load.total - last_load.total; last_load.nice = curr_load.nice;
result->user = curr_load.user - last_load.user; last_load.system = curr_load.system;
result->nice = curr_load.nice - last_load.nice; last_load.idle = curr_load.idle;
result->system = curr_load.system - last_load.system;
result->idle = curr_load.idle - last_load.idle;
last_load.total = curr_load.total;
last_load.user = curr_load.user;
last_load.nice = curr_load.nice;
last_load.system = curr_load.system;
last_load.idle = curr_load.idle;
} }
int cpu_init() int
cpu_init ()
{ {
if(!load_fd) if (!load_fd) {
{ load_fd = open ("/proc/stat", O_RDONLY);
load_fd = open("/proc/stat",O_RDONLY);
} }
return 0; return 0;
} }
int cpu_close() int
cpu_close ()
{ {
if(load_fd) if (load_fd)
close(load_fd); close (load_fd);
load_fd = 0; load_fd = 0;
return 0; return 0;
} }
@@ -69,105 +67,92 @@ int cpu_close()
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// CPU screen shows info about percentage of the CPU being used // CPU screen shows info about percentage of the CPU being used
// //
int cpu_screen(int rep, int display) int
cpu_screen (int rep, int display)
{ {
#undef CPU_BUF_SIZE #undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 4 #define CPU_BUF_SIZE 4
int i, j, n; int i, j, n;
static int first = 1; static int first = 1;
float value; float value;
static float cpu[CPU_BUF_SIZE + 1][5];// last buffer is scratch static float cpu[CPU_BUF_SIZE + 1][5]; // last buffer is scratch
struct load load; struct load load;
if(first) if (first) {
{
first = 0; first = 0;
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", host); sprintf (buffer, "screen_set C -name {CPU Use: %s}\n", host);
sock_send_string(sock, buffer); sock_send_string (sock, buffer);
if(lcd_hgt >= 4) if (lcd_hgt >= 4) {
{ sock_send_string (sock, "widget_add C title title\n");
sock_send_string(sock, "widget_add C title title\n"); sock_send_string (sock, "widget_set C title {CPU LOAD}\n");
sock_send_string(sock, "widget_set C title {CPU LOAD}\n"); 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_set C one 1 2 {0 1 Sys 0.0%}\n");
sock_send_string(sock, sock_send_string (sock, "widget_add C two string\n");
"widget_set C one 1 2 {0 1 Sys 0.0%}\n"); sock_send_string (sock, "widget_add C three string\n");
sock_send_string(sock, "widget_add C two string\n"); sock_send_string (sock, "widget_set C one 1 2 {Usr 0.0% Nice 0.0%}\n");
sock_send_string(sock, "widget_add C three string\n"); sock_send_string (sock, "widget_set C two 1 3 {Sys 0.0% Idle 0.0%}\n");
sock_send_string(sock, sock_send_string (sock, "widget_set C three 1 4 {0% 100%}\n");
"widget_set C one 1 2 {Usr 0.0% Nice 0.0%}\n"); sock_send_string (sock, "widget_add C usr string\n");
sock_send_string(sock, sock_send_string (sock, "widget_add C nice string\n");
"widget_set C two 1 3 {Sys 0.0% Idle 0.0%}\n"); sock_send_string (sock, "widget_add C idle string\n");
sock_send_string(sock, sock_send_string (sock, "widget_add C sys string\n");
"widget_set C three 1 4 {0% 100%}\n"); sock_send_string (sock, "widget_add C bar hbar\n");
sock_send_string(sock, "widget_add C usr string\n"); sock_send_string (sock, "widget_set C bar 3 4 0\n");
sock_send_string(sock, "widget_add C nice string\n"); } else {
sock_send_string(sock, "widget_add C idle string\n"); sock_send_string (sock, "widget_add C cpu0 string\n");
sock_send_string(sock, "widget_add C sys string\n"); if (lcd_wid >= 20)
sock_send_string(sock, "widget_add C bar hbar\n"); sock_send_string (sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n");
sock_send_string(sock, "widget_set C bar 3 4 0\n");
}
else
{
sock_send_string(sock, "widget_add C cpu0 string\n");
if(lcd_wid >= 20)
sock_send_string(sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n");
else else
sock_send_string(sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n"); sock_send_string (sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n");
sock_send_string(sock, "widget_add C cpu0% string\n"); sock_send_string (sock, "widget_add C cpu0% string\n");
sprintf(buffer, "widget_set C cpu0%% 1 %i { 0.0%%}\n", lcd_wid-4); sprintf (buffer, "widget_set C cpu0%% 1 %i { 0.0%%}\n", lcd_wid - 4);
sock_send_string(sock, buffer); 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");
sock_send_string(sock, sock_send_string (sock, "widget_set C usni 1 2 { U S N I}\n");
"widget_set C usni 1 2 { U S N I}\n"); sock_send_string (sock, "widget_add C usr hbar\n");
sock_send_string(sock, "widget_add C 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"); sock_send_string (sock, "widget_add C idle hbar\n");
sock_send_string(sock, "widget_add C idle hbar\n"); sock_send_string (sock, "widget_add C total hbar\n");
sock_send_string(sock, "widget_add C total hbar\n"); sock_send_string (sock, "widget_set C total 6 1 0\n");
sock_send_string(sock, "widget_set C total 6 1 0\n");
} }
return 0; return 0;
} }
//else return 0; //else return 0;
get_load(&load); get_load (&load);
// Shift values over by one // Shift values over by one
for(i=0; i<(CPU_BUF_SIZE-1); i++) for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
for(j=0; j<5; j++) for (j = 0; j < 5; j++)
cpu[i][j] = cpu[i+1][j]; cpu[i][j] = cpu[i + 1][j];
// Read new data // Read new data
cpu[CPU_BUF_SIZE-1][0] = ((float)load.user / (float)load.total) * 100.0; cpu[CPU_BUF_SIZE - 1][0] = ((float) load.user / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE-1][1] = ((float)load.system / (float)load.total) * 100.0; cpu[CPU_BUF_SIZE - 1][1] = ((float) load.system / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE-1][2] = ((float)load.nice / (float)load.total) * 100.0; cpu[CPU_BUF_SIZE - 1][2] = ((float) load.nice / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE-1][3] = ((float)load.idle / (float)load.total) * 100.0; cpu[CPU_BUF_SIZE - 1][3] = ((float) load.idle / (float) load.total) * 100.0;
cpu[CPU_BUF_SIZE-1][4] = (((float)load.user + (float)load.system + cpu[CPU_BUF_SIZE - 1][4] = (((float) load.user + (float) load.system + (float) load.nice) / (float) load.total) * 100.0;
(float)load.nice) / (float)load.total) * 100.0;
// Only clear on first display... // Only clear on first display...
if(!rep) if (!rep) {
{
/* /*
// Make all the same, if this is the first time... // Make all the same, if this is the first time...
for(i=0; i<CPU_BUF_SIZE-1; i++) for(i=0; i<CPU_BUF_SIZE-1; i++)
for(j=0; j<5; j++) for(j=0; j<5; j++)
cpu[i][j] = cpu[CPU_BUF_SIZE-1][j]; cpu[i][j] = cpu[CPU_BUF_SIZE-1][j];
*/ */
} }
// Average values for final result // Average values for final result
for(i=0; i<5; i++) for (i = 0; i < 5; i++) {
{
value = 0; value = 0;
for(j=0; j<CPU_BUF_SIZE; j++) for (j = 0; j < CPU_BUF_SIZE; j++) {
{
value += cpu[j][i]; value += cpu[j][i];
} }
value /= CPU_BUF_SIZE; value /= CPU_BUF_SIZE;
@@ -175,191 +160,213 @@ int cpu_screen(int rep, int display)
} }
if(lcd_hgt >= 4) if (lcd_hgt >= 4) {
{
value = cpu[CPU_BUF_SIZE][4]; value = cpu[CPU_BUF_SIZE][4];
n = (int)(value * 70.0); n = (int) (value * 70.0);
if (value >= 99.9) { sprintf(tmp, "100%%"); } if (value >= 99.9) {
else { sprintf(tmp, "%4.1f%%", value); } sprintf (tmp, "100%%");
sprintf(buffer, "widget_set C title {CPU %s: %s}\n", tmp, host); } else {
if(display) sock_send_string(sock, buffer); sprintf (tmp, "%4.1f%%", value);
}
value = cpu[CPU_BUF_SIZE][0]; sprintf (buffer, "widget_set C title {CPU %s: %s}\n", tmp, host);
if (value >= 99.9) { sprintf(tmp, " 100%%"); } if (display)
else { sprintf(tmp, "%4.1f%%", value); } sock_send_string (sock, buffer);
sprintf(buffer, "widget_set C usr 5 2 {%s}\n", tmp);
if(display) sock_send_string(sock, buffer);
value = cpu[CPU_BUF_SIZE][1];
if (value >= 99.9) { sprintf(tmp, " 100%%"); }
else { sprintf(tmp, "%4.1f%%", value); }
sprintf(buffer, "widget_set C sys 5 3 {%s}\n", tmp);
if(display) sock_send_string(sock, buffer);
value = cpu[CPU_BUF_SIZE][2];
if (value >= 99.9) { sprintf(tmp, " 100%%"); }
else { sprintf(tmp, "%4.1f%%", value); }
sprintf(buffer, "widget_set C nice 16 2 {%s}\n", tmp);
if(display) sock_send_string(sock, buffer);
value = cpu[CPU_BUF_SIZE][3];
if (value >= 99.9) { sprintf(tmp, " 100%%"); }
else { sprintf(tmp, "%4.1f%%", value); }
sprintf(buffer, "widget_set C idle 16 3 {%s}\n", tmp);
if(display) sock_send_string(sock, buffer);
value = cpu[CPU_BUF_SIZE][4];
n = (int)(value * (lcd_cellwid * 14) / 100.0);
sprintf(buffer, "widget_set C bar 3 4 %i\n", n);
if(display) sock_send_string(sock, buffer);
} // end if(lcd_hgt >= 4)
else // 20x2 version
{
value = cpu[CPU_BUF_SIZE][4];
if (value >= 99.9) { sprintf(tmp, "100%%"); }
else { sprintf(tmp, "%4.1f%%", value); }
sprintf(buffer, "widget_set C cpu0%% %i 1 {%s}\n", lcd_wid-4, tmp);
if(display) sock_send_string(sock, buffer);
n = (float)(value * lcd_cellwid * (float)(lcd_wid-11)) / 100.0;
sprintf(buffer, "widget_set C total 6 1 %i\n", n);
if(display) sock_send_string(sock, buffer);
value = cpu[CPU_BUF_SIZE][0]; value = cpu[CPU_BUF_SIZE][0];
n = (float)(value * lcd_cellwid * 4.0) / 100.0; if (value >= 99.9) {
sprintf(buffer, "widget_set C usr 1 2 %i\n", n); sprintf (tmp, " 100%%");
if(display) sock_send_string(sock, buffer); } else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C usr 5 2 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][1]; value = cpu[CPU_BUF_SIZE][1];
n = (float)(value * lcd_cellwid * 3.0) / 100.0; if (value >= 99.9) {
sprintf(buffer, "widget_set C sys 7 2 %i\n", n); sprintf (tmp, " 100%%");
if(display) sock_send_string(sock, buffer); } else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C sys 5 3 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][2]; value = cpu[CPU_BUF_SIZE][2];
n = (float)(value * lcd_cellwid * 3.0) / 100.0; if (value >= 99.9) {
sprintf(buffer, "widget_set C nice 12 2 %i\n", n); sprintf (tmp, " 100%%");
if(display) sock_send_string(sock, buffer); } else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C nice 16 2 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][3]; value = cpu[CPU_BUF_SIZE][3];
n = (float)(value * lcd_cellwid * 3.0) / 100.0; if (value >= 99.9) {
sprintf(buffer, "widget_set C idle 17 2 %i\n", n); sprintf (tmp, " 100%%");
if(display) sock_send_string(sock, buffer); } else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C idle 16 3 {%s}\n", tmp);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][4];
n = (int) (value * (lcd_cellwid * 14) / 100.0);
sprintf (buffer, "widget_set C bar 3 4 %i\n", n);
if (display)
sock_send_string (sock, buffer);
} // end if(lcd_hgt >= 4)
else // 20x2 version
{
value = cpu[CPU_BUF_SIZE][4];
if (value >= 99.9) {
sprintf (tmp, "100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C cpu0%% %i 1 {%s}\n", lcd_wid - 4, tmp);
if (display)
sock_send_string (sock, buffer);
n = (float) (value * lcd_cellwid * (float) (lcd_wid - 11)) / 100.0;
sprintf (buffer, "widget_set C total 6 1 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][0];
n = (float) (value * lcd_cellwid * 4.0) / 100.0;
sprintf (buffer, "widget_set C usr 1 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][1];
n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C sys 7 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][2];
n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C nice 12 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][3];
n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C idle 17 2 %i\n", n);
if (display)
sock_send_string (sock, buffer);
} }
return 0; return 0;
} // End cpu_screen() } // End cpu_screen()
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Cpu Graph Screen shows a quick-moving histogram of CPU use. // Cpu Graph Screen shows a quick-moving histogram of CPU use.
// //
int cpu_graph_screen(int rep, int display) int
cpu_graph_screen (int rep, int display)
{ {
int i, j, n=0; int i, j, n = 0;
static int first=1; static int first = 1;
float value, maxload; float value, maxload;
#undef CPU_BUF_SIZE #undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 2 #define CPU_BUF_SIZE 2
static float cpu[CPU_BUF_SIZE + 1];// last buffer is scratch static float cpu[CPU_BUF_SIZE + 1]; // last buffer is scratch
static int cpu_past[LCD_MAX_WIDTH]; static int cpu_past[LCD_MAX_WIDTH];
struct load load; struct load load;
int status=0; int status = 0;
if(first)
{ if (first) {
first = 0; first = 0;
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", host); sprintf (buffer, "screen_set G -name {CPU Graph: %s}\n", host);
sock_send_string(sock, buffer); 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", host);
sprintf(buffer, "widget_set G title {CPU: %s}\n", host); } else {
sock_send_string (sock, "widget_add G title string\n");
sprintf (buffer, "widget_set G title 1 1 {CPU: %s}\n", host);
} }
else sock_send_string (sock, buffer);
{
sock_send_string(sock, "widget_add G title string\n");
sprintf(buffer, "widget_set G title 1 1 {CPU: %s}\n", host);
}
sock_send_string(sock, buffer);
for(i=1; i<=lcd_wid; i++) for (i = 1; i <= lcd_wid; i++) {
{ sprintf (tmp, "widget_add G %i vbar\n", i);
sprintf(tmp, "widget_add G %i vbar\n", i); sock_send_string (sock, tmp);
sock_send_string(sock, tmp); sprintf (tmp, "widget_set G %i %i %i 0\n", i, i, lcd_hgt);
sprintf(tmp, "widget_set G %i %i %i 0\n", i, i, lcd_hgt); sock_send_string (sock, tmp);
sock_send_string(sock, tmp);
} }
} }
get_load(&load); get_load (&load);
// Shift values over by one // Shift values over by one
for(i=0; i<(CPU_BUF_SIZE-1); i++) for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
cpu[i] = cpu[i+1]; cpu[i] = cpu[i + 1];
// Read new data // Read new data
cpu[CPU_BUF_SIZE-1] = ((float)load.user + (float)load.system cpu[CPU_BUF_SIZE - 1] = ((float) load.user + (float) load.system + (float) load.nice) / (float) load.total;
+ (float)load.nice) / (float)load.total;
// Only clear on first display... // Only clear on first display...
if(!rep) if (!rep) {
{
/* /*
// Make all the same, if this is the first time... // Make all the same, if this is the first time...
for(i=0; i<CPU_BUF_SIZE-1; i++) for(i=0; i<CPU_BUF_SIZE-1; i++)
cpu[i] = cpu[CPU_BUF_SIZE-1]; cpu[i] = cpu[CPU_BUF_SIZE-1];
*/ */
} }
// Average values for final result // Average values for final result
value = 0; value = 0;
for(j=0; j<CPU_BUF_SIZE; j++) for (j = 0; j < CPU_BUF_SIZE; j++) {
{
value += cpu[j]; value += cpu[j];
} }
value /= (float)CPU_BUF_SIZE; value /= (float) CPU_BUF_SIZE;
cpu[CPU_BUF_SIZE] = value; cpu[CPU_BUF_SIZE] = value;
maxload=0; maxload = 0;
for(i=0; i<lcd_wid-1; i++) for (i = 0; i < lcd_wid - 1; i++) {
{ cpu_past[i] = cpu_past[i + 1];
cpu_past[i] = cpu_past[i+1];
j = cpu_past[i]; j = cpu_past[i];
sprintf(tmp, "widget_set G %i %i %i %i\n", sprintf (tmp, "widget_set G %i %i %i %i\n", i + 1, i + 1, lcd_hgt, j);
i+1, i+1, lcd_hgt, j); if (display)
if(display) sock_send_string(sock, tmp); sock_send_string (sock, tmp);
if(cpu_past[i] > maxload) maxload = cpu_past[i]; if (cpu_past[i] > maxload)
maxload = cpu_past[i];
} }
value = cpu[CPU_BUF_SIZE]; value = cpu[CPU_BUF_SIZE];
if(lcd_hgt > 2) if (lcd_hgt > 2)
n = (int)(value * (float)(lcd_cellhgt) * (float)(lcd_hgt-1)); n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt - 1));
else else
n = (int)(value * (float)(lcd_cellhgt) * (float)(lcd_hgt)); n = (int) (value * (float) (lcd_cellhgt) * (float) (lcd_hgt));
cpu_past[lcd_wid-1] = n; cpu_past[lcd_wid - 1] = n;
sprintf(tmp, "widget_set G %i %i %i %i\n", sprintf (tmp, "widget_set G %i %i %i %i\n", lcd_wid, lcd_wid, lcd_hgt, n);
lcd_wid, lcd_wid, lcd_hgt, n); if (display)
if(display) sock_send_string(sock, tmp); sock_send_string (sock, tmp);
if(n > maxload) maxload = n; if (n > maxload)
maxload = n;
if(cpu_past[lcd_wid-1] > 0 ) status = BACKLIGHT_ON;
if(maxload < 1) status = BACKLIGHT_OFF; if (cpu_past[lcd_wid - 1] > 0)
status = BACKLIGHT_ON;
if (maxload < 1)
status = BACKLIGHT_OFF;
// return status; // return status;
return 0; return 0;
} // End cpu_graph_screen() } // End cpu_graph_screen()
+4 -4
View File
@@ -2,11 +2,11 @@
#define CPU_H #define CPU_H
int cpu_init(); int cpu_init ();
int cpu_close(); int cpu_close ();
int cpu_screen(int rep, int display); int cpu_screen (int rep, int display);
int cpu_graph_screen(int rep, int display); int cpu_graph_screen (int rep, int display);
#endif #endif
+116 -123
View File
@@ -58,79 +58,74 @@
#define MAX_CPUS 8 #define MAX_CPUS 8
struct load { unsigned long total, user, system, nice, idle; }; struct load {
unsigned long total, user, system, nice, idle;
};
static int load_fd = 0; static int load_fd = 0;
static char *numnames[MAX_CPUS] = {"one", "two", "three", "four", "five", "six", "seven", "eight"}; static char *numnames[MAX_CPUS] = { "one", "two", "three", "four", "five", "six", "seven", "eight" };
static void static void
get_load(struct load *result, int *numcpus) get_load (struct load *result, int *numcpus)
{ {
char *token; char *token;
static struct load last_load[MAX_CPUS]; static struct load last_load[MAX_CPUS];
struct load curr_load[MAX_CPUS]; struct load curr_load[MAX_CPUS];
*numcpus = 0; *numcpus = 0;
reread (load_fd, "get_load"); reread (load_fd, "get_load");
// Look for lines starting with "cpu0", "cpu1", etc. // Look for lines starting with "cpu0", "cpu1", etc.
token = strtok (buffer, "\n"); token = strtok (buffer, "\n");
while (token) { while (token) {
if (token[0] == 'c') { if (token[0] == 'c') {
if (isdigit (token[3])) { if (isdigit (token[3])) {
sscanf(token, "%*s %lu %lu %lu %lu", sscanf (token, "%*s %lu %lu %lu %lu", &curr_load[*numcpus].user, &curr_load[*numcpus].nice, &curr_load[*numcpus].system, &curr_load[*numcpus].idle);
&curr_load[*numcpus].user,
&curr_load[*numcpus].nice, curr_load[*numcpus].total = curr_load[*numcpus].user + curr_load[*numcpus].nice + curr_load[*numcpus].system + curr_load[*numcpus].idle;
&curr_load[*numcpus].system, result[*numcpus].total = curr_load[*numcpus].total - last_load[*numcpus].total;
&curr_load[*numcpus].idle); result[*numcpus].user = curr_load[*numcpus].user - last_load[*numcpus].user;
result[*numcpus].nice = curr_load[*numcpus].nice - last_load[*numcpus].nice;
curr_load[*numcpus].total = curr_load[*numcpus].user result[*numcpus].system = curr_load[*numcpus].system - last_load[*numcpus].system;
+ curr_load[*numcpus].nice result[*numcpus].idle = curr_load[*numcpus].idle - last_load[*numcpus].idle;
+ curr_load[*numcpus].system last_load[*numcpus].total = curr_load[*numcpus].total;
+ curr_load[*numcpus].idle; last_load[*numcpus].user = curr_load[*numcpus].user;
result[*numcpus].total = curr_load[*numcpus].total - last_load[*numcpus].total; last_load[*numcpus].nice = curr_load[*numcpus].nice;
result[*numcpus].user = curr_load[*numcpus].user - last_load[*numcpus].user; last_load[*numcpus].system = curr_load[*numcpus].system;
result[*numcpus].nice = curr_load[*numcpus].nice - last_load[*numcpus].nice; last_load[*numcpus].idle = curr_load[*numcpus].idle;
result[*numcpus].system = curr_load[*numcpus].system - last_load[*numcpus].system;
result[*numcpus].idle = curr_load[*numcpus].idle - last_load[*numcpus].idle; (*numcpus)++;
last_load[*numcpus].total = curr_load[*numcpus].total; }
last_load[*numcpus].user = curr_load[*numcpus].user; } else {
last_load[*numcpus].nice = curr_load[*numcpus].nice; break;
last_load[*numcpus].system = curr_load[*numcpus].system; }
last_load[*numcpus].idle = curr_load[*numcpus].idle; token = strtok (NULL, "\n");
}
(*numcpus)++;
}
} else {
break;
}
token = strtok (NULL, "\n");
}
} }
int int
cpu_smp_init() cpu_smp_init ()
{ {
if(!load_fd) { if (!load_fd) {
load_fd = open ("/proc/stat", O_RDONLY); load_fd = open ("/proc/stat", O_RDONLY);
} }
return 0; return 0;
} }
int int
cpu_smp_close() cpu_smp_close ()
{ {
if (load_fd) if (load_fd)
close (load_fd); close (load_fd);
load_fd = 0; load_fd = 0;
return 0; return 0;
} }
@@ -138,112 +133,110 @@ cpu_smp_close()
// CPU screen shows info about percentage of the CPU being used // CPU screen shows info about percentage of the CPU being used
// //
int int
cpu_smp_screen(int rep, int display) cpu_smp_screen (int rep, int display)
{ {
#undef CPU_BUF_SIZE #undef CPU_BUF_SIZE
#define CPU_BUF_SIZE 4 #define CPU_BUF_SIZE 4
int i, j, n, z; int i, j, n, z;
static int first = 1; static int first = 1;
float value; float value;
static float cpu[MAX_CPUS][CPU_BUF_SIZE + 1][5];// last buffer is scratch static float cpu[MAX_CPUS][CPU_BUF_SIZE + 1][5]; // last buffer is scratch
struct load load[MAX_CPUS]; struct load load[MAX_CPUS];
int numprocs; int numprocs;
char buf[256]; char buf[256];
char* graphsize; char *graphsize;
if(first) if (first) {
{
first = 0; first = 0;
get_load(load, &numprocs); get_load (load, &numprocs);
sock_send_string(sock, "screen_add P\n"); sock_send_string (sock, "screen_add P\n");
sock_send_string(sock, "widget_del P heartbeat\n"); sock_send_string (sock, "widget_del P heartbeat\n");
sprintf(buffer, "screen_set P -name {CPU Use: %s}\n", host); sprintf (buffer, "screen_set P -name {CPU Use: %s}\n", host);
sock_send_string(sock, buffer); sock_send_string (sock, buffer);
graphsize = calloc (sizeof (char), lcd_wid); graphsize = calloc (sizeof (char), lcd_wid);
if (numprocs > lcd_hgt) { if (numprocs > lcd_hgt) {
for (i=0; i<lcd_wid/2-6; i++) { for (i = 0; i < lcd_wid / 2 - 6; i++) {
graphsize[i] = ' '; } graphsize[i] = ' ';
}
} else { } else {
for (i=0; i<lcd_wid-6; i++) { for (i = 0; i < lcd_wid - 6; i++) {
graphsize[i] = ' '; graphsize[i] = ' ';
} }
} }
for (i=0; i<numprocs; i++) { for (i = 0; i < numprocs; i++) {
if (i+1 > lcd_hgt*2) break; if (i + 1 > lcd_hgt * 2)
break;
sprintf (buf, "widget_add P %s_title string\n", numnames[i]); sprintf (buf, "widget_add P %s_title string\n", numnames[i]);
sock_send_string (sock, buf); sock_send_string (sock, buf);
if (numprocs > lcd_hgt) { if (numprocs > lcd_hgt) {
sprintf (buf, "widget_set P %s_title %d %d \"CPU%d[%s]\"\n", numnames[i], i%2 * lcd_wid/2 + 1, i/2+1, i, graphsize); sprintf (buf, "widget_set P %s_title %d %d \"CPU%d[%s]\"\n", numnames[i], i % 2 * lcd_wid / 2 + 1, i / 2 + 1, i, graphsize);
} else { } else {
sprintf (buf, "widget_set P %s_title 1 %d \"CPU%d[%s]\"\n", numnames[i], i+1, i, graphsize); sprintf (buf, "widget_set P %s_title 1 %d \"CPU%d[%s]\"\n", numnames[i], i + 1, i, graphsize);
} }
sock_send_string (sock, buf); sock_send_string (sock, buf);
sprintf (buf, "widget_add P %s_bar hbar\n", numnames[i]); sprintf (buf, "widget_add P %s_bar hbar\n", numnames[i]);
sock_send_string (sock, buf); sock_send_string (sock, buf);
} }
free (graphsize); free (graphsize);
return 0; return 0;
} }
get_load(load, &numprocs);
for (z=0; z<numprocs; z++) { get_load (load, &numprocs);
// Shift values over by one for (z = 0; z < numprocs; z++) {
for(i=0; i<(CPU_BUF_SIZE-1); i++)
for(j=4; j<5; j++)
cpu[z][i][j] = cpu[z][i+1][j];
if (load[z].total == 0) { // Shift values over by one
continue; for (i = 0; i < (CPU_BUF_SIZE - 1); i++)
} for (j = 4; j < 5; j++)
cpu[z][i][j] = cpu[z][i + 1][j];
// Read new data
#if 0 // we're only using 4 right now if (load[z].total == 0) {
cpu[z][CPU_BUF_SIZE-1][0] = ((float)load[z].user / (float)load[z].total) * 100.0; continue;
cpu[z][CPU_BUF_SIZE-1][1] = ((float)load[z].system / (float)load[z].total) * 100.0; }
cpu[z][CPU_BUF_SIZE-1][2] = ((float)load[z].nice / (float)load[z].total) * 100.0; // Read new data
cpu[z][CPU_BUF_SIZE-1][3] = ((float)load[z].idle / (float)load[z].total) * 100.0; #if 0 // we're only using 4 right now
cpu[z][CPU_BUF_SIZE - 1][0] = ((float) load[z].user / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][1] = ((float) load[z].system / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][2] = ((float) load[z].nice / (float) load[z].total) * 100.0;
cpu[z][CPU_BUF_SIZE - 1][3] = ((float) load[z].idle / (float) load[z].total) * 100.0;
#endif #endif
cpu[z][CPU_BUF_SIZE-1][4] = (((float)load[z].user + (float)load[z].system + cpu[z][CPU_BUF_SIZE - 1][4] = (((float) load[z].user + (float) load[z].system + (float) load[z].nice) / (float) load[z].total) * 100.0;
(float)load[z].nice) / (float)load[z].total) * 100.0;
// Average values for final result // Average values for final result
for(i=4; i<5; i++) for (i = 4; i < 5; i++) {
{ value = 0;
value = 0; for (j = 0; j < CPU_BUF_SIZE; j++) {
for(j=0; j<CPU_BUF_SIZE; j++) value += cpu[z][j][i];
{ }
value += cpu[z][j][i]; value /= CPU_BUF_SIZE;
} cpu[z][CPU_BUF_SIZE][i] = value;
value /= CPU_BUF_SIZE; }
cpu[z][CPU_BUF_SIZE][i] = value;
}
value = cpu[z][CPU_BUF_SIZE][4]; value = cpu[z][CPU_BUF_SIZE][4];
if (numprocs > lcd_hgt) { if (numprocs > lcd_hgt) {
n = (float)(value * lcd_cellwid * ((float)lcd_wid/2.f-6.f)) / 100.f + .5f; n = (float) (value * lcd_cellwid * ((float) lcd_wid / 2.f - 6.f)) / 100.f + .5f;
sprintf (buf, "widget_set P %s_bar %d %d %d\n", numnames[z], z%2 * lcd_wid/2 + 6, z/2+1, n); sprintf (buf, "widget_set P %s_bar %d %d %d\n", numnames[z], z % 2 * lcd_wid / 2 + 6, z / 2 + 1, n);
} else { } else {
n = (float)(value * lcd_cellwid * ((float)lcd_wid-6.f)) / 100.f + .5f; n = (float) (value * lcd_cellwid * ((float) lcd_wid - 6.f)) / 100.f + .5f;
sprintf (buf, "widget_set P %s_bar 6 %d %d\n", numnames[z], z+1, n); sprintf (buf, "widget_set P %s_bar 6 %d %d\n", numnames[z], z + 1, n);
} }
sock_send_string (sock, buf); sock_send_string (sock, buf);
if (z+1 > lcd_hgt*2) break; if (z + 1 > lcd_hgt * 2)
break;
} }
return 0; return 0;
} // End cpu_screen() } // End cpu_screen()
+3 -3
View File
@@ -2,10 +2,10 @@
#define CPU_SMP_H #define CPU_SMP_H
int cpu_smp_init(); int cpu_smp_init ();
int cpu_smp_close(); int cpu_smp_close ();
int cpu_smp_screen(int rep, int display); int cpu_smp_screen (int rep, int display);
#endif #endif
+133 -160
View File
@@ -17,7 +17,7 @@
#ifdef HAVE_SYS_MOUNT_H #ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h> #include <sys/mount.h>
#endif #endif
#ifdef HAVE_SYS_VFS_H #ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h> #include <sys/vfs.h>
#endif #endif
#ifdef HAVE_SYS_STATVFS_H #ifdef HAVE_SYS_STATVFS_H
@@ -37,81 +37,79 @@
FILE *mtab_fd; FILE *mtab_fd;
typedef struct mounts typedef struct mounts {
{ char dev[256], type[64], mpoint[256];
char dev[256], type[64], mpoint[256]; long bsize, blocks, bfree, files, ffree;
long bsize, blocks, bfree, files, ffree;
} mounts; } mounts;
static int get_fs(mounts fs[]) static int
get_fs (mounts fs[])
{ {
#ifdef STAT_STATVFS #ifdef STAT_STATVFS
struct statvfs fsinfo; struct statvfs fsinfo;
#else #else
struct statfs fsinfo; struct statfs fsinfo;
#endif #endif
char line[256]; char line[256];
int x = 0, y; int x = 0, y;
mtab_fd = fopen("/etc/mtab", "r");
// Get rid of old, unmounted filesystems... mtab_fd = fopen ("/etc/mtab", "r");
memset(fs, 0, sizeof(mounts)*256);
while (x < 256) // Get rid of old, unmounted filesystems...
{ memset (fs, 0, sizeof (mounts) * 256);
if(fgets(line, 256, mtab_fd) == NULL)
{ while (x < 256) {
fclose(mtab_fd); if (fgets (line, 256, mtab_fd) == NULL) {
return x; fclose (mtab_fd);
} return x;
}
sscanf(line, "%s %s %s", fs[x].dev, fs[x].mpoint, fs[x].type);
sscanf (line, "%s %s %s", fs[x].dev, fs[x].mpoint, fs[x].type);
if(strcmp(fs[x].type, "proc")
if (strcmp (fs[x].type, "proc")
#ifndef STAT_NFS #ifndef STAT_NFS
&& strcmp(fs[x].type, "nfs") && strcmp (fs[x].type, "nfs")
#endif #endif
#ifndef STAT_SMBFS #ifndef STAT_SMBFS
&& strcmp(fs[x].type, "smbfs") && strcmp (fs[x].type, "smbfs")
#endif #endif
) ) {
{
#ifdef STAT_STATVFS #ifdef STAT_STATVFS
y = statvfs(fs[x].mpoint, &fsinfo); y = statvfs (fs[x].mpoint, &fsinfo);
#elif STAT_STATFS2_BSIZE #elif STAT_STATFS2_BSIZE
y = statfs(fs[x].mpoint, &fsinfo); y = statfs (fs[x].mpoint, &fsinfo);
#elif STAT_STATFS4 #elif STAT_STATFS4
y = statfs(fs[x].mpoint, &fsinfo, sizeof(fsinfo), 0); y = statfs (fs[x].mpoint, &fsinfo, sizeof (fsinfo), 0);
#else #else
#error "statfs for this system noy yet supported" #error "statfs for this system noy yet supported"
#endif #endif
fs[x].blocks = fsinfo.f_blocks;
if(fs[x].blocks > 0)
{
fs[x].bsize = fsinfo.f_bsize;
fs[x].bfree = fsinfo.f_bfree;
fs[x].files = fsinfo.f_files;
fs[x].ffree = fsinfo.f_ffree;
x++;
}
}
}
fclose(mtab_fd); fs[x].blocks = fsinfo.f_blocks;
return x; if (fs[x].blocks > 0) {
fs[x].bsize = fsinfo.f_bsize;
fs[x].bfree = fsinfo.f_bfree;
fs[x].files = fsinfo.f_files;
fs[x].ffree = fsinfo.f_ffree;
x++;
}
}
}
fclose (mtab_fd);
return x;
} }
int disk_init() int
disk_init ()
{ {
return 0; return 0;
} }
int disk_close() int
disk_close ()
{ {
return 0; return 0;
@@ -126,159 +124,135 @@ int disk_close()
// TODO: Disk screen! Requires virtual pages in the server, though... // TODO: Disk screen! Requires virtual pages in the server, though...
int disk_screen(int rep, int display) int
disk_screen (int rep, int display)
{ {
static mounts mnt[256]; static mounts mnt[256];
static int count=0; static int count = 0;
// Holds info to display (avoid recalculating it) // Holds info to display (avoid recalculating it)
struct disp struct disp {
{ char dev[8];
char dev[8]; char cap[8];
char cap[8]; int full;
int full;
} table[256]; } table[256];
int i; int i;
static int num_disks=0; static int num_disks = 0;
static int first=1; // First line to display, sort of. static int first = 1; // First line to display, sort of.
#define huge long long int #define huge long long int
huge size; huge size;
if(first) if (first) {
{
first = 0; first = 0;
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", host); sprintf (buffer, "screen_set D -name {Disk Use: %s}\n", host);
sock_send_string(sock, buffer); 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");
sprintf(buffer, "widget_set D title {DISKS: %s}\n", host); sprintf (buffer, "widget_set D title {DISKS: %s}\n", host);
sock_send_string(sock, buffer); sock_send_string (sock, buffer);
sock_send_string(sock, "widget_add D f frame\n"); sock_send_string (sock, "widget_add D f frame\n");
//sock_send_string(sock, "widget_set D f 1 2 20 4 20 3 v 8\n"); //sock_send_string(sock, "widget_set D f 1 2 20 4 20 3 v 8\n");
sprintf(buffer, "widget_set D f 1 2 %i %i %i %i v 12\n", sprintf (buffer, "widget_set D f 1 2 %i %i %i %i v 12\n", lcd_wid, lcd_hgt, lcd_wid, lcd_hgt - 1);
lcd_wid, lcd_hgt, lcd_wid, lcd_hgt-1); sock_send_string (sock, buffer);
sock_send_string(sock, buffer); sock_send_string (sock, "widget_add D err1 string\n");
sock_send_string(sock, "widget_add D err1 string\n"); sock_send_string (sock, "widget_add D err2 string\n");
sock_send_string(sock, "widget_add D err2 string\n"); sock_send_string (sock, "widget_set D err1 5 2 { Reading }\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");
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...
memset(table, 0, sizeof(struct disp)*256); memset (table, 0, sizeof (struct disp) * 256);
count = get_fs(mnt);
first = 0;
// Fill the display structure...
if(count)
{
sock_send_string(sock, "widget_set D err1 30 5 .\n");
sock_send_string(sock, "widget_set D err2 30 5 .\n");
for(i=0; i<count; i++)
{
if(strlen(mnt[i].mpoint) > 6)
{
sprintf(table[i].dev, "%c%s", ELLIPSIS,
(mnt[i].mpoint)+(strlen(mnt[i].mpoint)-5));
}
else
{
sprintf(table[i].dev, "%s", mnt[i].mpoint);
}
//table[i].full = (lcd.cellwid * 4)
table[i].full = (huge)(lcd_cellwid * 4)
* (huge)(mnt[i].blocks - mnt[i].bfree)
/ (huge)mnt[i].blocks;
size = (huge)mnt[i].bsize * (huge)mnt[i].blocks; count = get_fs (mnt);
memset(table[i].cap, 0, 8); first = 0;
// Fill the display structure...
if (count) {
sock_send_string (sock, "widget_set D err1 30 5 .\n");
sock_send_string (sock, "widget_set D err2 30 5 .\n");
for (i = 0; i < count; i++) {
if (strlen (mnt[i].mpoint) > 6) {
sprintf (table[i].dev, "%c%s", ELLIPSIS, (mnt[i].mpoint) + (strlen (mnt[i].mpoint) - 5));
} else {
sprintf (table[i].dev, "%s", mnt[i].mpoint);
}
//table[i].full = (lcd.cellwid * 4)
table[i].full = (huge) (lcd_cellwid * 4)
* (huge) (mnt[i].blocks - mnt[i].bfree)
/ (huge) mnt[i].blocks;
size = (huge) mnt[i].bsize * (huge) mnt[i].blocks;
memset (table[i].cap, 0, 8);
// Kilobytes // Kilobytes
if(size > 0 && size < (huge)1000*(huge)1000) if (size > 0 && size < (huge) 1000 * (huge) 1000)
sprintf(table[i].cap, "%3.1fk", sprintf (table[i].cap, "%3.1fk", (double) (size) / 1024.0);
(double)(size)/1024.0);
// Megabytes // Megabytes
else if(size >= (huge)1000*(huge)1000 else if (size >= (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000)
&& size < (huge)1000*(huge)1000*(huge)1000) sprintf (table[i].cap, "%3.1fM", (float) (size / (huge) 1024) / 1024.0);
sprintf(table[i].cap, "%3.1fM",
(float)(size/(huge)1024)/1024.0);
// Gigabytes // Gigabytes
else if(size >= (huge)1000*(huge)1000*(huge)1000 else if (size >= (huge) 1000 * (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000)
&& size < (huge)1000*(huge)1000*(huge)1000*(huge)1000) sprintf (table[i].cap, "%3.1fG", (float) (size / ((huge) 1024 * (huge) 1024)) / 1024.0);
sprintf(table[i].cap, "%3.1fG",
(float)(size/((huge)1024*(huge)1024))/1024.0);
// Terabytes // Terabytes
else if(size >= (huge)1000*(huge)1000*(huge)1000*(huge)1000 else if (size >= (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000)
&& size < (huge)1000*(huge)1000*(huge)1000*(huge)1000*(huge)1000) sprintf (table[i].cap, "%3.1fT", (float) (size / ((huge) 1024 * (huge) 1024 * (huge) 1024)) / 1024.0);
sprintf(table[i].cap, "%3.1fT",
(float)(size/((huge)1024*(huge)1024*(huge)1024))/1024.0);
// PectaBytes -- Yeah! I want some! // PectaBytes -- Yeah! I want some!
else if(size >= (huge)1000*(huge)1000*(huge)1000*(huge)1000*(huge)1000 else if (size >= (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 && size < (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000 * (huge) 1000)
&& size < (huge)1000*(huge)1000*(huge)1000*(huge)1000*(huge)1000*(huge)1000) sprintf (table[i].cap, "%3.1fP", (float) (size / ((huge) 1024 * (huge) 1024 * (huge) 1024 * (huge) 1024)) / 1024.0);
sprintf(table[i].cap, "%3.1fP",
(float)(size/((huge)1024*(huge)1024*(huge)1024*(huge)1024))/1024.0);
} }
} }
if (!count) if (!count) {
{ 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", sprintf (buffer, "widget_set D f 1 2 %i %i %i %i v 12\n", lcd_wid, lcd_hgt, lcd_wid, count);
lcd_wid, lcd_hgt, lcd_wid, count); sock_send_string (sock, buffer);
sock_send_string(sock, buffer);
//sprintf(tmp, "widget_set D f 1 2 20 4 20 %i v 8\n", count); //sprintf(tmp, "widget_set D f 1 2 20 4 20 %i v 8\n", count);
//sock_send_string(sock, tmp); //sock_send_string(sock, tmp);
for(i=0; i<count; i++) for (i = 0; i < count; i++) {
{ 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); sprintf (tmp, "widget_add D s%i string -in f\n", i);
sock_send_string(sock, tmp); sock_send_string (sock, tmp);
sprintf(tmp, "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); sock_send_string (sock, tmp);
} }
sprintf(tmp, "widget_set D s%i 1 %i {%-6s %6s E F}\n", sprintf (tmp, "widget_set D s%i 1 %i {%-6s %6s E F}\n", i, i + 1, table[i].dev, table[i].cap);
i, i+1, table[i].dev, table[i].cap); sock_send_string (sock, tmp);
sock_send_string(sock, tmp); sprintf (tmp, "widget_set D h%i 16 %i %i\n", i, i + 1, table[i].full);
sprintf(tmp, "widget_set D h%i 16 %i %i\n", sock_send_string (sock, tmp);
i, i+1, table[i].full);
sock_send_string(sock, tmp);
} }
// 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);
sprintf(tmp, "widget_del D s%i\n", i); sock_send_string (sock, tmp);
sock_send_string(sock, tmp); sprintf (tmp, "widget_del D h%i\n", i);
sprintf(tmp, "widget_del D h%i\n", i); sock_send_string (sock, tmp);
sock_send_string(sock, tmp);
} }
num_disks = count; num_disks = count;
#undef huge #undef huge
/* /*
// ** FILESYSTEMS ***** // ** FILESYSTEMS *****
@@ -286,6 +260,5 @@ int disk_screen(int rep, int display)
// /dos/c 2.1G E----F // /dos/c 2.1G E----F
// /stuff 4.3G E----F // /stuff 4.3G E----F
*/ */
return 0; return 0;
} }
+3 -3
View File
@@ -1,9 +1,9 @@
#ifndef DISK_H #ifndef DISK_H
#define DISK_H #define DISK_H
int disk_init(); int disk_init ();
int disk_close(); int disk_close ();
int disk_screen(int rep, int display); int disk_screen (int rep, int display);
#endif #endif
+79 -85
View File
@@ -12,33 +12,36 @@
int loadavg_fd = 0; int loadavg_fd = 0;
static double get_loadavg(void); static double get_loadavg (void);
static double get_loadavg(void) static double
get_loadavg (void)
{ {
double load; double load;
reread(loadavg_fd, "get_load:"); reread (loadavg_fd, "get_load:");
sscanf(buffer, "%lf", &load); sscanf (buffer, "%lf", &load);
return load; return load;
} }
int load_init() int
load_init ()
{ {
if(!loadavg_fd) if (!loadavg_fd)
loadavg_fd = open("/proc/loadavg",O_RDONLY); loadavg_fd = open ("/proc/loadavg", O_RDONLY);
return 0; return 0;
} }
int load_close() int
load_close ()
{ {
if(loadavg_fd) if (loadavg_fd)
close(loadavg_fd); close (loadavg_fd);
loadavg_fd = 0; loadavg_fd = 0;
return 0; return 0;
} }
@@ -47,106 +50,97 @@ int load_close()
// Shows a display very similar to "xload"'s histogram. // Shows a display very similar to "xload"'s histogram.
// //
int xload_screen(int rep, int display) int
xload_screen (int rep, int display)
{ {
static int first = 1; static int first = 1;
static float loads[LCD_MAX_WIDTH]; static float loads[LCD_MAX_WIDTH];
int n, i; int n, i;
float loadmax=0, factor, x; float loadmax = 0, factor, x;
int status = 0; int status = 0;
if(first) // Only the first time this is ever called... if (first) // Only the first time this is ever called...
{ {
first = 0; first = 0;
memset(loads, 0, sizeof(float)*LCD_MAX_WIDTH); memset (loads, 0, sizeof (float) * LCD_MAX_WIDTH);
sock_send_string(sock, "screen_add X\n"); sock_send_string (sock, "screen_add X\n");
sprintf(buffer, "screen_set X -name {X-Load: %s}\n", host); sprintf (buffer, "screen_set X -name {X-Load: %s}\n", host);
sock_send_string(sock, buffer); 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 X %i vbar\n", i);
sprintf(tmp, "widget_add X %i vbar\n", i); sock_send_string (sock, tmp);
sock_send_string(sock, tmp); sprintf (tmp, "widget_set X %i %i %i 0\n", i, i, lcd_hgt);
sprintf(tmp, "widget_set X %i %i %i 0\n", i, i, lcd_hgt); sock_send_string (sock, tmp);
sock_send_string(sock, tmp);
} }
// And add a title... // And add a title...
if(lcd_hgt >= 4) if (lcd_hgt >= 4) {
{ sock_send_string (sock, "widget_add X title title\n");
sock_send_string(sock, "widget_add X title title\n"); sock_send_string (sock, "widget_set X title {LOAD }\n");
sock_send_string(sock, "widget_set X title {LOAD }\n"); } else {
sock_send_string (sock, "widget_add X title string\n");
sock_send_string (sock, "widget_set X title 1 1 {LOAD}\n");
sock_send_string (sock, "widget_del X heartbeat\n");
} }
else sock_send_string (sock, "widget_add X zero string\n");
{ sock_send_string (sock, "widget_add X top string\n");
sock_send_string(sock, "widget_add X title string\n"); sprintf (tmp, "widget_set X zero %i %i 0\n", lcd_wid, lcd_hgt);
sock_send_string(sock, "widget_set X title 1 1 {LOAD}\n"); sock_send_string (sock, tmp);
sock_send_string(sock, "widget_del X heartbeat\n"); sprintf (tmp, "widget_set X top %i %i 1\n", lcd_wid, (lcd_hgt == 2) ? 1 : 2);
} sock_send_string (sock, tmp);
sock_send_string(sock, "widget_add X zero string\n");
sock_send_string(sock, "widget_add X top string\n");
sprintf(tmp, "widget_set X zero %i %i 0\n", lcd_wid, lcd_hgt);
sock_send_string(sock, tmp);
sprintf(tmp, "widget_set X top %i %i 1\n",
lcd_wid, (lcd_hgt==2)?1:2);
sock_send_string(sock, tmp);
} }
for(n=0; n<(lcd_wid-2); n++) loads[n] = loads[n+1]; for (n = 0; n < (lcd_wid - 2); n++)
loads[lcd_wid-2] = get_loadavg(); loads[n] = loads[n + 1];
loads[lcd_wid - 2] = get_loadavg ();
for(n=0; n<lcd_wid-1; n++) for (n = 0; n < lcd_wid - 1; n++)
if(loads[n] > loadmax) loadmax = loads[n]; if (loads[n] > loadmax)
loadmax = loads[n];
n = (int)loadmax; n = (int) loadmax;
if ((float)n < loadmax) { n++; } if ((float) n < loadmax) {
sprintf(tmp, "widget_set X top %i %i %i\n", n++;
lcd_wid, (lcd_hgt==2)?1:2, n); }
sprintf (tmp, "widget_set X top %i %i %i\n", lcd_wid, (lcd_hgt == 2) ? 1 : 2, n);
//if(display) sock_send_string(sock, tmp); //if(display) sock_send_string(sock, tmp);
sock_send_string(sock, tmp); sock_send_string (sock, tmp);
if (loadmax < 1.0) factor = (float)(lcd_cellhgt) * ((lcd_hgt==2)?2.0:3.0);
else factor = (float)(lcd_cellhgt) * ((lcd_hgt==2)?2.0:3.0) / (float)n;
for(n=0; n<lcd_wid-1; n++) if (loadmax < 1.0)
{ factor = (float) (lcd_cellhgt) * ((lcd_hgt == 2) ? 2.0 : 3.0);
else
factor = (float) (lcd_cellhgt) * ((lcd_hgt == 2) ? 2.0 : 3.0) / (float) n;
for (n = 0; n < lcd_wid - 1; n++) {
x = (loads[n] * factor); x = (loads[n] * factor);
sprintf(tmp, "widget_set X %i %i %i %i\n", n+1, n+1, lcd_hgt, (int)x); 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); //if(display) sock_send_string(sock, tmp);
sock_send_string(sock, tmp); sock_send_string (sock, tmp);
}
if(loadmax < LOAD_MIN)
{
status = BACKLIGHT_OFF;
}
if(loadmax > LOAD_MIN)
{
status = BACKLIGHT_ON;
}
if(loads[lcd_wid-2] > LOAD_MAX)
{
status = BLINK_ON;
} }
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... // And now the title...
if(lcd_hgt >= 4) if (lcd_hgt >= 4)
sprintf(tmp, "widget_set X title {LOAD %2.2f: %s}\n", sprintf (tmp, "widget_set X title {LOAD %2.2f: %s}\n", loads[lcd_wid - 2], host);
loads[lcd_wid-2], host);
else else
sprintf(tmp, "widget_set X title 1 1 {%s %2.2f}\n", sprintf (tmp, "widget_set X title 1 1 {%s %2.2f}\n", host, loads[lcd_wid - 2]);
host, loads[lcd_wid-2]);
//if(display) sock_send_string(sock, tmp); //if(display) sock_send_string(sock, tmp);
sock_send_string(sock, tmp); sock_send_string (sock, tmp);
return status; return status;
} // End xload_screen() } // End xload_screen()
+3 -3
View File
@@ -10,10 +10,10 @@
int load_init(); int load_init ();
int load_close(); int load_close ();
int xload_screen(int rep, int display); int xload_screen (int rep, int display);
#endif #endif
+171 -202
View File
@@ -39,9 +39,9 @@ int lcd_cellhgt;
See below... (default_sequence[]) See below... (default_sequence[])
*/ */
void HelpScreen(); void HelpScreen ();
void exit_program(int val); void exit_program (int val);
void main_loop(mode *sequence); void main_loop (mode * sequence);
#define MAX_SEQUENCE 256 #define MAX_SEQUENCE 256
// 1/8th second is a single time unit... // 1/8th second is a single time unit...
@@ -49,27 +49,26 @@ void main_loop(mode *sequence);
// Contains a list of modes to run // Contains a list of modes to run
mode default_sequence[] = mode default_sequence[] = {
{
// which on off inv timer/visible // which on off inv timer/visible
{ 'C', 1, 2, 0, 0xffff,0,},// [C]PU {'C', 1, 2, 0, 0xffff, 0,}, // [C]PU
{ 'M', 4, 16, 0, 0xffff,0,},// [M]emory {'M', 4, 16, 0, 0xffff, 0,}, // [M]emory
{ 'X', 64, 128, 1, 0xffff,0,},// [X]-load (load histogram) {'X', 64, 128, 1, 0xffff, 0,}, // [X]-load (load histogram)
{ 'T', 4, 64, 0, 0xffff,0,},// [T]ime/Date {'T', 4, 64, 0, 0xffff, 0,}, // [T]ime/Date
{ 'A', 999,9999, 0, 0xffff,0,},// [A]bout (credits) {'A', 999, 9999, 0, 0xffff, 0,}, // [A]bout (credits)
{ 1 , 0, 0, 0, 0,0,},// Modes after this line will not be run by default... {1, 0, 0, 0, 0, 0,}, // Modes after this line will not be run by default...
// ... all non-default modes must be in here! // ... all non-default modes must be in here!
// ... they will not show up otherwise. // ... they will not show up otherwise.
{ 'P', 1, 2, 0, 0xffff,0,},// [O]ld Timescreen {'P', 1, 2, 0, 0xffff, 0,}, // [O]ld Timescreen
{ 'O', 4, 64, 0, 0xffff,0,},// [O]ld Timescreen {'O', 4, 64, 0, 0xffff, 0,}, // [O]ld Timescreen
{ 'K', 4, 64, 0, 0xffff,0,},// big cloc[K] {'K', 4, 64, 0, 0xffff, 0,}, // big cloc[K]
{ 'U', 4, 128, 0, 0xffff,0,},// Old [U]ptime Screen {'U', 4, 128, 0, 0xffff, 0,}, // Old [U]ptime Screen
{ 'B', 32, 256, 1, 0xffff,0,},// [B]attery Status {'B', 32, 256, 1, 0xffff, 0,}, // [B]attery Status
{ 'G', 1, 2, 0, 0xffff,0,},// Cpu histogram [G]raph {'G', 1, 2, 0, 0xffff, 0,}, // Cpu histogram [G]raph
{ 'S', 16, 256, 1, 0xffff,0,},// [S]ize of biggest programs {'S', 16, 256, 1, 0xffff, 0,}, // [S]ize of biggest programs
{ 'D', 256, 256, 1, 0xffff,0,},// [D]isk stats {'D', 256, 256, 1, 0xffff, 0,}, // [D]isk stats
{ 0, 0, 0, 0,0,},// No more.. all done. {0, 0, 0, 0, 0,}, // No more.. all done.
}; };
// TODO: Clean up main()... It is still way too big. // TODO: Clean up main()... It is still way too big.
@@ -77,7 +76,8 @@ mode default_sequence[] =
// TODO: Config file; not just command line // TODO: Config file; not just command line
int main(int argc, char **argv) int
main (int argc, char **argv)
{ {
mode sequence[MAX_SEQUENCE]; mode sequence[MAX_SEQUENCE];
char cfgfile[256] = "/etc/lcdproc.cf"; char cfgfile[256] = "/etc/lcdproc.cf";
@@ -86,294 +86,265 @@ int main(int argc, char **argv)
int i, j, k; int i, j, k;
int tmp; int tmp;
memset(sequence, 0, sizeof(mode) * MAX_SEQUENCE); memset (sequence, 0, sizeof (mode) * MAX_SEQUENCE);
// Ctrl-C will cause a clean exit... // Ctrl-C will cause a clean exit...
signal(SIGINT, exit_program); signal (SIGINT, exit_program);
// and "kill"... // and "kill"...
signal(SIGTERM, exit_program); signal (SIGTERM, exit_program);
// and "kill -HUP" (hangup)... // and "kill -HUP" (hangup)...
signal(SIGHUP, exit_program); signal (SIGHUP, exit_program);
// and just in case, "kill -KILL" (which cannot be trapped; but oh well) // and just in case, "kill -KILL" (which cannot be trapped; but oh well)
signal(SIGKILL, exit_program); signal (SIGKILL, exit_program);
// Command line // Command line
memcpy(sequence, default_sequence, sizeof(default_sequence)); memcpy (sequence, default_sequence, sizeof (default_sequence));
for(i=1, j=0; i<argc; i++) for (i = 1, j = 0; i < argc; i++) {
{ if (argv[i][0] == '-')
if(argv[i][0] == '-') switch(argv[i][1]) switch (argv[i][1]) {
{ // s is for server
// s is for server
case 'S': case 'S':
case 's': if(argc < i+1) HelpScreen(); case 's':
strcpy(server, argv[++i]); if (argc < i + 1)
HelpScreen ();
strcpy (server, argv[++i]);
break; break;
// p is for port // p is for port
case 'P': case 'P':
case 'p': if(argc < i+1) HelpScreen(); case 'p':
port = atoi(argv[++i]); if (argc < i + 1)
if(port < 1 && port > 0xffff) HelpScreen ();
fprintf(stderr, "Warning: Port %i outside of standard range\n", port = atoi (argv[++i]);
port); if (port < 1 && port > 0xffff)
fprintf (stderr, "Warning: Port %i outside of standard range\n", port);
break; break;
// otherwise... Get help! // otherwise... Get help!
default: HelpScreen(); break; default:
} HelpScreen ();
break;
}
// Parse command line here... read the man page. // Parse command line here... read the man page.
else if(strlen(argv[i]) == 1) else if (strlen (argv[i]) == 1) {
{
// Grab the mode letter... // Grab the mode letter...
sequence[j].which = argv[i][0]; sequence[j].which = argv[i][0];
// If we have just a letter with no numbers... // If we have just a letter with no numbers...
// Set the defaults... // Set the defaults...
for(tmp=0, k=0; default_sequence[k].which; k++) for (tmp = 0, k = 0; default_sequence[k].which; k++) {
{ if (toupper (sequence[j].which) == default_sequence[k].which) {
if(toupper(sequence[j].which) == default_sequence[k].which) memcpy (&sequence[j], &default_sequence[k], sizeof (mode));
{ tmp = 1;
memcpy(&sequence[j], &default_sequence[k], sizeof(mode));
tmp=1;
break; break;
} }
} }
if(!tmp) { printf("Invalid Mode: %c\n", argv[i][0]); exit(0); } if (!tmp) {
printf ("Invalid Mode: %c\n", argv[i][0]);
exit (0);
}
j++; j++;
// Set the last element to 0... // Set the last element to 0...
memset(sequence + j, 0, sizeof(mode)); memset (sequence + j, 0, sizeof (mode));
} // End if(strlen(argv == 1)) } // End if(strlen(argv == 1))
else else {
{
// A multicharacter parameter by itself // A multicharacter parameter by itself
// is assumed to be a config file.. // is assumed to be a config file..
strcpy(cfgfile, argv[i]); strcpy (cfgfile, argv[i]);
printf("Ignoring config file: %s\n", cfgfile); printf ("Ignoring config file: %s\n", cfgfile);
} }
} }
// Connect to the server... // Connect to the server...
usleep(500000); // wait for the server to start up usleep (500000); // wait for the server to start up
sock = sock_connect(server, port); sock = sock_connect (server, port);
if (sock <= 0) if (sock <= 0) {
{ printf ("Error connecting to server %s on port %i.\n", server, port);
printf("Error connecting to server %s on port %i.\n",
server, port);
return 0; return 0;
} }
sock_send_string(sock, "hello\n"); sock_send_string (sock, "hello\n");
usleep(500000); // wait for the server to say hi. usleep (500000); // wait for the server to say hi.
// We grab the real values below, from the "connect" line. // We grab the real values below, from the "connect" line.
lcd_wid = 20; lcd_wid = 20;
lcd_hgt = 4; lcd_hgt = 4;
lcd_cellwid = 5; lcd_cellwid = 5;
lcd_cellhgt = 8; lcd_cellhgt = 8;
// Init the status gatherers... // Init the status gatherers...
mode_init(sequence); mode_init (sequence);
// And spew stuff! // And spew stuff!
main_loop(sequence); main_loop (sequence);
// Clean up // Clean up
exit_program(0); exit_program (0);
return 0; return 0;
} }
void HelpScreen() void
HelpScreen ()
{ {
printf("LCDproc, %s\n", version); printf ("LCDproc, %s\n", version);
printf("Usage: lcdproc [-s server] [-p port] [modelist]\n"); printf ("Usage: lcdproc [-s server] [-p port] [modelist]\n");
printf("\tOptions in []'s are optional.\n"); printf ("\tOptions in []'s are optional.\n");
printf("\tmodelist is \"mode [mode mode ...]\"\n"); printf ("\tmodelist is \"mode [mode mode ...]\"\n");
printf("\tMode letters: \t[C]pu [G]raph [T]ime [M]emory [X]load [D]isk [B]attery\n\t\t\tproc_[S]izes [O]ld_time big_cloc[K] [U]ptime CPU_SM[P]\n\t\t\t[A]bout\n"); printf ("\tMode letters: \t[C]pu [G]raph [T]ime [M]emory [X]load [D]isk [B]attery\n\t\t\tproc_[S]izes [O]ld_time big_cloc[K] [U]ptime CPU_SM[P]\n\t\t\t[A]bout\n");
printf("\n"); printf ("\n");
printf("\tUse \"man lcdproc\" for more info.\n"); printf ("\tUse \"man lcdproc\" for more info.\n");
printf("Example:\n"); printf ("Example:\n");
printf("\tlcdproc -s my.lcdproc.server.com C M X -p 13666\n"); printf ("\tlcdproc -s my.lcdproc.server.com C M X -p 13666\n");
printf("\n"); printf ("\n");
exit(0); exit (0);
} }
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// Called upon TERM and INTR signals... // Called upon TERM and INTR signals...
// //
void exit_program(int val) void
exit_program (int val)
{ {
Quit = 1; Quit = 1;
sock_close(sock); sock_close (sock);
mode_close(); mode_close ();
exit(0); exit (0);
} }
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// Main program loop... // Main program loop...
// //
void main_loop(mode *sequence) void
main_loop (mode * sequence)
{ {
int i=0, j; int i = 0, j;
//int status=0; //int status=0;
char buf[8192]; char buf[8192];
char *argv[256]; char *argv[256];
int argc, newtoken; int argc, newtoken;
int len; int len;
// Main loop // Main loop
// Run whatever screen we want, then wait. Woo-hoo! // Run whatever screen we want, then wait. Woo-hoo!
while(!Quit) while (!Quit) {
{
// Check for server input... // Check for server input...
len = sock_recv(sock, buf, 8000); len = sock_recv (sock, buf, 8000);
// Handle server input... // Handle server input...
while(len > 0) while (len > 0) {
{
// Now split the string into tokens... // Now split the string into tokens...
//for(i=0; i<argc; i++) argv[i]=NULL; // Get rid of old tokens //for(i=0; i<argc; i++) argv[i]=NULL; // Get rid of old tokens
argc = 0; newtoken = 1; argc = 0;
for(i=0; i<len; i++) newtoken = 1;
{ for (i = 0; i < len; i++) {
if(buf[i]) // For regular letters, keep tokenizing... if (buf[i]) // For regular letters, keep tokenizing...
{ {
switch(buf[i]) switch (buf[i]) {
{ case ' ':
case ' ': newtoken = 1;
newtoken = 1; buf[i] = 0;
buf[i] = 0; break;
break; case '\n':
case '\n': buf[i] = 0;
buf[i] = 0; default:
default: if (newtoken) {
if(newtoken) argv[argc] = buf + i;
{ argc++;
argv[argc] = buf+i; }
argc++; newtoken = 0;
} break;
newtoken = 0;
break;
} }
} } else // If we've got a zero, it's the end of a string...
else // If we've got a zero, it's the end of a string...
{ {
if(argc > 0) if (argc > 0) {
{
//printf("%s %s\n", argv[0], argv[1]); //printf("%s %s\n", argv[0], argv[1]);
if(0 == strcmp(argv[0], "listen")) if (0 == strcmp (argv[0], "listen")) {
{ for (j = 0; sequence[j].which; j++) {
for(j=0; sequence[j].which; j++) if (sequence[j].which == argv[1][0]) {
{
if(sequence[j].which == argv[1][0])
{
sequence[j].visible = 1; sequence[j].visible = 1;
//debug("Listen %s\n", argv[1]); //debug("Listen %s\n", argv[1]);
} }
} }
} } else if (0 == strcmp (argv[0], "ignore")) {
else if(0 == strcmp(argv[0], "ignore")) for (j = 0; sequence[j].which; j++) {
{ if (sequence[j].which == argv[1][0]) {
for(j=0; sequence[j].which; j++)
{
if(sequence[j].which == argv[1][0])
{
sequence[j].visible = 0; sequence[j].visible = 0;
//debug("Ignore %s\n", argv[1]); //debug("Ignore %s\n", argv[1]);
} }
} }
} } else if (0 == strcmp (argv[0], "key")) {
else if(0 == strcmp(argv[0], "key")) debug ("Key %s\n", argv[1]);
{ } else if (0 == strcmp (argv[0], "menu")) {
debug("Key %s\n", argv[1]); } else if (0 == strcmp (argv[0], "connect")) {
}
else if(0 == strcmp(argv[0], "menu"))
{
}
else if(0 == strcmp(argv[0], "connect"))
{
int a; int a;
for(a=1; a<argc; a++) for (a = 1; a < argc; a++) {
{ if (0 == strcmp (argv[a], "wid"))
if(0 == strcmp(argv[a], "wid")) lcd_wid = atoi (argv[++a]);
lcd_wid = atoi(argv[++a]); else if (0 == strcmp (argv[a], "hgt"))
else if(0 == strcmp(argv[a], "hgt")) lcd_hgt = atoi (argv[++a]);
lcd_hgt = atoi(argv[++a]); else if (0 == strcmp (argv[a], "cellwid"))
else if(0 == strcmp(argv[a], "cellwid")) lcd_cellwid = atoi (argv[++a]);
lcd_cellwid = atoi(argv[++a]); else if (0 == strcmp (argv[a], "cellhgt"))
else if(0 == strcmp(argv[a], "cellhgt")) lcd_cellhgt = atoi (argv[++a]);
lcd_cellhgt = atoi(argv[++a]);
} }
sock_send_string(sock, "client_set -name LCDproc\n"); sock_send_string (sock, "client_set -name LCDproc\n");
} } else if (0 == strcmp (argv[0], "bye")) {
else if(0 == strcmp(argv[0], "bye"))
{
//printf("Exiting LCDproc\n"); //printf("Exiting LCDproc\n");
exit_program(0); exit_program (0);
} } else {
else
{
int j; int j;
for(j=0; j<argc; j++) for (j = 0; j < argc; j++)
printf("%s ", argv[j]); printf ("%s ", argv[j]);
printf("\n"); printf ("\n");
} }
} }
argc = 0; newtoken = 1; argc = 0;
newtoken = 1;
} }
} }
len = sock_recv(sock, buf, 8000); len = sock_recv (sock, buf, 8000);
//debug("\n"); //debug("\n");
} }
// Gather stats... // Gather stats...
// Update screens... // Update screens...
for(i=0; sequence[i].which > 1; i++) for (i = 0; sequence[i].which > 1; i++) {
{
sequence[i].timer++; sequence[i].timer++;
if(sequence[i].visible) if (sequence[i].visible) {
{ if (sequence[i].timer >= sequence[i].on_time) {
if(sequence[i].timer >= sequence[i].on_time)
{
sequence[i].timer = 0; sequence[i].timer = 0;
// Now, update the screen... // Now, update the screen...
update_screen(sequence+i, 1); update_screen (sequence + i, 1);
} }
} } else {
else if (sequence[i].show_invisible) {
{ if (sequence[i].timer >= sequence[i].off_time) {
if(sequence[i].show_invisible)
{
if(sequence[i].timer >= sequence[i].off_time)
{
sequence[i].timer = 0; sequence[i].timer = 0;
// Now, update the screen... // Now, update the screen...
update_screen(sequence+i, 1); update_screen (sequence + i, 1);
} }
} } else {
else if (sequence[i].timer >= sequence[i].off_time) {
{
if(sequence[i].timer >= sequence[i].off_time)
{
sequence[i].timer = 0; sequence[i].timer = 0;
// Now, update the screen... // Now, update the screen...
update_screen(sequence+i, 0); update_screen (sequence + i, 0);
} }
} }
} }
} }
// Now sleep... // Now sleep...
usleep(TIME_UNIT); usleep (TIME_UNIT);
/* Old stuff /* Old stuff
timer=0; timer=0;
for(j=0; hold || (j<sequence[i].num_times && !Quit); j++) for(j=0; hold || (j<sequence[i].num_times && !Quit); j++)
@@ -442,5 +413,3 @@ void main_loop(mode *sequence)
*/ */
} }
} }
+8 -8
View File
@@ -3,8 +3,8 @@
extern int Quit; extern int Quit;
extern int sock; extern int sock;
extern char * version; extern char *version;
extern char * build_date; extern char *build_date;
extern int lcd_wid; extern int lcd_wid;
extern int lcd_hgt; extern int lcd_hgt;
@@ -13,12 +13,12 @@ extern int lcd_cellhgt;
typedef struct mode { typedef struct mode {
char which; // Which screen is it? char which; // Which screen is it?
int on_time; // How often to update while visible? int on_time; // How often to update while visible?
int off_time; // How often to get stats while not visible? int off_time; // How often to get stats while not visible?
int show_invisible; // Send stats while not visible? int show_invisible; // Send stats while not visible?
int timer; // Time since last update int timer; // Time since last update
int visible; // Can we be seen right now? int visible; // Can we be seen right now?
} mode; } mode;
+286 -323
View File
@@ -15,44 +15,48 @@
#include "mode.h" #include "mode.h"
#include "mem.h" #include "mem.h"
struct meminfo { int total, cache, buffers, free, shared; }; struct meminfo {
int total, cache, buffers, free, shared;
};
int meminfo_fd = 0; int meminfo_fd = 0;
static void get_mem_info(struct meminfo *result); static void get_mem_info (struct meminfo *result);
static void get_mem_info(struct meminfo *result) static void
get_mem_info (struct meminfo *result)
{ {
// int i, res; char *bufptr; // int i, res; char *bufptr;
reread(meminfo_fd, "get_meminfo:"); reread (meminfo_fd, "get_meminfo:");
result[0].total = getentry("MemTotal:", buffer); result[0].total = getentry ("MemTotal:", buffer);
result[0].free = getentry("MemFree:", buffer); result[0].free = getentry ("MemFree:", buffer);
result[0].shared = getentry("MemShared:", buffer); result[0].shared = getentry ("MemShared:", buffer);
result[0].buffers = getentry("Buffers:", buffer); result[0].buffers = getentry ("Buffers:", buffer);
result[0].cache = getentry("Cached:", buffer); result[0].cache = getentry ("Cached:", buffer);
result[1].total = getentry("SwapTotal:", buffer); result[1].total = getentry ("SwapTotal:", buffer);
result[1].free = getentry("SwapFree:", buffer); result[1].free = getentry ("SwapFree:", buffer);
} }
int mem_init() int
mem_init ()
{ {
if(!meminfo_fd) if (!meminfo_fd) {
{ meminfo_fd = open ("/proc/meminfo", O_RDONLY);
meminfo_fd = open("/proc/meminfo",O_RDONLY);
} }
return 0; return 0;
} }
int mem_close() int
mem_close ()
{ {
if(meminfo_fd) if (meminfo_fd)
meminfo_fd = open("/proc/meminfo",O_RDONLY); meminfo_fd = open ("/proc/meminfo", O_RDONLY);
meminfo_fd = 0; meminfo_fd = 0;
return 0; return 0;
} }
@@ -60,407 +64,366 @@ int mem_close()
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// Mem Screen displays info about memory and swap usage... // Mem Screen displays info about memory and swap usage...
// //
int mem_screen(int rep, int display) int
mem_screen (int rep, int display)
{ {
int n; int n;
struct meminfo mem[2]; struct meminfo mem[2];
static int first = 1; static int first = 1;
static int which_title=0; static int which_title = 0;
float value; float value;
if(first)
{
first = 0;
sock_send_string(sock, "screen_add M\n"); if (first) {
sprintf(buffer, "screen_set M -name {Memory & Swap: %s}\n", host); first = 0;
sock_send_string(sock, buffer);
if(lcd_hgt >= 4) sock_send_string (sock, "screen_add M\n");
{ sprintf (buffer, "screen_set M -name {Memory & Swap: %s}\n", host);
sock_send_string(sock, "widget_add M title title\n"); sock_send_string (sock, buffer);
sock_send_string(sock, "widget_set M title { MEM -==- SWAP}\n");
sock_send_string(sock, "widget_add M totl string\n");
sock_send_string(sock, "widget_add M used string\n");
sock_send_string(sock, "widget_set M totl 9 2 Totl\n");
sock_send_string(sock, "widget_set M used 9 3 Free\n");
sock_send_string(sock, "widget_add M EF string\n");
sock_send_string(sock, "widget_set M EF 1 4 {E F E F}\n");
sock_send_string(sock, "widget_add M memused string\n");
sock_send_string(sock, "widget_add M swapused string\n");
//sock_send_string(sock, "widget_set M memgauge 2 4 0\n");
//sock_send_string(sock, "widget_set M swapgauge 13 4 0\n");
}
else
{
sock_send_string(sock, "widget_add M m string\n");
sock_send_string(sock, "widget_add M s string\n");
if(lcd_wid >= 20)
{
sock_send_string(sock, "widget_set M m 1 1 {M [ ]}\n");
sock_send_string(sock, "widget_set M s 1 2 {S [ ]}\n");
}
else
{
sock_send_string(sock, "widget_set M m 1 1 {M [ ]}\n");
sock_send_string(sock, "widget_set M s 1 2 {S [ ]}\n");
}
sock_send_string(sock, "widget_add M mem% string\n");
sock_send_string(sock, "widget_add M swap% string\n");
sock_send_string(sock, "widget_set M mem% 16 1 { 0.0%}\n");
sock_send_string(sock, "widget_set M swap% 16 2 { 0.0%}\n");
//sock_send_string(sock, "widget_set M memgauge 8 1 0\n");
//sock_send_string(sock, "widget_set M swapgauge 8 2 0\n");
}
sock_send_string(sock, "widget_add M memtotl string\n"); if (lcd_hgt >= 4) {
sock_send_string(sock, "widget_add M swaptotl string\n"); sock_send_string (sock, "widget_add M title title\n");
sock_send_string (sock, "widget_set M title { MEM -==- SWAP}\n");
sock_send_string(sock, "widget_add M memgauge hbar\n"); sock_send_string (sock, "widget_add M totl string\n");
sock_send_string(sock, "widget_add M swapgauge hbar\n"); sock_send_string (sock, "widget_add M used string\n");
sock_send_string (sock, "widget_set M totl 9 2 Totl\n");
//sock_send_string(sock, "\n"); sock_send_string (sock, "widget_set M used 9 3 Free\n");
} sock_send_string (sock, "widget_add M EF string\n");
sock_send_string (sock, "widget_set M EF 1 4 {E F E F}\n");
sock_send_string (sock, "widget_add M memused string\n");
sock_send_string (sock, "widget_add M swapused string\n");
//sock_send_string(sock, "widget_set M memgauge 2 4 0\n");
//sock_send_string(sock, "widget_set M swapgauge 13 4 0\n");
} else {
sock_send_string (sock, "widget_add M m string\n");
sock_send_string (sock, "widget_add M s string\n");
if (lcd_wid >= 20) {
sock_send_string (sock, "widget_set M m 1 1 {M [ ]}\n");
sock_send_string (sock, "widget_set M s 1 2 {S [ ]}\n");
} else {
sock_send_string (sock, "widget_set M m 1 1 {M [ ]}\n");
sock_send_string (sock, "widget_set M s 1 2 {S [ ]}\n");
}
sock_send_string (sock, "widget_add M mem% string\n");
sock_send_string (sock, "widget_add M swap% string\n");
sock_send_string (sock, "widget_set M mem% 16 1 { 0.0%}\n");
sock_send_string (sock, "widget_set M swap% 16 2 { 0.0%}\n");
//sock_send_string(sock, "widget_set M memgauge 8 1 0\n");
//sock_send_string(sock, "widget_set M swapgauge 8 2 0\n");
}
sock_send_string (sock, "widget_add M memtotl string\n");
sock_send_string (sock, "widget_add M swaptotl string\n");
sock_send_string (sock, "widget_add M memgauge hbar\n");
sock_send_string (sock, "widget_add M swapgauge hbar\n");
//sock_send_string(sock, "\n");
}
get_mem_info(mem); get_mem_info (mem);
// flip the title back and forth...
if(lcd_hgt >= 4)
{
if(which_title & 4)
{
sprintf(buffer, "widget_set M title {%s}\n", host);
sock_send_string(sock, buffer);
}
else sock_send_string(sock, "widget_set M title { MEM -==- SWAP}\n");
which_title = (which_title + 1)&7;
// Total memory // flip the title back and forth...
sprintf(tmp, "widget_set M memtotl 1 2 {%6dk}\n", mem[0].total); if (lcd_hgt >= 4) {
if(display) sock_send_string(sock, tmp); if (which_title & 4) {
sprintf (buffer, "widget_set M title {%s}\n", host);
// Free memory (plus buffers and cache) sock_send_string (sock, buffer);
sprintf(tmp, "widget_set M memused 1 3 {%6dk}\n", } else
mem[0].free + mem[0].buffers + mem[0].cache); sock_send_string (sock, "widget_set M title { MEM -==- SWAP}\n");
if(display) sock_send_string(sock, tmp); which_title = (which_title + 1) & 7;
// Total swap
sprintf(tmp, "widget_set M swaptotl 14 2 {%6dk}\n", mem[1].total);
if(display) sock_send_string(sock, tmp);
// Free swap
sprintf(tmp, "widget_set M swapused 14 3 {%6dk}\n", mem[1].free);
if(display) sock_send_string(sock, tmp);
// Free memory graph // Total memory
n = (int)(35.0 - sprintf (tmp, "widget_set M memtotl 1 2 {%6dk}\n", mem[0].total);
((float)mem[0].free + (float)mem[0].buffers + (float)mem[0].cache) if (display)
/ (float)mem[0].total sock_send_string (sock, tmp);
* 35.0);
sprintf(tmp, "widget_set M memgauge 2 4 %i\n", n);
if(display) sock_send_string(sock, tmp);
// Free swap graph
n = (int)(35.0 -
(float)mem[1].free / (float)mem[1].total
* 35.0);
sprintf(tmp, "widget_set M swapgauge 13 4 %i\n", n);
if(display) sock_send_string(sock, tmp);
}
else
{
// Total memory
sprintf(tmp, "widget_set M memtotl 2 1 {%4dM}\n",
(int)(mem[0].total / 1024.0));
if(display) sock_send_string(sock, tmp);
// Total swap // Free memory (plus buffers and cache)
sprintf(tmp, "widget_set M swaptotl 2 2 {%4dM}\n", sprintf (tmp, "widget_set M memused 1 3 {%6dk}\n", mem[0].free + mem[0].buffers + mem[0].cache);
(int)(mem[1].total / 1024.0)); if (display)
if(display) sock_send_string(sock, tmp); sock_send_string (sock, tmp);
// Total swap
sprintf (tmp, "widget_set M swaptotl 14 2 {%6dk}\n", mem[1].total);
if (display)
sock_send_string (sock, tmp);
// Free swap
sprintf (tmp, "widget_set M swapused 14 3 {%6dk}\n", mem[1].free);
if (display)
sock_send_string (sock, tmp);
// Free memory graph // Free memory graph
value = ((float)mem[0].free + (float)mem[0].buffers + (float)mem[0].cache) n = (int) (35.0 - ((float) mem[0].free + (float) mem[0].buffers + (float) mem[0].cache)
/ (float)mem[0].total; / (float) mem[0].total * 35.0);
value = 1.0 - value; sprintf (tmp, "widget_set M memgauge 2 4 %i\n", n);
n = (int)((lcd_cellwid * (float)(lcd_wid-13))*(value)); if (display)
sprintf(tmp, "widget_set M memgauge 8 1 %i\n", n); sock_send_string (sock, tmp);
if(display) sock_send_string(sock, tmp);
value *= 100.0; // Free swap graph
if (value >= 99.9) { sprintf(buffer, "100%%"); } n = (int) (35.0 - (float) mem[1].free / (float) mem[1].total * 35.0);
else { sprintf(buffer, "%4.1f%%", value); } sprintf (tmp, "widget_set M swapgauge 13 4 %i\n", n);
sprintf(tmp, "widget_set M mem%% %i 1 {%s}\n", lcd_wid-4, buffer); if (display)
if(display) sock_send_string(sock, tmp); sock_send_string (sock, tmp);
} else {
// Total memory
sprintf (tmp, "widget_set M memtotl 2 1 {%4dM}\n", (int) (mem[0].total / 1024.0));
if (display)
sock_send_string (sock, tmp);
// Free swap graph // Total swap
value = ((float)mem[1].free / (float)mem[1].total); sprintf (tmp, "widget_set M swaptotl 2 2 {%4dM}\n", (int) (mem[1].total / 1024.0));
value = 1.0 - value; if (display)
n = (int)((lcd_cellwid * (float)(lcd_wid-13))*(value)); sock_send_string (sock, tmp);
sprintf(tmp, "widget_set M swapgauge 8 2 %i\n", n);
if(display) sock_send_string(sock, tmp);
value *= 100.0;
if (value >= 99.9) { sprintf(buffer, "100%%"); }
else { sprintf(buffer, "%4.1f%%", value); }
sprintf(tmp, "widget_set M swap%% %i 2 {%s}\n", lcd_wid-4, buffer);
if(display) sock_send_string(sock, tmp);
} // Free memory graph
value = ((float) mem[0].free + (float) mem[0].buffers + (float) mem[0].cache)
/ (float) mem[0].total;
value = 1.0 - value;
n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value));
sprintf (tmp, "widget_set M memgauge 8 1 %i\n", n);
if (display)
sock_send_string (sock, tmp);
value *= 100.0;
if (value >= 99.9) {
sprintf (buffer, "100%%");
} else {
sprintf (buffer, "%4.1f%%", value);
}
sprintf (tmp, "widget_set M mem%% %i 1 {%s}\n", lcd_wid - 4, buffer);
if (display)
sock_send_string (sock, tmp);
// Free swap graph
value = ((float) mem[1].free / (float) mem[1].total);
value = 1.0 - value;
n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value));
sprintf (tmp, "widget_set M swapgauge 8 2 %i\n", n);
if (display)
sock_send_string (sock, tmp);
value *= 100.0;
if (value >= 99.9) {
sprintf (buffer, "100%%");
} else {
sprintf (buffer, "%4.1f%%", value);
}
sprintf (tmp, "widget_set M swap%% %i 2 {%s}\n", lcd_wid - 4, buffer);
if (display)
sock_send_string (sock, tmp);
return 0; }
} // End mem_screen()
typedef struct proc_mem_info return 0;
{ } // End mem_screen()
char name[16]; // Is this really long enough?
// Size isn't used any more...
// Totl stores the "size" of the program now...
int size, totl; typedef struct proc_mem_info {
int number; char name[16]; // Is this really long enough?
// Size isn't used any more...
// Totl stores the "size" of the program now...
int size, totl;
int number;
} proc_mem_info; } proc_mem_info;
static int sort_procs(void *a, void *b) static int
sort_procs (void *a, void *b)
{ {
proc_mem_info *one, *two; proc_mem_info *one, *two;
if(!a) return 0;
if(!b) return 0;
one = (proc_mem_info *)a; if (!a)
two = (proc_mem_info *)b; return 0;
if (!b)
return 0;
one = (proc_mem_info *) a;
two = (proc_mem_info *) b;
return (two->totl > one->totl); return (two->totl > one->totl);
} }
int mem_top_screen(int rep, int display) int
mem_top_screen (int rep, int display)
{ {
// Much of this code was ripped from "gmemusage" // Much of this code was ripped from "gmemusage"
char buf[128]; char buf[128];
DIR *proc; DIR *proc;
FILE *StatusFile; FILE *StatusFile;
struct dirent * procdir; struct dirent *procdir;
char procName[16]; char procName[16];
int int
procSize , procSize, procRSS, procData, procStk, procExe;
procRSS ,
procData ,
procStk ,
procExe ;
const char const char
*NameLine = "Name:" , *NameLine = "Name:", *VmSizeLine = "VmSize:", *VmRSSLine = "VmRSS", *VmDataLine = "VmData", *VmStkLine = "VmStk", *VmExeLine = "VmExe";
*VmSizeLine = "VmSize:" ,
*VmRSSLine = "VmRSS" ,
*VmDataLine = "VmData" ,
*VmStkLine = "VmStk" ,
*VmExeLine = "VmExe" ;
const int const int
NameLineLen = strlen ( NameLine ) , NameLineLen = strlen (NameLine), VmSizeLineLen = strlen (VmSizeLine), VmDataLineLen = strlen (VmDataLine), VmStkLineLen = strlen (VmStkLine), VmExeLineLen = strlen (VmExeLine), VmRSSLineLen = strlen (VmRSSLine);
VmSizeLineLen = strlen ( VmSizeLine ) ,
VmDataLineLen = strlen ( VmDataLine ) ,
VmStkLineLen = strlen ( VmStkLine ) ,
VmExeLineLen = strlen ( VmExeLine ) ,
VmRSSLineLen = strlen ( VmRSSLine ) ;
int threshold = 400, unique; int threshold = 400, unique;
int i; int i;
proc_mem_info *p; proc_mem_info *p;
LL * procs; LL *procs;
static int first = 1; static int first = 1;
if(first) if (first) {
{
first = 0; first = 0;
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", host); sprintf (buffer, "screen_set S -name {Top Memory Use: %s}\n", host);
sock_send_string(sock, buffer); 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", host); sprintf (buffer, "widget_set S title {TOP MEM: %s}\n", host);
sock_send_string(sock, buffer); sock_send_string (sock, buffer);
sock_send_string(sock, "widget_add S f frame\n"); sock_send_string (sock, "widget_add S f frame\n");
if(lcd_hgt >= 4) if (lcd_hgt >= 4)
sock_send_string(sock, "widget_set S f 1 2 20 4 20 5 v 8\n"); sock_send_string (sock, "widget_set S f 1 2 20 4 20 5 v 8\n");
else else
sock_send_string(sock, "widget_set S f 1 2 20 2 20 5 v 16\n"); sock_send_string (sock, "widget_set S f 1 2 20 2 20 5 v 16\n");
for(i=1; i<=5; i++) for (i = 1; i <= 5; i++) {
{ sprintf (buffer, "widget_add S %i string -in f\n", i);
sprintf(buffer, "widget_add S %i string -in f\n", i); sock_send_string (sock, buffer);
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();
if(!procs) procs = LL_new ();
{ if (!procs) {
fprintf(stderr, "mem_top_screen: Error allocating list\n"); fprintf (stderr, "mem_top_screen: Error allocating list\n");
return -1; return -1;
} }
if ( ( proc = opendir ( "/proc" ) ) == NULL ) if ((proc = opendir ("/proc")) == NULL) {
{ fprintf (stderr, "mem_top_screen: unable to open /proc");
fprintf ( stderr , "mem_top_screen: unable to open /proc" ) ; perror ("");
perror ( "" ) ;
return -1; return -1;
} }
while ( (procdir = readdir ( proc )) ) while ((procdir = readdir (proc))) {
{ if (!index ("1234567890", procdir->d_name[0])) {
if ( !index ( "1234567890" , procdir -> d_name [0] ) ) continue;
{
continue ;
} }
sprintf ( buf , "/proc/%s/status" , procdir -> d_name ) ; sprintf (buf, "/proc/%s/status", procdir->d_name);
if ( ( StatusFile = fopen ( buf , "r" ) ) == NULL ) if ((StatusFile = fopen (buf, "r")) == NULL) {
{
// Not a serious error; process has finished before we could // Not a serious error; process has finished before we could
// examine it: // examine it:
//fprintf ( stderr , "mem_top_screen: cannot open %s for reading" , //fprintf ( stderr , "mem_top_screen: cannot open %s for reading" ,
// buf ) ; // buf ) ;
//perror ( "" ) ; //perror ( "" ) ;
continue ; continue;
} }
procRSS = procSize = procData = procStk = procExe = 0 ; procRSS = procSize = procData = procStk = procExe = 0;
while ( fgets ( buf , sizeof ( buf ) , StatusFile ) ) while (fgets (buf, sizeof (buf), StatusFile)) {
{ if (!strncmp (buf, NameLine, NameLineLen)) {
if ( !strncmp ( buf , NameLine , NameLineLen ) ) /* Name: procName */
{ sscanf (buf, "%*s %s", procName);
/* Name: procName */ } else if (!strncmp (buf, VmSizeLine, VmSizeLineLen)) {
sscanf ( buf , "%*s %s" , procName ) ; /* VmSize: procSize kB */
} sscanf (buf, "%*s %d", &procSize);
else if ( !strncmp ( buf , VmSizeLine , VmSizeLineLen ) ) } else if (!strncmp (buf, VmRSSLine, VmRSSLineLen)) {
{ /* VmRSS: procRSS kB */
/* VmSize: procSize kB */ sscanf (buf, "%*s %d", &procRSS);
sscanf ( buf , "%*s %d" , &procSize ) ; } else if (!strncmp (buf, VmDataLine, VmDataLineLen)) {
} /* VmData: procData kB */
else if ( !strncmp ( buf , VmRSSLine , VmRSSLineLen ) ) sscanf (buf, "%*s %d", &procData);
{ } else if (!strncmp (buf, VmStkLine, VmStkLineLen)) {
/* VmRSS: procRSS kB */ /* VmStk: procStk kB */
sscanf ( buf , "%*s %d" , &procRSS ) ; sscanf (buf, "%*s %d", &procStk);
} } else if (!strncmp (buf, VmExeLine, VmExeLineLen)) {
else if ( !strncmp ( buf , VmDataLine , VmDataLineLen ) ) /* VmExe: procExe kB */
{ sscanf (buf, "%*s %d", &procExe);
/* VmData: procData kB */ }
sscanf ( buf , "%*s %d" , &procData ) ;
}
else if ( !strncmp ( buf , VmStkLine , VmStkLineLen ) )
{
/* VmStk: procStk kB */
sscanf ( buf , "%*s %d" , &procStk ) ;
}
else if ( !strncmp ( buf , VmExeLine , VmExeLineLen ) )
{
/* VmExe: procExe kB */
sscanf ( buf , "%*s %d" , &procExe ) ;
}
} }
fclose ( StatusFile ) ; fclose (StatusFile);
if(procSize > threshold) if (procSize > threshold) {
{
// Figure out if it's sharing any memory... // Figure out if it's sharing any memory...
unique = 1; unique = 1;
LL_Rewind(procs); LL_Rewind (procs);
do { do {
p = LL_Get(procs); p = LL_Get (procs);
if(p) if (p) {
{ if (0 == strcmp (p->name, procName)) {
if(0 == strcmp(p->name, procName))
{
unique = 0; unique = 0;
p->number ++; p->number++;
p->totl += procData + procStk + procExe; p->totl += procData + procStk + procExe;
} }
} }
} while(LL_Next(procs) == 0); } while (LL_Next (procs) == 0);
// If this is the first one by this name... // If this is the first one by this name...
if(unique) if (unique) {
{ p = malloc (sizeof (proc_mem_info));
p = malloc(sizeof(proc_mem_info)); if (!p) {
if(!p) fprintf (stderr, "mem_top_screen: Error allocating process entry\n");
{ goto end; // Ack! I hate goto's!
fprintf(stderr,
"mem_top_screen: Error allocating process entry\n");
goto end; // Ack! I hate goto's!
} }
strcpy(p->name, procName); strcpy (p->name, procName);
p->size = procSize; p->size = procSize;
p->totl = procData + procStk + procExe; p->totl = procData + procStk + procExe;
p->number = 1; p->number = 1;
// TODO: Check for errors here? // TODO: Check for errors here?
LL_Push(procs, (void *)p); LL_Push (procs, (void *) p);
} }
} }
} }
closedir ( proc ) ; closedir (proc);
// Now, print some info... // Now, print some info...
LL_Rewind(procs); LL_Rewind (procs);
LL_Sort(procs, sort_procs); LL_Sort (procs, sort_procs);
LL_Rewind(procs); LL_Rewind (procs);
for(i=1; i<=5; i++) for (i = 1; i <= 5; i++) {
{ p = LL_Get (procs);
p = LL_Get(procs); if (p) {
if(p)
{
//printf("Mem hog: %s: %ik\n", p->name, p->size); //printf("Mem hog: %s: %ik\n", p->name, p->size);
if(p->number > 1) if (p->number > 1)
sprintf(buffer, "widget_set S %i 1 %i {%i%6ik %s(%i)}\n", i, i, i, sprintf (buffer, "widget_set S %i 1 %i {%i%6ik %s(%i)}\n", i, i, i, p->totl, p->name, p->number);
p->totl, p->name, p->number);
else else
sprintf(buffer, "widget_set S %i 1 %i {%i%6ik %s}\n", i, i, i, sprintf (buffer, "widget_set S %i 1 %i {%i%6ik %s}\n", i, i, i, p->totl, p->name);
p->totl, p->name); if (display)
if(display) sock_send_string(sock, buffer); sock_send_string (sock, buffer);
} } 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);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
} }
LL_Next(procs); LL_Next (procs);
} }
end: // Ack! I hate using labels!
end: // Ack! I hate using labels!
// Now clean it all up... // Now clean it all up...
LL_Rewind(procs); LL_Rewind (procs);
do { do {
p = (proc_mem_info *)LL_Get(procs); p = (proc_mem_info *) LL_Get (procs);
if(p) if (p) {
{
//printf("Proc: %6ik %s\n", p->size, p->name); //printf("Proc: %6ik %s\n", p->size, p->name);
free(p); free (p);
} }
} while(LL_Next(procs) == 0); } while (LL_Next (procs) == 0);
LL_Destroy(procs); LL_Destroy (procs);
return 0; return 0;
} // End mem_top_screen()
} // End mem_top_screen()
+4 -4
View File
@@ -1,11 +1,11 @@
#ifndef MEM_H #ifndef MEM_H
#define MEM_H #define MEM_H
int mem_init(); int mem_init ();
int mem_close(); int mem_close ();
int mem_screen(int rep, int display); int mem_screen (int rep, int display);
int mem_top_screen(int rep, int display); int mem_top_screen (int rep, int display);
#endif #endif
+199 -188
View File
@@ -30,205 +30,229 @@
#include "mem.h" #include "mem.h"
int ELLIPSIS='-'; int ELLIPSIS = '-';
// TODO: Clean this up... Support multiple display sizes.. // TODO: Clean this up... Support multiple display sizes..
char buffer[1024]; char buffer[1024];
char host[16]; char host[16];
void reread(int f, char *errmsg); void reread (int f, char *errmsg);
int getentry(const char *tag, const char *bufptr); int getentry (const char *tag, const char *bufptr);
int mode_init(mode *sequence) int
mode_init (mode * sequence)
{ {
int i; int i;
struct utsname Uname; struct utsname Uname;
// Grab the host name // Grab the host name
if(0 > uname(&Uname)) if (0 > uname (&Uname)) {
{ perror ("Can't get hostname");
perror("Can't get hostname"); strcpy (host, "host");
strcpy(host, "host"); } else {
} strncpy (host, Uname.nodename, 15);
else host[16] = 0;
{ if (index (host, '.')) // truncate at the first dot
strncpy(host, Uname.nodename, 15); *(index (host, '.')) = '\0';
host[16]=0; for (i = 0; i < 16; i++)
if(index(host,'.')) // truncate at the first dot if (host[i] == '\n')
*(index(host, '.'))='\0'; host[i] = 0;
for(i=0; i<16; i++)
if(host[i] == '\n') host[i]=0;
} }
// Init all the modescreens we need // Init all the modescreens we need
for(i=0; sequence[i].which > 1; i++) for (i = 0; sequence[i].which > 1; i++) {
{ switch (sequence[i].which) {
switch(sequence[i].which) case 'g':
{ case 'G': // cpu_graph_screen
case 'g': cpu_init ();
case 'G': // cpu_graph_screen break;
cpu_init(); case 'c':
break; case 'C': // cpu_screen
case 'c': cpu_init ();
case 'C': // cpu_screen break;
cpu_init(); case 'o':
break; case 'O': // clock_screen
case 'o': chrono_init ();
case 'O': // clock_screen break;
chrono_init(); case 'k':
break; case 'K': // big_clock_screen
case 'k': chrono_init ();
case 'K': // big_clock_screen break;
chrono_init(); case 'm':
break; case 'M': // mem_screen
case 'm': mem_init ();
case 'M': // mem_screen break;
mem_init(); case 's':
break; case 'S': // mem_info_screen
case 's': mem_init ();
case 'S': // mem_info_screen break;
mem_init(); case 'u':
break; case 'U': // uptime_screen
case 'u': chrono_init ();
case 'U': // uptime_screen break;
chrono_init(); case 't':
break; case 'T': // time_screen
case 't': chrono_init ();
case 'T': // time_screen break;
chrono_init(); case 'd':
break; case 'D': // disk_screen
case 'd': disk_init ();
case 'D': // disk_screen break;
disk_init(); case 'x':
break; case 'X': // xload_screen
case 'x': load_init ();
case 'X': // xload_screen break;
load_init(); case 'b':
break; case 'B': // battery_screen
case 'b': batt_init ();
case 'B': // battery_screen break;
batt_init(); case 'a':
break; case 'A': // credit_screen
case 'a': break;
case 'A': // credit_screen case 'p':
break; case 'P': // cpu_smp_screen
case 'p': cpu_smp_init ();
case 'P': // cpu_smp_screen break;
cpu_smp_init (); default:
break; break;
default: break;
} }
} }
return 0;
return 0;
} }
void mode_close() void
mode_close ()
{ {
batt_close(); batt_close ();
chrono_close(); chrono_close ();
cpu_close(); cpu_close ();
disk_close(); disk_close ();
load_close(); load_close ();
mem_close(); mem_close ();
cpu_smp_close (); cpu_smp_close ();
} }
int update_screen(mode *m, int display) int
update_screen (mode * m, int display)
{ {
static int status = -1; static int status = -1;
int old_status = status; int old_status = status;
if(m) if (m) {
{ switch (m->which) {
switch(m->which) case 'g':
{ case 'G':
case 'g': status = cpu_graph_screen (m->timer, display);
case 'G': status = cpu_graph_screen(m->timer, display); break; break;
case 'c': case 'c':
case 'C': status = cpu_screen(m->timer, display); break; case 'C':
case 'o': status = cpu_screen (m->timer, display);
case 'O': status = clock_screen(m->timer, display); break; break;
case 'k': case 'o':
case 'K': status = big_clock_screen(m->timer, display); break; case 'O':
case 'm': status = clock_screen (m->timer, display);
case 'M': status = mem_screen(m->timer, display); break; break;
case 's': case 'k':
case 'S': status = mem_top_screen(m->timer, display); break; case 'K':
case 'u': status = big_clock_screen (m->timer, display);
case 'U': status = uptime_screen(m->timer, display); break; break;
case 't': case 'm':
case 'T': status = time_screen(m->timer, display); break; case 'M':
case 'd': status = mem_screen (m->timer, display);
case 'D': status = disk_screen(m->timer, display); break; break;
case 'x': case 's':
case 'X': status = xload_screen(m->timer, display); break; case 'S':
case 'b': status = mem_top_screen (m->timer, display);
case 'B': status = battery_screen(m->timer, display); break; break;
case 'a': case 'u':
case 'A': status = credit_screen(m->timer, display); break; case 'U':
case 'p': status = uptime_screen (m->timer, display);
case 'P': status = cpu_smp_screen (m->timer, display); break; break;
default: break; case 't':
case 'T':
status = time_screen (m->timer, display);
break;
case 'd':
case 'D':
status = disk_screen (m->timer, display);
break;
case 'x':
case 'X':
status = xload_screen (m->timer, display);
break;
case 'b':
case 'B':
status = battery_screen (m->timer, display);
break;
case 'a':
case 'A':
status = credit_screen (m->timer, display);
break;
case 'p':
case 'P':
status = cpu_smp_screen (m->timer, display);
break;
default:
break;
} }
/* Debugging tool... /* Debugging tool...
if(display) if(display)
{ {
printf("Displayed Mode %c\n", m->which); printf("Displayed Mode %c\n", m->which);
} }
*/ */
} }
if(status != old_status) if (status != old_status) {
{ if (status == BACKLIGHT_OFF) {
if(status == BACKLIGHT_OFF) sock_send_string (sock, "backlight off\n");
{
sock_send_string(sock, "backlight off\n");
} }
if(status == BACKLIGHT_ON) if (status == BACKLIGHT_ON) {
{ sock_send_string (sock, "backlight on\n");
sock_send_string(sock, "backlight on\n");
} }
if(status == BLINK_ON) if (status == BLINK_ON) {
{ sock_send_string (sock, "backlight blink\n");
sock_send_string(sock, "backlight blink\n");
} }
} }
return status; return status;
} }
void reread(int f, char *errmsg) void
reread (int f, char *errmsg)
{ {
if (lseek(f, 0L, 0) == 0 && read(f, buffer, sizeof(buffer) - 1 ) > 0 ) if (lseek (f, 0L, 0) == 0 && read (f, buffer, sizeof (buffer) - 1) > 0)
return; return;
perror(errmsg); perror (errmsg);
exit(1); exit (1);
} }
int getentry(const char *tag, const char *bufptr) int
getentry (const char *tag, const char *bufptr)
{ {
char *tail; char *tail;
int retval, len = strlen(tag); int retval, len = strlen (tag);
while (bufptr) while (bufptr) {
{ if (*bufptr == '\n')
if (*bufptr == '\n') bufptr++; bufptr++;
if (!strncmp(tag, bufptr, len)) if (!strncmp (tag, bufptr, len)) {
{ retval = strtol (bufptr + len, &tail, 10);
retval = strtol(bufptr + len, &tail, 10); if (tail == bufptr + len)
if (tail == bufptr + len) return -1; return -1;
else return retval; else
} return retval;
bufptr = strchr( bufptr, '\n'); }
} bufptr = strchr (bufptr, '\n');
return -1; }
return -1;
} }
@@ -246,44 +270,31 @@ char tmp[1024];
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Credit Screen shows who wrote this... // Credit Screen shows who wrote this...
// //
int credit_screen(int rep, int display) int
credit_screen (int rep, int display)
{ {
static int first = 1; static int first = 1;
if(first) if (first) {
{
first = 0; first = 0;
sock_send_string(sock, "screen_add A\n"); sock_send_string (sock, "screen_add A\n");
sock_send_string(sock, sock_send_string (sock, "screen_set A -name {Credits for LCDproc}\n");
"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 (tmp, "widget_set A title {LCDPROC %s}\n", version);
sprintf(tmp, "widget_set A title {LCDPROC %s}\n", version); sock_send_string (sock, tmp);
sock_send_string(sock, tmp); 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 two string\n");
sock_send_string(sock, "widget_add A one string\n"); sock_send_string (sock, "widget_add A three string\n");
sock_send_string(sock, "widget_add A two string\n"); sock_send_string (sock, "widget_set A one 1 2 { for Linux }\n");
sock_send_string(sock, "widget_add A three string\n"); sock_send_string (sock, "widget_set A two 1 3 { by William Ferrell}\n");
sock_send_string(sock, sock_send_string (sock, "widget_set A three 1 4 { and Scott Scriven}\n");
"widget_set A one 1 2 { for Linux }\n"); } else {
sock_send_string(sock, sock_send_string (sock, "widget_add A text scroller\n");
"widget_set A two 1 3 { by William Ferrell}\n"); sock_send_string (sock, "widget_set A text 1 2 20 2 v 8 { for Linux by William Ferrell and Scott Scriven}\n");
sock_send_string(sock,
"widget_set A three 1 4 { and Scott Scriven}\n");
}
else
{
sock_send_string(sock, "widget_add A text scroller\n");
sock_send_string(sock,
"widget_set A text 1 2 20 2 v 8 { for Linux by William Ferrell and Scott Scriven}\n");
} }
} }
return 0; return 0;
} // End credit_screen() } // End credit_screen()
+6 -6
View File
@@ -16,16 +16,16 @@ extern int PAD;
// Character for the "..." symbol. // Character for the "..." symbol.
extern int ELLIPSIS; extern int ELLIPSIS;
int mode_init(mode *sequence); int mode_init (mode * sequence);
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 credit_screen (int rep, int display);
// These are for the modescreens' use only.. // These are for the modescreens' use only..
void reread(int f, char *errmsg); void reread (int f, char *errmsg);
int getentry(const char *tag, const char *bufptr); int getentry (const char *tag, const char *bufptr);
#endif #endif
+31 -33
View File
@@ -19,71 +19,69 @@
int client_data_init(client_data *d) int
client_data_init (client_data * d)
{ {
if(!d) return -1; if (!d)
return -1;
d->ack = 0; d->ack = 0;
d->name = NULL; d->name = NULL;
d->screenlist = LL_new(); d->screenlist = LL_new ();
if(!d->screenlist) if (!d->screenlist) {
{ fprintf (stderr, "client_data_init: Error allocating screenlist\n");
fprintf(stderr, "client_data_init: Error allocating screenlist\n");
return -1; return -1;
} }
/* TODO: this section... (client menus) /* TODO: this section... (client menus)
d->menulist = LL_new(); d->menulist = LL_new();
if(!d->menulist) if(!d->menulist)
{ {
fprintf(stderr, "client_data_init: Error allocating menulist\n"); fprintf(stderr, "client_data_init: Error allocating menulist\n");
return -1; return -1;
} }
*/ */
return 0; return 0;
} }
int client_data_destroy(client_data *d) int
client_data_destroy (client_data * d)
{ {
screen *s; screen *s;
debug("client_data_destroy\n"); debug ("client_data_destroy\n");
if(!d) return -1; if (!d)
return -1;
d->ack = 0; d->ack = 0;
// Clean up the name... // Clean up the name...
if(d->name) if (d->name)
free(d->name); free (d->name);
// Clean up the screenlist... // Clean up the screenlist...
debug("client_data_destroy: Cleaning screenlist\n"); debug ("client_data_destroy: Cleaning screenlist\n");
LL_Rewind(d->screenlist); LL_Rewind (d->screenlist);
do { do {
s = (screen *)LL_Get(d->screenlist); s = (screen *) LL_Get (d->screenlist);
if(s) if (s) {
{ debug ("client_data_destroy: removing screen %s\n", s->id);
debug("client_data_destroy: removing screen %s\n", s->id);
// FIXME? This shouldn't be handled here... // FIXME? This shouldn't be handled here...
// Now, remove it from the screenlist... // Now, remove it from the screenlist...
if(screenlist_remove_all(s) < 0) if (screenlist_remove_all (s) < 0) {
{
// Not a serious error.. // Not a serious error..
fprintf(stderr, "client_data_destroy: Error dequeueing screen\n"); fprintf (stderr, "client_data_destroy: Error dequeueing screen\n");
return 0; return 0;
} }
// Free its memory... // Free its memory...
screen_destroy(s); screen_destroy (s);
} }
} while(LL_Next(d->screenlist) == 0); } while (LL_Next (d->screenlist) == 0);
LL_Destroy(d->screenlist); LL_Destroy (d->screenlist);
// TODO: clean up the rest of the data... // TODO: clean up the rest of the data...
return 0; return 0;
} }
+10 -11
View File
@@ -6,21 +6,20 @@
#define CLIENT_NAME_SIZE 256 #define CLIENT_NAME_SIZE 256
typedef struct client_data typedef struct client_data {
{ int ack;
int ack; char *name;
char *name; // and other stuff... doesn't matter yet
// and other stuff... doesn't matter yet LL *screenlist;
LL * screenlist; // list of accepted keys... (?)
// list of accepted keys... (?) LL *menulist;
LL * menulist;
} client_data; } client_data;
// sets up an existing (empty) client_data struct // sets up an existing (empty) client_data struct
int client_data_init(client_data *d); int client_data_init (client_data * d);
// destroys members of a client's data // destroys members of a client's data
int client_data_destroy(client_data *d); int client_data_destroy (client_data * d);
#endif #endif
+503 -599
View File
File diff suppressed because it is too large Load Diff
+22 -23
View File
@@ -7,32 +7,31 @@
point to a function to call, defined below. point to a function to call, defined below.
*/ */
typedef struct client_function typedef struct client_function {
{ char *keyword;
char *keyword; int (*function) (client * c, int argc, char **argv);
int (*function)(client *c, int argc, char **argv);
} client_function; } client_function;
// FIXME? Do these really need to be visible from other sources? // FIXME? Do these really need to be visible from other sources?
int test_func_func(client *c, int argc, char **argv); int test_func_func (client * c, int argc, char **argv);
int hello_func(client *c, int argc, char **argv); int hello_func (client * c, int argc, char **argv);
int client_set_func(client *c, int argc, char **argv); int client_set_func (client * c, int argc, char **argv);
int client_add_key_func(client *c, int argc, char **argv); int client_add_key_func (client * c, int argc, char **argv);
int client_del_key_func(client *c, int argc, char **argv); int client_del_key_func (client * c, int argc, char **argv);
int screen_add_func(client *c, int argc, char **argv); int screen_add_func (client * c, int argc, char **argv);
int screen_del_func(client *c, int argc, char **argv); int screen_del_func (client * c, int argc, char **argv);
int screen_set_func(client *c, int argc, char **argv); int screen_set_func (client * c, int argc, char **argv);
int widget_add_func(client *c, int argc, char **argv); int widget_add_func (client * c, int argc, char **argv);
int widget_del_func(client *c, int argc, char **argv); int widget_del_func (client * c, int argc, char **argv);
int widget_set_func(client *c, int argc, char **argv); int widget_set_func (client * c, int argc, char **argv);
int menu_add_func(client *c, int argc, char **argv); int menu_add_func (client * c, int argc, char **argv);
int menu_del_func(client *c, int argc, char **argv); int menu_del_func (client * c, int argc, char **argv);
int menu_set_func(client *c, int argc, char **argv); int menu_set_func (client * c, int argc, char **argv);
int menu_item_add_func(client *c, int argc, char **argv); int menu_item_add_func (client * c, int argc, char **argv);
int menu_item_del_func(client *c, int argc, char **argv); int menu_item_del_func (client * c, int argc, char **argv);
int menu_item_set_func(client *c, int argc, char **argv); int menu_item_set_func (client * c, int argc, char **argv);
int backlight_func(client *c, int argc, char **argv); int backlight_func (client * c, int argc, char **argv);
int output_func(client *c, int argc, char **argv); int output_func (client * c, int argc, char **argv);
extern client_function commands[]; extern client_function commands[];
+9 -11
View File
@@ -8,19 +8,17 @@
what the user does. what the user does.
*/ */
typedef struct client_menu typedef struct client_menu {
{ char id[];
char id[]; LL *items;
LL * items;
} client_menu; } client_menu;
typedef struct client_menu_item typedef struct client_menu_item {
{ char id[];
char id[]; int type; // Title, function, submenu, slider, checkbox, etc...
int type; // Title, function, submenu, slider, checkbox, etc... int value; // Holds stuff like "true", 43, etc...
int value; // Holds stuff like "true", 43, etc... char text[]; // Text to display here...
char text[]; // Text to display here... char child[]; // For the "submenu" type
char child[]; // For the "submenu" type
} client_menu; } client_menu;
+107 -114
View File
@@ -22,81 +22,72 @@
LL * clients; LL *clients;
// Initialize and kill client list... // Initialize and kill client list...
int client_init() int
client_init ()
{ {
debug("client_init()\n"); debug ("client_init()\n");
clients = LL_new(); clients = LL_new ();
if(!clients) if (!clients) {
{ fprintf (stderr, "client_init: Unable to create client list\n");
fprintf(stderr, "client_init: Unable to create client list\n");
return -1; return -1;
} }
return 0; return 0;
} }
int client_shutdown() int
client_shutdown ()
{ {
// TODO: Close all connections first... // TODO: Close all connections first...
client *c; client *c;
debug("client_shutdown()\n"); debug ("client_shutdown()\n");
// Free all client structures... // Free all client structures...
// Note that the regular list loop doesn't work here, because // Note that the regular list loop doesn't work here, because
// client_destroy() calls LL_Remove() // client_destroy() calls LL_Remove()
for(c = LL_Pop(clients); for (c = LL_Pop (clients); c; c = LL_Pop (clients)) {
c; debug ("client_shutdown: ...\n");
c = LL_Pop(clients)) if (c) {
{ debug ("client_shutdown: ... %i ...\n", c->sock);
debug("client_shutdown: ...\n"); if (0 != client_destroy (c)) {
if(c) fprintf (stderr, "client_shutdown: Error freeing client\n");
{ } else {
debug("client_shutdown: ... %i ...\n", c->sock); debug ("client_shutdown: Freed client...\n");
if(0 != client_destroy(c))
{
fprintf(stderr, "client_shutdown: Error freeing client\n");
} }
else } else {
{ debug ("client_shutdown: No client!\n");
debug("client_shutdown: Freed client...\n");
}
}
else
{
debug("client_shutdown: No client!\n");
} }
} }
// Then, free the list... // Then, free the list...
LL_Destroy(clients); LL_Destroy (clients);
debug("client_shutdown: done\n"); debug ("client_shutdown: done\n");
return 0; return 0;
} }
// Create and destroy clients.... // Create and destroy clients....
client * client_create(int sock) client *
client_create (int sock)
{ {
client *c; client *c;
debug("client_create(%i)\n", sock); debug ("client_create(%i)\n", sock);
// Allocate new client... // Allocate new client...
c = malloc(sizeof(client)); c = malloc (sizeof (client));
if(!c) if (!c) {
{ fprintf (stderr, "client_create: error allocating new client\n");
fprintf(stderr, "client_create: error allocating new client\n");
return NULL; return NULL;
} }
// Init struct members // Init struct members
c->sock = 0; c->sock = 0;
c->data = NULL; c->data = NULL;
@@ -106,75 +97,72 @@ client * client_create(int sock)
c->sock = sock; c->sock = sock;
// Set up message list... // Set up message list...
c->messages = LL_new(); c->messages = LL_new ();
if(!c->messages) if (!c->messages) {
{ fprintf (stderr, "client_create: error allocating message list\n");
fprintf(stderr, "client_create: error allocating message list\n"); free (c);
free(c);
return NULL; return NULL;
} }
// TODO: allocate and init client data... // TODO: allocate and init client data...
c->data = malloc(sizeof(client_data)); c->data = malloc (sizeof (client_data));
if(!c->data) if (!c->data) {
{ fprintf (stderr, "client_create: error allocating client data\n");
fprintf(stderr, "client_create: error allocating client data\n"); free (c->messages);
free(c->messages); free (c);
free(c); return NULL;
} else if (client_data_init (c->data) < 0) {
return NULL; return NULL;
} }
else if(client_data_init(c->data) < 0)
{
return NULL;
}
// TODO: Check for errors while adding the client to the list? // TODO: Check for errors while adding the client to the list?
LL_Push(clients, (void *)c); LL_Push (clients, (void *) c);
return c; return c;
} }
int client_destroy(client *c)
int
client_destroy (client * c)
{ {
// TODO: Close the socket connection here? // TODO: Close the socket connection here?
int err; int err;
char *str; char *str;
debug("client_destroy()\n"); debug ("client_destroy()\n");
if(!c) return -1; if (!c)
return -1;
// Eat the rest of the incoming requests... // Eat the rest of the incoming requests...
debug("client_destroy: get_messages\n"); debug ("client_destroy: get_messages\n");
while((str = client_get_message(c))) while ((str = client_get_message (c))) {
{ if (str) {
if(str) { debug ("client_destroy: kill message %s\n", str);
debug("client_destroy: kill message %s\n", str); free (str);
free(str);
} }
} }
err = LL_Destroy(c->messages); err = LL_Destroy (c->messages);
// Free client's other data // Free client's other data
client_data_destroy(c->data); client_data_destroy (c->data);
/* /*
// FIXME? Should the connection get closed here or elsewhere? // FIXME? Should the connection get closed here or elsewhere?
if(c->sock) close(c->sock); if(c->sock) close(c->sock);
c->sock = 0; c->sock = 0;
*/ */
// Remove the client from the clients list... // Remove the client from the clients list...
LL_Remove(clients, c); LL_Remove (clients, c);
free(c); free (c);
return 0; return 0;
} }
// Add and remove messages from the client's queue... // Add and remove messages from the client's queue...
int client_add_message(client *c, char *message) int
client_add_message (client * c, char *message)
{ {
int err = 0; int err = 0;
char *dup; char *dup;
@@ -183,59 +171,64 @@ int client_add_message(client *c, char *message)
// int len; // int len;
//debug("client_add_message(%s)\n", message); //debug("client_add_message(%s)\n", message);
if(!c) return -1; if (!c)
if(!message) return -1; return -1;
if (!message)
return -1;
// len = strlen(message); // len = strlen(message);
// if(len < 1) return 0; // if(len < 1) return 0;
// Copy the string to avoid overwriting the original... // Copy the string to avoid overwriting the original...
dup = strdup(message); dup = strdup (message);
if(!dup) if (!dup) {
{ fprintf (stderr, "client_add_message: Error allocating new string\n");
fprintf(stderr, "client_add_message: Error allocating new string\n");
return -1; return -1;
} }
// Now split the string into lines and enqueue each one... // Now split the string into lines and enqueue each one...
for(str = strtok(dup, delimiters); str; str=strtok(NULL, delimiters)) for (str = strtok (dup, delimiters); str; str = strtok (NULL, delimiters)) {
{ cp = strdup (str);
cp = strdup(str); debug ("client_add_message: %s\n", cp);
debug("client_add_message: %s\n", cp); err += LL_Enqueue (c->messages, (void *) cp);
err += LL_Enqueue(c->messages, (void *)cp);
} }
//debug("client_add_message(%s): %i errors\n", message, err); //debug("client_add_message(%s): %i errors\n", message, err);
free(dup); // Fixed memory leak... free (dup); // Fixed memory leak...
// Err is the number of errors encountered... // Err is the number of errors encountered...
return err; return err;
} }
// Woo-hoo! A simple function. :) // Woo-hoo! A simple function. :)
char * client_get_message(client *c) char *
client_get_message (client * c)
{ {
char *str; char *str;
//debug("client_get_message()\n"); //debug("client_get_message()\n");
if(!c) return NULL; if (!c)
return NULL;
str = (char *)LL_Dequeue(c->messages);
str = (char *) LL_Dequeue (c->messages);
//debug("client_get_message: \"%s\"\n", str); //debug("client_get_message: \"%s\"\n", str);
return str; return str;
} }
// Get and set the client's data... // Get and set the client's data...
int client_set(client *c, void *data) int
client_set (client * c, void *data)
{ {
// You know, I really doubt this function will be useful... // You know, I really doubt this function will be useful...
return 0; return 0;
} }
void * client_get(client *c)
void *
client_get (client * c)
{ {
// But this one might be handy... // But this one might be handy...
@@ -243,24 +236,24 @@ void * client_get(client *c)
} }
client * client_find_sock(int sock) client *
client_find_sock (int sock)
{ {
client * c; client *c;
// debug("client_find_sock(%i)\n", sock); // debug("client_find_sock(%i)\n", sock);
LL_Rewind(clients); LL_Rewind (clients);
do{ do {
c = (client *)LL_Get(clients); c = (client *) LL_Get (clients);
// debug("client_find_sock: ... %i ...\n", c->sock); // debug("client_find_sock: ... %i ...\n", c->sock);
if(c->sock == sock) if (c->sock == sock) {
{ // debug("client_find_sock: ..! %i !..\n", c->sock);
// debug("client_find_sock: ..! %i !..\n", c->sock);
return c; return c;
} }
} while(LL_Next(clients) == 0); } while (LL_Next (clients) == 0);
debug ("client_find_sock: failed\n");
debug("client_find_sock: failed\n");
return NULL; return NULL;
} }
+14 -15
View File
@@ -4,37 +4,36 @@
#include "client_data.h" #include "client_data.h"
#include "../shared/LL.h" #include "../shared/LL.h"
typedef struct client typedef struct client {
{ int sock;
int sock; LL *messages;
LL *messages; client_data *data;
client_data *data;
} client; } client;
extern LL *clients; extern LL *clients;
// Initialize and kill client list... // Initialize and kill client list...
int client_init(); int client_init ();
int client_shutdown(); int client_shutdown ();
// Create and destroy clients.... // Create and destroy clients....
client * client_create(int sock); client *client_create (int sock);
int client_destroy(client *c); int client_destroy (client * c);
// Add and remove messages from the client's queue... // Add and remove messages from the client's queue...
int client_add_message(client *c, char *message); int client_add_message (client * c, char *message);
char * client_get_message(client *c); char *client_get_message (client * c);
// Get and set the client's data... // Get and set the client's data...
// Not used at all yet, and may never be. Oh, well. // Not used at all yet, and may never be. Oh, well.
int client_set(client *c, void *data); int client_set (client * c, void *data);
void * client_get(client *c); void *client_get (client * c);
// Search for a client with a particular filedescriptor... // Search for a client with a particular filedescriptor...
client * client_find_sock(int sock); client *client_find_sock (int sock);
#endif #endif
+462 -481
View File
File diff suppressed because it is too large Load Diff
+16 -16
View File
@@ -4,22 +4,22 @@
extern lcd_logical_driver *CFontz; extern lcd_logical_driver *CFontz;
int CFontz_init(lcd_logical_driver *driver, char *device); int CFontz_init (lcd_logical_driver * driver, char *device);
void CFontz_close(); void CFontz_close ();
void CFontz_flush(); void CFontz_flush ();
void CFontz_flush_box(int lft, int top, int rgt, int bot); void CFontz_flush_box (int lft, int top, int rgt, int bot);
void CFontz_chr(int x, int y, char c) ; void CFontz_chr (int x, int y, char c);
int CFontz_contrast(int contrast); int CFontz_contrast (int contrast);
void CFontz_backlight(int on); void CFontz_backlight (int on);
void CFontz_init_vbar(); void CFontz_init_vbar ();
void CFontz_init_hbar(); void CFontz_init_hbar ();
void CFontz_vbar(int x, int len); void CFontz_vbar (int x, int len);
void CFontz_hbar(int x, int y, int len); void CFontz_hbar (int x, int y, int len);
void CFontz_init_num(); void CFontz_init_num ();
void CFontz_num(int x, int num); void CFontz_num (int x, int num);
void CFontz_set_char(int n, char *dat); void CFontz_set_char (int n, char *dat);
void CFontz_icon(int which, char dest); void CFontz_icon (int which, char dest);
void CFontz_draw_frame(char *dat); void CFontz_draw_frame (char *dat);
+706 -653
View File
File diff suppressed because it is too large Load Diff
+22 -22
View File
@@ -4,28 +4,28 @@
extern lcd_logical_driver *MtxOrb; extern lcd_logical_driver *MtxOrb;
int MtxOrb_init(lcd_logical_driver *driver, char *device); int MtxOrb_init (lcd_logical_driver * driver, char *device);
void MtxOrb_clear(); void MtxOrb_clear ();
void MtxOrb_close(); void MtxOrb_close ();
void MtxOrb_flush(); void MtxOrb_flush ();
void MtxOrb_flush_box(int lft, int top, int rgt, int bot); void MtxOrb_flush_box (int lft, int top, int rgt, int bot);
void MtxOrb_chr(int x, int y, char c) ; void MtxOrb_chr (int x, int y, char c);
int MtxOrb_contrast(int contrast); int MtxOrb_contrast (int contrast);
void MtxOrb_backlight(int on); void MtxOrb_backlight (int on);
void MtxOrb_output(int on); void MtxOrb_output (int on);
void MtxOrb_init_vbar(); void MtxOrb_init_vbar ();
void MtxOrb_init_hbar(); void MtxOrb_init_hbar ();
void MtxOrb_vbar(int x, int len); void MtxOrb_vbar (int x, int len);
void MtxOrb_hbar(int x, int y, int len); void MtxOrb_hbar (int x, int y, int len);
void MtxOrb_init_num(); void MtxOrb_init_num ();
void MtxOrb_num(int x, int num); void MtxOrb_num (int x, int num);
void MtxOrb_set_char(int n, char *dat); void MtxOrb_set_char (int n, char *dat);
void MtxOrb_icon(int which, char dest); void MtxOrb_icon (int which, char dest);
void MtxOrb_draw_frame(char *dat); void MtxOrb_draw_frame (char *dat);
char MtxOrb_getkey(); char MtxOrb_getkey ();
void MtxOrb_init_all(int type); void MtxOrb_init_all (int type);
int MtxOrb_ask_bar(int type); int MtxOrb_ask_bar (int type);
void MtxOrb_set_known_char(int car, int type); void MtxOrb_set_known_char (int car, int type);
#endif #endif
+142 -134
View File
@@ -24,8 +24,8 @@
lcd_logical_driver *curses_drv; lcd_logical_driver *curses_drv;
int PAD=255; int PAD = 255;
int ELLIPSIS=7; int ELLIPSIS = 7;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////// For Curses Terminal Output //////////////////////// ////////////////////// For Curses Terminal Output ////////////////////////
@@ -34,85 +34,65 @@ int ELLIPSIS=7;
static char icon_char = '@'; static char icon_char = '@';
int curses_drv_init(struct lcd_logical_driver *driver, char *args) int
curses_drv_init (struct lcd_logical_driver *driver, char *args)
{ {
char *argv[64]; char *argv[64];
int argc; int argc;
int i,j; int i, j;
argc = get_args(argv, args, 64);
for(i=0; i<argc; i++)
{ argc = get_args (argv, args, 64);
if(0 == strcmp(argv[i], "-f") ||
0 == strcmp(argv[i], "--forecolor")) for (i = 0; i < argc; i++) {
{ if (0 == strcmp (argv[i], "-f") || 0 == strcmp (argv[i], "--forecolor")) {
if(i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "curses_init: %s requires an argument\n", fprintf (stderr, "curses_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} }
// TODO: color display in curses driver! // TODO: color display in curses driver!
printf("Sorry, colors not yet implemented...\n"); printf ("Sorry, colors not yet implemented...\n");
//strcpy(device, argv[++i]); //strcpy(device, argv[++i]);
} } else if (0 == strcmp (argv[i], "-b") || 0 == strcmp (argv[i], "--backcolor")) {
else if(0 == strcmp(argv[i], "-b") || if (i + 1 > argc) {
0 == strcmp(argv[i], "--backcolor")) fprintf (stderr, "curses_init: %s requires an argument\n", argv[i]);
{
if(i + 1 > argc) {
fprintf(stderr, "curses_init: %s requires an argument\n",
argv[i]);
return -1; return -1;
} }
// TODO: color display in curses driver! // TODO: color display in curses driver!
printf("Sorry, colors not yet implemented...\n"); printf ("Sorry, colors not yet implemented...\n");
//strcpy(device, argv[++i]); //strcpy(device, argv[++i]);
} } else if (0 == strcmp (argv[i], "-B") || 0 == strcmp (argv[i], "--backlight")) {
else if(0 == strcmp(argv[i], "-B") || if (i + 1 > argc) {
0 == strcmp(argv[i], "--backlight")) fprintf (stderr, "curses_init: %s requires an argument\n", argv[i]);
{
if(i + 1 > argc) {
fprintf(stderr, "curses_init: %s requires an argument\n",
argv[i]);
return -1; return -1;
} }
// TODO: color display in curses driver! // TODO: color display in curses driver!
printf("Sorry, colors not yet implemented...\n"); printf ("Sorry, colors not yet implemented...\n");
//strcpy(device, argv[++i]); //strcpy(device, argv[++i]);
} } else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
else if(0 == strcmp(argv[i], "-h") || printf ("LCDproc [n]curses driver\n" "\t-f\t--forecolor\tChange the foreground color\n" "\t-b\t--backcolor\tChange the backlight's \"off\" color\n" "\t-B\t--backlight\tChange the backlight's \"on\" color\n" "\t-h\t--help\t\tShow this help information\n");
0 == strcmp(argv[i], "--help"))
{
printf("LCDproc [n]curses driver\n"
"\t-f\t--forecolor\tChange the foreground color\n"
"\t-b\t--backcolor\tChange the backlight's \"off\" color\n"
"\t-B\t--backlight\tChange the backlight's \"on\" color\n"
"\t-h\t--help\t\tShow this help information\n");
return -1; return -1;
} else {
printf ("Invalid parameter: %s\n", argv[i]);
} }
else
{
printf("Invalid parameter: %s\n", argv[i]);
}
} }
curses_drv = driver; curses_drv = driver;
// Init curses... // Init curses...
initscr(); initscr ();
cbreak(); cbreak ();
noecho(); noecho ();
nodelay(stdscr, TRUE); nodelay (stdscr, TRUE);
nonl(); nonl ();
intrflush(stdscr, FALSE); intrflush (stdscr, FALSE);
keypad(stdscr, TRUE); keypad (stdscr, TRUE);
curses_drv_clear(); curses_drv_clear ();
// Override output functions... // Override output functions...
driver->clear = curses_drv_clear; driver->clear = curses_drv_clear;
driver->string = curses_drv_string; driver->string = curses_drv_string;
driver->chr = curses_drv_chr; driver->chr = curses_drv_chr;
@@ -122,7 +102,7 @@ int curses_drv_init(struct lcd_logical_driver *driver, char *args)
driver->init_hbar = NULL; driver->init_hbar = NULL;
driver->num = curses_drv_num; driver->num = curses_drv_num;
driver->init_num = curses_drv_init_num; driver->init_num = curses_drv_init_num;
driver->init = curses_drv_init; driver->init = curses_drv_init;
driver->close = curses_drv_close; driver->close = curses_drv_close;
driver->flush = curses_drv_flush; driver->flush = curses_drv_flush;
@@ -139,29 +119,31 @@ int curses_drv_init(struct lcd_logical_driver *driver, char *args)
PAD = '#'; PAD = '#';
// Change the character used for "..." // Change the character used for "..."
ELLIPSIS = '~'; ELLIPSIS = '~';
return 200; // 200 is arbitrary. (must be 1 or more) return 200; // 200 is arbitrary. (must be 1 or more)
} }
void curses_drv_close() void
curses_drv_close ()
{ {
// Close curses // Close curses
clear(); clear ();
move(0,0); move (0, 0);
refresh(); refresh ();
endwin(); endwin ();
drv_base_close ();
drv_base_close();
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void curses_drv_clear() void
curses_drv_clear ()
{ {
clear(); clear ();
} }
@@ -169,100 +151,111 @@ void curses_drv_clear()
// Prints a string on the lcd display, at position (x,y). The // Prints a string on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void curses_drv_string(int x, int y, char string[]) void
curses_drv_string (int x, int y, char string[])
{ {
int i; int i;
unsigned char *c; unsigned char *c;
for(i=0; string[i]; i++) for (i = 0; string[i]; i++) {
{
c = &string[i]; c = &string[i];
switch(*c) switch (*c) {
{ case 0:
case 0: *c = icon_char; break; *c = icon_char;
case 255: *c = '#'; break; break;
case 255:
*c = '#';
break;
} }
} }
mvaddstr(y-1, x-1, string); mvaddstr (y - 1, x - 1, string);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The // Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void curses_drv_chr(int x, int y, char c) void
curses_drv_chr (int x, int y, char c)
{ {
switch(c) switch (c) {
{ case 0:
case 0: c = icon_char; break; c = icon_char;
case -1: c = '#'; break; break;
case -1:
c = '#';
break;
} }
mvaddch(y-1, x-1, c); mvaddch (y - 1, x - 1, c);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for big numbers. // Sets up for big numbers.
// //
void curses_drv_init_num() void
curses_drv_init_num ()
{ {
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. // Writes a big number.
// //
void curses_drv_num(int x, int num) void
curses_drv_num (int x, int num)
{ {
char c; char c;
int y, dx; int y, dx;
c='0'+num; c = '0' + num;
// printf(&c,"%1d",num); // printf(&c,"%1d",num);
for(y=1; y<5; y++) for (y = 1; y < 5; y++)
for(dx=0; dx<3; dx++) for (dx = 0; dx < 3; dx++)
curses_drv_chr(x+dx, y, c); curses_drv_chr (x + dx, y, c);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen. // Draws a vertical bar; erases entire column onscreen.
// //
void curses_drv_vbar(int x, int len) void
curses_drv_vbar (int x, int len)
{ {
char map[]="_.,,ooO8"; char map[] = "_.,,ooO8";
int y; int y;
for(y=lcd.hgt; y > 0 && len>0; y--) for (y = lcd.hgt; y > 0 && len > 0; y--) {
{ if (len >= lcd.cellhgt)
if(len >= lcd.cellhgt) curses_drv_chr(x, y, '8'); curses_drv_chr (x, y, '8');
else curses_drv_chr(x, y, map[len-1]); else
curses_drv_chr (x, y, map[len - 1]);
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
// move(4-len/lcd.cellhgt, x-1); // move(4-len/lcd.cellhgt, x-1);
// vline(0, len/lcd.cellhgt); // vline(0, len/lcd.cellhgt);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void curses_drv_hbar(int x, int y, int len) void
curses_drv_hbar (int x, int y, int len)
{ {
for(; x<=lcd.wid && len>0; x++) for (; x <= lcd.wid && len > 0; x++) {
{ if (len >= lcd.cellwid)
if(len>=lcd.cellwid) curses_drv_chr (x, y, '=');
curses_drv_chr(x, y, '=');
else else
curses_drv_chr(x, y, '-'); curses_drv_chr (x, y, '-');
len -= lcd.cellwid; len -= lcd.cellwid;
} }
// move(y-1, x-1); // move(y-1, x-1);
// hline(0, len/lcd.cellwid); // hline(0, len/lcd.cellwid);
} }
@@ -271,56 +264,71 @@ void curses_drv_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void curses_drv_icon(int which, char dest) void
curses_drv_icon (int which, char dest)
{ {
if(dest == 0) if (dest == 0)
switch(which) switch (which) {
{ case 0:
case 0: icon_char = '+'; break; icon_char = '+';
case 1: icon_char = '*'; break; break;
default: icon_char = '#'; break; case 1:
icon_char = '*';
break;
default:
icon_char = '#';
break;
} }
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void curses_drv_flush() void
curses_drv_flush ()
{ {
curses_drv_draw_frame(curses_drv->framebuf); curses_drv_draw_frame (curses_drv->framebuf);
} }
void curses_drv_flush_box(int lft, int top, int rgt, int bot) void
curses_drv_flush_box (int lft, int top, int rgt, int bot)
{ {
curses_drv_flush(); curses_drv_flush ();
} }
void curses_drv_draw_frame(char *dat) void
curses_drv_draw_frame (char *dat)
{ {
// border(0, 0, 0, 0, 0, 0, lcd.wid+1, lcd.hgt+1); // border(0, 0, 0, 0, 0, 0, lcd.wid+1, lcd.hgt+1);
refresh(); refresh ();
} }
char curses_drv_getkey() char
curses_drv_getkey ()
{ {
int i; int i;
i = getch();
if(i == KEY_LEFT) return 'D';
if(i == KEY_UP) return 'B';
if(i == KEY_DOWN) return 'C';
if(i == KEY_RIGHT) return 'A';
if(i != ERR) return i; i = getch ();
else return 0;
if (i == KEY_LEFT)
return 'D';
if (i == KEY_UP)
return 'B';
if (i == KEY_DOWN)
return 'C';
if (i == KEY_RIGHT)
return 'A';
if (i != ERR)
return i;
else
return 0;
} }
+15 -15
View File
@@ -4,21 +4,21 @@
extern lcd_logical_driver *curses_drv; extern lcd_logical_driver *curses_drv;
int curses_drv_init(struct lcd_logical_driver *driver, char *args); int curses_drv_init (struct lcd_logical_driver *driver, char *args);
void curses_drv_close(); void curses_drv_close ();
void curses_drv_clear(); void curses_drv_clear ();
void curses_drv_flush(); void curses_drv_flush ();
void curses_drv_string(int x, int y, char string[]); void curses_drv_string (int x, int y, char string[]);
void curses_drv_chr(int x, int y, char c); void curses_drv_chr (int x, int y, char c);
void curses_drv_vbar(int x, int len); void curses_drv_vbar (int x, int len);
void curses_drv_hbar(int x, int y, int len); void curses_drv_hbar (int x, int y, int len);
void curses_drv_icon(int which, char dest); void curses_drv_icon (int which, char dest);
void curses_drv_flush(); void curses_drv_flush ();
void curses_drv_flush_box(int lft, int top, int rgt, int bot); void curses_drv_flush_box (int lft, int top, int rgt, int bot);
void curses_drv_draw_frame(char *dat); void curses_drv_draw_frame (char *dat);
char curses_drv_getkey(); char curses_drv_getkey ();
void curses_drv_init_num(); void curses_drv_init_num ();
void curses_drv_num(int x, int num); void curses_drv_num (int x, int num);
#endif #endif
+159 -148
View File
@@ -18,88 +18,93 @@
// function... // function...
int debug_init(struct lcd_logical_driver *driver, char *args) int
debug_init (struct lcd_logical_driver *driver, char *args)
{ {
printf("debug_init(%s)\n", device); printf ("debug_init(%s)\n", device);
if(!driver->framebuf)
{
printf("Allocating frame buffer (%ix%i)\n", lcd.wid, lcd.hgt);
driver->framebuf = malloc(lcd.wid * lcd.hgt);
}
if(!driver->framebuf) if (!driver->framebuf) {
{ printf ("Allocating frame buffer (%ix%i)\n", lcd.wid, lcd.hgt);
debug_close(); driver->framebuf = malloc (lcd.wid * lcd.hgt);
}
if (!driver->framebuf) {
debug_close ();
return -1; return -1;
} }
if(driver->framebuf) printf("Frame buffer: %i\n", (int)driver->framebuf); if (driver->framebuf)
printf ("Frame buffer: %i\n", (int) driver->framebuf);
debug_clear(); debug_clear ();
driver->clear = debug_clear; driver->clear = debug_clear;
driver->string = debug_string; driver->string = debug_string;
driver->chr = debug_chr; driver->chr = debug_chr;
driver->vbar = debug_vbar; driver->vbar = debug_vbar;
driver->hbar = debug_hbar; driver->hbar = debug_hbar;
driver->init_num = debug_init_num; driver->init_num = debug_init_num;
driver->num = debug_num; driver->num = debug_num;
driver->init = debug_init;
driver->close = debug_close;
driver->flush = debug_flush;
driver->flush_box = debug_flush_box;
driver->contrast = debug_contrast;
driver->backlight = debug_backlight;
driver->set_char = debug_set_char;
driver->icon = debug_icon;
driver->init_vbar = debug_init_vbar;
driver->init_hbar = debug_init_hbar;
driver->draw_frame = debug_draw_frame;
driver->getkey = debug_getkey; driver->init = debug_init;
driver->close = debug_close;
driver->flush = debug_flush;
return 200; // 200 is arbitrary. (must be 1 or more) driver->flush_box = debug_flush_box;
driver->contrast = debug_contrast;
driver->backlight = debug_backlight;
driver->set_char = debug_set_char;
driver->icon = debug_icon;
driver->init_vbar = debug_init_vbar;
driver->init_hbar = debug_init_hbar;
driver->draw_frame = debug_draw_frame;
driver->getkey = debug_getkey;
return 200; // 200 is arbitrary. (must be 1 or more)
} }
void debug_close() void
debug_close ()
{ {
// Ack! This shouldn't crash the program, but does.. Why?? // Ack! This shouldn't crash the program, but does.. Why??
printf("debug_close()\n"); printf ("debug_close()\n");
// This is the line which crashes. // This is the line which crashes.
if(driver->framebuf) free(driver->framebuf); if (driver->framebuf)
free (driver->framebuf);
if(driver->framebuf) printf("Frame buffer: %i\n", (int)driver->framebuf); if (driver->framebuf)
driver->framebuf = NULL; printf ("Frame buffer: %i\n", (int) driver->framebuf);
driver->framebuf = NULL;
// printf("debug_close() finished\n"); // printf("debug_close() finished\n");
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void debug_clear() void
debug_clear ()
{ {
printf("clear()\n"); printf ("clear()\n");
memset(driver->framebuf, ' ', lcd.wid*lcd.hgt); memset (driver->framebuf, ' ', lcd.wid * lcd.hgt);
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void debug_flush() void
debug_flush ()
{ {
printf("flush()\n"); printf ("flush()\n");
lcd.draw_frame(); lcd.draw_frame ();
} }
@@ -107,182 +112,188 @@ void debug_flush()
// Prints a string on the lcd display, at position (x,y). The // Prints a string on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void debug_string(int x, int y, char string[]) void
debug_string (int x, int y, char string[])
{ {
int i; int i;
printf("string(%i, %i):%s \n", x, y, string); printf ("string(%i, %i):%s \n", x, y, string);
x -= 1; // Convert 1-based coords to 0-based...
y -= 1; x -= 1; // Convert 1-based coords to 0-based...
y -= 1;
for(i=0; string[i]; i++)
{ for (i = 0; string[i]; i++) {
driver->framebuf[(y*lcd.wid) + x + i] = string[i]; driver->framebuf[(y * lcd.wid) + x + i] = string[i];
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The // Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void debug_chr(int x, int y, char c) void
debug_chr (int x, int y, char c)
{ {
printf("character(%i, %i):%c\n", x, y, c); printf ("character(%i, %i):%c\n", x, y, c);
y--;
x--; y--;
x--;
lcd.framebuf[(y*lcd.wid) + x] = c;
lcd.framebuf[(y * lcd.wid) + x] = c;
} }
void debug_contrast(int contrast) void
debug_contrast (int contrast)
{ {
printf("Contrast: %i\n", contrast); printf ("Contrast: %i\n", contrast);
} }
void debug_backlight(int on) void
debug_backlight (int on)
{ {
if(on) if (on) {
{ printf ("Backlight ON\n");
printf("Backlight ON\n"); } else {
} printf ("Backlight OFF\n");
else }
{
printf("Backlight OFF\n");
}
} }
void debug_init_vbar() void
debug_init_vbar ()
{ {
printf("Vertical bars.\n"); printf ("Vertical bars.\n");
} }
void debug_init_hbar() void
debug_init_hbar ()
{ {
printf("Horizontal bars.\n"); printf ("Horizontal bars.\n");
} }
void debug_init_num() void
debug_init_num ()
{ {
printf("Big Numbers.\n"); printf ("Big Numbers.\n");
} }
void debug_num(int x, int num) void
debug_num (int x, int num)
{ {
printf("BigNum(%i, %i)\n", x, num); printf ("BigNum(%i, %i)\n", x, num);
} }
void debug_set_char(int n, char *dat) void
debug_set_char (int n, char *dat)
{ {
printf("Set Character %i\n", n); printf ("Set Character %i\n", n);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen. // Draws a vertical bar; erases entire column onscreen.
// //
void debug_vbar(int x, int len) void
debug_vbar (int x, int len)
{ {
int y; int y;
printf("Vbar(%i, %i)\n", x, len); printf ("Vbar(%i, %i)\n", x, len);
for(y=lcd.hgt; y > 0 && len>0; y--)
{ for (y = lcd.hgt; y > 0 && len > 0; y--) {
debug_chr(x, y, '|'); debug_chr (x, y, '|');
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void debug_hbar(int x, int y, int len) void
debug_hbar (int x, int y, int len)
{ {
printf("Hbar(%i, %i, %i)\n", x, y, len); printf ("Hbar(%i, %i, %i)\n", x, y, len);
for(; x<lcd.wid && len>0; x++) for (; x < lcd.wid && len > 0; x++) {
{ debug_chr (x, y, '-');
debug_chr(x,y,'-');
len -= lcd.cellwid; len -= lcd.cellwid;
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void debug_icon(int which, char dest) void
debug_icon (int which, char dest)
{ {
printf("Char %i is icon %i\n", dest, which); printf ("Char %i is icon %i\n", dest, which);
} }
void debug_flush_box(int lft, int top, int rgt, int bot) void
debug_flush_box (int lft, int top, int rgt, int bot)
{ {
printf("Flush Box(%i, %i)-(%i, %i)\n", lft, top, rgt, bot); printf ("Flush Box(%i, %i)-(%i, %i)\n", lft, top, rgt, bot);
debug_flush ();
debug_flush();
} }
void debug_draw_frame(char *dat) void
debug_draw_frame (char *dat)
{ {
int i, j; int i, j;
char out[LCD_MAX_WIDTH]; char out[LCD_MAX_WIDTH];
printf("draw_frame()\n"); printf ("draw_frame()\n");
if(!dat) return;
if (!dat)
return;
// printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat); // printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat);
for(i=0; i<lcd.wid; i++) for (i = 0; i < lcd.wid; i++) {
{
out[i] = '-'; out[i] = '-';
} }
out[lcd.wid] = 0; out[lcd.wid] = 0;
printf("+%s+\n", out); printf ("+%s+\n", out);
for(i=0; i<lcd.hgt; i++) for (i = 0; i < lcd.hgt; i++) {
{ for (j = 0; j < lcd.wid; j++) {
for(j=0; j<lcd.wid; j++) out[j] = dat[j + (i * lcd.wid)];
{ }
out[j] = dat[j+(i*lcd.wid)];
}
out[lcd.wid] = 0; out[lcd.wid] = 0;
printf("|%s|\n", out); printf ("|%s|\n", out);
} }
for(i=0; i<lcd.wid; i++) for (i = 0; i < lcd.wid; i++) {
{
out[i] = '-'; out[i] = '-';
} }
out[lcd.wid] = 0; out[lcd.wid] = 0;
printf("+%s+\n", out); printf ("+%s+\n", out);
} }
char debug_getkey() char
debug_getkey ()
{ {
printf("Trying to grab keypress.\n"); printf ("Trying to grab keypress.\n");
return 0; return 0;
} }
+19 -19
View File
@@ -2,25 +2,25 @@
#define LCD_DEBUG_H #define LCD_DEBUG_H
int debug_init(struct lcd_logical_driver *driver, char *args); int debug_init (struct lcd_logical_driver *driver, char *args);
void debug_close(); void debug_close ();
void debug_clear(); void debug_clear ();
void debug_flush(); void debug_flush ();
void debug_string(int x, int y, char string[]); void debug_string (int x, int y, char string[]);
void debug_chr(int x, int y, char c); void debug_chr (int x, int y, char c);
void debug_contrast(int contrast); void debug_contrast (int contrast);
void debug_backlight(int on); void debug_backlight (int on);
void debug_init_vbar(); void debug_init_vbar ();
void debug_init_hbar(); void debug_init_hbar ();
void debug_init_num(); void debug_init_num ();
void debug_vbar(int x, int len); void debug_vbar (int x, int len);
void debug_hbar(int x, int y, int len); void debug_hbar (int x, int y, int len);
void debug_num(int x, int num); void debug_num (int x, int num);
void debug_set_char(int n, char *dat); void debug_set_char (int n, char *dat);
void debug_icon(int which, char dest); void debug_icon (int which, char dest);
void debug_flush_box(int lft, int top, int rgt, int bot); void debug_flush_box (int lft, int top, int rgt, int bot);
void debug_draw_frame(char *dat); void debug_draw_frame (char *dat);
char debug_getkey(); char debug_getkey ();
#endif #endif
+115 -99
View File
@@ -22,57 +22,57 @@ lcd_logical_driver *drv_base;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// init() should set up any device-specific stuff, and // init() should set up any device-specific stuff, and
// point all the function pointers. // point all the function pointers.
int drv_base_init(struct lcd_logical_driver *driver, char *args) int
drv_base_init (struct lcd_logical_driver *driver, char *args)
{ {
// printf("drv_base_init()\n"); // printf("drv_base_init()\n");
drv_base = driver; drv_base = driver;
driver->wid = 20;
driver->hgt = 4;
// You must use driver->framebuf here, but may use lcd.framebuf later. driver->wid = 20;
if(!driver->framebuf) driver->hgt = 4;
driver->framebuf = malloc(driver->wid * driver->hgt);
if(!driver->framebuf) // You must use driver->framebuf here, but may use lcd.framebuf later.
{ if (!driver->framebuf)
drv_base_close(); driver->framebuf = malloc (driver->wid * driver->hgt);
if (!driver->framebuf) {
drv_base_close ();
return -1; return -1;
} }
// Debugging... // Debugging...
// if(lcd.framebuf) printf("Frame buffer: %i\n", (int)lcd.framebuf); // if(lcd.framebuf) printf("Frame buffer: %i\n", (int)lcd.framebuf);
memset(driver->framebuf, ' ', driver->wid*driver->hgt); memset (driver->framebuf, ' ', driver->wid * driver->hgt);
// drv_base_clear(); // drv_base_clear();
driver->cellwid = 5; driver->cellwid = 5;
driver->cellhgt = 8; driver->cellhgt = 8;
driver->clear = drv_base_clear;
driver->string = drv_base_string;
driver->chr = drv_base_chr;
driver->vbar = drv_base_vbar;
driver->init_vbar = drv_base_init_vbar;
driver->hbar = drv_base_hbar;
driver->init_hbar = drv_base_init_hbar;
driver->num = drv_base_num;
driver->init_num = drv_base_init_num;
driver->init = drv_base_init;
driver->close = drv_base_close;
driver->flush = drv_base_flush;
driver->flush_box = drv_base_flush_box;
driver->contrast = drv_base_contrast;
driver->backlight = drv_base_backlight;
driver->set_char = drv_base_set_char;
driver->icon = drv_base_icon;
driver->draw_frame = drv_base_draw_frame;
driver->getkey = drv_base_getkey; driver->clear = drv_base_clear;
driver->string = drv_base_string;
driver->chr = drv_base_chr;
return 200; // 200 is arbitrary. (must be 1 or more) driver->vbar = drv_base_vbar;
driver->init_vbar = drv_base_init_vbar;
driver->hbar = drv_base_hbar;
driver->init_hbar = drv_base_init_hbar;
driver->num = drv_base_num;
driver->init_num = drv_base_init_num;
driver->init = drv_base_init;
driver->close = drv_base_close;
driver->flush = drv_base_flush;
driver->flush_box = drv_base_flush_box;
driver->contrast = drv_base_contrast;
driver->backlight = drv_base_backlight;
driver->set_char = drv_base_set_char;
driver->icon = drv_base_icon;
driver->draw_frame = drv_base_draw_frame;
driver->getkey = drv_base_getkey;
return 200; // 200 is arbitrary. (must be 1 or more)
} }
@@ -80,27 +80,31 @@ int drv_base_init(struct lcd_logical_driver *driver, char *args)
// lcd.framebuf will be set to the appropriate buffer before calling // lcd.framebuf will be set to the appropriate buffer before calling
// your driver. // your driver.
void drv_base_close() void
drv_base_close ()
{ {
if(lcd.framebuf != NULL) free(lcd.framebuf); if (lcd.framebuf != NULL)
free (lcd.framebuf);
lcd.framebuf = NULL; lcd.framebuf = NULL;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void drv_base_clear() void
drv_base_clear ()
{ {
memset(lcd.framebuf, ' ', lcd.wid*lcd.hgt); memset (lcd.framebuf, ' ', lcd.wid * lcd.hgt);
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void drv_base_flush() void
drv_base_flush ()
{ {
//lcd.draw_frame(lcd.framebuf); //lcd.draw_frame(lcd.framebuf);
} }
@@ -110,31 +114,33 @@ void drv_base_flush()
// Prints a string on the lcd display, at position (x,y). The // Prints a string on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void drv_base_string(int x, int y, char string[]) void
drv_base_string (int x, int y, char string[])
{ {
int i; int i;
x -= 1; // Convert 1-based coords to 0-based... x -= 1; // Convert 1-based coords to 0-based...
y -= 1; y -= 1;
for(i=0; string[i]; i++) for (i = 0; string[i]; i++) {
{ // Check for buffer overflows...
// Check for buffer overflows... if ((y * lcd.wid) + x + i > (lcd.wid * lcd.hgt))
if((y*lcd.wid) + x + i > (lcd.wid*lcd.hgt)) break; break;
lcd.framebuf[(y*lcd.wid) + x + i] = string[i]; lcd.framebuf[(y * lcd.wid) + x + i] = string[i];
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The // Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void drv_base_chr(int x, int y, char c) void
drv_base_chr (int x, int y, char c)
{ {
y--; y--;
x--; x--;
lcd.framebuf[(y*lcd.wid) + x] = c; lcd.framebuf[(y * lcd.wid) + x] = c;
} }
@@ -142,33 +148,36 @@ void drv_base_chr(int x, int y, char c)
// Sets the contrast of the display. Value is 0-255, where 140 is // Sets the contrast of the display. Value is 0-255, where 140 is
// what I consider "just right". // what I consider "just right".
// //
int drv_base_contrast(int contrast) int
drv_base_contrast (int contrast)
{ {
// printf("Contrast: %i\n", contrast); // printf("Contrast: %i\n", contrast);
return -1; return -1;
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Turns the lcd backlight on or off... // Turns the lcd backlight on or off...
// //
void drv_base_backlight(int on) void
drv_base_backlight (int on)
{ {
/* /*
if(on) if(on)
{ {
printf("Backlight ON\n"); printf("Backlight ON\n");
} }
else else
{ {
printf("Backlight OFF\n"); printf("Backlight OFF\n");
} }
*/ */
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for vertical bargraphs. // Tells the driver to get ready for vertical bargraphs.
// //
void drv_base_init_vbar() void
drv_base_init_vbar ()
{ {
// printf("Vertical bars.\n"); // printf("Vertical bars.\n");
} }
@@ -176,7 +185,8 @@ void drv_base_init_vbar()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for horizontal bargraphs. // Tells the driver to get ready for horizontal bargraphs.
// //
void drv_base_init_hbar() void
drv_base_init_hbar ()
{ {
// printf("Horizontal bars.\n"); // printf("Horizontal bars.\n");
} }
@@ -184,7 +194,8 @@ void drv_base_init_hbar()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for big numbers, if possible. // Tells the driver to get ready for big numbers, if possible.
// //
void drv_base_init_num() void
drv_base_init_num ()
{ {
// printf("Big Numbers.\n"); // printf("Big Numbers.\n");
} }
@@ -192,7 +203,8 @@ void drv_base_init_num()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Draws a big (4-row) number. // Draws a big (4-row) number.
// //
void drv_base_num(int x, int num) void
drv_base_num (int x, int num)
{ {
// printf("BigNum(%i, %i)\n", x, num); // printf("BigNum(%i, %i)\n", x, num);
} }
@@ -200,7 +212,8 @@ void drv_base_num(int x, int num)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Changes the font data of character n. // Changes the font data of character n.
// //
void drv_base_set_char(int n, char *dat) void
drv_base_set_char (int n, char *dat)
{ {
// printf("Set Character %i\n", n); // printf("Set Character %i\n", n);
} }
@@ -208,37 +221,38 @@ void drv_base_set_char(int n, char *dat)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar, from the bottom of the screen up. // Draws a vertical bar, from the bottom of the screen up.
// //
void drv_base_vbar(int x, int len) void
drv_base_vbar (int x, int len)
{ {
int y; int y;
for(y=lcd.hgt; y > 0 && len>0; y--) for (y = lcd.hgt; y > 0 && len > 0; y--) {
{ drv_base_chr (x, y, '|');
drv_base_chr(x, y, '|');
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void drv_base_hbar(int x, int y, int len) void
drv_base_hbar (int x, int y, int len)
{ {
for(; x<=lcd.wid && len>0; x++) for (; x <= lcd.wid && len > 0; x++) {
{ drv_base_chr (x, y, '-');
drv_base_chr(x,y,'-');
len -= lcd.cellwid; len -= lcd.cellwid;
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void drv_base_icon(int which, char dest) void
drv_base_icon (int which, char dest)
{ {
// printf("Char %i set to icon %i\n", dest, which); // printf("Char %i set to icon %i\n", dest, which);
} }
@@ -250,10 +264,11 @@ void drv_base_icon(int which, char dest)
// I've just called drv_base_flush() because there's not much point yet // I've just called drv_base_flush() because there's not much point yet
// in flushing less than the entire framebuffer. // in flushing less than the entire framebuffer.
// //
void drv_base_flush_box(int lft, int top, int rgt, int bot) void
drv_base_flush_box (int lft, int top, int rgt, int bot)
{ {
//drv_base_flush(); //drv_base_flush();
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@@ -261,7 +276,8 @@ void drv_base_flush_box(int lft, int top, int rgt, int bot)
// //
// The commented-out code is from the text driver. // The commented-out code is from the text driver.
// //
void drv_base_draw_frame(char *dat) void
drv_base_draw_frame (char *dat)
{ {
/* /*
int i, j; int i, j;
@@ -304,8 +320,8 @@ void drv_base_draw_frame(char *dat)
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
char drv_base_getkey() char
drv_base_getkey ()
{ {
return 0; return 0;
} }
+20 -20
View File
@@ -94,26 +94,26 @@
extern lcd_logical_driver *drv_base; extern lcd_logical_driver *drv_base;
int drv_base_init(struct lcd_logical_driver *driver, char *args); int drv_base_init (struct lcd_logical_driver *driver, char *args);
void drv_base_close(); void drv_base_close ();
void drv_base_clear(); void drv_base_clear ();
void drv_base_flush(); void drv_base_flush ();
void drv_base_string(int x, int y, char string[]); void drv_base_string (int x, int y, char string[]);
void drv_base_chr(int x, int y, char c); void drv_base_chr (int x, int y, char c);
int drv_base_contrast(int contrast); int drv_base_contrast (int contrast);
void drv_base_backlight(int on); void drv_base_backlight (int on);
void drv_base_output(int on); void drv_base_output (int on);
void drv_base_vbar(int x, int len); void drv_base_vbar (int x, int len);
void drv_base_init_vbar(); void drv_base_init_vbar ();
void drv_base_hbar(int x, int y, int len); void drv_base_hbar (int x, int y, int len);
void drv_base_init_hbar(); void drv_base_init_hbar ();
void drv_base_num(int x, int num); void drv_base_num (int x, int num);
void drv_base_init_num(); void drv_base_init_num ();
void drv_base_set_char(int n, char *dat); void drv_base_set_char (int n, char *dat);
void drv_base_icon(int which, char dest); void drv_base_icon (int which, char dest);
void drv_base_flush_box(int lft, int top, int rgt, int bot); void drv_base_flush_box (int lft, int top, int rgt, int bot);
void drv_base_draw_frame(char *dat); void drv_base_draw_frame (char *dat);
char drv_base_getkey(); char drv_base_getkey ();
#endif #endif
+100 -107
View File
@@ -49,9 +49,7 @@
// implemented separately for each HW design. This is typically just // implemented separately for each HW design. This is typically just
// HD44780_senddata // HD44780_senddata
void lcdstat_HD44780_senddata(unsigned char displayID, void lcdstat_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch);
unsigned char flags,
unsigned char ch);
#define RS 0x10 #define RS 0x10
@@ -61,136 +59,131 @@ void lcdstat_HD44780_senddata(unsigned char displayID,
#define EN3 0x20 #define EN3 0x20
static unsigned char EnMask[] = { EN1, EN2, EN3, STRB, LF, INIT, SEL }; static unsigned char EnMask[] = { EN1, EN2, EN3, STRB, LF, INIT, SEL };
static int EnMaskSize = sizeof(EnMask) / sizeof(unsigned char); static int EnMaskSize = sizeof (EnMask) / sizeof (unsigned char);
static unsigned int lptPort; static unsigned int lptPort;
static int extIF = 0; // non-zero if extended interface static int extIF = 0; // non-zero if extended interface
// initialisation function // initialisation function
int hd_init_4bit(HD44780_functions *hd44780_functions, int
lcd_logical_driver *driver, hd_init_4bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port)
char *args,
unsigned int port)
{ {
// TODO: remove magic numbers below // TODO: remove magic numbers below
char *argv[64]; char *argv[64];
int argc; int argc;
int i; int i;
int displayID = EN1 | EN2; int displayID = EN1 | EN2;
lptPort = port; lptPort = port;
hd44780_functions->senddata = lcdstat_HD44780_senddata; hd44780_functions->senddata = lcdstat_HD44780_senddata;
// parse command-line arguments // parse command-line arguments
argc = get_args(argv, args, 64); argc = get_args (argv, args, 64);
for (i = 0; i < argc; ++i) for (i = 0; i < argc; ++i) {
{ if (strcmp (argv[i], "-e") == 0 || strcmp (argv[i], "--extended") == 0) {
if (strcmp(argv[i], "-e") == 0 || extIF = 1;
strcmp(argv[i], "--extended") == 0) if ((ioperm (port + 2, 1, 255)) == -1) {
{ fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno));
extIF = 1; return -1;
if ((ioperm(port + 2, 1, 255)) == -1) { }
fprintf(stderr, "HD44780_init: failed (%s)\n", strerror(errno));
return -1;
} }
} }
}
// powerup the lcd now
if (extIF)
{
displayID |= EN3;
port_out(lptPort + 2, 0 ^ OUTMASK);
}
port_out(lptPort, displayID | 0x03); // powerup the lcd now
if (extIF) port_out(lptPort + 2, if (extIF) {
(EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6]) ^ OUTMASK); displayID |= EN3;
hd44780_functions->uPause(1); port_out (lptPort + 2, 0 ^ OUTMASK);
port_out(lptPort, 0x03); }
if (extIF) port_out(lptPort + 2, 0 ^ OUTMASK);
hd44780_functions->uPause(4100);
port_out(lptPort, displayID | 0x03); port_out (lptPort, displayID | 0x03);
if (extIF) port_out(lptPort + 2, if (extIF)
(EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6]) ^ OUTMASK); port_out (lptPort + 2, (EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6]) ^ OUTMASK);
hd44780_functions->uPause(1); hd44780_functions->uPause (1);
port_out(lptPort, 0x03); port_out (lptPort, 0x03);
if (extIF) port_out(lptPort + 2, 0 ^ OUTMASK); if (extIF)
hd44780_functions->uPause(100); port_out (lptPort + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (4100);
port_out(lptPort, displayID | 0x03); port_out (lptPort, displayID | 0x03);
if (extIF) port_out(lptPort + 2, if (extIF)
(EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6]) ^ OUTMASK); port_out (lptPort + 2, (EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6]) ^ OUTMASK);
hd44780_functions->uPause(1); hd44780_functions->uPause (1);
port_out(lptPort, 0x03); port_out (lptPort, 0x03);
if (extIF) port_out(lptPort + 2, 0 ^ OUTMASK); if (extIF)
hd44780_functions->uPause(40); port_out (lptPort + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (100);
// now in 8-bit mode... set 4-bit mode port_out (lptPort, displayID | 0x03);
port_out(lptPort,displayID | 0x02); if (extIF)
if (extIF) port_out(lptPort + 2, port_out (lptPort + 2, (EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6]) ^ OUTMASK);
(EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6]) ^ OUTMASK); hd44780_functions->uPause (1);
hd44780_functions->uPause(1); port_out (lptPort, 0x03);
port_out(lptPort, 0x02); if (extIF)
if (extIF) port_out(lptPort + 2, 0 ^ OUTMASK); port_out (lptPort + 2, 0 ^ OUTMASK);
hd44780_functions->uPause(40); hd44780_functions->uPause (40);
common_init(IF_4bit); // now in 8-bit mode... set 4-bit mode
return 0; port_out (lptPort, displayID | 0x02);
if (extIF)
port_out (lptPort + 2, (EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6]) ^ OUTMASK);
hd44780_functions->uPause (1);
port_out (lptPort, 0x02);
if (extIF)
port_out (lptPort + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (40);
common_init (IF_4bit);
return 0;
} }
// lcdstat_HD44780_senddata // lcdstat_HD44780_senddata
void lcdstat_HD44780_senddata(unsigned char displayID, void
unsigned char iflags, lcdstat_HD44780_senddata (unsigned char displayID, unsigned char iflags, unsigned char ch)
unsigned char ch)
{ {
unsigned char dispID = 0, flags = 0; unsigned char dispID = 0, flags = 0;
unsigned char h = (ch >> 4) & 0x0f; // high and low nibbles unsigned char h = (ch >> 4) & 0x0f; // high and low nibbles
unsigned char l = ch & 0x0f; unsigned char l = ch & 0x0f;
if (iflags == RS_INSTR) if (iflags == RS_INSTR)
flags = 0; flags = 0;
else //if (iflags == RS_DATA) else //if (iflags == RS_DATA)
flags = RS; flags = RS;
if (displayID <= 3) if (displayID <= 3) {
{ if (displayID == 0)
if (displayID == 0) dispID = EnMask[0] | EnMask[1] | EnMask[2];
dispID = EnMask[0] | EnMask[1] | EnMask[2]; else
else dispID = EnMask[displayID - 1];
dispID = EnMask[displayID - 1];
port_out(lptPort, flags | h); port_out (lptPort, flags | h);
hd44780_functions->uPause(2); hd44780_functions->uPause (2);
port_out(lptPort, dispID | flags | h); port_out (lptPort, dispID | flags | h);
hd44780_functions->uPause(4); hd44780_functions->uPause (4);
port_out(lptPort, flags | h); port_out (lptPort, flags | h);
port_out(lptPort, dispID | flags | l); port_out (lptPort, dispID | flags | l);
hd44780_functions->uPause(4); hd44780_functions->uPause (4);
port_out(lptPort, flags | l); port_out (lptPort, flags | l);
} }
if (extIF && (displayID == 0 || displayID >= 4)) if (extIF && (displayID == 0 || displayID >= 4)) {
{ if (displayID == 0)
if (displayID == 0) dispID = EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6];
dispID = EnMask[3] | EnMask[4] | EnMask[5] | EnMask[6]; else
else dispID = EnMask[(displayID - 1) % EnMaskSize];
dispID = EnMask[(displayID - 1) % EnMaskSize];
port_out(lptPort, flags | h); port_out (lptPort, flags | h);
hd44780_functions->uPause(2); hd44780_functions->uPause (2);
port_out(lptPort + 2, dispID ^ OUTMASK); port_out (lptPort + 2, dispID ^ OUTMASK);
hd44780_functions->uPause(4); hd44780_functions->uPause (4);
port_out(lptPort + 2, 0 ^ OUTMASK); port_out (lptPort + 2, 0 ^ OUTMASK);
port_out(lptPort, flags | l); port_out (lptPort, flags | l);
port_out(lptPort + 2, dispID ^ OUTMASK); port_out (lptPort + 2, dispID ^ OUTMASK);
hd44780_functions->uPause(4); hd44780_functions->uPause (4);
port_out(lptPort + 2, 0 ^ OUTMASK); port_out (lptPort + 2, 0 ^ OUTMASK);
} }
} }
+1 -4
View File
@@ -5,9 +5,6 @@
#include "hd44780-low.h" /* for HD44780_functions */ #include "hd44780-low.h" /* for HD44780_functions */
// initialise this particular driver // initialise this particular driver
int hd_init_4bit(HD44780_functions *hd44780_functions, int hd_init_4bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port);
lcd_logical_driver *driver,
char *args,
unsigned int port);
#endif #endif
+21 -27
View File
@@ -18,36 +18,30 @@
// add new connection type header files here // add new connection type header files here
enum connectionType { HD_4bit, HD_8bit, HD_serialLpt, HD_winamp, enum connectionType { HD_4bit, HD_8bit, HD_serialLpt, HD_winamp,
// add new connection types here // add new connection types here
HD_unknown }; HD_unknown
};
static struct ConnectionMapping static struct ConnectionMapping {
{ enum connectionType type;
enum connectionType type; char *connectionTypeStr;
char *connectionTypeStr; int (*init_fn) (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port);
int (*init_fn)(HD44780_functions *hd44780_functions, const char *helpMsg;
lcd_logical_driver *driver,
char *args,
unsigned int port);
const char *helpMsg;
} connectionMapping[] = { } connectionMapping[] = {
// connectionType enumerator // connectionType enumerator
// string to identify connection on command line // string to identify connection on command line
// your initialisation function // your initialisation function
// help string for your particular connection // help string for your particular connection
{ HD_4bit, "4bit", hd_init_4bit, {
"\t-e\t--extended\tEnable three or more displays\n" }, HD_4bit, "4bit", hd_init_4bit, "\t-e\t--extended\tEnable three or more displays\n"}, {
{ HD_8bit, "8bit", hd_init_ext8bit, HD_8bit, "8bit", hd_init_ext8bit, "\tnone\n"}, {
"\tnone\n" }, HD_serialLpt, "serialLpt", hd_init_serialLpt, "\tnone\n"}, {
{ HD_serialLpt, "serialLpt", hd_init_serialLpt, HD_winamp, "winamp", hd_init_winamp, "\t-e\t--extended\tEnable three or more displays\n"},
"\tnone\n" }, // add new connection types and their string specifier here
{ HD_winamp, "winamp", hd_init_winamp, // default, end of structure element (do not delete)
"\t-e\t--extended\tEnable three or more displays\n" }, {
// add new connection types and their string specifier here HD_unknown, "", NULL, ""}
// default, end of structure element (do not delete)
{ HD_unknown, "", NULL, "" }
}; };
#endif #endif
+30 -35
View File
@@ -43,9 +43,7 @@
// restricted to): // restricted to):
// HD44780_senddata // HD44780_senddata
void lcdtime_HD44780_senddata(unsigned char displayID, void lcdtime_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch);
unsigned char flags,
unsigned char ch);
#define nRS nSTRB #define nRS nSTRB
@@ -62,48 +60,45 @@ static int semid;
// initialise the driver // initialise the driver
int hd_init_ext8bit(HD44780_functions *hd44780_functions, int
lcd_logical_driver *driver, hd_init_ext8bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port)
char *args,
unsigned int port)
{ {
lptPort = port; lptPort = port;
semid = sem_get(); semid = sem_get ();
hd44780_functions->senddata = lcdtime_HD44780_senddata; hd44780_functions->senddata = lcdtime_HD44780_senddata;
if ((ioperm(port + 2, 1, 255)) == -1) { if ((ioperm (port + 2, 1, 255)) == -1) {
fprintf(stderr, "HD44780_init: failed (%s)\n", strerror(errno)); fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno));
return -1; return -1;
} }
common_init(IF_8bit); common_init (IF_8bit);
return 0; return 0;
} }
// lcdtime_HD44780_senddata // lcdtime_HD44780_senddata
void lcdtime_HD44780_senddata(unsigned char displayID, void
unsigned char flags, lcdtime_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch)
unsigned char ch)
{ {
unsigned char dispID = 0, portControl; unsigned char dispID = 0, portControl;
if (displayID == 1) if (displayID == 1)
dispID |= EN1; dispID |= EN1;
else //if (displayID == 0) else //if (displayID == 0)
dispID |= EN1; dispID |= EN1;
if (flags == RS_DATA) if (flags == RS_DATA)
portControl = CHAR; portControl = CHAR;
else else
portControl = CTRL; portControl = CTRL;
sem_wait(semid); sem_wait (semid);
port_out(lptPort + 2, SETUPLCD); port_out (lptPort + 2, SETUPLCD);
port_out(lptPort, ch); port_out (lptPort, ch);
port_out(lptPort + 2, dispID | portControl); port_out (lptPort + 2, dispID | portControl);
hd44780_functions->uPause(1); hd44780_functions->uPause (1);
port_out(lptPort + 2, portControl); port_out (lptPort + 2, portControl);
sem_signal(semid); sem_signal (semid);
} }
+1 -4
View File
@@ -5,9 +5,6 @@
#include "hd44780-low.h" /* for HD44780_functions */ #include "hd44780-low.h" /* for HD44780_functions */
// initialise this particular driver // initialise this particular driver
int hd_init_ext8bit(HD44780_functions *hd44780_functions, int hd_init_ext8bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port);
lcd_logical_driver *driver,
char *args,
unsigned int port);
#endif #endif
+39 -42
View File
@@ -6,29 +6,28 @@
enum ifWidth { IF_4bit, IF_8bit }; enum ifWidth { IF_4bit, IF_8bit };
void common_init(enum ifWidth ifwidth); void common_init (enum ifWidth ifwidth);
// Structures holding pointers to HD44780 specific functions // Structures holding pointers to HD44780 specific functions
typedef struct hwDependentFns typedef struct hwDependentFns {
{ // microsec pauses
// microsec pauses void (*uPause) (int microSecondsTenths);
void (*uPause)(int microSecondsTenths);
// senddata to the LCD // senddata to the LCD
// dispID - display to send data to (0 = all displays) // dispID - display to send data to (0 = all displays)
// flags - data or instruction command (RS_DATA | RS_INSTR) // flags - data or instruction command (RS_DATA | RS_INSTR)
// ch - character to display or instruction value // ch - character to display or instruction value
void (*senddata)(unsigned char dispID, unsigned char flags, unsigned char ch); void (*senddata) (unsigned char dispID, unsigned char flags, unsigned char ch);
// position the cursor // position the cursor
// dispID - display to send data to (0 = all displays) // dispID - display to send data to (0 = all displays)
// DDaddr - display data address (see sect 2.5.2 of the LCD module FAQ) // DDaddr - display data address (see sect 2.5.2 of the LCD module FAQ)
void (*position)(int dispID, int DDaddr); void (*position) (int dispID, int DDaddr);
// toggle vertical autoscroll on all displays // toggle vertical autoscroll on all displays
// on - non-zero turns autoscroll on, zero value turns it off // on - non-zero turns autoscroll on, zero value turns it off
void (*autoscroll)(int on); void (*autoscroll) (int on);
} HD44780_functions; /* for want of a better name :-) */ } HD44780_functions; /* for want of a better name :-) */
extern HD44780_functions *hd44780_functions; extern HD44780_functions *hd44780_functions;
@@ -42,32 +41,32 @@ extern HD44780_functions *hd44780_functions;
#define HOMECURSOR 0x02 #define HOMECURSOR 0x02
#define ENTRYMODE 0x04 #define ENTRYMODE 0x04
#define E_MOVERIGHT 0x02 #define E_MOVERIGHT 0x02
#define E_MOVELEFT 0x00 #define E_MOVELEFT 0x00
#define EDGESCROLL 0x01 #define EDGESCROLL 0x01
#define NOSCROLL 0x00 #define NOSCROLL 0x00
#define ONOFFCTRL 0x08 #define ONOFFCTRL 0x08
#define DISPON 0x04 #define DISPON 0x04
#define DISPOFF 0x00 #define DISPOFF 0x00
#define CURSORON 0x02 #define CURSORON 0x02
#define CURSOROFF 0x00 #define CURSOROFF 0x00
#define CURSORBLINK 0x01 #define CURSORBLINK 0x01
#define CURSORNOBLINK 0x00 #define CURSORNOBLINK 0x00
#define CURSORSHIFT 0x10 #define CURSORSHIFT 0x10
#define SCROLLDISP 0x08 #define SCROLLDISP 0x08
#define MOVECURSOR 0x00 #define MOVECURSOR 0x00
#define MOVERIGHT 0x04 #define MOVERIGHT 0x04
#define MOVELEFT 0x00 #define MOVELEFT 0x00
#define FUNCSET 0x20 #define FUNCSET 0x20
#define IF_8BIT 0x10 #define IF_8BIT 0x10
#define IF_4BIT 0x00 #define IF_4BIT 0x00
#define TWOLINE 0x08 #define TWOLINE 0x08
#define ONELINE 0x00 #define ONELINE 0x00
#define LARGECHAR 0x04 /* 5x11 characters */ #define LARGECHAR 0x04 /* 5x11 characters */
#define SMALLCHAR 0x00 /* 5x8 characters */ #define SMALLCHAR 0x00 /* 5x8 characters */
#define SETCHAR 0x40 #define SETCHAR 0x40
@@ -76,11 +75,11 @@ extern HD44780_functions *hd44780_functions;
// Parallel port pin definitions // Parallel port pin definitions
// Output lines // Output lines
#define nSTRB 0x01 /* negative logic */ #define nSTRB 0x01 /* negative logic */
#define STRB 0x01 #define STRB 0x01
#define nLF 0x02 #define nLF 0x02
#define LF 0x02 #define LF 0x02
#define INIT 0x04 /* the only positive logic output line */ #define INIT 0x04 /* the only positive logic output line */
#define nSEL 0x08 #define nSEL 0x08
#define SEL 0x08 #define SEL 0x08
@@ -98,5 +97,3 @@ extern HD44780_functions *hd44780_functions;
#define INMASK 0x48 #define INMASK 0x48
#endif #endif
+85 -96
View File
@@ -31,13 +31,11 @@
#include "port.h" #include "port.h"
// Hardware specific functions // Hardware specific functions
void lcdserLpt_HD44780_senddata(unsigned char displayID, void lcdserLpt_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch);
unsigned char flags,
unsigned char ch);
static char lcdserLpt_HD44780_getkey(void); static char lcdserLpt_HD44780_getkey (void);
void rawshift(unsigned char r); void rawshift (unsigned char r);
void shiftreg(unsigned char displayID, unsigned char r); void shiftreg (unsigned char displayID, unsigned char r);
#define RS 16 #define RS 16
#define LCDDATA 8 #define LCDDATA 8
@@ -47,127 +45,118 @@ void shiftreg(unsigned char displayID, unsigned char r);
static unsigned int lp; static unsigned int lp;
static char lastkey=0; static char lastkey = 0;
// Initialisation // Initialisation
int hd_init_serialLpt(HD44780_functions *hd44780_functions, int
lcd_logical_driver *driver, hd_init_serialLpt (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port)
char *args,
unsigned int port)
{ {
int displayID = EN1 | EN2; int displayID = EN1 | EN2;
lp = port; lp = port;
hd44780_functions->senddata = lcdserLpt_HD44780_senddata; hd44780_functions->senddata = lcdserLpt_HD44780_senddata;
// TODO: enable keypad only if specified on command line // TODO: enable keypad only if specified on command line
driver->getkey = lcdserLpt_HD44780_getkey; driver->getkey = lcdserLpt_HD44780_getkey;
// setup the lcd in 4 bit mode // setup the lcd in 4 bit mode
shiftreg(displayID,3); shiftreg (displayID, 3);
hd44780_functions->uPause(4100); hd44780_functions->uPause (4100);
shiftreg(displayID,3); shiftreg (displayID, 3);
hd44780_functions->uPause(100); hd44780_functions->uPause (100);
shiftreg(displayID,3); shiftreg (displayID, 3);
hd44780_functions->uPause(40); hd44780_functions->uPause (40);
shiftreg(displayID,2); shiftreg (displayID, 2);
hd44780_functions->uPause(40); hd44780_functions->uPause (40);
// set display type functions // set display type functions
lcdserLpt_HD44780_senddata(0, lcdserLpt_HD44780_senddata (0, RS_INSTR, FUNCSET | IF_4BIT | TWOLINE | SMALLCHAR);
RS_INSTR, // clear
FUNCSET | IF_4BIT | TWOLINE | SMALLCHAR); lcdserLpt_HD44780_senddata (0, RS_INSTR, CLEAR);
// clear hd44780_functions->uPause (1600);
lcdserLpt_HD44780_senddata(0, RS_INSTR, CLEAR); // Now turn on the display
hd44780_functions->uPause(1600); lcdserLpt_HD44780_senddata (displayID, RS_INSTR, ONOFFCTRL | DISPON | CURSOROFF | CURSORNOBLINK);
// Now turn on the display hd44780_functions->uPause (1600);
lcdserLpt_HD44780_senddata(displayID,
RS_INSTR,
ONOFFCTRL | DISPON | CURSOROFF | CURSORNOBLINK);
hd44780_functions->uPause(1600);
return 0; return 0;
} }
void lcdserLpt_HD44780_senddata(unsigned char displayID, void
unsigned char flags, lcdserLpt_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch)
unsigned char ch)
{ {
unsigned char dispID = 0, unsigned char dispID = 0, portControl = 0, h = ch >> 4, l = ch & 15;
portControl = 0,
h = ch >> 4,
l = ch & 15;
if (displayID == 1) if (displayID == 1)
dispID |= EN1; dispID |= EN1;
else if (displayID == 2) else if (displayID == 2)
dispID |= EN2; dispID |= EN2;
else else
dispID |= EN1 | EN2; dispID |= EN1 | EN2;
if (flags == RS_DATA) if (flags == RS_DATA)
portControl = RS; portControl = RS;
else else
portControl = 0; portControl = 0;
shiftreg(displayID,flags | portControl | h); shiftreg (displayID, flags | portControl | h);
shiftreg(displayID,flags | portControl | l); shiftreg (displayID, flags | portControl | l);
/* TODO: instead of delay read keys here */ /* TODO: instead of delay read keys here */
} }
char lcdserLpt_HD44780_getkey() char
lcdserLpt_HD44780_getkey ()
{ {
// TODO: a keypad scan that does not use shift register // TODO: a keypad scan that does not use shift register
// define a key table // define a key table
char keytr[]="ABCDEFGH"; char keytr[] = "ABCDEFGH";
int n; int n;
rawshift(0); //send all line on shift register low rawshift (0); //send all line on shift register low
hd44780_functions->uPause(1); hd44780_functions->uPause (1);
if ((port_in(lp+1)&32)==0) //test if line back is low - if not return(0) if ((port_in (lp + 1) & 32) == 0) //test if line back is low - if not return(0)
{ //else { //else
//start walking a single zero across the eight lines //start walking a single zero across the eight lines
for(n=7;n>=0;n--) for (n = 7; n >= 0; n--) {
{ rawshift (255 - (1 << n));
rawshift(255 - (1<<n)); hd44780_functions->uPause (1);
hd44780_functions->uPause(1);
if ((port_in (lp + 1) & 32) == 0) // check if line back is low if yes debounce
if ((port_in(lp+1)&32)==0) // check if line back is low if yes debounce {
{ if (lastkey == keytr[n])
if (lastkey==keytr[n]) return (0);
return(0); // printf("key is %c %d\n",keytr[n],n);
// printf("key is %c %d\n",keytr[n],n); lastkey = keytr[n];
lastkey=keytr[n]; return (keytr[n]); //return correct key code.
return(keytr[n]); //return correct key code. }
} }
} } //else fall out and return(0) [too transient a keypress]
} //else fall out and return(0) [too transient a keypress] lastkey = 0;
lastkey=0; return (0);
return(0);
} }
/* this function sends r out onto the shift register */ /* this function sends r out onto the shift register */
void rawshift (unsigned char r) void
rawshift (unsigned char r)
{ {
int i; int i;
for (i=7;i>=0;i--) /* MSB first */ for (i = 7; i >= 0; i--) { /* MSB first */
{ port_out (lp, ((r >> i) & 1) * LCDDATA); /*set up data */
port_out(lp,((r>>i)&1)*LCDDATA); /*set up data */ port_out (lp, (((r >> i) & 1) * LCDDATA) | LCDCLOCK); /*rising edge of clock */
port_out(lp,(((r>>i)&1)*LCDDATA)|LCDCLOCK);/*rising edge of clock */ }
}
} }
// displayID = value on parallel port to toggle the correct display // displayID = value on parallel port to toggle the correct display
void shiftreg (unsigned char displayID, unsigned char r) void
{ shiftreg (unsigned char displayID, unsigned char r)
rawshift(r); {
port_out(lp,displayID); //latch it, to correct display rawshift (r);
port_out(lp,0); port_out (lp, displayID); //latch it, to correct display
port_out (lp, 0);
} }
+3 -6
View File
@@ -1,13 +1,10 @@
#ifndef HD_SERIALLPT_H #ifndef HD_SERIALLPT_H
#define HD_SERIALLPT_H #define HD_SERIALLPT_H
#include "lcd.h" /* for lcd_logical_driver */ #include "lcd.h" /* for lcd_logical_driver */
#include "hd44780-low.h" /* for HD44780_functions */ #include "hd44780-low.h" /* for HD44780_functions */
// initialise this particular driver // initialise this particular driver
int hd_init_serialLpt(HD44780_functions *hd44780_functions, int hd_init_serialLpt (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port);
lcd_logical_driver *driver,
char *args,
unsigned int port);
#endif #endif
+37 -44
View File
@@ -36,9 +36,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
void lcdwinamp_HD44780_senddata(unsigned char displayID, void lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch);
unsigned char flags,
unsigned char ch);
#define EN1 STRB #define EN1 STRB
#define EN2 SEL #define EN2 SEL
@@ -46,64 +44,59 @@ void lcdwinamp_HD44780_senddata(unsigned char displayID,
#define RS INIT #define RS INIT
static unsigned char EnMask[] = { EN1, EN2, EN3 }; static unsigned char EnMask[] = { EN1, EN2, EN3 };
static int EnMaskSize = sizeof(EnMask) / sizeof(unsigned char); static int EnMaskSize = sizeof (EnMask) / sizeof (unsigned char);
static unsigned int lptPort; static unsigned int lptPort;
static int extIF = 0; // non-zero if extended interface static int extIF = 0; // non-zero if extended interface
// initialise the driver // initialise the driver
int hd_init_winamp(HD44780_functions *hd44780_functions, int
lcd_logical_driver *driver, hd_init_winamp (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port)
char *args,
unsigned int port)
{ {
// TODO: remove magic numbers below // TODO: remove magic numbers below
char *argv[64]; char *argv[64];
int argc; int argc;
int i; int i;
hd44780_functions->senddata = lcdwinamp_HD44780_senddata;
lptPort = port;
// parse command-line arguments hd44780_functions->senddata = lcdwinamp_HD44780_senddata;
argc = get_args(argv, args, 64); lptPort = port;
for (i = 0; i < argc; ++i) // parse command-line arguments
if (strcmp(argv[i], "-e") == 0 || argc = get_args (argv, args, 64);
strcmp(argv[i], "--extended") == 0)
extIF = 1;
if ((ioperm(lptPort + 2, 1, 255)) == -1) { for (i = 0; i < argc; ++i)
fprintf(stderr, "HD44780_init: failed (%s)\n", strerror(errno)); if (strcmp (argv[i], "-e") == 0 || strcmp (argv[i], "--extended") == 0)
return -1; extIF = 1;
}
common_init(IF_8bit); if ((ioperm (lptPort + 2, 1, 255)) == -1) {
return 0; fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno));
return -1;
}
common_init (IF_8bit);
return 0;
} }
// lcdwinamp_HD44780_senddata // lcdwinamp_HD44780_senddata
void lcdwinamp_HD44780_senddata(unsigned char displayID, void
unsigned char flags, lcdwinamp_HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch)
unsigned char ch)
{ {
unsigned char dispID = 0, portControl; unsigned char dispID = 0, portControl;
if (flags == RS_DATA) if (flags == RS_DATA)
portControl = RS; portControl = RS;
else else
portControl = 0; portControl = 0;
if (displayID == 0) if (displayID == 0)
dispID = EnMask[0] | EnMask [1] | ((extIF) ? EnMask[2] : 0); dispID = EnMask[0] | EnMask[1] | ((extIF) ? EnMask[2] : 0);
else else
dispID = EnMask[displayID - 1]; dispID = EnMask[displayID - 1];
port_out(lptPort, ch); port_out (lptPort, ch);
port_out(lptPort + 2, (dispID | portControl) ^ OUTMASK); port_out (lptPort + 2, (dispID | portControl) ^ OUTMASK);
hd44780_functions->uPause(1); hd44780_functions->uPause (1);
port_out(lptPort + 2, portControl ^ OUTMASK); port_out (lptPort + 2, portControl ^ OUTMASK);
} }
+1 -4
View File
@@ -6,9 +6,6 @@
// initialise this particular driver, args is probably not used but keep // initialise this particular driver, args is probably not used but keep
// for consistency // for consistency
int hd_init_winamp(HD44780_functions *hd44780_functions, int hd_init_winamp (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port);
lcd_logical_driver *driver,
char *args,
unsigned int port);
#endif #endif
+508 -561
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -17,7 +17,7 @@
#include "port.h" #include "port.h"
int HD44780_init(struct lcd_logical_driver *driver, char *args); int HD44780_init (struct lcd_logical_driver *driver, char *args);
/* The following methods can all be hidden. They are used through function ptrs /* The following methods can all be hidden. They are used through function ptrs
void HD44780_close(); void HD44780_close();
void HD44780_flush(); void HD44780_flush();
+97 -109
View File
@@ -32,34 +32,34 @@
char *progname = "irmanin"; char *progname = "irmanin";
char *codes[] = { char *codes[] = {
/* dummy */ NULL, /* dummy */ NULL,
/* KeyToLcd */ "lcdproc-A", /* KeyToLcd */ "lcdproc-A",
/* KeyToLcd */ "lcdproc-B", /* KeyToLcd */ "lcdproc-B",
/* KeyToLcd */ "lcdproc-C", /* KeyToLcd */ "lcdproc-C",
/* KeyToLcd */ "lcdproc-D", /* KeyToLcd */ "lcdproc-D",
/* KeyToLcd */ "lcdproc-E", /* KeyToLcd */ "lcdproc-E",
/* KeyToLcd */ "lcdproc-F", /* KeyToLcd */ "lcdproc-F",
/* KeyToLcd */ "lcdproc-G", /* KeyToLcd */ "lcdproc-G",
/* KeyToLcd */ "lcdproc-H", /* KeyToLcd */ "lcdproc-H",
/* KeyToLcd */ "lcdproc-I", /* KeyToLcd */ "lcdproc-I",
/* KeyToLcd */ "lcdproc-J", /* KeyToLcd */ "lcdproc-J",
/* KeyToLcd */ "lcdproc-K", /* KeyToLcd */ "lcdproc-K",
/* KeyToLcd */ "lcdproc-L", /* KeyToLcd */ "lcdproc-L",
/* KeyToLcd */ "lcdproc-M", /* KeyToLcd */ "lcdproc-M",
/* KeyToLcd */ "lcdproc-N", /* KeyToLcd */ "lcdproc-N",
/* KeyToLcd */ "lcdproc-O", /* KeyToLcd */ "lcdproc-O",
/* KeyToLcd */ "lcdproc-P", /* KeyToLcd */ "lcdproc-P",
/* KeyToLcd */ "lcdproc-Q", /* KeyToLcd */ "lcdproc-Q",
/* KeyToLcd */ "lcdproc-R", /* KeyToLcd */ "lcdproc-R",
/* KeyToLcd */ "lcdproc-S", /* KeyToLcd */ "lcdproc-S",
/* KeyToLcd */ "lcdproc-T", /* KeyToLcd */ "lcdproc-T",
/* KeyToLcd */ "lcdproc-U", /* KeyToLcd */ "lcdproc-U",
/* KeyToLcd */ "lcdproc-V", /* KeyToLcd */ "lcdproc-V",
/* KeyToLcd */ "lcdproc-W", /* KeyToLcd */ "lcdproc-W",
/* KeyToLcd */ "lcdproc-X", /* KeyToLcd */ "lcdproc-X",
/* KeyToLcd */ "lcdproc-Y", /* KeyToLcd */ "lcdproc-Y",
/* KeyToLcd */ "lcdproc-Z", /* KeyToLcd */ "lcdproc-Z",
/* end */ NULL /* end */ NULL
}; };
@@ -80,7 +80,8 @@ lcd_logical_driver *irmanin;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// init() should set up any device-specific stuff, and // init() should set up any device-specific stuff, and
// point all the function pointers. // point all the function pointers.
int irmanin_init(struct lcd_logical_driver *driver, char *args) int
irmanin_init (struct lcd_logical_driver *driver, char *args)
{ {
char device[256]; char device[256];
char *ptrdevice; char *ptrdevice;
@@ -93,99 +94,85 @@ int irmanin_init(struct lcd_logical_driver *driver, char *args)
int argc, i, j; int argc, i, j;
char *filename; char *filename;
ptrconfig=NULL; ptrconfig = NULL;
ptrdevice=NULL; ptrdevice = NULL;
irmanin = driver; irmanin = driver;
argc = get_args(argv, args, 64); argc = get_args (argv, args, 64);
for(i=0; i<argc; i++) for (i = 0; i < argc; i++) {
{
//printf("Arg(%i): %s\n", i, argv[i]); //printf("Arg(%i): %s\n", i, argv[i]);
if(0 == strcmp(argv[i], "-d") || if (0 == strcmp (argv[i], "-d") || 0 == strcmp (argv[i], "--device")) {
0 == strcmp(argv[i], "--device")) if (i + 1 > argc) {
{ fprintf (stderr, "irmanin_init: %s requires an argument\n", argv[i]);
if(i + 1 > argc) {
fprintf(stderr, "irmanin_init: %s requires an argument\n",
argv[i]);
return -1; return -1;
} }
strcpy(device, argv[++i]); strcpy (device, argv[++i]);
ptrdevice=device; ptrdevice = device;
} } else if (0 == strcmp (argv[i], "-c") || 0 == strcmp (argv[i], "--config")) {
else if(0 == strcmp(argv[i], "-c") || if (i + 1 > argc) {
0 == strcmp(argv[i], "--config")) fprintf (stderr, "irmanin_init: %s requires an argument\n", argv[i]);
{
if(i + 1 > argc) {
fprintf(stderr, "irmanin_init: %s requires an argument\n",
argv[i]);
return -1; return -1;
} }
strcpy(config, argv[++i]); strcpy (config, argv[++i]);
ptrconfig=config; ptrconfig = config;
} } else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
else if(0 == strcmp(argv[i], "-h") || printf ("LCDproc IrMan input driver\n" "\t-d\t--device\tSelect the input device to use\n" "\t-d\t--config\tSelect the configuration file to use\n" "\t-h\t--help\t\tShow this help information\n");
0 == strcmp(argv[i], "--help"))
{
printf("LCDproc IrMan input driver\n"
"\t-d\t--device\tSelect the input device to use\n"
"\t-d\t--config\tSelect the configuration file to use\n"
"\t-h\t--help\t\tShow this help information\n");
return -1; return -1;
} else {
printf ("Invalid parameter: %s\n", argv[i]);
} }
else
{
printf("Invalid parameter: %s\n", argv[i]);
}
}
if (ir_init_commands(ptrconfig, 1) < 0) {
fprintf(stderr, "error initialising commands: %s\n", strerror(errno));
exit(1);
} }
portname = ir_default_portname(); if (ir_init_commands (ptrconfig, 1) < 0) {
if(portname==NULL){ fprintf (stderr, "error initialising commands: %s\n", strerror (errno));
if(ptrdevice==NULL){ exit (1);
portname=ptrdevice; }
}else{
fprintf(stderr, "error no device defined\n"); portname = ir_default_portname ();
exit(1); if (portname == NULL) {
} if (ptrdevice == NULL) {
portname = ptrdevice;
} else {
fprintf (stderr, "error no device defined\n");
exit (1);
}
} }
driver->getkey = irmanin_getkey; driver->getkey = irmanin_getkey;
driver->close = irmanin_close; driver->close = irmanin_close;
for (i=1; codes[i] != NULL; i++) { for (i = 1; codes[i] != NULL; i++) {
if (ir_register_command(codes[i], i) < 0) { if (ir_register_command (codes[i], i) < 0) {
if (errno == ENOENT) { if (errno == ENOENT) {
fprintf(stderr, "%s: no code set for `%s'\n", progname, codes[i]); fprintf (stderr, "%s: no code set for `%s'\n", progname, codes[i]);
} else { } else {
fprintf(stderr, "error registering `%s': `%s'\n", codes[i], strerror(errno)); fprintf (stderr, "error registering `%s': `%s'\n", codes[i], strerror (errno));
} }
} }
} }
errno = 0; errno = 0;
if (ir_init(portname) < 0) { if (ir_init (portname) < 0) {
fprintf(stderr, "%s: error initialising Irman: `%s'\n", strerror(errno), portname); fprintf (stderr, "%s: error initialising Irman: `%s'\n", strerror (errno), portname);
exit(1); exit (1);
} }
return 1; // 200 is arbitrary. (must be 1 or more) return 1; // 200 is arbitrary. (must be 1 or more)
} }
void irmanin_close() void
irmanin_close ()
{ {
if(irmanin->framebuf != NULL) free(irmanin->framebuf); if (irmanin->framebuf != NULL)
free (irmanin->framebuf);
irmanin->framebuf = NULL;
ir_free_commands(); irmanin->framebuf = NULL;
ir_finish();
ir_free_commands ();
ir_finish ();
} }
@@ -194,25 +181,26 @@ void irmanin_close()
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
char irmanin_getkey() char
irmanin_getkey ()
{ {
int i; int i;
int cmd; int cmd;
char key; char key;
key=(char)0; key = (char) 0;
switch (cmd=ir_poll_command()) { switch (cmd = ir_poll_command ()) {
case IR_CMD_ERROR: case IR_CMD_ERROR:
fprintf(stderr, "%s: error reading command: %s\n", progname, strerror(errno)); fprintf (stderr, "%s: error reading command: %s\n", progname, strerror (errno));
break; break;
case IR_CMD_UNKNOWN: case IR_CMD_UNKNOWN:
break; break;
default: default:
key=(char)('A'-1+cmd); key = (char) ('A' - 1 + cmd);
break; break;
} }
return key; return key;
} }
/* end of irmanin.c */ /* end of irmanin.c */
+3 -3
View File
@@ -4,9 +4,9 @@
extern lcd_logical_driver *joy; extern lcd_logical_driver *joy;
int irmanin_init(struct lcd_logical_driver *driver, char *args); int irmanin_init (struct lcd_logical_driver *driver, char *args);
void irmanin_close(); void irmanin_close ();
char irmanin_getkey(); char irmanin_getkey ();
#endif #endif
+85 -102
View File
@@ -46,125 +46,105 @@ int *button;
// Configured for a Gravis Gamepad (2 axis, 4 button) // Configured for a Gravis Gamepad (2 axis, 4 button)
char *axismap = "EFGHIJKLMNOPQRST"; char *axismap = "EFGHIJKLMNOPQRST";
char *buttonmap = "BDACEFGHIJKLMNOP"; char *buttonmap = "BDACEFGHIJKLMNOP";
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// init() should set up any device-specific stuff, and // init() should set up any device-specific stuff, and
// point all the function pointers. // point all the function pointers.
int joy_init(struct lcd_logical_driver *driver, char *args) int
joy_init (struct lcd_logical_driver *driver, char *args)
{ {
char device[256]; char device[256];
char *argv[64]; char *argv[64];
int argc, i, j; int argc, i, j;
joy = driver; joy = driver;
strcpy(device, "/dev/js0");
argc = get_args(argv, args, 64); strcpy (device, "/dev/js0");
for(i=0; i<argc; i++) argc = get_args (argv, args, 64);
{
for (i = 0; i < argc; i++) {
//printf("Arg(%i): %s\n", i, argv[i]); //printf("Arg(%i): %s\n", i, argv[i]);
if(0 == strcmp(argv[i], "-d") || if (0 == strcmp (argv[i], "-d") || 0 == strcmp (argv[i], "--device")) {
0 == strcmp(argv[i], "--device")) if (i + 1 > argc) {
{ fprintf (stderr, "joy_init: %s requires an argument\n", argv[i]);
if(i + 1 > argc) {
fprintf(stderr, "joy_init: %s requires an argument\n",
argv[i]);
return -1; return -1;
} }
strcpy(device, argv[++i]); strcpy (device, argv[++i]);
} } else if (0 == strcmp (argv[i], "-a") || 0 == strcmp (argv[i], "--axes")) {
else if(0 == strcmp(argv[i], "-a") || if (i + 1 > argc) {
0 == strcmp(argv[i], "--axes")) fprintf (stderr, "joy_init: %s requires an argument\n", argv[i]);
{
if(i + 1 > argc) {
fprintf(stderr, "joy_init: %s requires an argument\n",
argv[i]);
return -1; return -1;
} }
strncpy(axismap, argv[++i], 16); strncpy (axismap, argv[++i], 16);
} } else if (0 == strcmp (argv[i], "-b") || 0 == strcmp (argv[i], "--buttons")) {
else if(0 == strcmp(argv[i], "-b") || if (i + 1 > argc) {
0 == strcmp(argv[i], "--buttons")) fprintf (stderr, "joy_init: %s requires an argument\n", argv[i]);
{
if(i + 1 > argc) {
fprintf(stderr, "joy_init: %s requires an argument\n",
argv[i]);
return -1; return -1;
} }
strncpy(buttonmap, argv[++i], 16); strncpy (buttonmap, argv[++i], 16);
} } else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
else if(0 == strcmp(argv[i], "-h") || printf ("LCDproc Joystick input driver\n" "\t-d\t--device\tSelect the input device to use [/dev/js0]\n" "\t-a\t--axes\t\tModify the axis map [%s]\n" "\t-b\t--buttons\tModify the button map [%s]\n" "\t-h\t--help\t\tShow this help information\n", axismap, buttonmap);
0 == strcmp(argv[i], "--help"))
{
printf("LCDproc Joystick input driver\n"
"\t-d\t--device\tSelect the input device to use [/dev/js0]\n"
"\t-a\t--axes\t\tModify the axis map [%s]\n"
"\t-b\t--buttons\tModify the button map [%s]\n"
"\t-h\t--help\t\tShow this help information\n",
axismap, buttonmap);
return -1; return -1;
} else {
printf ("Invalid parameter: %s\n", argv[i]);
} }
else
{
printf("Invalid parameter: %s\n", argv[i]);
}
} }
driver->getkey = joy_getkey; driver->getkey = joy_getkey;
driver->close = joy_close; driver->close = joy_close;
/* FIXME: This crashes! /* FIXME: This crashes!
if(args) if(args)
{ {
if(strlen(args) > 0) if(strlen(args) > 0)
strcpy(device, args); strcpy(device, args);
} }
*/ */
fd = open (device, O_RDONLY); fd = open (device, O_RDONLY);
fcntl(fd, F_SETFL, O_NONBLOCK); fcntl (fd, F_SETFL, O_NONBLOCK);
if(fd < 0) return -1; if (fd < 0)
return -1;
ioctl(fd, JSIOCGVERSION, &jsversion);
ioctl(fd, JSIOCGAXES, &axes);
ioctl(fd, JSIOCGBUTTONS, &buttons);
ioctl(fd, JSIOCGNAME(NAME_LENGTH), jsname);
debug("Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n",
jsname, axes, buttons,
jsversion >> 16, (jsversion >> 8) & 0xff, jsversion & 0xff);
axis = calloc(axes, sizeof(int));
button = calloc(buttons, sizeof(char));
return fd; // 200 is arbitrary. (must be 1 or more) ioctl (fd, JSIOCGVERSION, &jsversion);
ioctl (fd, JSIOCGAXES, &axes);
ioctl (fd, JSIOCGBUTTONS, &buttons);
ioctl (fd, JSIOCGNAME (NAME_LENGTH), jsname);
debug ("Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n", jsname, axes, buttons, jsversion >> 16, (jsversion >> 8) & 0xff, jsversion & 0xff);
axis = calloc (axes, sizeof (int));
button = calloc (buttons, sizeof (char));
return fd; // 200 is arbitrary. (must be 1 or more)
} }
void joy_close() void
joy_close ()
{ {
if(joy->framebuf != NULL) free(joy->framebuf); if (joy->framebuf != NULL)
close(fd); free (joy->framebuf);
close (fd);
joy->framebuf = NULL;
joy->framebuf = NULL;
// Why do I have so much trouble getting memory freed without segfaults??
//if(axis) free(axis);
//if(button) free(button);
// Why do I have so much trouble getting memory freed without segfaults??
//if(axis) free(axis);
//if(button) free(button);
} }
@@ -173,46 +153,49 @@ void joy_close()
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
char joy_getkey() char
joy_getkey ()
{ {
int i; int i;
int err; int err;
err = read(fd, &js, sizeof(struct js_event)); err = read (fd, &js, sizeof (struct js_event));
if (err <= 0) return 0; if (err <= 0)
if (err != sizeof(struct js_event)) { return 0;
fprintf(stderr, "\nerror reading joystick\n"); if (err != sizeof (struct js_event)) {
fprintf (stderr, "\nerror reading joystick\n");
return 0; return 0;
} }
// if(js.type & JS_EVENT_INIT) return 0; // if(js.type & JS_EVENT_INIT) return 0;
switch(js.type & ~JS_EVENT_INIT) { switch (js.type & ~JS_EVENT_INIT) {
case JS_EVENT_BUTTON: case JS_EVENT_BUTTON:
button[js.number] = js.value; button[js.number] = js.value;
break; break;
case JS_EVENT_AXIS: case JS_EVENT_AXIS:
axis[js.number] = js.value; axis[js.number] = js.value;
break; break;
} }
if (buttons) { if (buttons) {
//printf("Buttons: "); //printf("Buttons: ");
for (i = 0; i < buttons; i++) for (i = 0; i < buttons; i++)
//printf("%2d:%s ", i, button[i] ? "on " : "off"); //printf("%2d:%s ", i, button[i] ? "on " : "off");
if(button[i]) return buttonmap[i]; if (button[i])
return buttonmap[i];
} }
if (axes) { if (axes) {
//printf("Axes: "); //printf("Axes: ");
for (i = 0; i < axes; i++) for (i = 0; i < axes; i++) {
{
//printf("%2d:%6d ", i, axis[i]); //printf("%2d:%6d ", i, axis[i]);
// Eliminate noise... // Eliminate noise...
if(axis[i] > 20000) return axismap[(2*i) + 1]; if (axis[i] > 20000)
if(axis[i] < -20000) return axismap[(2*i)]; return axismap[(2 * i) + 1];
if (axis[i] < -20000)
return axismap[(2 * i)];
} }
} }
return 0; return 0;
} }
+3 -3
View File
@@ -4,9 +4,9 @@
extern lcd_logical_driver *joy; extern lcd_logical_driver *joy;
int joy_init(struct lcd_logical_driver *driver, char *args); int joy_init (struct lcd_logical_driver *driver, char *args);
void joy_close(); void joy_close ();
char joy_getkey(); char joy_getkey ();
#endif #endif
+338 -364
View File
@@ -61,41 +61,40 @@
lcd_logical_driver lcd; lcd_logical_driver lcd;
lcd_physical_driver drivers[] = lcd_physical_driver drivers[] = {
{ {"base", drv_base_init,},
{ "base", drv_base_init, },
#ifdef MTXORB_DRV #ifdef MTXORB_DRV
{ "MtxOrb", MtxOrb_init, }, {"MtxOrb", MtxOrb_init,},
#endif #endif
#ifdef CFONTZ_DRV #ifdef CFONTZ_DRV
{ "CFontz", CFontz_init, }, {"CFontz", CFontz_init,},
#endif #endif
#ifdef HD44780_DRV #ifdef HD44780_DRV
{ "HD44780", HD44780_init, }, {"HD44780", HD44780_init,},
#endif #endif
#ifdef SLI_DRV #ifdef SLI_DRV
{ "sli", sli_init, }, {"sli", sli_init,},
#endif #endif
#ifdef TEXT_DRV #ifdef TEXT_DRV
{ "text", text_init, }, {"text", text_init,},
#endif #endif
#ifdef DEBUG_DRV #ifdef DEBUG_DRV
{ "debug", debug_init, }, {"debug", debug_init,},
#endif #endif
#ifdef CURSES_DRV #ifdef CURSES_DRV
{ "curses", curses_drv_init, }, {"curses", curses_drv_init,},
#endif #endif
#ifdef JOY_DRV #ifdef JOY_DRV
{ "joy", joy_init, }, {"joy", joy_init,},
#endif #endif
#ifdef IRMANIN_DRV #ifdef IRMANIN_DRV
{ "irmanin", irmanin_init, }, {"irmanin", irmanin_init,},
#endif #endif
#ifdef LIRCIN_DRV #ifdef LIRCIN_DRV
{ "lircin", lircin_init, }, {"lircin", lircin_init,},
#endif #endif
{ NULL, NULL, }, {NULL, NULL,},
}; };
LL *list; LL *list;
@@ -103,92 +102,90 @@ LL *list;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// This sets up which driver to use and initializes stuff. // This sets up which driver to use and initializes stuff.
// //
int lcd_init(char *args) int
lcd_init (char *args)
{ {
// int i; // int i;
int err; int err;
list = LL_new();
if(!list)
{
printf("Error allocating driver list.\n");
return -1;
}
lcd_drv_init(NULL, NULL);
err = lcd_add_driver("base", args); list = LL_new ();
if (!list) {
printf ("Error allocating driver list.\n");
return -1;
}
lcd.wid = 20; lcd_drv_init (NULL, NULL);
lcd.hgt = 4;
return err; err = lcd_add_driver ("base", args);
/*
drv_base_init(args);
for(i=0; drivers[i].name; i++) lcd.wid = 20;
{ lcd.hgt = 4;
if(!strcmp(driver, drivers[i].name))
{ return err;
/*
drv_base_init(args);
for(i=0; drivers[i].name; i++)
{
if(!strcmp(driver, drivers[i].name))
{
return drivers[i].init(args); return drivers[i].init(args);
} }
} }
printf("Invalid driver: %s\n", driver);
return -1;
*/
printf("Invalid driver: %s\n", driver);
return -1;
*/
} }
// TODO: lcd_remove_driver() // TODO: lcd_remove_driver()
int lcd_add_driver(char *driver, char *args) int
lcd_add_driver (char *driver, char *args)
{ {
int i; int i;
lcd_logical_driver *add; lcd_logical_driver *add;
for(i=0; drivers[i].name; i++) for (i = 0; drivers[i].name; i++) {
{
//printf("Checking driver: %s\n", drivers[i].name); //printf("Checking driver: %s\n", drivers[i].name);
if(0 == strcmp(driver, drivers[i].name)) if (0 == strcmp (driver, drivers[i].name)) {
{
//printf("Found driver: %s (%s)\n", drivers[i].name, driver); //printf("Found driver: %s (%s)\n", drivers[i].name, driver);
add = malloc(sizeof(lcd_logical_driver)); add = malloc (sizeof (lcd_logical_driver));
if(!add) if (!add) {
{ printf ("Couldn't allocate driver \"%s\".\n", driver);
printf("Couldn't allocate driver \"%s\".\n", driver);
return -1; return -1;
} }
//printf("Allocated driver\n"); //printf("Allocated driver\n");
memset(add, 0, sizeof(lcd_logical_driver)); memset (add, 0, sizeof (lcd_logical_driver));
add->wid = lcd.wid; add->hgt = lcd.hgt; add->wid = lcd.wid;
add->cellwid = lcd.cellwid; add->cellhgt = lcd.cellhgt; add->hgt = lcd.hgt;
add->cellwid = lcd.cellwid;
add->cellhgt = lcd.cellhgt;
// printf("LCD driver info:\n\twid: %i\thgt: %i\n", // printf("LCD driver info:\n\twid: %i\thgt: %i\n",
// add->wid, add->hgt); // add->wid, add->hgt);
add->framebuf = malloc(add->wid * add->hgt);
if(!add->framebuf) add->framebuf = malloc (add->wid * add->hgt);
{
printf("Couldn't allocate framebuffer for driver \"%s\".\n", if (!add->framebuf) {
driver); printf ("Couldn't allocate framebuffer for driver \"%s\".\n", driver);
free(add); free (add);
return -1; return -1;
} }
//printf("Allocated frame buffer\n"); //printf("Allocated frame buffer\n");
LL_Push(list, (void *)add); LL_Push (list, (void *) add);
return drivers[i].init(add, args); return drivers[i].init (add, args);
} }
} }
@@ -196,49 +193,47 @@ int lcd_add_driver(char *driver, char *args)
} }
// TODO: Put lcd_shutdown in the shutdown function... // TODO: Put lcd_shutdown in the shutdown function...
int lcd_shutdown() int
lcd_shutdown ()
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
//printf("driver...\n"); //printf("driver...\n");
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->close > 0) if ((int) driver->close > 0) {
{ driver->close ();
driver->close(); } else if ((int) driver->close == -1) {
} drv_base->close ();
else if((int)driver->close == -1)
{
drv_base->close();
} }
LL_Shift(list); LL_Shift (list);
// FIXME: This crashes! // FIXME: This crashes!
//if(driver) free(driver); //if(driver) free(driver);
//printf("...freed\n"); //printf("...freed\n");
} }
} while(LL_Length(list) > 0); } while (LL_Length (list) > 0);
return 0; return 0;
} }
int lcd_drv_init(struct lcd_logical_driver *driver, char *args) int
lcd_drv_init (struct lcd_logical_driver *driver, char *args)
{ {
// printf("lcd_drv_init()\n"); // printf("lcd_drv_init()\n");
lcd.wid = LCD_MAX_WID;
lcd.hgt = LCD_MAX_HGT;
lcd.framebuf = NULL; lcd.wid = LCD_MAX_WID;
lcd.hgt = LCD_MAX_HGT;
lcd.framebuf = NULL;
/* /*
if(!lcd.framebuf) if(!lcd.framebuf)
lcd.framebuf = malloc(lcd.wid * lcd.hgt); lcd.framebuf = malloc(lcd.wid * lcd.hgt);
@@ -253,35 +248,35 @@ int lcd_drv_init(struct lcd_logical_driver *driver, char *args)
// Debugging... // Debugging...
// if(lcd.framebuf) printf("Frame buffer: %i\n", (int)lcd.framebuf); // if(lcd.framebuf) printf("Frame buffer: %i\n", (int)lcd.framebuf);
lcd.cellwid = 5; lcd.cellwid = 5;
lcd.cellhgt = 8; lcd.cellhgt = 8;
// Set up these wrapper functions...
lcd.clear = lcd_drv_clear;
lcd.string = lcd_drv_string;
lcd.chr = lcd_drv_chr;
lcd.vbar = lcd_drv_vbar;
lcd.hbar = lcd_drv_hbar;
lcd.init_num = lcd_drv_init_num;
lcd.num = lcd_drv_num;
lcd.init = lcd_drv_init;
lcd.close = lcd_drv_close;
lcd.flush = lcd_drv_flush;
lcd.flush_box = lcd_drv_flush_box;
lcd.contrast = lcd_drv_contrast;
lcd.backlight = lcd_drv_backlight;
lcd.output = lcd_drv_output;
lcd.set_char = lcd_drv_set_char;
lcd.icon = lcd_drv_icon;
lcd.init_vbar = lcd_drv_init_vbar;
lcd.init_hbar = lcd_drv_init_hbar;
lcd.draw_frame = lcd_drv_draw_frame;
lcd.getkey = lcd_drv_getkey; // Set up these wrapper functions...
lcd.clear = lcd_drv_clear;
lcd.string = lcd_drv_string;
return 1; // 1 is arbitrary. (must be 1 or more) lcd.chr = lcd_drv_chr;
lcd.vbar = lcd_drv_vbar;
lcd.hbar = lcd_drv_hbar;
lcd.init_num = lcd_drv_init_num;
lcd.num = lcd_drv_num;
lcd.init = lcd_drv_init;
lcd.close = lcd_drv_close;
lcd.flush = lcd_drv_flush;
lcd.flush_box = lcd_drv_flush_box;
lcd.contrast = lcd_drv_contrast;
lcd.backlight = lcd_drv_backlight;
lcd.output = lcd_drv_output;
lcd.set_char = lcd_drv_set_char;
lcd.icon = lcd_drv_icon;
lcd.init_vbar = lcd_drv_init_vbar;
lcd.init_hbar = lcd_drv_init_hbar;
lcd.draw_frame = lcd_drv_draw_frame;
lcd.getkey = lcd_drv_getkey;
return 1; // 1 is arbitrary. (must be 1 or more)
} }
@@ -302,437 +297,416 @@ int lcd_drv_init(struct lcd_logical_driver *driver, char *args)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
void lcd_drv_close() void
lcd_drv_close ()
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
// printf("lcd_drv_close()\n"); // printf("lcd_drv_close()\n");
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->close > 0) if ((int) driver->close > 0) {
{ printf ("Calling close()\n");
printf("Calling close()\n"); driver->close ();
driver->close(); } else if ((int) driver->close == -1) {
} drv_base->close ();
else if((int)driver->close == -1)
{
drv_base->close();
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_clear() void
lcd_drv_clear ()
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->clear > 0) if ((int) driver->clear > 0)
driver->clear(); driver->clear ();
else if((int)driver->clear == -1) else if ((int) driver->clear == -1) {
{ drv_base->clear ();
drv_base->clear();
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_flush() void
lcd_drv_flush ()
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->flush > 0) if ((int) driver->flush > 0)
driver->flush(); driver->flush ();
else if((int)driver->flush == -1) else if ((int) driver->flush == -1) {
{ drv_base->flush ();
drv_base->flush();
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_string(int x, int y, char string[]) void
lcd_drv_string (int x, int y, char string[])
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->string > 0) if ((int) driver->string > 0)
driver->string(x,y,string); driver->string (x, y, string);
else if((int)driver->string == -1) else if ((int) driver->string == -1) {
{ drv_base->string (x, y, string);
drv_base->string(x,y,string);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_chr(int x, int y, char c) void
lcd_drv_chr (int x, int y, char c)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->chr > 0) if ((int) driver->chr > 0)
driver->chr(x,y,c); driver->chr (x, y, c);
else if((int)driver->chr == -1) else if ((int) driver->chr == -1) {
{ drv_base->chr (x, y, c);
drv_base->chr(x,y,c);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
int lcd_drv_contrast(int contrast) int
lcd_drv_contrast (int contrast)
{ {
int res=0; int res = 0;
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->contrast > 0) if ((int) driver->contrast > 0) {
{ res = driver->contrast (contrast);
res=driver->contrast(contrast); if (res >= 0)
if(res >= 0) return res; return res;
} }
/* /*
else if((int)driver->contrast == -1) else if((int)driver->contrast == -1)
{ {
res=drv_base->contrast(contrast); res=drv_base->contrast(contrast);
} }
*/ */
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
return res; return res;
} }
void lcd_drv_backlight(int on) void
lcd_drv_backlight (int on)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->backlight > 0) if ((int) driver->backlight > 0)
driver->backlight(on); driver->backlight (on);
else if((int)driver->backlight == -1) else if ((int) driver->backlight == -1) {
{ drv_base->backlight (on);
drv_base->backlight(on);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_output(int on) void
lcd_drv_output (int on)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do do {
{ driver = (lcd_logical_driver *) LL_Get (list);
driver = (lcd_logical_driver *)LL_Get(list); if (driver) {
if(driver)
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->output > 0) if ((int) driver->output > 0)
driver->output(on); driver->output (on);
else if((int)driver->output == -1) else if ((int) driver->output == -1) {
{ drv_base->output (on);
drv_base->output(on);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_init_vbar() void
lcd_drv_init_vbar ()
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->init_vbar > 0) if ((int) driver->init_vbar > 0)
driver->init_vbar(); driver->init_vbar ();
else if((int)driver->init_vbar == -1) else if ((int) driver->init_vbar == -1) {
{ drv_base->init_vbar ();
drv_base->init_vbar();
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_init_hbar() void
lcd_drv_init_hbar ()
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->init_hbar > 0) if ((int) driver->init_hbar > 0)
driver->init_hbar(); driver->init_hbar ();
else if((int)driver->init_hbar == -1) else if ((int) driver->init_hbar == -1) {
{ drv_base->init_hbar ();
drv_base->init_hbar();
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_init_num() void
lcd_drv_init_num ()
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->init_num > 0) if ((int) driver->init_num > 0)
driver->init_num(); driver->init_num ();
else if((int)driver->init_num == -1) else if ((int) driver->init_num == -1) {
{ drv_base->init_num ();
drv_base->init_num();
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_num(int x, int num) void
lcd_drv_num (int x, int num)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->num > 0) if ((int) driver->num > 0)
driver->num(x,num); driver->num (x, num);
else if((int)driver->num == -1) else if ((int) driver->num == -1) {
{ drv_base->num (x, num);
drv_base->num(x,num);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_set_char(int n, char *dat) void
lcd_drv_set_char (int n, char *dat)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->set_char > 0) if ((int) driver->set_char > 0)
driver->set_char(n,dat); driver->set_char (n, dat);
else if((int)driver->set_char == -1) else if ((int) driver->set_char == -1) {
{ drv_base->set_char (n, dat);
drv_base->set_char(n,dat);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_vbar(int x, int len) void
lcd_drv_vbar (int x, int len)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->vbar > 0) if ((int) driver->vbar > 0)
driver->vbar(x,len); driver->vbar (x, len);
else if((int)driver->vbar == -1) else if ((int) driver->vbar == -1) {
{ drv_base->vbar (x, len);
drv_base->vbar(x,len);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_hbar(int x, int y, int len) void
lcd_drv_hbar (int x, int y, int len)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->hbar > 0) if ((int) driver->hbar > 0)
driver->hbar(x,y,len); driver->hbar (x, y, len);
else if((int)driver->hbar == -1) else if ((int) driver->hbar == -1) {
{ drv_base->hbar (x, y, len);
drv_base->hbar(x,y,len);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_icon(int which, char dest) void
lcd_drv_icon (int which, char dest)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->icon > 0) if ((int) driver->icon > 0)
driver->icon(which,dest); driver->icon (which, dest);
else if((int)driver->icon == -1) else if ((int) driver->icon == -1) {
{ drv_base->icon (which, dest);
drv_base->icon(which,dest);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
void lcd_drv_flush_box(int lft, int top, int rgt, int bot) void
lcd_drv_flush_box (int lft, int top, int rgt, int bot)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->flush_box > 0) if ((int) driver->flush_box > 0)
driver->flush_box(lft,top,rgt,bot); driver->flush_box (lft, top, rgt, bot);
else if((int)driver->flush_box == -1) else if ((int) driver->flush_box == -1) {
{ drv_base->flush_box (lft, top, rgt, bot);
drv_base->flush_box(lft,top,rgt,bot);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
// TODO: Check whether lcd.draw_frame() should really take a framebuffer // TODO: Check whether lcd.draw_frame() should really take a framebuffer
// TODO: as an argument, or if it should always use lcd.framebuf // TODO: as an argument, or if it should always use lcd.framebuf
void lcd_drv_draw_frame(char *dat) void
lcd_drv_draw_frame (char *dat)
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->draw_frame > 0) if ((int) driver->draw_frame > 0)
driver->draw_frame(dat); driver->draw_frame (dat);
else if((int)driver->draw_frame == -1) else if ((int) driver->draw_frame == -1) {
{ drv_base->draw_frame (dat);
drv_base->draw_frame(dat);
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
} }
char lcd_drv_getkey() char
lcd_drv_getkey ()
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
char key; char key;
LL_Rewind(list); LL_Rewind (list);
do { do {
driver = (lcd_logical_driver *)LL_Get(list); driver = (lcd_logical_driver *) LL_Get (list);
if(driver) if (driver) {
{
lcd.framebuf = driver->framebuf; lcd.framebuf = driver->framebuf;
if((int)driver->getkey > 0) if ((int) driver->getkey > 0) {
{ key = driver->getkey ();
key = driver->getkey(); if (key)
if(key) return key; return key;
} } else if ((int) driver->getkey == -1) {
else if((int)driver->getkey == -1) key = drv_base->getkey ();
{ if (key)
key = drv_base->getkey(); return key;
if(key) return key;
} }
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
return 0; return 0;
} }
+61 -64
View File
@@ -8,9 +8,9 @@
#define LCD_MAX_HEIGHT 256 #define LCD_MAX_HEIGHT 256
int lcd_init(char *args); int lcd_init (char *args);
int lcd_add_driver(char *driver, char *args); int lcd_add_driver (char *driver, char *args);
int lcd_shutdown(); int lcd_shutdown ();
@@ -20,76 +20,73 @@ int lcd_shutdown();
// Feel free to override any/all functions here with real driver // Feel free to override any/all functions here with real driver
// functions... // functions...
// //
typedef struct lcd_logical_driver typedef struct lcd_logical_driver {
{ // Size in cells of the LCD
// Size in cells of the LCD int wid, hgt;
int wid, hgt; // Size of each LCD cell, in pixels
// Size of each LCD cell, in pixels int cellwid, cellhgt;
int cellwid, cellhgt; // Frame buffer...
// Frame buffer... char *framebuf;
char *framebuf;
// Functions which might be the same for all drivers... // Functions which might be the same for all drivers...
void (*clear)(); void (*clear) ();
void (*string)(int x, int y, char lcd[]); void (*string) (int x, int y, char lcd[]);
void (*chr)(int x, int y, char c); void (*chr) (int x, int y, char c);
void (*vbar)(int x, int len); void (*vbar) (int x, int len);
void (*hbar)(int x, int y, int len); void (*hbar) (int x, int y, int len);
void (*init_num)(); void (*init_num) ();
void (*num)(int x, int num); void (*num) (int x, int num);
// Functions which should probably be implemented in each driver... // Functions which should probably be implemented in each driver...
int (*init)(struct lcd_logical_driver *driver, char *args); int (*init) (struct lcd_logical_driver * driver, char *args);
void (*close)(); void (*close) ();
void (*flush)(); void (*flush) ();
void (*flush_box)(int lft, int top, int rgt, int bot); void (*flush_box) (int lft, int top, int rgt, int bot);
int (*contrast)(int contrast); int (*contrast) (int contrast);
void (*backlight)(int on); void (*backlight) (int on);
void (*output)(int on); void (*output) (int on);
void (*set_char)(int n, char *dat); void (*set_char) (int n, char *dat);
void (*icon)(int which, char dest); void (*icon) (int which, char dest);
void (*init_vbar)(); void (*init_vbar) ();
void (*init_hbar)(); void (*init_hbar) ();
void (*draw_frame)(); void (*draw_frame) ();
// Returns 0 for "no key pressed", or (A-Z).
char (*getkey) ();
// more?
// Returns 0 for "no key pressed", or (A-Z).
char (*getkey)();
// more?
} lcd_logical_driver; } lcd_logical_driver;
typedef struct lcd_physical_driver typedef struct lcd_physical_driver {
{ char *name;
char *name; int (*init) (struct lcd_logical_driver * driver, char *device);
int (*init)(struct lcd_logical_driver *driver, char *device);
} lcd_physical_driver; } lcd_physical_driver;
extern lcd_logical_driver lcd; extern lcd_logical_driver lcd;
int lcd_drv_init(lcd_logical_driver *driver, char *args); int lcd_drv_init (lcd_logical_driver * driver, char *args);
void lcd_drv_close(); void lcd_drv_close ();
void lcd_drv_clear(); void lcd_drv_clear ();
void lcd_drv_flush(); void lcd_drv_flush ();
void lcd_drv_string(int x, int y, char string[]); void lcd_drv_string (int x, int y, char string[]);
void lcd_drv_chr(int x, int y, char c); void lcd_drv_chr (int x, int y, char c);
int lcd_drv_contrast(int contrast); int lcd_drv_contrast (int contrast);
void lcd_drv_backlight(int on); void lcd_drv_backlight (int on);
void lcd_drv_output(int on); void lcd_drv_output (int on);
void lcd_drv_init_vbar(); void lcd_drv_init_vbar ();
void lcd_drv_init_hbar(); void lcd_drv_init_hbar ();
void lcd_drv_init_num(); void lcd_drv_init_num ();
void lcd_drv_num(int x, int num); void lcd_drv_num (int x, int num);
void lcd_drv_set_char(int n, char *dat); void lcd_drv_set_char (int n, char *dat);
void lcd_drv_vbar(int x, int len); void lcd_drv_vbar (int x, int len);
void lcd_drv_hbar(int x, int y, int len); void lcd_drv_hbar (int x, int y, int len);
void lcd_drv_icon(int which, char dest); void lcd_drv_icon (int which, char dest);
void lcd_drv_flush_box(int lft, int top, int rgt, int bot); void lcd_drv_flush_box (int lft, int top, int rgt, int bot);
void lcd_drv_draw_frame(); void lcd_drv_draw_frame ();
char lcd_drv_getkey(); char lcd_drv_getkey ();
#endif #endif
+71 -84
View File
@@ -23,7 +23,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> /* for semaphore functions */ #include <sys/types.h> /* for semaphore functions */
#include <sys/ipc.h> #include <sys/ipc.h>
#include <sys/sem.h> #include <sys/sem.h>
#include <errno.h> #include <errno.h>
@@ -31,19 +31,19 @@
#include "lcd_sem.h" #include "lcd_sem.h"
#define SEMAPHORE "portctrl" #define SEMAPHORE "portctrl"
#define SEMKEY 0x706f7274 /* semaphore key */ #define SEMKEY 0x706f7274 /* semaphore key */
#define SEMCOUNT 1 /* number of semaphores to create */ #define SEMCOUNT 1 /* number of semaphores to create */
#define WMODE 0660 /* access permissions */ #define WMODE 0660 /* access permissions */
#define SEM_SIGNAL 0,1,SEM_UNDO #define SEM_SIGNAL 0,1,SEM_UNDO
#define SEM_WAIT 0,-1,SEM_UNDO #define SEM_WAIT 0,-1,SEM_UNDO
/* functions local to this file */ /* functions local to this file */
static key_t getkey(register char *p); static key_t getkey (register char *p);
/* global variables */ /* global variables */
static struct sembuf semaphore_wait = {SEM_WAIT}; static struct sembuf semaphore_wait = { SEM_WAIT };
static struct sembuf semaphore_signal = {SEM_SIGNAL}; static struct sembuf semaphore_signal = { SEM_SIGNAL };
static char rcsId[] = "$Id$"; static char rcsId[] = "$Id$";
@@ -52,9 +52,9 @@ static char rcsId[] = "$Id$";
*/ */
static key_t static key_t
getkey(register char *p) getkey (register char *p)
{ {
return((key_t) SEMKEY); return ((key_t) SEMKEY);
} }
/* /*
@@ -63,50 +63,42 @@ getkey(register char *p)
*/ */
int int
sem_get(void) sem_get (void)
{ {
int semid; int semid;
union semun semval; union semun semval;
if ((semid = semget(getkey(SEMAPHORE), SEMCOUNT, if ((semid = semget (getkey (SEMAPHORE), SEMCOUNT, IPC_CREAT | IPC_EXCL | WMODE)) < 0) {
IPC_CREAT | IPC_EXCL | WMODE)) < 0) switch (errno) {
{ case EEXIST:
switch (errno) /* semaphore set exists, get id and return it */
{ if ((semid = semget (getkey (SEMAPHORE), SEMCOUNT, IPC_EXCL | WMODE)) < 0) {
case EEXIST: perror ("semget");
/* semaphore set exists, get id and return it */ exit (1);
if ((semid = semget(getkey(SEMAPHORE), SEMCOUNT, }
IPC_EXCL | WMODE)) < 0) return semid;
{ break;
perror("semget"); case EACCES:
exit(1); /* don't have permissions for semaphore, need to change key */
} perror ("semget, can't get permissions for semaphore");
return semid; exit (1);
break; break;
case EACCES: default:
/* don't have permissions for semaphore, need to change key */ perror ("semget");
perror("semget, can't get permissions for semaphore"); exit (1);
exit(1); break;
break; }
default: } else {
perror("semget"); /* initialise semaphore to 1 */
exit(1); semval.val = 1;
break;
}
}
else
{
/* initialise semaphore to 1 */
semval.val = 1;
if (semctl(semid, 0, SETVAL, semval) < 0) if (semctl (semid, 0, SETVAL, semval) < 0) {
{ perror ("setval, can't initialise semaphore");
perror("setval, can't initialise semaphore"); exit (1);
exit(1); }
} }
}
return semid;
return semid;
} }
/* /*
@@ -114,15 +106,14 @@ sem_get(void)
*/ */
int int
sem_wait(int sid) sem_wait (int sid)
{ {
if (semop(sid, &semaphore_wait, 1) < -1) if (semop (sid, &semaphore_wait, 1) < -1) {
{ perror (SEMAPHORE);
perror(SEMAPHORE); exit (1);
exit(1); }
}
return 0; return 0;
} }
/* /*
@@ -130,15 +121,14 @@ sem_wait(int sid)
*/ */
int int
sem_signal(int sid) sem_signal (int sid)
{ {
if (semop(sid, &semaphore_signal, 1) < -1) if (semop (sid, &semaphore_signal, 1) < -1) {
{ perror (SEMAPHORE);
perror(SEMAPHORE); exit (1);
exit(1); }
}
return 0; return 0;
} }
/* /*
@@ -146,25 +136,22 @@ sem_signal(int sid)
*/ */
int int
sem_remove(int sid) sem_remove (int sid)
{ {
int i; int i;
union semun dummy; union semun dummy;
if ((i = semctl(sid, 0, IPC_RMID, dummy)) < 0)
{
switch(i)
{
case EIDRM:
/* semaphore removed */
return 0;
break;
default:
perror("semctl, removing semaphore");
exit(1);
}
}
return 0; if ((i = semctl (sid, 0, IPC_RMID, dummy)) < 0) {
switch (i) {
case EIDRM:
/* semaphore removed */
return 0;
break;
default:
perror ("semctl, removing semaphore");
exit (1);
}
}
return 0;
} }
+4 -4
View File
@@ -5,9 +5,9 @@
#ifndef LCD_SEM_H #ifndef LCD_SEM_H
#define LCD_SEM_H #define LCD_SEM_H
int sem_get(void); int sem_get (void);
int sem_wait(int sid); int sem_wait (int sid);
int sem_signal(int sid); int sem_signal (int sid);
int sem_remove(int sid); int sem_remove (int sid);
#endif #endif
-124
View File
@@ -1,124 +0,0 @@
/* lcddriver.cd - test/demo of LIBIR's to interface with lcdproc (LCDd) */
/* Copyright (C) 1999 David Glaude loosely based on workmanir.c */
/* workmanir.c - test/demo of LIBIR's high level command functions */
/* Copyright (C) 1998 Tom Wheeley, see file COPYING for details */
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "irman.h"
char *progname = "lcddriver";
char *codes[] = {
/* dummy */ NULL,
/* KeyToLcd */ "lcdproc-A",
/* KeyToLcd */ "lcdproc-B",
/* KeyToLcd */ "lcdproc-C",
/* KeyToLcd */ "lcdproc-D",
/* KeyToLcd */ "lcdproc-E",
/* KeyToLcd */ "lcdproc-F",
/* KeyToLcd */ "lcdproc-G",
/* KeyToLcd */ "lcdproc-H",
/* KeyToLcd */ "lcdproc-I",
/* KeyToLcd */ "lcdproc-J",
/* KeyToLcd */ "lcdproc-K",
/* KeyToLcd */ "lcdproc-L",
/* KeyToLcd */ "lcdproc-M",
/* KeyToLcd */ "lcdproc-N",
/* KeyToLcd */ "lcdproc-O",
/* KeyToLcd */ "lcdproc-P",
/* KeyToLcd */ "lcdproc-Q",
/* KeyToLcd */ "lcdproc-R",
/* KeyToLcd */ "lcdproc-S",
/* KeyToLcd */ "lcdproc-T",
/* KeyToLcd */ "lcdproc-U",
/* KeyToLcd */ "lcdproc-V",
/* KeyToLcd */ "lcdproc-W",
/* KeyToLcd */ "lcdproc-X",
/* KeyToLcd */ "lcdproc-Y",
/* KeyToLcd */ "lcdproc-Z",
/* end */ NULL
};
//void sigterm(int sig)
//{
// ir_free_commands();
// ir_finish();
// raise(sig);
//}
// INIT $$$
int INIT()
{
int i;
char *filename;
if (ir_init_commands(NULL, 1) < 0) {
fprintf(stderr, "error initialising commands: %s\n", strerror(errno));
exit(1);
}
filename = ir_default_portname();
filename = "option";
}
for (i=1; codes[i] != NULL; i++) {
if (ir_register_command(codes[i], i) < 0) {
if (errno == ENOENT) {
fprintf(stderr, "%s: no code set for `%s'\n", progname, codes[i]);
} else {
fprintf(stderr, "error registering `%s': `%s'\n", codes[i], strerror(errno));
}
}
}
errno = 0;
if (ir_init(filename) < 0) {
fprintf(stderr, "%s: error initialising Irman: `%s'\n", strerror(errno));
exit(1);
}
return 0;
}
// KEY $$$
int KEY(void)
{
int i;
int cmd;
char key;
key=(char)0;
for(i=1;i;) {
switch (cmd=ir_get_command()) {
case IR_CMD_ERROR:
fprintf(stderr, "%s: error reading command: %s\n", progname, strerror(errno));
// No exit in LCDd !!!
// exit(1);
case IR_CMD_UNKNOWN:
fprintf(stderr,"IR unknown command\n");
default: key='A'-1+cmd; break;
}
}
}
// CLOSE $$$
int CLOSE()
{
ir_free_commands();
ir_finish();
return 0;
}
/* end of lcddriver.c */
+41 -40
View File
@@ -49,10 +49,11 @@ lcd_logical_driver *lircin;
// raise(sig); // raise(sig);
//} //}
void lircin_close() void
lircin_close ()
{ {
lirc_freeconfig(config); lirc_freeconfig (config);
lirc_deinit(); lirc_deinit ();
} }
@@ -61,33 +62,34 @@ void lircin_close()
// //
// Return 0 for "nothing available". // Return 0 for "nothing available".
// //
char lircin_getkey() char
lircin_getkey ()
{ {
char key; char key;
char *ir,*cmd; char *ir, *cmd;
if (!(ir = lirc_nextir()))
{
return 0;
} else
{
if (!(cmd = lirc_ir2char(config,ir))) return 0;
printf("lirc: \"%s\"\n", cmd);
sscanf(cmd,"%c",&key);
printf("\n%c\n",key);
free(ir);
return key;
}
return 0; if (!(ir = lirc_nextir ())) {
return 0;
} else {
if (!(cmd = lirc_ir2char (config, ir)))
return 0;
printf ("lirc: \"%s\"\n", cmd);
sscanf (cmd, "%c", &key);
printf ("\n%c\n", key);
free (ir);
return key;
}
return 0;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// init() should set up any device-specific stuff, and // init() should set up any device-specific stuff, and
// point all the function pointers. // point all the function pointers.
int lircin_init(struct lcd_logical_driver *driver, char *args) int
lircin_init (struct lcd_logical_driver *driver, char *args)
{ {
/* assign funktions */ /* assign funktions */
@@ -99,24 +101,23 @@ int lircin_init(struct lcd_logical_driver *driver, char *args)
/* open socket to lirc */ /* open socket to lirc */
if (-1 == (fd = lirc_init("lcdd",1))) { if (-1 == (fd = lirc_init ("lcdd", 1))) {
fprintf(stderr,"no infrared remote support available\n"); fprintf (stderr, "no infrared remote support available\n");
return -1; return -1;
} }
if (0 != lirc_readconfig(NULL,&config,NULL)) { if (0 != lirc_readconfig (NULL, &config, NULL)) {
lirc_deinit(); lirc_deinit ();
return -1; return -1;
} }
fcntl(fd,F_SETFL,O_NONBLOCK); fcntl (fd, F_SETFL, O_NONBLOCK);
fcntl(fd,F_SETFD,FD_CLOEXEC); fcntl (fd, F_SETFD, FD_CLOEXEC);
/* socket shouldn block lcdd */ /* socket shouldn block lcdd */
fcntl(fd,F_SETFL,O_NONBLOCK); fcntl (fd, F_SETFL, O_NONBLOCK);
fcntl(fd,F_SETFD,FD_CLOEXEC); fcntl (fd, F_SETFD, FD_CLOEXEC);
return 1; // 200 is arbitrary. (must be 1 or more)
}
return 1; // 200 is arbitrary. (must be 1 or more)
}
+3 -3
View File
@@ -4,9 +4,9 @@
extern lcd_logical_driver *lircin; extern lcd_logical_driver *lircin;
int lircin_init(struct lcd_logical_driver *driver, char *args); int lircin_init (struct lcd_logical_driver *driver, char *args);
void lircin_close(); void lircin_close ();
char lircin_getkey(); char lircin_getkey ();
#endif #endif
+15 -15
View File
@@ -15,36 +15,36 @@
#endif #endif
#ifndef DOS #ifndef DOS
static inline int port_in( int port ) static inline int
port_in (int port)
{ {
unsigned char value; unsigned char value;
__asm__ volatile ("inb %1,%0" __asm__ volatile ("inb %1,%0":"=a" (value)
: "=a" (value) :"d" ((unsigned short) port));
: "d" ((unsigned short)port));
return value; return value;
} }
static inline void port_out( unsigned short int port, unsigned char val ) static inline void
port_out (unsigned short int port, unsigned char val)
{ {
__asm__ volatile ( __asm__ volatile ("outb %0,%1\n"::"a" (val), "d" (port)
"outb %0,%1\n" );
:
: "a" (val), "d" (port)
);
} }
#else #else
#include <pc.h> #include <pc.h>
static inline int port_in( int port ) static inline int
port_in (int port)
{ {
unsigned char value; unsigned char value;
value = inportb((unsigned short) port); value = inportb ((unsigned short) port);
return (int)value; return (int) value;
} }
static inline void port_out( unsigned int port, unsigned char val ) static inline void
port_out (unsigned int port, unsigned char val)
{ {
outportb((unsigned short) port, val); outportb ((unsigned short) port, val);
} }
#endif #endif
+355 -291
View File
@@ -38,141 +38,141 @@
/* Small font */ /* Small font */
const unsigned char simple_font5x7[] = { const unsigned char simple_font5x7[] = {
/* ascii '0' ( ) */ 31,31,31,31,31,31,31, /* ascii '0' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '1' ( ) */ 31,31,31,31,31,31,31, /* ascii '1' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '2' ( ) */ 31,31,31,31,31,31,31, /* ascii '2' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '3' ( ) */ 31,31,31,31,31,31,31, /* ascii '3' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '4' ( ) */ 31,31,31,31,31,31,31, /* ascii '4' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '5' ( ) */ 31,31,31,31,31,31,31, /* ascii '5' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '6' ( ) */ 31,31,31,31,31,31,31, /* ascii '6' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '7' ( ) */ 31,31,31,31,31,31,31, /* ascii '7' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '8' ( ) */ 31,31,31,31,31,31,31, /* ascii '8' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '9' ( ) */ 31,31,31,31,31,31,31, /* ascii '9' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '10' ( ) */ 31,31,31,31,31,31,31, /* ascii '10' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '11' ( ) */ 31,31,31,31,31,31,31, /* ascii '11' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '12' ( ) */ 31,31,31,31,31,31,31, /* ascii '12' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '13' ( ) */ 31,31,31,31,31,31,31, /* ascii '13' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '14' ( ) */ 31,31,31,31,31,31,31, /* ascii '14' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '15' ( ) */ 31,31,31,31,31,31,31, /* ascii '15' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '16' ( ) */ 31,31,31,31,31,31,31, /* ascii '16' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '17' ( ) */ 31,31,31,31,31,31,31, /* ascii '17' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '18' ( ) */ 31,31,31,31,31,31,31, /* ascii '18' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '19' ( ) */ 31,31,31,31,31,31,31, /* ascii '19' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '20' ( ) */ 31,31,31,31,31,31,31, /* ascii '20' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '21' ( ) */ 31,31,31,31,31,31,31, /* ascii '21' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '22' ( ) */ 31,31,31,31,31,31,31, /* ascii '22' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '23' ( ) */ 31,31,31,31,31,31,31, /* ascii '23' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '24' ( ) */ 31,31,31,31,31,31,31, /* ascii '24' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '25' ( ) */ 31,31,31,31,31,31,31, /* ascii '25' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '26' ( ) */ 31,31,31,31,31,31,31, /* ascii '26' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '27' ( ) */ 31,31,31,31,31,31,31, /* ascii '27' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '28' ( ) */ 31,31,31,31,31,31,31, /* ascii '28' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '29' ( ) */ 31,31,31,31,31,31,31, /* ascii '29' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '30' ( ) */ 31,31,31,31,31,31,31, /* ascii '30' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '31' ( ) */ 31,31,31,31,31,31,31, /* ascii '31' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '32' ( ) */ 31,31,31,31,31,31,31, /* ascii '32' ( ) */ 31, 31, 31, 31, 31, 31, 31,
/* ascii '33' (!) */ 27,27,27,27,31,31,27, /* ascii '33' (!) */ 27, 27, 27, 27, 31, 31, 27,
/* ascii '34' (") */ 21,21,21,31,31,31,31, /* ascii '34' (") */ 21, 21, 21, 31, 31, 31, 31,
/* ascii '35' (#) */ 21,21,0,21,0,21,21, /* ascii '35' (#) */ 21, 21, 0, 21, 0, 21, 21,
/* ascii '36' ($) */ 27,1,26,17,11,16,27, /* ascii '36' ($) */ 27, 1, 26, 17, 11, 16, 27,
/* ascii '37' (%) */ 28,12,23,27,29,6,7, /* ascii '37' (%) */ 28, 12, 23, 27, 29, 6, 7,
/* ascii '38' (&) */ 25,22,26,29,10,22,9, /* ascii '38' (&) */ 25, 22, 26, 29, 10, 22, 9,
/* ascii '39' (') */ 25,27,29,31,31,31,31, /* ascii '39' (') */ 25, 27, 29, 31, 31, 31, 31,
/* ascii '40' (() */ 23,27,29,29,29,27,23, /* ascii '40' (() */ 23, 27, 29, 29, 29, 27, 23,
/* ascii '41' ()) */ 29,27,23,23,23,27,29, /* ascii '41' ()) */ 29, 27, 23, 23, 23, 27, 29,
/* ascii '42' (*) */ 31,27,10,17,10,27,31, /* ascii '42' (*) */ 31, 27, 10, 17, 10, 27, 31,
/* ascii '43' (+) */ 31,27,27,0,27,27,31, /* ascii '43' (+) */ 31, 27, 27, 0, 27, 27, 31,
/* ascii '44' (,) */ 31,31,31,31,25,27,29, /* ascii '44' (,) */ 31, 31, 31, 31, 25, 27, 29,
/* ascii '45' (-) */ 31,31,31,0,31,31,31, /* ascii '45' (-) */ 31, 31, 31, 0, 31, 31, 31,
/* ascii '46' (.) */ 31,31,31,31,31,25,25, /* ascii '46' (.) */ 31, 31, 31, 31, 31, 25, 25,
/* ascii '47' (/) */ 31,15,23,27,29,30,31, /* ascii '47' (/) */ 31, 15, 23, 27, 29, 30, 31,
/* ascii '48' (0) */ 17,14,6,10,12,14,17, /* ascii '48' (0) */ 17, 14, 6, 10, 12, 14, 17,
/* ascii '49' (1) */ 27,25,27,27,27,27,17, /* ascii '49' (1) */ 27, 25, 27, 27, 27, 27, 17,
/* ascii '50' (2) */ 17,14,15,23,27,29,0, /* ascii '50' (2) */ 17, 14, 15, 23, 27, 29, 0,
/* ascii '51' (3) */ 0,23,27,23,15,14,17, /* ascii '51' (3) */ 0, 23, 27, 23, 15, 14, 17,
/* ascii '52' (4) */ 23,19,21,22,0,23,23, /* ascii '52' (4) */ 23, 19, 21, 22, 0, 23, 23,
/* ascii '53' (5) */ 0,30,16,15,15,14,17, /* ascii '53' (5) */ 0, 30, 16, 15, 15, 14, 17,
/* ascii '54' (6) */ 19,29,30,16,14,14,17, /* ascii '54' (6) */ 19, 29, 30, 16, 14, 14, 17,
/* ascii '55' (7) */ 0,15,23,27,29,29,29, /* ascii '55' (7) */ 0, 15, 23, 27, 29, 29, 29,
/* ascii '56' (8) */ 17,14,14,17,14,14,17, /* ascii '56' (8) */ 17, 14, 14, 17, 14, 14, 17,
/* ascii '57' (9) */ 17,14,14,1,15,23,25, /* ascii '57' (9) */ 17, 14, 14, 1, 15, 23, 25,
/* ascii '58' (:) */ 31,25,25,31,25,25,31, /* ascii '58' (:) */ 31, 25, 25, 31, 25, 25, 31,
/* ascii '59' (;) */ 31,25,25,31,25,27,29, /* ascii '59' (;) */ 31, 25, 25, 31, 25, 27, 29,
/* ascii '60' (<) */ 23,27,29,30,29,27,23, /* ascii '60' (<) */ 23, 27, 29, 30, 29, 27, 23,
/* ascii '61' (=) */ 31,31,0,31,0,31,31, /* ascii '61' (=) */ 31, 31, 0, 31, 0, 31, 31,
/* ascii '62' (>) */ 29,27,23,15,23,27,29, /* ascii '62' (>) */ 29, 27, 23, 15, 23, 27, 29,
/* ascii '63' (?) */ 17,14,15,23,27,31,27, /* ascii '63' (?) */ 17, 14, 15, 23, 27, 31, 27,
/* ascii '64' (@) */ 17,14,15,9,10,10,17, /* ascii '64' (@) */ 17, 14, 15, 9, 10, 10, 17,
/* ascii '65' (A) */ 17,14,14,14,0,14,14, /* ascii '65' (A) */ 17, 14, 14, 14, 0, 14, 14,
/* ascii '66' (B) */ 16,14,14,16,14,14,16, /* ascii '66' (B) */ 16, 14, 14, 16, 14, 14, 16,
/* ascii '67' (C) */ 16,14,30,30,30,14,16, /* ascii '67' (C) */ 16, 14, 30, 30, 30, 14, 16,
/* ascii '68' (D) */ 24,22,14,14,14,22,24, /* ascii '68' (D) */ 24, 22, 14, 14, 14, 22, 24,
/* ascii '69' (E) */ 0,30,30,16,30,30,0, /* ascii '69' (E) */ 0, 30, 30, 16, 30, 30, 0,
/* ascii '70' (F) */ 0,30,30,16,30,30,30, /* ascii '70' (F) */ 0, 30, 30, 16, 30, 30, 30,
/* ascii '71' (G) */ 17,14,30,2,14,14,1, /* ascii '71' (G) */ 17, 14, 30, 2, 14, 14, 1,
/* ascii '72' (H) */ 14,14,14,0,14,14,14, /* ascii '72' (H) */ 14, 14, 14, 0, 14, 14, 14,
/* ascii '73' (I) */ 17,27,27,27,27,27,17, /* ascii '73' (I) */ 17, 27, 27, 27, 27, 27, 17,
/* ascii '74' (J) */ 3,23,23,23,23,22,25, /* ascii '74' (J) */ 3, 23, 23, 23, 23, 22, 25,
/* ascii '75' (K) */ 14,22,26,28,26,22,14, /* ascii '75' (K) */ 14, 22, 26, 28, 26, 22, 14,
/* ascii '76' (L) */ 30,30,30,30,30,30,0, /* ascii '76' (L) */ 30, 30, 30, 30, 30, 30, 0,
/* ascii '77' (M) */ 14,4,10,10,14,14,14, /* ascii '77' (M) */ 14, 4, 10, 10, 14, 14, 14,
/* ascii '78' (N) */ 14,14,12,10,6,14,14, /* ascii '78' (N) */ 14, 14, 12, 10, 6, 14, 14,
/* ascii '79' (O) */ 17,14,14,14,14,14,17, /* ascii '79' (O) */ 17, 14, 14, 14, 14, 14, 17,
/* ascii '80' (P) */ 16,14,14,16,30,30,30, /* ascii '80' (P) */ 16, 14, 14, 16, 30, 30, 30,
/* ascii '81' (Q) */ 17,14,14,14,10,22,9, /* ascii '81' (Q) */ 17, 14, 14, 14, 10, 22, 9,
/* ascii '82' (R) */ 16,14,14,16,26,22,14, /* ascii '82' (R) */ 16, 14, 14, 16, 26, 22, 14,
/* ascii '83' (S) */ 1,30,30,17,15,15,16, /* ascii '83' (S) */ 1, 30, 30, 17, 15, 15, 16,
/* ascii '84' (T) */ 0,27,27,27,27,27,27, /* ascii '84' (T) */ 0, 27, 27, 27, 27, 27, 27,
/* ascii '85' (U) */ 14,14,14,14,14,14,17, /* ascii '85' (U) */ 14, 14, 14, 14, 14, 14, 17,
/* ascii '86' (V) */ 14,14,14,14,14,21,27, /* ascii '86' (V) */ 14, 14, 14, 14, 14, 21, 27,
/* ascii '87' (W) */ 14,14,14,14,10,10,21, /* ascii '87' (W) */ 14, 14, 14, 14, 10, 10, 21,
/* ascii '88' (X) */ 14,14,21,27,21,14,14, /* ascii '88' (X) */ 14, 14, 21, 27, 21, 14, 14,
/* ascii '89' (Y) */ 14,14,14,21,27,27,27, /* ascii '89' (Y) */ 14, 14, 14, 21, 27, 27, 27,
/* ascii '90' (Z) */ 0,15,23,27,29,30,0, /* ascii '90' (Z) */ 0, 15, 23, 27, 29, 30, 0,
/* ascii '91' ([) */ 17,29,29,29,29,29,17, /* ascii '91' ([) */ 17, 29, 29, 29, 29, 29, 17,
/* ascii '92' (\) */ 31,30,29,27,23,15,31, /* ascii '92' (\) */ 31, 30, 29, 27, 23, 15, 31,
/* ascii '93' (]) */ 17,23,23,23,23,23,17, /* ascii '93' (]) */ 17, 23, 23, 23, 23, 23, 17,
/* ascii '94' (^) */ 27,21,14,31,31,31,31, /* ascii '94' (^) */ 27, 21, 14, 31, 31, 31, 31,
/* ascii '95' (_) */ 31,31,31,31,31,31,0, /* ascii '95' (_) */ 31, 31, 31, 31, 31, 31, 0,
/* ascii '96' (`) */ 29,27,23,31,31,31,31, /* ascii '96' (`) */ 29, 27, 23, 31, 31, 31, 31,
/* ascii '97' (a) */ 31,31,17,15,1,14,1, /* ascii '97' (a) */ 31, 31, 17, 15, 1, 14, 1,
/* ascii '98' (b) */ 30,30,18,12,14,14,16, /* ascii '98' (b) */ 30, 30, 18, 12, 14, 14, 16,
/* ascii '99' (c) */ 31,31,17,30,30,14,17, /* ascii '99' (c) */ 31, 31, 17, 30, 30, 14, 17,
/* ascii '100' (d) */ 15,15,9,6,14,14,1, /* ascii '100' (d) */ 15, 15, 9, 6, 14, 14, 1,
/* ascii '101' (e) */ 31,31,17,14,0,30,17, /* ascii '101' (e) */ 31, 31, 17, 14, 0, 30, 17,
/* ascii '102' (f) */ 19,13,29,24,29,29,29, /* ascii '102' (f) */ 19, 13, 29, 24, 29, 29, 29,
/* ascii '103' (g) */ 31,1,14,14,1,15,17, /* ascii '103' (g) */ 31, 1, 14, 14, 1, 15, 17,
/* ascii '104' (h) */ 30,30,18,12,14,14,14, /* ascii '104' (h) */ 30, 30, 18, 12, 14, 14, 14,
/* ascii '105' (i) */ 27,31,25,27,27,27,17, /* ascii '105' (i) */ 27, 31, 25, 27, 27, 27, 17,
/* ascii '106' (j) */ 23,31,19,23,23,22,25, /* ascii '106' (j) */ 23, 31, 19, 23, 23, 22, 25,
/* ascii '107' (k) */ 30,30,22,26,28,26,22, /* ascii '107' (k) */ 30, 30, 22, 26, 28, 26, 22,
/* ascii '108' (l) */ 25,27,27,27,27,27,17, /* ascii '108' (l) */ 25, 27, 27, 27, 27, 27, 17,
/* ascii '109' (m) */ 31,31,20,10,10,14,14, /* ascii '109' (m) */ 31, 31, 20, 10, 10, 14, 14,
/* ascii '110' (n) */ 31,31,18,12,14,14,14, /* ascii '110' (n) */ 31, 31, 18, 12, 14, 14, 14,
/* ascii '111' (o) */ 31,31,17,14,14,14,17, /* ascii '111' (o) */ 31, 31, 17, 14, 14, 14, 17,
/* ascii '112' (p) */ 31,31,16,14,16,30,30, /* ascii '112' (p) */ 31, 31, 16, 14, 16, 30, 30,
/* ascii '113' (q) */ 31,31,9,6,1,15,15, /* ascii '113' (q) */ 31, 31, 9, 6, 1, 15, 15,
/* ascii '114' (r) */ 31,31,18,12,30,30,30, /* ascii '114' (r) */ 31, 31, 18, 12, 30, 30, 30,
/* ascii '115' (s) */ 31,31,17,30,17,15,16, /* ascii '115' (s) */ 31, 31, 17, 30, 17, 15, 16,
/* ascii '116' (t) */ 29,29,24,29,29,13,19, /* ascii '116' (t) */ 29, 29, 24, 29, 29, 13, 19,
/* ascii '117' (u) */ 31,31,14,14,14,6,9, /* ascii '117' (u) */ 31, 31, 14, 14, 14, 6, 9,
/* ascii '118' (v) */ 31,31,14,14,14,21,27, /* ascii '118' (v) */ 31, 31, 14, 14, 14, 21, 27,
/* ascii '119' (w) */ 31,31,14,14,10,10,21, /* ascii '119' (w) */ 31, 31, 14, 14, 10, 10, 21,
/* ascii '120' (x) */ 31,31,14,21,27,21,14, /* ascii '120' (x) */ 31, 31, 14, 21, 27, 21, 14,
/* ascii '121' (y) */ 31,31,14,14,1,15,17, /* ascii '121' (y) */ 31, 31, 14, 14, 1, 15, 17,
/* ascii '122' (z) */ 31,31,0,23,27,29,0, /* ascii '122' (z) */ 31, 31, 0, 23, 27, 29, 0,
/* ascii '123' ({) */ 23,27,27,29,27,27,23, /* ascii '123' ({) */ 23, 27, 27, 29, 27, 27, 23,
/* ascii '124' (|) */ 27,27,27,27,27,27,27, /* ascii '124' (|) */ 27, 27, 27, 27, 27, 27, 27,
/* ascii '125' (}) */ 29,27,27,23,27,27,29, /* ascii '125' (}) */ 29, 27, 27, 23, 27, 27, 29,
/* ascii '126' (~) */ 31,27,23,0,23,27,31 /* ascii '126' (~) */ 31, 27, 23, 0, 23, 27, 31
}; };
// <start user definable!!!> // <start user definable!!!>
#define SVGALIB_FONT_VER 10 /* vertical spacing between lines (pixels) */ #define SVGALIB_FONT_VER 10 /* vertical spacing between lines (pixels) */
#define SVGALIB_Y_OFFSET 40 /* distance from the top of the screen (pixels) */ #define SVGALIB_Y_OFFSET 40 /* distance from the top of the screen (pixels) */
// <end user defineable!!!> // <end user defineable!!!>
@@ -186,12 +186,12 @@ const unsigned char simple_font5x7[] = {
lcd_logical_driver *svgalib_drv; lcd_logical_driver *svgalib_drv;
int SVGALIB_PAD=255; int SVGALIB_PAD = 255;
int SVGALIB_ELLIPSIS=7; int SVGALIB_ELLIPSIS = 7;
void* SVGALIB_font; /* normal font */ void *SVGALIB_font; /* normal font */
void* SVGALIB_highfont; /* highlighted font (not used yet) */ void *SVGALIB_highfont; /* highlighted font (not used yet) */
void* SVGALIB_warnfont; /* warning font (not used yet) */ void *SVGALIB_warnfont; /* warning font (not used yet) */
/* /*
@@ -202,7 +202,7 @@ void* SVGALIB_warnfont; /* warning font (not used yet) */
Ahem... don't do this unless you can get to another console to kill the Ahem... don't do this unless you can get to another console to kill the
process after. process after.
*/ */
int SVGALIB_figure_mappings=0; int SVGALIB_figure_mappings = 0;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////// For Output on SVGALIB screen ////////////////////// ////////////////////// For Output on SVGALIB screen //////////////////////
@@ -212,42 +212,43 @@ void* SVGALIB_warnfont; /* warning font (not used yet) */
void ExpandGroovyFont( int w, int ht, unsigned char col, void
const unsigned char* fnt, unsigned char* ptr ) ExpandGroovyFont (int w, int ht, unsigned char col, const unsigned char *fnt, unsigned char *ptr)
// Expand groovy 5x7 font into an area of memory // Expand groovy 5x7 font into an area of memory
{ {
int x,n,y; int x, n, y;
unsigned char mask; unsigned char mask;
unsigned char base; unsigned char base;
unsigned char *p; unsigned char *p;
p = ptr; p = ptr;
for (n=0;n<127;n++) { for (n = 0; n < 127; n++) {
for (y=0;y<ht;y++) { for (y = 0; y < ht; y++) {
mask = 1; mask = 1;
base = fnt[n*ht+y]; base = fnt[n * ht + y];
for (x=0;x<w;x++) { for (x = 0; x < w; x++) {
if (base & mask) { if (base & mask) {
*p = 0; *p = 0;
} else { } else {
*p = col; *p = col;
}
p++;
mask *= 2;
}
} }
p++; }
mask*=2;
}
}
}
} }
void spaced_gl_writen( int x, int y, int count, char * text ) void
spaced_gl_writen (int x, int y, int count, char *text)
// //
// Like gl_write but this one gets the spacing correct. // Like gl_write but this one gets the spacing correct.
// //
{ {
int i; int i;
for (i=0;i<count;i++) { for (i = 0; i < count; i++) {
gl_writen( 20+x+i*6, y,1, &text[i] ); gl_writen (20 + x + i * 6, y, 1, &text[i]);
} }
} }
@@ -255,42 +256,43 @@ int i;
static char icon_char = '@'; static char icon_char = '@';
int svgalib_drv_init(struct lcd_logical_driver *driver, char *args) int
svgalib_drv_init (struct lcd_logical_driver *driver, char *args)
{ {
char *argv[64]; char *argv[64];
int argc; int argc;
int i,j; int i, j;
int VGAMODE; int VGAMODE;
int fgtemp; int fgtemp;
char param[100]; char param[100];
char buffer[1024]; char buffer[1024];
/* not used at the moment */ /* not used at the moment */
argc = get_args(argv, args, 64 ); argc = get_args (argv, args, 64);
svgalib_drv = driver; svgalib_drv = driver;
vga_init(); vga_init ();
VGAMODE = G320x200x256; /* Default mode. */ VGAMODE = G320x200x256; /* Default mode. */
if (!vga_hasmode(VGAMODE)) { if (!vga_hasmode (VGAMODE)) {
printf("320x200x256 Mode not available.\n"); printf ("320x200x256 Mode not available.\n");
return -1; return -1;
} else { } else {
vga_setmode(VGAMODE); vga_setmode (VGAMODE);
gl_setcontextvga(VGAMODE); /* Physical screen context. */ gl_setcontextvga (VGAMODE); /* Physical screen context. */
gl_setrgbpalette(); gl_setrgbpalette ();
/* get the font */
SVGALIB_font = malloc( 256*8*8*1 );
ExpandGroovyFont( 5, 7, gl_rgbcolor(0,255,0), simple_font5x7, SVGALIB_font );
gl_setfont( 5, 7, SVGALIB_font );
}
gl_clearscreen(gl_rgbcolor(0,0,0)); /* get the font */
SVGALIB_font = malloc (256 * 8 * 8 * 1);
ExpandGroovyFont (5, 7, gl_rgbcolor (0, 255, 0), simple_font5x7, SVGALIB_font);
gl_setfont (5, 7, SVGALIB_font);
}
gl_clearscreen (gl_rgbcolor (0, 0, 0));
// Override output functions... // Override output functions...
driver->clear = svgalib_drv_clear; driver->clear = svgalib_drv_clear;
driver->string = svgalib_drv_string; driver->string = svgalib_drv_string;
driver->chr = svgalib_drv_chr; driver->chr = svgalib_drv_chr;
@@ -300,7 +302,7 @@ int svgalib_drv_init(struct lcd_logical_driver *driver, char *args)
driver->init_hbar = NULL; driver->init_hbar = NULL;
driver->num = svgalib_drv_num; driver->num = svgalib_drv_num;
driver->init_num = svgalib_drv_init_num; driver->init_num = svgalib_drv_init_num;
driver->init = svgalib_drv_init; driver->init = svgalib_drv_init;
driver->close = svgalib_drv_close; driver->close = svgalib_drv_close;
driver->flush = svgalib_drv_flush; driver->flush = svgalib_drv_flush;
@@ -317,20 +319,22 @@ int svgalib_drv_init(struct lcd_logical_driver *driver, char *args)
SVGALIB_PAD = '#'; SVGALIB_PAD = '#';
// Change the character used for "..." // Change the character used for "..."
SVGALIB_ELLIPSIS = '~'; SVGALIB_ELLIPSIS = '~';
return 1; return 1;
} }
void svgalib_drv_close() void
svgalib_drv_close ()
{ {
vga_setmode(TEXT); vga_setmode (TEXT);
drv_base_close(); drv_base_close ();
} }
void svgalib_drv_clear() void
svgalib_drv_clear ()
{ {
vga_waitretrace(); vga_waitretrace ();
gl_clearscreen(gl_rgbcolor(0,0,0)); gl_clearscreen (gl_rgbcolor (0, 0, 0));
} }
@@ -338,75 +342,88 @@ void svgalib_drv_clear()
// Prints a string on the lcd display, at position (x,y). The // Prints a string on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void svgalib_drv_string(int x, int y, char string[]) void
svgalib_drv_string (int x, int y, char string[])
{ {
int i; int i;
unsigned char *c; unsigned char *c;
for(i=0; string[i]; i++) for (i = 0; string[i]; i++) {
{
c = &string[i]; c = &string[i];
switch(*c) { switch (*c) {
case 0: *c = icon_char; break; case 0:
case 255: *c = '#'; break; *c = icon_char;
break;
case 255:
*c = '#';
break;
} }
} }
gl_setfont( 5,7,SVGALIB_font ); gl_setfont (5, 7, SVGALIB_font);
spaced_gl_writen( x*8,y*SVGALIB_FONT_VER+SVGALIB_Y_OFFSET, i, string ); spaced_gl_writen (x * 8, y * SVGALIB_FONT_VER + SVGALIB_Y_OFFSET, i, string);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The // Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void svgalib_drv_chr(int x, int y, char c) void
svgalib_drv_chr (int x, int y, char c)
{ {
char buffer[2]; char buffer[2];
switch(c) { switch (c) {
case 0: c=icon_char; break; case 0:
case -1: c = '#'; break; c = icon_char;
break;
case -1:
c = '#';
break;
} }
buffer[0] = c; buffer[0] = c;
buffer[1] = 0; buffer[1] = 0;
gl_setfont( 5,7,SVGALIB_font ); gl_setfont (5, 7, SVGALIB_font);
spaced_gl_writen( x*8,y*SVGALIB_FONT_VER+SVGALIB_Y_OFFSET, 1, buffer ); spaced_gl_writen (x * 8, y * SVGALIB_FONT_VER + SVGALIB_Y_OFFSET, 1, buffer);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for big numbers. // Sets up for big numbers.
// //
void svgalib_drv_init_num() void
svgalib_drv_init_num ()
{ {
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number, but not. A bit like the curses driver. // Writes a big number, but not. A bit like the curses driver.
// //
void svgalib_drv_num(int x, int num) void
svgalib_drv_num (int x, int num)
{ {
char c; char c;
int y, dx; int y, dx;
c='0'+num; c = '0' + num;
for(y=1; y<5; y++) for (y = 1; y < 5; y++)
for(dx=0; dx<3; dx++) for (dx = 0; dx < 3; dx++)
svgalib_drv_chr(x+dx, y, c); svgalib_drv_chr (x + dx, y, c);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen. // Draws a vertical bar; erases entire column onscreen.
// //
void svgalib_drv_vbar(int x, int len) void
svgalib_drv_vbar (int x, int len)
{ {
char map[]="_.,,ooO8"; char map[] = "_.,,ooO8";
int y; int y;
for(y=lcd.hgt; y > 0 && len>0; y--) for (y = lcd.hgt; y > 0 && len > 0; y--) {
{ if (len >= lcd.cellhgt)
if(len >= lcd.cellhgt) svgalib_drv_chr(x, y, '8'); svgalib_drv_chr (x, y, '8');
else svgalib_drv_chr(x, y, map[len-1]); else
svgalib_drv_chr (x, y, map[len - 1]);
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
} }
@@ -414,15 +431,15 @@ void svgalib_drv_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void svgalib_drv_hbar(int x, int y, int len) void
svgalib_drv_hbar (int x, int y, int len)
{ {
for(; x<=lcd.wid && len>0; x++) for (; x <= lcd.wid && len > 0; x++) {
{ if (len >= lcd.cellwid)
if(len>=lcd.cellwid) svgalib_drv_chr (x, y, '=');
svgalib_drv_chr(x, y, '=');
else else
svgalib_drv_chr(x, y, '-'); svgalib_drv_chr (x, y, '-');
len -= lcd.cellwid; len -= lcd.cellwid;
} }
} }
@@ -431,89 +448,136 @@ void svgalib_drv_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets character 0 to an icon... // Sets character 0 to an icon...
// //
void svgalib_drv_icon(int which, char dest) void
svgalib_drv_icon (int which, char dest)
{ {
if(dest == 0) if (dest == 0)
switch(which) switch (which) {
{ case 0:
case 0: icon_char = '+'; break; icon_char = '+';
case 1: icon_char = '*'; break; break;
default: icon_char = '#'; break; case 1:
} icon_char = '*';
break;
default:
icon_char = '#';
break;
}
} }
void svgalib_drv_flush() void
svgalib_drv_flush ()
{ {
} }
void svgalib_drv_flush_box(int lft, int top, int rgt, int bot) void
svgalib_drv_flush_box (int lft, int top, int rgt, int bot)
{ {
} }
void svgalib_drv_draw_frame(char *dat) void
svgalib_drv_draw_frame (char *dat)
{ {
} }
char svgalib_drv_getkey() char
svgalib_drv_getkey ()
{ {
int i; int i;
int loop; int loop;
FILE* fd; FILE *fd;
i = vga_getkey(); i = vga_getkey ();
if (i) { if (i) {
switch (i) { switch (i) {
/* map the cursor keys to something sensible. */ /* map the cursor keys to something sensible. */
case 27 : case 27:
i = vga_getkey(); i = vga_getkey ();
if (i==91) { if (i == 91) {
i = vga_getkey(); i = vga_getkey ();
switch (i) { switch (i) {
case VGAKEY_LEFT: i= 'D';break; case VGAKEY_LEFT:
case VGAKEY_UP: i= 'B';break; i = 'D';
case VGAKEY_DOWN: i= 'C';break; break;
case VGAKEY_RIGHT: i= 'A';break; case VGAKEY_UP:
default: i = 'B';
i=0; /* key not recognised */ break;
} case VGAKEY_DOWN:
} else { i = 'C';
i=0; break;
} case VGAKEY_RIGHT:
break; i = 'A';
break;
default:
i = 0; /* key not recognised */
}
} else {
i = 0;
}
break;
/* /*
Change this bit to your liking. I only set these values because Change this bit to your liking. I only set these values because
they tie in with my keypads use of the keyboard controller chip they tie in with my keypads use of the keyboard controller chip
see http://www.gofree.co.uk/home/smh/mp3 for details. see http://www.gofree.co.uk/home/smh/mp3 for details.
Having said that try to make sure four keys map to D,B,C,A so you'll Having said that try to make sure four keys map to D,B,C,A so you'll
be able to quit LCDproc from the emulation. be able to quit LCDproc from the emulation.
*/
case 'j' : i= 'D';break; /* left */
case 'm' : i= 'B';break; /* up */
case '7' : i= 'C';break; /* down */
case 'u' : i= 'A';break; /* right */
case 'v':i='Q';break; /* one */
case 'c':i='W';break; /* two */
case 'z':i='E';break; /* three */
case '4':i='R';break; /* four */
case '3':i='T';break; /* five */
case '1':i='Y';break; /* six */
case 'f':i='U';break; /* seven */
case 'd':i='I';break; /* eight */
case 'a':i='O';break; /* nine */
case 'e':i='P';break; /* zero */
case 'r':i='L';break; /* 'C' key */
default :
i = 0;
}
} /* if (i) */
*/
case 'j':
i = 'D';
break; /* left */
case 'm':
i = 'B';
break; /* up */
case '7':
i = 'C';
break; /* down */
case 'u':
i = 'A';
break; /* right */
case 'v':
i = 'Q';
break; /* one */
case 'c':
i = 'W';
break; /* two */
case 'z':
i = 'E';
break; /* three */
case '4':
i = 'R';
break; /* four */
case '3':
i = 'T';
break; /* five */
case '1':
i = 'Y';
break; /* six */
case 'f':
i = 'U';
break; /* seven */
case 'd':
i = 'I';
break; /* eight */
case 'a':
i = 'O';
break; /* nine */
case 'e':
i = 'P';
break; /* zero */
case 'r':
i = 'L';
break; /* 'C' key */
default:
i = 0;
}
}
/* if (i) */
return i; return i;
} }
+15 -15
View File
@@ -4,21 +4,21 @@
extern lcd_logical_driver *vgalib_drv; extern lcd_logical_driver *vgalib_drv;
int svgalib_drv_init(struct lcd_logical_driver *driver, char *args); int svgalib_drv_init (struct lcd_logical_driver *driver, char *args);
void svgalib_drv_close(); void svgalib_drv_close ();
void svgalib_drv_clear(); void svgalib_drv_clear ();
void svgalib_drv_flush(); void svgalib_drv_flush ();
void svgalib_drv_string(int x, int y, char string[]); void svgalib_drv_string (int x, int y, char string[]);
void svgalib_drv_chr(int x, int y, char c); void svgalib_drv_chr (int x, int y, char c);
void svgalib_drv_vbar(int x, int len); void svgalib_drv_vbar (int x, int len);
void svgalib_drv_hbar(int x, int y, int len); void svgalib_drv_hbar (int x, int y, int len);
void svgalib_drv_icon(int which, char dest); void svgalib_drv_icon (int which, char dest);
void svgalib_drv_flush(); void svgalib_drv_flush ();
void svgalib_drv_flush_box(int lft, int top, int rgt, int bot); void svgalib_drv_flush_box (int lft, int top, int rgt, int bot);
void svgalib_drv_draw_frame(char *dat); void svgalib_drv_draw_frame (char *dat);
char svgalib_drv_getkey(); char svgalib_drv_getkey ();
void svgalib_drv_init_num(); void svgalib_drv_init_num ();
void svgalib_drv_num(int x, int num); void svgalib_drv_num (int x, int num);
#endif #endif
+116 -107
View File
@@ -17,69 +17,72 @@ lcd_logical_driver *text;
////////////////////// For Text-Mode Output ////////////////////////////// ////////////////////// For Text-Mode Output //////////////////////////////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
int text_init(lcd_logical_driver *driver, char *args) int
text_init (lcd_logical_driver * driver, char *args)
{ {
text = driver; text = driver;
if(!driver->framebuf) if (!driver->framebuf) {
{ driver->close ();
driver->close();
return -1; return -1;
} }
driver->wid = 20;
driver->hgt = 4;
driver->cellwid = 5;
driver->cellhgt = 8;
driver->clear = (void *)-1;
driver->string = (void *)-1;
driver->chr = (void *)-1;
driver->vbar = text_vbar;
driver->init_vbar = NULL;
driver->hbar = text_hbar;
driver->init_hbar = NULL;
driver->num = (void *)-1;
driver->init_num = NULL;
driver->init = text_init;
driver->close = text_close;
driver->flush = text_flush;
driver->flush_box = NULL;
driver->contrast = NULL;
driver->backlight = NULL;
driver->set_char = NULL;
driver->icon = NULL;
driver->draw_frame = text_draw_frame;
driver->getkey = NULL;
return 200; // 200 is arbitrary. (must be 1 or more) driver->wid = 20;
driver->hgt = 4;
driver->cellwid = 5;
driver->cellhgt = 8;
driver->clear = (void *) -1;
driver->string = (void *) -1;
driver->chr = (void *) -1;
driver->vbar = text_vbar;
driver->init_vbar = NULL;
driver->hbar = text_hbar;
driver->init_hbar = NULL;
driver->num = (void *) -1;
driver->init_num = NULL;
driver->init = text_init;
driver->close = text_close;
driver->flush = text_flush;
driver->flush_box = NULL;
driver->contrast = NULL;
driver->backlight = NULL;
driver->set_char = NULL;
driver->icon = NULL;
driver->draw_frame = text_draw_frame;
driver->getkey = NULL;
return 200; // 200 is arbitrary. (must be 1 or more)
} }
void text_close() void
text_close ()
{ {
drv_base_close(); drv_base_close ();
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void text_clear() void
text_clear ()
{ {
memset(lcd.framebuf, ' ', lcd.wid*lcd.hgt); memset (lcd.framebuf, ' ', lcd.wid * lcd.hgt);
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void text_flush() void
text_flush ()
{ {
text_draw_frame(lcd.framebuf); text_draw_frame (lcd.framebuf);
} }
@@ -87,40 +90,43 @@ void text_flush()
// Prints a string on the lcd display, at position (x,y). The // Prints a string on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void text_string(int x, int y, char string[]) void
text_string (int x, int y, char string[])
{ {
int i; int i;
x -= 1; // Convert 1-based coords to 0-based... x -= 1; // Convert 1-based coords to 0-based...
y -= 1; y -= 1;
for(i=0; string[i]; i++) for (i = 0; string[i]; i++) {
{ lcd.framebuf[(y * lcd.wid) + x + i] = string[i];
lcd.framebuf[(y*lcd.wid) + x + i] = string[i]; }
}
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The // Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void text_chr(int x, int y, char c) void
text_chr (int x, int y, char c)
{ {
y--; y--;
x--; x--;
lcd.framebuf[(y*lcd.wid) + x] = c; lcd.framebuf[(y * lcd.wid) + x] = c;
} }
int text_contrast(int contrast) int
text_contrast (int contrast)
{ {
// printf("Contrast: %i\n", contrast); // printf("Contrast: %i\n", contrast);
return 0; return 0;
} }
void text_backlight(int on) void
text_backlight (int on)
{ {
/* /*
if(on) if(on)
@@ -134,27 +140,32 @@ void text_backlight(int on)
*/ */
} }
void text_init_vbar() void
text_init_vbar ()
{ {
// printf("Vertical bars.\n"); // printf("Vertical bars.\n");
} }
void text_init_hbar() void
text_init_hbar ()
{ {
// printf("Horizontal bars.\n"); // printf("Horizontal bars.\n");
} }
void text_init_num() void
text_init_num ()
{ {
// printf("Big Numbers.\n"); // printf("Big Numbers.\n");
} }
void text_num(int x, int num) void
text_num (int x, int num)
{ {
// printf("BigNum(%i, %i)\n", x, num); // printf("BigNum(%i, %i)\n", x, num);
} }
void text_set_char(int n, char *dat) void
text_set_char (int n, char *dat)
{ {
// printf("Set Character %i\n", n); // printf("Set Character %i\n", n);
} }
@@ -162,75 +173,73 @@ void text_set_char(int n, char *dat)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen. // Draws a vertical bar; erases entire column onscreen.
// //
void text_vbar(int x, int len) void
text_vbar (int x, int len)
{ {
int y; int y;
for(y=lcd.hgt; y > 0 && len>0; y--) for (y = lcd.hgt; y > 0 && len > 0; y--) {
{ text_chr (x, y, '|');
text_chr(x, y, '|');
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void text_hbar(int x, int y, int len) void
text_hbar (int x, int y, int len)
{ {
for(; x<=lcd.wid && len>0; x++) for (; x <= lcd.wid && len > 0; x++) {
{ text_chr (x, y, '-');
text_chr(x,y,'-');
len -= lcd.cellwid; len -= lcd.cellwid;
} }
} }
void text_flush_box(int lft, int top, int rgt, int bot) void
text_flush_box (int lft, int top, int rgt, int bot)
{ {
text_flush(); text_flush ();
} }
void text_draw_frame(char *dat) void
text_draw_frame (char *dat)
{ {
int i, j; int i, j;
char out[LCD_MAX_WIDTH]; char out[LCD_MAX_WIDTH];
if(!dat) return; if (!dat)
return;
// printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat); // printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat);
for(i=0; i<lcd.wid; i++) for (i = 0; i < lcd.wid; i++) {
{
out[i] = '-'; out[i] = '-';
} }
out[lcd.wid] = 0; out[lcd.wid] = 0;
printf("+%s+\n", out); printf ("+%s+\n", out);
for(i=0; i<lcd.hgt; i++) for (i = 0; i < lcd.hgt; i++) {
{ for (j = 0; j < lcd.wid; j++) {
for(j=0; j<lcd.wid; j++) out[j] = dat[j + (i * lcd.wid)];
{ }
out[j] = dat[j+(i*lcd.wid)];
}
out[lcd.wid] = 0; out[lcd.wid] = 0;
printf("|%s|\n", out); printf ("|%s|\n", out);
} }
for(i=0; i<lcd.wid; i++) for (i = 0; i < lcd.wid; i++) {
{
out[i] = '-'; out[i] = '-';
} }
out[lcd.wid] = 0; out[lcd.wid] = 0;
printf("+%s+\n", out); printf ("+%s+\n", out);
} }
+17 -17
View File
@@ -3,23 +3,23 @@
extern lcd_logical_driver *text; extern lcd_logical_driver *text;
int text_init(struct lcd_logical_driver *driver, char *args); int text_init (struct lcd_logical_driver *driver, char *args);
void text_close(); void text_close ();
void text_clear(); void text_clear ();
void text_flush(); void text_flush ();
void text_string(int x, int y, char string[]); void text_string (int x, int y, char string[]);
void text_chr(int x, int y, char c); void text_chr (int x, int y, char c);
int text_contrast(int contrast); int text_contrast (int contrast);
void text_backlight(int on); void text_backlight (int on);
void text_init_vbar(); void text_init_vbar ();
void text_init_hbar(); void text_init_hbar ();
void text_init_num(); void text_init_num ();
void text_vbar(int x, int len); void text_vbar (int x, int len);
void text_hbar(int x, int y, int len); void text_hbar (int x, int y, int len);
void text_num(int x, int num); void text_num (int x, int num);
void text_set_char(int n, char *dat); void text_set_char (int n, char *dat);
void text_flush_box(int lft, int top, int rgt, int bot); void text_flush_box (int lft, int top, int rgt, int bot);
void text_draw_frame(char *dat); void text_draw_frame (char *dat);
#endif #endif
+370 -366
View File
@@ -18,12 +18,13 @@
#include "../../shared/debug.h" #include "../../shared/debug.h"
#include "../../shared/str.h" #include "../../shared/str.h"
static int custom=0; static int custom = 0;
typedef enum { typedef enum {
hbar = 1, hbar = 1,
vbar = 2, vbar = 2,
bign = 4, bign = 4,
beat = 8 } custom_type; beat = 8
} custom_type;
static int fd; static int fd;
static char lastframe[32]; static char lastframe[32];
@@ -33,7 +34,8 @@ lcd_logical_driver *sli;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly... // Opens com port and sets baud correctly...
// //
int sli_init(lcd_logical_driver *driver, char *args) int
sli_init (lcd_logical_driver * driver, char *args)
{ {
char *argv[64]; char *argv[64];
int argc; int argc;
@@ -43,108 +45,95 @@ int sli_init(lcd_logical_driver *driver, char *args)
char out[2]; char out[2];
char device[256] = "/dev/lcd"; char device[256] = "/dev/lcd";
int speed=B19200; int speed = B19200;
sli = driver; sli = driver;
//debug("sli_init: Args(all): %s\n", args); //debug("sli_init: Args(all): %s\n", args);
argc = get_args(argv, args, 64); argc = get_args (argv, args, 64);
/* /*
for(i=0; i<argc; i++) for(i=0; i<argc; i++)
{ {
printf("Arg(%i): %s\n", i, argv[i]); printf("Arg(%i): %s\n", i, argv[i]);
} }
*/ */
for(i=0; i<argc; i++) for (i = 0; i < argc; i++) {
{
//printf("Arg(%i): %s\n", i, argv[i]); //printf("Arg(%i): %s\n", i, argv[i]);
if(0 == strcmp(argv[i], "-d") || if (0 == strcmp (argv[i], "-d") || 0 == strcmp (argv[i], "--device")) {
0 == strcmp(argv[i], "--device")) if (i + 1 > argc) {
{ fprintf (stderr, "sli_init: %s requires an argument\n", argv[i]);
if(i + 1 > argc) {
fprintf(stderr, "sli_init: %s requires an argument\n",
argv[i]);
return -1; return -1;
} }
strcpy(device, argv[++i]); strcpy (device, argv[++i]);
} } else if (0 == strcmp (argv[i], "-s") || 0 == strcmp (argv[i], "--speed")) {
else if(0 == strcmp(argv[i], "-s") || if (i + 1 > argc) {
0 == strcmp(argv[i], "--speed")) fprintf (stderr, "sli_init: %s requires an argument\n", argv[i]);
{
if(i + 1 > argc) {
fprintf(stderr, "sli_init: %s requires an argument\n",
argv[i]);
return -1; return -1;
} }
tmp = atoi(argv[++i]); tmp = atoi (argv[++i]);
if(tmp==1200) speed=B1200; if (tmp == 1200)
else if(tmp==2400) speed=B2400; speed = B1200;
else if(tmp==9600) speed=B9600; else if (tmp == 2400)
else if(tmp==19200) speed=B19200; speed = B2400;
else if(tmp==38400) speed=B38400; else if (tmp == 9600)
else if(tmp==57600) speed=B57600; speed = B9600;
else if(tmp==115200) speed=B115200; else if (tmp == 19200)
else { speed = B19200;
fprintf(stderr, "sli_init: %s argument must be 1200, 2400, 9600, 19200, 38400, 57600, or 115200. Using default value (19200).\n", else if (tmp == 38400)
argv[i]); speed = B38400;
} else if (tmp == 57600)
} speed = B57600;
else if(0 == strcmp(argv[i], "-h") || else if (tmp == 115200)
0 == strcmp(argv[i], "--help")) speed = B115200;
{ else {
printf("LCDproc Wirz SLI LCD driver\n" fprintf (stderr, "sli_init: %s argument must be 1200, 2400, 9600, 19200, 38400, 57600, or 115200. Using default value (19200).\n", argv[i]);
"\t-d\t--device\tSelect the output device to use [/dev/lcd]\n" }
"\t-s\t--speed\t\tSet the communication speed [19200]\n" } else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
"\t-h\t--help\t\tShow this help information\n"); printf ("LCDproc Wirz SLI LCD driver\n" "\t-d\t--device\tSelect the output device to use [/dev/lcd]\n" "\t-s\t--speed\t\tSet the communication speed [19200]\n" "\t-h\t--help\t\tShow this help information\n");
return -1; return -1;
} else {
printf ("Invalid parameter: %s\n", argv[i]);
} }
else
{
printf("Invalid parameter: %s\n", argv[i]);
}
} }
// Set up io port correctly, and open it... // Set up io port correctly, and open it...
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) if (fd == -1) {
{ fprintf (stderr, "sli_init: failed (%s)\n", strerror (errno));
fprintf(stderr, "sli_init: failed (%s)\n", strerror(errno));
return -1; return -1;
} }
//else fprintf(stderr, "sli_init: opened device %s\n", device); //else fprintf(stderr, "sli_init: opened device %s\n", device);
tcgetattr(fd, &portset); tcgetattr (fd, &portset);
// This is necessary in Linux, but does not exist in irix. // This is necessary in Linux, but does not exist in irix.
#ifndef IRIX #ifndef IRIX
cfmakeraw(&portset); cfmakeraw (&portset);
#endif #endif
cfsetospeed(&portset, speed); cfsetospeed (&portset, speed);
tcsetattr(fd, TCSANOW, &portset); tcsetattr (fd, TCSANOW, &portset);
/* Initialize SLI using autobaud detection, and then turn off cursor /* Initialize SLI using autobaud detection, and then turn off cursor
and clear screen */ and clear screen */
usleep(150000); /* 150ms delay to allow SLI to power on */ usleep (150000); /* 150ms delay to allow SLI to power on */
out[0]=13; /* CR for SLI autobaud */ out[0] = 13; /* CR for SLI autobaud */
write(fd, out, 1); write (fd, out, 1);
usleep(3000); /* 3ms delay.. wait for it to autobaud */ usleep (3000); /* 3ms delay.. wait for it to autobaud */
out[0]=0x0FE; out[0] = 0x0FE;
out[1]=0x00C; /* No cursor */ out[1] = 0x00C; /* No cursor */
write(fd, out, 2); write (fd, out, 2);
out[0]=0x0FE; out[0] = 0x0FE;
out[1]=0x001; /* Clear LCD, not sure if this belongs here */ out[1] = 0x001; /* Clear LCD, not sure if this belongs here */
write(fd, out, 2); write (fd, out, 2);
if(!driver->framebuf) if (!driver->framebuf) {
{ fprintf (stderr, "sli_init: No frame buffer.\n");
fprintf(stderr, "sli_init: No frame buffer.\n"); driver->close ();
driver->close();
return -1; return -1;
} }
// Set LCD parameters (I use a 16x2 LCD) -- small but still useful // Set LCD parameters (I use a 16x2 LCD) -- small but still useful
// Its also much cheaper than the higher quality Matrix Orbital modules // Its also much cheaper than the higher quality Matrix Orbital modules
// Currently, $30 for interface kit and 16x2 non-backlit LCD... // Currently, $30 for interface kit and 16x2 non-backlit LCD...
@@ -154,46 +143,49 @@ int sli_init(lcd_logical_driver *driver, char *args)
// Set the functions the driver supports... // Set the functions the driver supports...
driver->clear = (void *)-1; driver->clear = (void *) -1;
driver->string = (void *)-1; driver->string = (void *) -1;
driver->chr = (void *)-1; driver->chr = (void *) -1;
driver->vbar = sli_vbar; driver->vbar = sli_vbar;
driver->init_vbar = sli_init_vbar; driver->init_vbar = sli_init_vbar;
driver->hbar = sli_hbar; driver->hbar = sli_hbar;
driver->init_hbar = sli_init_hbar; driver->init_hbar = sli_init_hbar;
driver->num = (void *)-1; driver->num = (void *) -1;
driver->init_num = (void *)-1; driver->init_num = (void *) -1;
driver->init = sli_init; driver->init = sli_init;
driver->close = sli_close; driver->close = sli_close;
driver->flush = sli_flush; driver->flush = sli_flush;
driver->flush_box = sli_flush_box; driver->flush_box = sli_flush_box;
driver->contrast = (void *)-1; driver->contrast = (void *) -1;
driver->backlight = (void *)-1; driver->backlight = (void *) -1;
driver->set_char = sli_set_char; driver->set_char = sli_set_char;
driver->icon = sli_icon; driver->icon = sli_icon;
driver->draw_frame = sli_draw_frame; driver->draw_frame = sli_draw_frame;
driver->getkey = (void *)-1; driver->getkey = (void *) -1;
return fd; return fd;
} }
/* Clean-up */ /* Clean-up */
void sli_close() void
sli_close ()
{ {
close(fd); close (fd);
if(sli->framebuf) free(sli->framebuf); if (sli->framebuf)
free (sli->framebuf);
sli->framebuf = NULL; sli->framebuf = NULL;
} }
void sli_flush() void
sli_flush ()
{ {
sli_draw_frame(lcd.framebuf); sli_draw_frame (lcd.framebuf);
} }
@@ -201,44 +193,45 @@ void sli_flush()
this is bad imho, so I added it.. may remove later this is bad imho, so I added it.. may remove later
speed is not a huge issue though, this isnt a speed is not a huge issue though, this isnt a
device driver or anything ;) */ device driver or anything ;) */
void sli_flush_box(int lft, int top, int rgt, int bot) void
sli_flush_box (int lft, int top, int rgt, int bot)
{ {
int y; int y;
char out[2]; /* Why does the matrix driver allocate so much here? */ char out[2]; /* Why does the matrix driver allocate so much here? */
/* simple bounds checking */ /* simple bounds checking */
if((top>lcd.hgt)|(bot>lcd.hgt)) if ((top > lcd.hgt) | (bot > lcd.hgt))
return; return;
if ((lft > lcd.wid) | (rgt > lcd.wid))
return;
if((lft>lcd.wid)|(rgt>lcd.wid))
return;
// printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot); // printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot);
/* I like having hex, everywhere and all the time */ /* I like having hex, everywhere and all the time */
for(y=top; y<=bot; y++) for (y = top; y <= bot; y++) {
{ if (y == 1)
if(y==1) sprintf (out, "%c%c", 0x0FE, 0x080 + lft);
sprintf(out, "%c%c", 0x0FE, 0x080+lft); if (y == 2)
if(y==2) sprintf (out, "%c%c", 0x0FE, 0x0C0 + lft);
sprintf(out, "%c%c", 0x0FE, 0x0C0+lft); write (fd, out, 0x002);
write(fd, out, 0x002); write (fd, lcd.framebuf + (y * lcd.wid) + lft, rgt - lft + 1);
write(fd, lcd.framebuf+(y*lcd.wid)+lft, rgt-lft+1); }
}
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The // Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4). // upper-left is (1,1), and the lower right should be (20,4).
// //
void sli_chr(int x, int y, char c) void
sli_chr (int x, int y, char c)
{ {
y--; y--;
x--; x--;
lcd.framebuf[(y*lcd.wid) + x] = c; lcd.framebuf[(y * lcd.wid) + x] = c;
} }
@@ -255,145 +248,147 @@ void sli_chr(int x, int y, char c)
characters, so that you can do both bar types at once.. maybe I characters, so that you can do both bar types at once.. maybe I
will release a new version of the SLI driver that attempts this */ will release a new version of the SLI driver that attempts this */
void sli_init_vbar() void
sli_init_vbar ()
{ {
char a[] = { char a[] = {
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
1,1,1,1,1, 1, 1, 1, 1, 1,
}; };
char b[] = { char b[] = {
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
}; };
char c[] = { char c[] = {
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
}; };
char d[] = { char d[] = {
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
}; };
char e[] = { char e[] = {
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
}; };
char f[] = { char f[] = {
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
}; };
char g[] = { char g[] = {
0,0,0,0,0, 0, 0, 0, 0, 0,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
}; };
if(custom!=vbar) { if (custom != vbar) {
sli_set_char(1,a); sli_set_char (1, a);
sli_set_char(2,b); sli_set_char (2, b);
sli_set_char(3,c); sli_set_char (3, c);
sli_set_char(4,d); sli_set_char (4, d);
sli_set_char(5,e); sli_set_char (5, e);
sli_set_char(6,f); sli_set_char (6, f);
sli_set_char(7,g); sli_set_char (7, g);
custom=vbar; custom = vbar;
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Inits horizontal bars... // Inits horizontal bars...
// //
void sli_init_hbar() void
sli_init_hbar ()
{ {
char a[] = { char a[] = {
1,0,0,0,0, 1, 0, 0, 0, 0,
1,0,0,0,0, 1, 0, 0, 0, 0,
1,0,0,0,0, 1, 0, 0, 0, 0,
1,0,0,0,0, 1, 0, 0, 0, 0,
1,0,0,0,0, 1, 0, 0, 0, 0,
1,0,0,0,0, 1, 0, 0, 0, 0,
1,0,0,0,0, 1, 0, 0, 0, 0,
1,0,0,0,0, 1, 0, 0, 0, 0,
}; };
char b[] = { char b[] = {
1,1,0,0,0, 1, 1, 0, 0, 0,
1,1,0,0,0, 1, 1, 0, 0, 0,
1,1,0,0,0, 1, 1, 0, 0, 0,
1,1,0,0,0, 1, 1, 0, 0, 0,
1,1,0,0,0, 1, 1, 0, 0, 0,
1,1,0,0,0, 1, 1, 0, 0, 0,
1,1,0,0,0, 1, 1, 0, 0, 0,
1,1,0,0,0, 1, 1, 0, 0, 0,
}; };
char c[] = { char c[] = {
1,1,1,0,0, 1, 1, 1, 0, 0,
1,1,1,0,0, 1, 1, 1, 0, 0,
1,1,1,0,0, 1, 1, 1, 0, 0,
1,1,1,0,0, 1, 1, 1, 0, 0,
1,1,1,0,0, 1, 1, 1, 0, 0,
1,1,1,0,0, 1, 1, 1, 0, 0,
1,1,1,0,0, 1, 1, 1, 0, 0,
1,1,1,0,0, 1, 1, 1, 0, 0,
}; };
char d[] = { char d[] = {
1,1,1,1,0, 1, 1, 1, 1, 0,
1,1,1,1,0, 1, 1, 1, 1, 0,
1,1,1,1,0, 1, 1, 1, 1, 0,
1,1,1,1,0, 1, 1, 1, 1, 0,
1,1,1,1,0, 1, 1, 1, 1, 0,
1,1,1,1,0, 1, 1, 1, 1, 0,
1,1,1,1,0, 1, 1, 1, 1, 0,
1,1,1,1,0, 1, 1, 1, 1, 0,
}; };
if(custom!=hbar) { if (custom != hbar) {
sli_set_char(1,a); sli_set_char (1, a);
sli_set_char(2,b); sli_set_char (2, b);
sli_set_char(3,c); sli_set_char (3, c);
sli_set_char(4,d); sli_set_char (4, d);
custom=hbar; custom = hbar;
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -405,37 +400,41 @@ void sli_init_hbar()
since we only have 2 lines anyway this is rather pointless since we only have 2 lines anyway this is rather pointless
for me to add */ for me to add */
void sli_vbar(int x, int len) void
sli_vbar (int x, int len)
{ {
char map[9] = {32, 1, 2, 3, 4, 5, 6, 7, 255 }; char map[9] = { 32, 1, 2, 3, 4, 5, 6, 7, 255 };
int y;
for(y=lcd.hgt; y > 0 && len>0; y--) int y;
{ for (y = lcd.hgt; y > 0 && len > 0; y--) {
if(len >= lcd.cellhgt) sli_chr(x, y, 255); if (len >= lcd.cellhgt)
else sli_chr(x, y, map[len]); sli_chr (x, y, 255);
else
sli_chr (x, y, map[len]);
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void sli_hbar(int x, int y, int len) void
sli_hbar (int x, int y, int len)
{ {
char map[6] = { 32, 1, 2, 3, 4, 255 }; char map[6] = { 32, 1, 2, 3, 4, 255 };
for (; x <= lcd.wid && len > 0; x++) {
if (len >= lcd.cellwid)
sli_chr (x, y, 255);
else
sli_chr (x, y, map[len]);
for(; x<=lcd.wid && len>0; x++)
{
if(len >= lcd.cellwid) sli_chr(x,y,255);
else sli_chr(x, y, map[len]);
len -= lcd.cellwid; len -= lcd.cellwid;
} }
} }
@@ -447,80 +446,83 @@ void sli_hbar(int x, int y, int len)
// //
// The input is just an array of characters... // The input is just an array of characters...
// //
void sli_set_char(int n, char *dat) void
sli_set_char (int n, char *dat)
{ {
char out[2]; char out[2];
int row, col; int row, col;
int letter; int letter;
/* SLI also has 8 user definable characters */ /* SLI also has 8 user definable characters */
if(n < 0 || n > 7) return; if (n < 0 || n > 7)
if(!dat) return; return;
if (!dat)
return;
/* Move cursor to CGRAM */ /* Move cursor to CGRAM */
out[0]=0x0FE; out[0] = 0x0FE;
out[1]=0x040+8*n; out[1] = 0x040 + 8 * n;
write(fd, out, 2); write (fd, out, 2);
for(row=0; row<lcd.cellhgt; row++) for (row = 0; row < lcd.cellhgt; row++) {
{ letter = 0;
letter = 0; for (col = 0; col < lcd.cellwid; col++) {
for(col=0; col<lcd.cellwid; col++) letter <<= 1;
{ letter |= (dat[(row * lcd.cellwid) + col] > 0);
letter <<= 1; }
letter |= (dat[(row*lcd.cellwid) + col] > 0); letter |= 0x020; /* SLI can't accept CR, LF, etc in this character! */
} write (fd, &letter, 1);
letter|=0x020; /* SLI can't accept CR, LF, etc in this character! */ }
write(fd, &letter, 1);
}
/* Move cursor back to DDRAM */ /* Move cursor back to DDRAM */
out[0]=0x0FE; out[0] = 0x0FE;
out[1]=0x080; out[1] = 0x080;
write(fd, out, 2); write (fd, out, 2);
} }
void sli_icon(int which, char dest) void
sli_icon (int which, char dest)
{ {
char icons[3][5*8] = { char icons[3][5 * 8] = {
{ {
1,1,1,1,1, // Empty Heart 1, 1, 1, 1, 1, // Empty Heart
1,0,1,0,1, 1, 0, 1, 0, 1,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
1,0,0,0,1, 1, 0, 0, 0, 1,
1,1,0,1,1, 1, 1, 0, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
}, },
{ {
1,1,1,1,1, // Filled Heart 1, 1, 1, 1, 1, // Filled Heart
1,0,1,0,1, 1, 0, 1, 0, 1,
0,1,0,1,0, 0, 1, 0, 1, 0,
0,1,1,1,0, 0, 1, 1, 1, 0,
0,1,1,1,0, 0, 1, 1, 1, 0,
1,0,1,0,1, 1, 0, 1, 0, 1,
1,1,0,1,1, 1, 1, 0, 1, 1,
1,1,1,1,1, 1, 1, 1, 1, 1,
}, },
{ {
0,0,0,0,0, // Ellipsis 0, 0, 0, 0, 0, // Ellipsis
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
0,0,0,0,0, 0, 0, 0, 0, 0,
1,0,1,0,1, 1, 0, 1, 0, 1,
}, },
}; };
if(custom==bign) custom=beat; if (custom == bign)
sli_set_char(dest, &icons[which][0]); custom = beat;
sli_set_char (dest, &icons[which][0]);
} }
@@ -529,34 +531,36 @@ void sli_icon(int which, char dest)
// //
// Input is a character array, sized lcd.wid*lcd.hgt // Input is a character array, sized lcd.wid*lcd.hgt
// //
void sli_draw_frame(char *dat) void
sli_draw_frame (char *dat)
{ {
char out[2]; /* Again, why does the Matrix driver allocate so much here? */ char out[2]; /* Again, why does the Matrix driver allocate so much here? */
int y; int y;
if(!dat) return;
/* if (!dat)
out[0]=0x0FE; return;
out[1]=0x001;
write(fd, out, 2);
*/
/* Don't update if we have no new data /*
this keeps me from getting a migraine out[0]=0x0FE;
(just like those copyleft penguin mints... mmmmmm) */ out[1]=0x001;
write(fd, out, 2);
*/
// if (!strncmp(dat,lastframe,32)) /* Nothing has changed */ /* Don't update if we have no new data
// return; this keeps me from getting a migraine
(just like those copyleft penguin mints... mmmmmm) */
/* Do the actual refresh */ // if (!strncmp(dat,lastframe,32)) /* Nothing has changed */
out[0]=0x0FE; // return;
out[1]=0x080;
write(fd, out, 2);
write(fd, &dat[0], 16);
usleep(10);
write(fd, &dat[16],15);
// strncpy(lastframe,dat,32); // Update lastframe... /* Do the actual refresh */
out[0] = 0x0FE;
out[1] = 0x080;
write (fd, out, 2);
write (fd, &dat[0], 16);
usleep (10);
write (fd, &dat[16], 15);
// strncpy(lastframe,dat,32); // Update lastframe...
} }
+17 -17
View File
@@ -10,23 +10,23 @@
extern lcd_logical_driver *sli; extern lcd_logical_driver *sli;
int sli_init(lcd_logical_driver *driver, char *device); int sli_init (lcd_logical_driver * driver, char *device);
void sli_close(); void sli_close ();
void sli_flush(); void sli_flush ();
void sli_flush_box(int lft, int top, int rgt, int bot); void sli_flush_box (int lft, int top, int rgt, int bot);
void sli_chr(int x, int y, char c) ; void sli_chr (int x, int y, char c);
int sli_contrast(int contrast); int sli_contrast (int contrast);
void sli_backlight(int on); void sli_backlight (int on);
void sli_init_vbar(); void sli_init_vbar ();
void sli_init_hbar(); void sli_init_hbar ();
void sli_vbar(int x, int len); void sli_vbar (int x, int len);
void sli_hbar(int x, int y, int len); void sli_hbar (int x, int y, int len);
void sli_init_num(); void sli_init_num ();
void sli_num(int x, int num); void sli_num (int x, int num);
void sli_set_char(int n, char *dat); void sli_set_char (int n, char *dat);
void sli_icon(int which, char dest); void sli_icon (int which, char dest);
void sli_draw_frame(char *dat); void sli_draw_frame (char *dat);
char sli_getkey(); char sli_getkey ();
+46 -52
View File
@@ -41,53 +41,48 @@
#include "input.h" #include "input.h"
int server_input(int key); int server_input (int key);
// FIXME! The server tends to crash when "E" is pressed.. (?!) // FIXME! The server tends to crash when "E" is pressed.. (?!)
// (but only when the joystick driver is the last one on the list...) // (but only when the joystick driver is the last one on the list...)
// Checks for keypad input, and dispatches it // Checks for keypad input, and dispatches it
int handle_input() int
handle_input ()
{ {
char str[256]; char str[256];
int key; int key;
screen *s; screen *s;
client *c; client *c;
key = lcd.getkey();
if (!key) return 0; key = lcd.getkey ();
debug("handle_input(%c)\n", (char)key); if (!key)
return 0;
if(key)
{ debug ("handle_input(%c)\n", (char) key);
s = screenlist_current();
if(s) if (key) {
{ s = screenlist_current ();
if (s) {
c = s->parent; c = s->parent;
if(c) if (c) {
{
// TODO: Interpret and translate keys! // TODO: Interpret and translate keys!
// If the client should have this keypress... // If the client should have this keypress...
// Send keypress to client // Send keypress to client
if(key >= 'E' && key <= 'Z') if (key >= 'E' && key <= 'Z') {
{
// TODO: Implement client "acceptable key" lists // TODO: Implement client "acceptable key" lists
sprintf(str, "key %c\n", key); sprintf (str, "key %c\n", key);
sock_send_string(c->sock, str); sock_send_string (c->sock, str);
} }
// Otherwise, tell the server about it. // Otherwise, tell the server about it.
else else {
{ server_input (key);
server_input(key);
} }
} } else {
else
{
// If no parent, it means we're on the server screen. // If no parent, it means we're on the server screen.
// so, the server gets all keypresses there. // so, the server gets all keypresses there.
server_input(key); server_input (key);
} }
} }
} }
@@ -97,34 +92,33 @@ int handle_input()
int server_input(int key) int
server_input (int key)
{ {
debug("server_input(%c)\n", (char)key); debug ("server_input(%c)\n", (char) key);
switch(key) switch (key) {
{ case 'A':
case 'A': if (screenlist_action == SCR_HOLD)
if(screenlist_action == SCR_HOLD) screenlist_action = 0;
screenlist_action = 0; else
else screenlist_action = SCR_HOLD;
screenlist_action = SCR_HOLD; break;
break; case 'B':
case 'B': screenlist_action = SCR_BACK;
screenlist_action = SCR_BACK; screenlist_prev ();
screenlist_prev(); break;
break; case 'C':
case 'C': screenlist_action = SCR_SKIP;
screenlist_action = SCR_SKIP; screenlist_next ();
screenlist_next(); break;
break; case 'D':
case 'D': debug ("got the menu key!\n");
debug("got the menu key!\n"); server_menu ();
server_menu(); break;
break; default:
default: debug ("server_input: Invalid key \"%c\" (%i)\n", (char) key, key);
debug("server_input: Invalid key \"%c\" (%i)\n", break;
(char)key, key);
break;
} }
return 0; return 0;
+1 -1
View File
@@ -3,7 +3,7 @@
// Accepts and uses keypad input while displaying screens... // Accepts and uses keypad input while displaying screens...
int handle_input(); int handle_input ();
#endif #endif
+138 -172
View File
@@ -54,8 +54,7 @@ static screen_size sizes[] =
// This is currently only a list of available arguments, but doesn't // This is currently only a list of available arguments, but doesn't
// really *do* anything. It just helps to figure out which parameters // really *do* anything. It just helps to figure out which parameters
// go to the server, and which ones go to individual drivers... // go to the server, and which ones go to individual drivers...
static parameter args[] = static parameter args[] = {
{
{"-h", "--help"}, {"-h", "--help"},
{"-d", "--driver"}, {"-d", "--driver"},
{"-t", "--type"}, {"-t", "--type"},
@@ -65,150 +64,127 @@ static parameter args[] =
}; };
void exit_program(int val); void exit_program (int val);
void HelpScreen(); void HelpScreen ();
int main(int argc, char **argv) int
main (int argc, char **argv)
{ {
// TODO: Use a config file! // TODO: Use a config file!
//char cfgfile[256] = "/etc/LCDd.cf"; //char cfgfile[256] = "/etc/LCDd.cf";
int i, err, tmp; int i, err, tmp;
int daemon_mode=1; int daemon_mode = 1;
int disable_server_screen=1; int disable_server_screen = 1;
int child; int child;
screen *s = NULL; screen *s = NULL;
char *str, *ing; // strings for commandline handling char *str, *ing; // strings for commandline handling
// screen_size *size = &sizes[0]; // No longer needed // screen_size *size = &sizes[0]; // No longer needed
// Ctrl-C will cause a clean exit... // Ctrl-C will cause a clean exit...
signal(SIGINT, exit_program); signal (SIGINT, exit_program);
// and "kill"... // and "kill"...
signal(SIGTERM, exit_program); signal (SIGTERM, exit_program);
// and "kill -HUP" (hangup)... // and "kill -HUP" (hangup)...
signal(SIGHUP, exit_program); signal (SIGHUP, exit_program);
// and just in case, "kill -KILL" (which cannot be trapped; but oh well) // and just in case, "kill -KILL" (which cannot be trapped; but oh well)
signal(SIGKILL, exit_program); signal (SIGKILL, exit_program);
// If no paramaters given, give the help screen. // If no paramaters given, give the help screen.
if(argc == 1) HelpScreen(); if (argc == 1)
HelpScreen ();
// Don't spawn a child if we're using the curses driver // Don't spawn a child if we're using the curses driver
for(i=1; i<argc; i++) for (i = 1; i < argc; i++) {
{ if (0 == strcmp (argv[i], "-f") || 0 == strcmp (argv[i], "--foreground") || 0 == strcmp (argv[i], "curses"))
if(0 == strcmp(argv[i], "-f") ||
0 == strcmp(argv[i], "--foreground") ||
0 == strcmp(argv[i], "curses"))
daemon_mode = 0; daemon_mode = 0;
} }
// Now, go into daemon mode... // Now, go into daemon mode...
#ifndef DEBUG #ifndef DEBUG
if(daemon_mode) if (daemon_mode) {
{ if ((child = fork ()) != 0) {
if ((child = fork()) != 0) usleep (1500000); // Wait for child to initialize
{ exit (0); /* PARENT EXITS */
usleep(1500000); // Wait for child to initialize
exit(0); /* PARENT EXITS */
} }
// This line removed because it eats error messages... // This line removed because it eats error messages...
//setsid(); /* RELEASE TTY */ //setsid(); /* RELEASE TTY */
} }
#endif #endif
// Set up lcd driver base system // Set up lcd driver base system
lcd_init(""); lcd_init ("");
// Parse the command line now... // Parse the command line now...
// TODO: Move this to a separate function? // TODO: Move this to a separate function?
for(i=1; i<argc; i++) for (i = 1; i < argc; i++) {
{ if (0 == strcmp (argv[i], "-d") || 0 == strcmp (argv[i], "--driver")) {
if(0 == strcmp(argv[i], "-d") || if (argc <= i + 1)
0 == strcmp(argv[i], "--driver")) HelpScreen ();
{
if(argc <= i+1) HelpScreen();
str = argv[++i]; str = argv[++i];
ing = NULL; ing = NULL;
// Check to see if the next parameter is intended for LCDd, // Check to see if the next parameter is intended for LCDd,
// or if it should be passed to the driver... // or if it should be passed to the driver...
if(argc > i+1) if (argc > i + 1) {
{ int j, skip = 0;
int j, skip=0; for (j = 1; args[j].lg; j++) // check each option except "help"
for(j=1; args[j].lg; j++) // check each option except "help" if (!strcmp (argv[i + 1], args[j].sh) || !strcmp (argv[i + 1], args[j].lg))
if(! strcmp(argv[i+1], args[j].sh) || skip = 1;
! strcmp(argv[i+1], args[j].lg)) skip=1;
if(! skip) if (!skip) {
{
ing = argv[++i]; ing = argv[++i];
} }
//else i++; //else i++;
} }
err = lcd_add_driver(str, ing); err = lcd_add_driver (str, ing);
if(err <= 0) if (err <= 0) {
{ printf ("Error loading driver %s. Continuing anyway...\n", str);
printf("Error loading driver %s. Continuing anyway...\n",
str);
} }
if((err > 0) && (0 == strcmp(str, "curses"))) daemon_mode=0; if ((err > 0) && (0 == strcmp (str, "curses")))
} daemon_mode = 0;
else if(0 == strcmp(argv[i], "-h") || } else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
0 == strcmp(argv[i], "--help")) HelpScreen ();
{
HelpScreen();
} }
// Redundant, but it prevents errors... // Redundant, but it prevents errors...
else if(0 == strcmp(argv[i], "-f") || else if (0 == strcmp (argv[i], "-f") || 0 == strcmp (argv[i], "--foreground")) {
0 == strcmp(argv[i], "--foreground")) daemon_mode = 0;
{ } else if (0 == strcmp (argv[i], "-b") || 0 == strcmp (argv[i], "--backlight")) {
daemon_mode = 0; if (argc <= i + 1)
} HelpScreen ();
else if(0 == strcmp(argv[i], "-b") ||
0 == strcmp(argv[i], "--backlight"))
{
if(argc <= i+1) HelpScreen();
str = argv[++i]; str = argv[++i];
if(0 == strcmp(str, "off")) if (0 == strcmp (str, "off"))
backlight_state = backlight = BACKLIGHT_OFF; backlight_state = backlight = BACKLIGHT_OFF;
else if(0 == strcmp(str, "on")) else if (0 == strcmp (str, "on"))
backlight_state = backlight = BACKLIGHT_ON; backlight_state = backlight = BACKLIGHT_ON;
else if(0 == strcmp(str, "open")) else if (0 == strcmp (str, "open"))
backlight = BACKLIGHT_OPEN; backlight = BACKLIGHT_OPEN;
else HelpScreen();
}
else if(0 == strcmp(argv[i], "-t") ||
0 == strcmp(argv[i], "--type"))
{
if(i + 1 > argc)
HelpScreen();
else else
{ HelpScreen ();
} else if (0 == strcmp (argv[i], "-t") || 0 == strcmp (argv[i], "--type")) {
if (i + 1 > argc)
HelpScreen ();
else {
int wid, hgt; int wid, hgt;
i++; i++;
sscanf(argv[i], "%ix%i", &wid, &hgt); sscanf (argv[i], "%ix%i", &wid, &hgt);
if(wid>80 || wid<16 || hgt>25 || hgt<2) if (wid > 80 || wid < 16 || hgt > 25 || hgt < 2) {
{ fprintf (stderr, "LCDd: Invalid lcd size \"%s\". Using 20x4.\n", argv[i]);
fprintf(stderr,
"LCDd: Invalid lcd size \"%s\". Using 20x4.\n",
argv[i]);
lcd.wid = 20; lcd.wid = 20;
lcd.hgt = 4; lcd.hgt = 4;
} } else {
else
{
lcd.wid = wid; lcd.wid = wid;
lcd.hgt = hgt; lcd.hgt = hgt;
} }
/* no longer needed /* no longer needed
int j=0, valid=0; int j=0, valid=0;
i++; i++;
@@ -228,70 +204,57 @@ int main(int argc, char **argv)
} }
*/ */
} }
} } else if (0 == strcmp (argv[i], "-i") || 0 == strcmp (argv[i], "--serverinfo")) {
else if(0 == strcmp(argv[i], "-i") || if (i + 1 > argc)
0 == strcmp(argv[i], "--serverinfo")) HelpScreen ();
{ else {
if(i + 1 > argc)
HelpScreen();
else
{
i++; i++;
if(0 == strcmp(argv[i], "off")) disable_server_screen = 1; if (0 == strcmp (argv[i], "off"))
if(0 == strcmp(argv[i], "on")) disable_server_screen = 0; disable_server_screen = 1;
if (0 == strcmp (argv[i], "on"))
disable_server_screen = 0;
} }
} } else {
else
{
// otherwise... Get help! // otherwise... Get help!
printf("Invalid parameter: %s\n", argv[i]); printf ("Invalid parameter: %s\n", argv[i]);
HelpScreen(); HelpScreen ();
} }
} }
// Now init a bunch of required stuff... // Now init a bunch of required stuff...
if(sock_create_server() <= 0) if (sock_create_server () <= 0) {
{ printf ("Error opening socket.\n");
printf("Error opening socket.\n");
return 1; return 1;
} }
if(client_init() < 0) if (client_init () < 0) {
{ printf ("Error initializing client list\n");
printf("Error initializing client list\n");
return 1;
}
if(screenlist_init() < 0)
{
printf("Error initializing screen list\n");
return 1; return 1;
} }
if (screenlist_init () < 0) {
printf ("Error initializing screen list\n");
return 1;
}
// Make sure the server screen shows up every once in a while.. // Make sure the server screen shows up every once in a while..
if(server_screen_init() < 0) if (server_screen_init () < 0) {
{ printf ("Error initializing server screens\n");
printf("Error initializing server screens\n");
return 1; return 1;
} } else if (disable_server_screen) {
else if(disable_server_screen)
{
server_screen->priority = 256; server_screen->priority = 256;
} }
// Main loop... // Main loop...
while(1) while (1) {
{ sock_poll_clients ();
sock_poll_clients(); parse_all_client_messages ();
parse_all_client_messages(); handle_input ();
handle_input();
// TODO: Move this code to screenlist.c... // TODO: Move this code to screenlist.c...
// ... it should just say "handle_screens();" // ... it should just say "handle_screens();"
@@ -299,73 +262,76 @@ int main(int argc, char **argv)
timer++; timer++;
// this line's here because s was getting overwritten at one time... // this line's here because s was getting overwritten at one time...
//s = screenlist_current(); //s = screenlist_current();
if(s && (timer >= s->duration)) if (s && (timer >= s->duration)) {
{ screenlist_next ();
screenlist_next();
} }
// Just in case it gets out of hand... // Just in case it gets out of hand...
if(timer >= 0x10000) timer = 0; if (timer >= 0x10000)
update_server_screen(timer); timer = 0;
s = screenlist_current(); update_server_screen (timer);
s = screenlist_current ();
// render something here... // render something here...
if(s) draw_screen(s, timer); if (s)
else no_screen_screen(timer); draw_screen (s, timer);
else
usleep(TIME_UNIT); no_screen_screen (timer);
usleep (TIME_UNIT);
} }
// Quit! // Quit!
exit_program(0); exit_program (0);
return 0; return 0;
} }
void exit_program(int val) void
exit_program (int val)
{ {
// TODO: These things shouldn't be so interdependent. The order // TODO: These things shouldn't be so interdependent. The order
// things are shut down in shouldn't matter... // things are shut down in shouldn't matter...
// Say goodbye! // Say goodbye!
goodbye_screen(); goodbye_screen ();
// Can go anywhere... // Can go anywhere...
lcd_shutdown(); lcd_shutdown ();
// Must come before screenlist_shutdown // Must come before screenlist_shutdown
client_shutdown(); client_shutdown ();
// Must come after client_shutdown // Must come after client_shutdown
screenlist_shutdown(); screenlist_shutdown ();
// Should come after client_shutdown // Should come after client_shutdown
sock_close_all(); sock_close_all ();
exit(0); exit (0);
} }
void HelpScreen() void
HelpScreen ()
{ {
printf("LCDproc server daemon, %s\n", version); printf ("LCDproc server daemon, %s\n", version);
printf("Copyright (c) 1999 Scott Scriven, William Ferrell, and misc contributors\n"); printf ("Copyright (c) 1999 Scott Scriven, William Ferrell, and misc contributors\n");
printf("This program is freely redistributable under the terms of the GNU Public License\n\n"); printf ("This program is freely redistributable under the terms of the GNU Public License\n\n");
printf("Usage: LCDd [options]\n"); printf ("Usage: LCDd [options]\n");
printf("\tOptions in []'s are optional. Available options are:\n"); printf ("\tOptions in []'s are optional. Available options are:\n");
printf("\t-h\t--help\n\t\t\tDisplay this help screen\n"); printf ("\t-h\t--help\n\t\t\tDisplay this help screen\n");
printf("\t-t\t--type <size>\n\t\t\tSelect an LCD size (20x4, 16x2, etc...)\n"); printf ("\t-t\t--type <size>\n\t\t\tSelect an LCD size (20x4, 16x2, etc...)\n");
printf("\t-d\t--driver <driver> [args]\n\t\t\tAdd a driver to use:\n"); printf ("\t-d\t--driver <driver> [args]\n\t\t\tAdd a driver to use:\n");
printf("\t\t\tCFontz, curses, HD44780, irmanin, joy,\n\t\t\tMtxOrb, text\n"); printf ("\t\t\tCFontz, curses, HD44780, irmanin, joy,\n\t\t\tMtxOrb, text\n");
printf("\t\t\t(args will be passed to the driver for init)\n"); printf ("\t\t\t(args will be passed to the driver for init)\n");
printf("\t-f\t--foreground\n\t\t\tRun in the foreground (no daemon)\n"); printf ("\t-f\t--foreground\n\t\t\tRun in the foreground (no daemon)\n");
printf("\t-b\t--backlight <mode>\n\t\t\tSet backlight mode (on, off, open)\n"); printf ("\t-b\t--backlight <mode>\n\t\t\tSet backlight mode (on, off, open)\n");
printf("\t-i\t--serverinfo off\n\t\t\tSet the server screen to low priority\n"); printf ("\t-i\t--serverinfo off\n\t\t\tSet the server screen to low priority\n");
printf("\n"); printf ("\n");
printf("\tUse \"man LCDd\" for more info.\n"); printf ("\tUse \"man LCDd\" for more info.\n");
printf("\tHelp on each driver's parameters are obtained upon request:\n\t\t\"LCDd -d driver --help\"\n"); printf ("\tHelp on each driver's parameters are obtained upon request:\n\t\t\"LCDd -d driver --help\"\n");
printf("Example:\n"); printf ("Example:\n");
printf("\tLCDd -d MtxOrb \"--device /dev/lcd --contrast 200\" -d joy\n"); printf ("\tLCDd -d MtxOrb \"--device /dev/lcd --contrast 200\" -d joy\n");
printf("\n"); printf ("\n");
exit(0); exit (0);
} }
+7 -9
View File
@@ -3,7 +3,7 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
/* /*
contains a few things that other parts of the program might want contains a few things that other parts of the program might want
@@ -14,22 +14,20 @@ extern char *version;
extern char *protocol_version; extern char *protocol_version;
extern char *build_date; extern char *build_date;
void exit_program(int val); void exit_program (int val);
// 1/8th second is a single time unit... // 1/8th second is a single time unit...
#define TIME_UNIT 125000 #define TIME_UNIT 125000
// But I plan to double the framerate soon, or make it variable... // But I plan to double the framerate soon, or make it variable...
//#define TIME_UNIT (125000/2) //#define TIME_UNIT (125000/2)
typedef struct screen_size typedef struct screen_size {
{ char *size;
char * size; int wid, hgt;
int wid, hgt;
} screen_size; } screen_size;
typedef struct parameter typedef struct parameter {
{ char *sh, *lg; // short and long versions
char * sh, * lg; // short and long versions
} parameter; } parameter;
+255 -253
View File
@@ -29,26 +29,27 @@
// FIXME: Implement this where it is supposed to be... // FIXME: Implement this where it is supposed to be...
#include <time.h> #include <time.h>
void framedelay() void
framedelay ()
{ {
sock_poll_clients(); sock_poll_clients ();
parse_all_client_messages(); parse_all_client_messages ();
usleep(TIME_UNIT); usleep (TIME_UNIT);
} }
static void draw_heartbeat() static void
draw_heartbeat ()
{ {
static int timer = 0; static int timer = 0;
if(heartbeat) if (heartbeat) {
{ // Set this to pulsate like a real heart beat...
// Set this to pulsate like a real heart beat... // (binary is fun... :)
// (binary is fun... :) lcd.icon (!((timer + 4) & 5), 0);
lcd.icon(!((timer+4)&5), 0); lcd.chr (lcd.wid, 1, 0);
lcd.chr(lcd.wid, 1, 0);
} }
lcd.flush(); lcd.flush ();
timer++; timer++;
timer &= 0x0f; timer &= 0x0f;
@@ -58,298 +59,299 @@ static int PAD = 255;
typedef struct menu_info typedef struct menu_info {
{ int selected;
int selected; int length;
int length;
} menu_info; } menu_info;
static int draw_menu(Menu menu, menu_info *info); static int draw_menu (Menu menu, menu_info * info);
static int fill_menu_info(Menu menu, menu_info *info); static int fill_menu_info (Menu menu, menu_info * info);
static int menu_handle_action(menu_item *item); static int menu_handle_action (menu_item * item);
static int slid_func(menu_item *item); static int slid_func (menu_item * item);
int do_menu(Menu menu) int
do_menu (Menu menu)
{ {
menu_info info; menu_info info;
int key=0; int key = 0;
int status=MENU_OK; int status = MENU_OK;
int done=0; int done = 0;
int (*func)(); int (*func) ();
int (*readfunc)(int); int (*readfunc) (int);
if(!menu) return MENU_ERROR;
fill_menu_info(menu, &info);
while(!done) if (!menu)
{ return MENU_ERROR;
// Keep the cursor off titles... (?)
while(menu[info.selected].type == TYPE_TITL)
{
info.selected++;
// If the title is the last thing in the menu...
if(!menu[info.selected].text) info.selected -= 2;
}
draw_menu(menu, &info);
// FIXME: This should use a better keypress interface, which fill_menu_info (menu, &info);
// FIXME: handles things according to keybindings...
for(key = lcd.getkey(); key==0; key = lcd.getkey())
{
// sleep for 1/8th second...
framedelay();
// do the heartbeat...
draw_heartbeat();
// Check for client input...
}
// Handle the key according to the keybindings...
switch(key)
{
case 'D': done=1; break;
case 'B': if(info.selected > 0) info.selected--;
while(menu[info.selected].type == TYPE_TITL)
{
if(info.selected > 0)
info.selected--;
else break;
}
break;
case 'C': if(menu[info.selected+1].text) info.selected++; break;
case 'A':
switch(menu[info.selected].type)
{
case TYPE_MENU: status = do_menu(menu[info.selected].data);
break;
case TYPE_FUNC:
func = menu[info.selected].data;
if(func)
status = func();
break;
case TYPE_CHEK:
readfunc = menu[info.selected].data;
if(readfunc)
status = readfunc(MENU_CHECK);
status &= 0xffff0000;
break;
case TYPE_SLID:
func = menu[info.selected].data;
if(func)
status = slid_func(&menu[info.selected]);
break;
default:
break;
}
switch(status)
{
case MENU_OK:
break;
case MENU_CLOSE:
return MENU_OK;
case MENU_QUIT:
return MENU_QUIT;
// case MENU_KILL:
// return MENU_KILL;
case MENU_ERROR:
return MENU_ERROR;
}
// status = menu_handle_action(&menu[info.selected]);
// TODO: It should now do special stuff for "mover" widgets,
// TODO: and handle the return code appropriately.
break;
default: break;
}
}
return status;
}
static int draw_menu(Menu menu, menu_info *info) while (!done) {
{ // Keep the cursor off titles... (?)
int i; while (menu[info.selected].type == TYPE_TITL) {
int x=1, y=1; info.selected++;
int top=0, bottom=0; // If the title is the last thing in the menu...
if (!menu[info.selected].text)
info.selected -= 2;
}
int (*readfunc)(int);
// these should maybe be removed:
int wid=lcd.wid, hgt=lcd.hgt;
if(!menu) return MENU_ERROR; draw_menu (menu, &info);
lcd.clear(); // FIXME: This should use a better keypress interface, which
// FIXME: handles things according to keybindings...
for (key = lcd.getkey (); key == 0; key = lcd.getkey ()) {
// Scroll down until the selected item is centered, if possible... // sleep for 1/8th second...
top = info->selected - (hgt/2); framedelay ();
if(top<0) top=0; // do the heartbeat...
bottom = top+hgt; draw_heartbeat ();
if(bottom > info->length) bottom=info->length; // Check for client input...
top = bottom-hgt; }
if(top<0) top=0;
// Draw all visible items...
for(i=top; i<bottom; i++, y++) // Handle the key according to the keybindings...
{ switch (key) {
if(i == info->selected) lcd.chr(2,y,'>'); case 'D':
done = 1;
switch(menu[i].type) break;
{ case 'B':
case TYPE_TITL: if (info.selected > 0)
lcd.chr(1,y,PAD); info.selected--;
lcd.chr(2,y,PAD); while (menu[info.selected].type == TYPE_TITL) {
lcd.string(4,y,menu[i].text); if (info.selected > 0)
for(x=strlen(menu[i].text)+5; x <= wid; x++) info.selected--;
lcd.chr(x,y,PAD); else
break; break;
case TYPE_MENU: }
lcd.string(3,y,menu[i].text); break;
lcd.chr(wid,y,'>'); case 'C':
break; if (menu[info.selected + 1].text)
case TYPE_FUNC: info.selected++;
lcd.string(3,y,menu[i].text); break;
break; case 'A':
case TYPE_CHEK: switch (menu[info.selected].type) {
if(menu[i].data) case TYPE_MENU:
{ status = do_menu (menu[info.selected].data);
readfunc = menu[i].data; break;
if(readfunc(MENU_READ)) case TYPE_FUNC:
lcd.chr(wid,y,'Y'); func = menu[info.selected].data;
else if (func)
lcd.chr(wid,y,'N'); status = func ();
} break;
lcd.string(3,y,menu[i].text); case TYPE_CHEK:
break; readfunc = menu[info.selected].data;
case TYPE_SLID: if (readfunc)
lcd.string(3,y,menu[i].text); status = readfunc (MENU_CHECK);
break; status &= 0xffff0000;
case TYPE_MOVE: break;
break; case TYPE_SLID:
func = menu[info.selected].data;
if (func)
status = slid_func (&menu[info.selected]);
break;
default:
break;
}
switch (status) {
case MENU_OK:
break;
case MENU_CLOSE:
return MENU_OK;
case MENU_QUIT:
return MENU_QUIT;
// case MENU_KILL:
// return MENU_KILL;
case MENU_ERROR:
return MENU_ERROR;
}
// status = menu_handle_action(&menu[info.selected]);
// TODO: It should now do special stuff for "mover" widgets,
// TODO: and handle the return code appropriately.
break;
default: default:
break; break;
} }
}
if(top != 0) }
lcd.chr(1,1,'^');
if(bottom < info->length) return status;
lcd.chr(1,hgt,'v');
draw_heartbeat();
//lcd.flush();
return 0;
} }
static int
static int fill_menu_info(Menu menu, menu_info *info) draw_menu (Menu menu, menu_info * info)
{ {
int i; int i;
int x = 1, y = 1;
int top = 0, bottom = 0;
info->selected = 0; int (*readfunc) (int);
// count the entries in the menu // these should maybe be removed:
for(i=0; menu[i].text; i++); int wid = lcd.wid, hgt = lcd.hgt;
info->length = i;
if (!menu)
return 0; return MENU_ERROR;
lcd.clear ();
// Scroll down until the selected item is centered, if possible...
top = info->selected - (hgt / 2);
if (top < 0)
top = 0;
bottom = top + hgt;
if (bottom > info->length)
bottom = info->length;
top = bottom - hgt;
if (top < 0)
top = 0;
// Draw all visible items...
for (i = top; i < bottom; i++, y++) {
if (i == info->selected)
lcd.chr (2, y, '>');
switch (menu[i].type) {
case TYPE_TITL:
lcd.chr (1, y, PAD);
lcd.chr (2, y, PAD);
lcd.string (4, y, menu[i].text);
for (x = strlen (menu[i].text) + 5; x <= wid; x++)
lcd.chr (x, y, PAD);
break;
case TYPE_MENU:
lcd.string (3, y, menu[i].text);
lcd.chr (wid, y, '>');
break;
case TYPE_FUNC:
lcd.string (3, y, menu[i].text);
break;
case TYPE_CHEK:
if (menu[i].data) {
readfunc = menu[i].data;
if (readfunc (MENU_READ))
lcd.chr (wid, y, 'Y');
else
lcd.chr (wid, y, 'N');
}
lcd.string (3, y, menu[i].text);
break;
case TYPE_SLID:
lcd.string (3, y, menu[i].text);
break;
case TYPE_MOVE:
break;
default:
break;
}
}
if (top != 0)
lcd.chr (1, 1, '^');
if (bottom < info->length)
lcd.chr (1, hgt, 'v');
draw_heartbeat ();
//lcd.flush();
return 0;
} }
static int menu_handle_action(menu_item *item)
static int
fill_menu_info (Menu menu, menu_info * info)
{ {
return MENU_OK; int i;
info->selected = 0;
// count the entries in the menu
for (i = 0; menu[i].text; i++);
info->length = i;
return 0;
}
static int
menu_handle_action (menu_item * item)
{
return MENU_OK;
} }
static int slid_func(menu_item *item) static int
slid_func (menu_item * item)
{ {
char str[16]; char str[16];
int key = 0; int key = 0;
int value = 0; int value = 0;
int x, y=1; int x, y = 1;
int (*readfunc)(int); int (*readfunc) (int);
readfunc = item->data; readfunc = item->data;
lcd.init_hbar(); lcd.init_hbar ();
while(key != 'A' && key != 'D') while (key != 'A' && key != 'D') {
{
// Draw the title... // Draw the title...
lcd.clear(); lcd.clear ();
lcd.chr(1,y,PAD); lcd.chr (1, y, PAD);
lcd.chr(2,y,PAD); lcd.chr (2, y, PAD);
lcd.string(4,y,item->text); lcd.string (4, y, item->text);
for(x=strlen(item->text)+5; x <= lcd.wid; x++) for (x = strlen (item->text) + 5; x <= lcd.wid; x++)
lcd.chr(x,y,PAD); lcd.chr (x, y, PAD);
// Draw the slider now... // Draw the slider now...
value = readfunc(MENU_READ); value = readfunc (MENU_READ);
if(value < 0 || value >= MENU_CLOSE) if (value < 0 || value >= MENU_CLOSE)
return value; return value;
sprintf(str, "%i", value); sprintf (str, "%i", value);
if(lcd.hgt >= 4) if (lcd.hgt >= 4) {
{ lcd.string (8, 4, str);
lcd.string(8, 4, str);
value = (lcd.wid * lcd.cellwid * value / 256); value = (lcd.wid * lcd.cellwid * value / 256);
lcd.hbar(1, 3, value); lcd.hbar (1, 3, value);
} } else {
else lcd.string (17, 2, str);
{ value = ((lcd.wid - 4) * lcd.cellwid * value / 256);
lcd.string(17, 2, str); lcd.hbar (1, 2, value);
value = ((lcd.wid-4) * lcd.cellwid * value / 256);
lcd.hbar(1, 2, value);
} }
//lcd.flush(); //lcd.flush();
for(key = lcd.getkey(); key==0; key = lcd.getkey()) for (key = lcd.getkey (); key == 0; key = lcd.getkey ()) {
{
// do the heartbeat... // do the heartbeat...
draw_heartbeat(); draw_heartbeat ();
// sleep for 1/8th second... // sleep for 1/8th second...
framedelay(); framedelay ();
// Check for client input... // Check for client input...
} }
switch(key) switch (key) {
{ case 'B':
case 'B': value = readfunc (MENU_MINUS);
value = readfunc(MENU_MINUS); break;
break; case 'C':
case 'C': value = readfunc (MENU_PLUS);
value = readfunc(MENU_PLUS); break;
break;
} }
if(value >= MENU_CLOSE if (value >= MENU_CLOSE || value < 0 || key == 'A' || key == 'D')
|| value < 0
|| key == 'A'
|| key == 'D')
return value; return value;
} }
return MENU_OK; return MENU_OK;
} }
+7 -8
View File
@@ -121,23 +121,22 @@ and sliders should return 0-255.
// User actions, sent to item-handling functions as input. // User actions, sent to item-handling functions as input.
#define MENU_SELECT 1 #define MENU_SELECT 1
#define MENU_CHECK 2 #define MENU_CHECK 2
#define MENU_PLUS 3 #define MENU_PLUS 3
#define MENU_MINUS 4 #define MENU_MINUS 4
#define MENU_READ 5 #define MENU_READ 5
typedef struct menu_item typedef struct menu_item {
{ char *text;
char *text; int type;
int type; void *data;
void *data;
} menu_item; } menu_item;
#define Menu menu_item * #define Menu menu_item *
int do_menu(Menu menu); int do_menu (Menu menu);
#endif #endif
+214 -176
View File
@@ -25,71 +25,71 @@
#include "serverscreens.h" #include "serverscreens.h"
int Shutdown_func(); int Shutdown_func ();
int System_halt_func(); int System_halt_func ();
int Reboot_func(); int Reboot_func ();
int Close_func(); int Close_func ();
int OK_func(); int OK_func ();
int Time24_func(int input); int Time24_func (int input);
int Heartbeat_func(int input); int Heartbeat_func (int input);
int Backlight_func(int input); int Backlight_func (int input);
int Server_screen_func(int input); int Server_screen_func (int input);
int Contrast_func(int input); int Contrast_func (int input);
int Backlight_Brightness_func(int input); int Backlight_Brightness_func (int input);
int Backlight_Off_Brightness_func(int input); int Backlight_Off_Brightness_func (int input);
int Backlight_Off_func(); int Backlight_Off_func ();
int Backlight_On_func(); int Backlight_On_func ();
int Backlight_Open_func(); int Backlight_Open_func ();
menu_item main_menu[] = { menu_item main_menu[] = {
{ "LCDproc", 0, 0 },// Title {"LCDproc", 0, 0}, // Title
{ "Options", TYPE_MENU, (void *)options_menu}, {"Options", TYPE_MENU, (void *) options_menu},
{ "Screens", TYPE_MENU, (void *)screens_menu}, {"Screens", TYPE_MENU, (void *) screens_menu},
{ "Shutdown", TYPE_MENU, (void *)shutdown_menu }, {"Shutdown", TYPE_MENU, (void *) shutdown_menu},
{ 0, 0, 0 }, {0, 0, 0},
}; };
menu_item options_menu[] = { menu_item options_menu[] = {
{ "OPTIONS", TYPE_TITL, 0}, // Title {"OPTIONS", TYPE_TITL, 0}, // Title
// "24-hour Time", TYPE_CHEK, (void *)Time24_func, // "24-hour Time", TYPE_CHEK, (void *)Time24_func,
{ "Contrast...", TYPE_SLID, (void *)Contrast_func}, {"Contrast...", TYPE_SLID, (void *) Contrast_func},
{ "Backlight", TYPE_MENU, (void *)Backlight_menu}, {"Backlight", TYPE_MENU, (void *) Backlight_menu},
{ "Heartbeat", TYPE_CHEK, (void *)Heartbeat_func}, {"Heartbeat", TYPE_CHEK, (void *) Heartbeat_func},
// { "Backlight...", TYPE_SLID, (void *)Backlight_func}, // { "Backlight...", TYPE_SLID, (void *)Backlight_func},
// "OK", TYPE_FUNC, (void *)OK_func, // "OK", TYPE_FUNC, (void *)OK_func,
// "Close Menu", TYPE_FUNC, (void *)Close_func, // "Close Menu", TYPE_FUNC, (void *)Close_func,
// "Exit Program", TYPE_FUNC, (void *)Shutdown_func, // "Exit Program", TYPE_FUNC, (void *)Shutdown_func,
// "Another Title",TYPE_TITL, 0, // "Another Title",TYPE_TITL, 0,
// "Main menu?", TYPE_MENU, (void *)main_menu, // "Main menu?", TYPE_MENU, (void *)main_menu,
// "Nothing!", TYPE_FUNC, 0, // "Nothing!", TYPE_FUNC, 0,
{ 0, 0, 0}, {0, 0, 0},
}; };
menu_item screens_menu[] = { menu_item screens_menu[] = {
{ "SCREENS", TYPE_TITL, 0}, // Title {"SCREENS", TYPE_TITL, 0}, // Title
{ "Server Scr",TYPE_CHEK, (void *)Server_screen_func}, {"Server Scr", TYPE_CHEK, (void *) Server_screen_func},
{ 0, 0, 0}, {0, 0, 0},
}; };
menu_item shutdown_menu[] = { menu_item shutdown_menu[] = {
{ "Shut Down...", TYPE_TITL, 0}, // Title {"Shut Down...", TYPE_TITL, 0}, // Title
{ "Kill LCDproc", TYPE_FUNC, (void *)Shutdown_func}, {"Kill LCDproc", TYPE_FUNC, (void *) Shutdown_func},
{ "System halt", TYPE_FUNC, (void *)System_halt_func}, {"System halt", TYPE_FUNC, (void *) System_halt_func},
{ "Reboot", TYPE_FUNC, (void *)Reboot_func}, {"Reboot", TYPE_FUNC, (void *) Reboot_func},
{ 0, 0, 0}, {0, 0, 0},
}; };
menu_item Backlight_menu[] = { menu_item Backlight_menu[] = {
{ "BACKLIGHT MENU", TYPE_TITL, 0}, // Title {"BACKLIGHT MENU", TYPE_TITL, 0}, // Title
{ "Brightness...", TYPE_SLID, (void *)Backlight_Brightness_func}, {"Brightness...", TYPE_SLID, (void *) Backlight_Brightness_func},
{ "\"Off\" Brightness", TYPE_SLID, (void *)Backlight_Off_Brightness_func}, {"\"Off\" Brightness", TYPE_SLID, (void *) Backlight_Off_Brightness_func},
{ "Backlight Mode:", TYPE_FUNC, 0}, // Label {"Backlight Mode:", TYPE_FUNC, 0}, // Label
{ " - Off", TYPE_FUNC, Backlight_Off_func}, {" - Off", TYPE_FUNC, Backlight_Off_func},
{ " - On", TYPE_FUNC, Backlight_On_func}, {" - On", TYPE_FUNC, Backlight_On_func},
{ " - Open", TYPE_FUNC, Backlight_Open_func}, {" - Open", TYPE_FUNC, Backlight_Open_func},
{ 0, 0, 0}, {0, 0, 0},
}; };
@@ -99,241 +99,279 @@ menu_item Backlight_menu[] = {
// //
// Exits the program. // Exits the program.
int Shutdown_func() int
Shutdown_func ()
{ {
exit_program(0); exit_program (0);
return MENU_KILL; return MENU_KILL;
} }
// Shuts down the system, if possible // Shuts down the system, if possible
int System_halt_func() int
System_halt_func ()
{ {
int err; int err;
uid_t id; uid_t id;
id = geteuid(); id = geteuid ();
err = system("init 0");
if(err < 0) return MENU_KILL; err = system ("init 0");
if(err == 127) return MENU_KILL;
if (err < 0)
return MENU_KILL;
if (err == 127)
return MENU_KILL;
// If we're root, exit // If we're root, exit
if(id == 0) exit_program(0); if (id == 0)
exit_program (0);
// Otherwise, assume shutdown will fail; and show more stats. // Otherwise, assume shutdown will fail; and show more stats.
return MENU_KILL; return MENU_KILL;
} }
// Shuts down the system and restarts it // Shuts down the system and restarts it
int Reboot_func() int
Reboot_func ()
{ {
int err; int err;
uid_t id; uid_t id;
id = geteuid(); id = geteuid ();
err = system("init 6");
if(err < 0) return MENU_KILL; err = system ("init 6");
if(err == 127) return MENU_KILL;
if (err < 0)
return MENU_KILL;
if (err == 127)
return MENU_KILL;
// If we're root, exit // If we're root, exit
if(id == 0) exit_program(0); if (id == 0)
exit_program (0);
// Otherwise, assume shutdown will fail; and show more stats. // Otherwise, assume shutdown will fail; and show more stats.
return MENU_KILL; return MENU_KILL;
} }
int Close_func() int
Close_func ()
{ {
return MENU_CLOSE; return MENU_CLOSE;
} }
int OK_func() int
OK_func ()
{ {
return MENU_OK; return MENU_OK;
} }
int Time24_func(int input) int
Time24_func (int input)
{ {
static int status=0; static int status = 0;
if(input == MENU_READ) return status; if (input == MENU_READ)
if(input == MENU_CHECK) status ^= 1; // does something. return status;
if (input == MENU_CHECK)
status ^= 1; // does something.
return (status | MENU_OK); return (status | MENU_OK);
// The status is "or"-ed with the MENU value to let do_menu() // The status is "or"-ed with the MENU value to let do_menu()
// know what to do after selecting the item. (two return // know what to do after selecting the item. (two return
// values in one. :) // values in one. :)
// Also, "MENU_OK" happens to be zero, so it does not matter // Also, "MENU_OK" happens to be zero, so it does not matter
// unless you want something else (like MENU_CLOSE) // unless you want something else (like MENU_CLOSE)
} }
int Heartbeat_func(int input) int
Heartbeat_func (int input)
{ {
if(input == MENU_READ) return (heartbeat != HEART_OFF); if (input == MENU_READ)
if(input == MENU_CHECK) return (heartbeat != HEART_OFF);
{ if (input == MENU_CHECK) {
if(heartbeat) heartbeat = HEART_OFF; if (heartbeat)
else heartbeat = HEART_OPEN; heartbeat = HEART_OFF;
else
heartbeat = HEART_OPEN;
} }
return ((heartbeat != HEART_OFF) | MENU_OK); return ((heartbeat != HEART_OFF) | MENU_OK);
} }
int Backlight_func(int input) int
Backlight_func (int input)
{ {
int status = 128; int status = 128;
switch(backlight) switch (backlight) {
{ case BACKLIGHT_OFF:
case BACKLIGHT_OFF: if (input == MENU_READ)
if(input == MENU_READ) status = 0; status = 0;
if(input == MENU_PLUS) if (input == MENU_PLUS) {
{ backlight = BACKLIGHT_OPEN;
backlight = BACKLIGHT_OPEN; status = 128;
status = 128; }
} if (input == MENU_MINUS) {
if(input == MENU_MINUS) status = 0;
{ }
status = 0; break;
} case BACKLIGHT_ON:
break; if (input == MENU_READ)
case BACKLIGHT_ON: status = 255;
if(input == MENU_READ) status = 255; if (input == MENU_PLUS) {
if(input == MENU_PLUS) status = 255;
{ }
status = 255; if (input == MENU_MINUS) {
} backlight = BACKLIGHT_OPEN;
if(input == MENU_MINUS) status = 128;
{ }
backlight = BACKLIGHT_OPEN; break;
status = 128; case BACKLIGHT_OPEN:
} if (input == MENU_READ)
break; status = 128;
case BACKLIGHT_OPEN: if (input == MENU_PLUS) {
if(input == MENU_READ) status = 128; backlight = BACKLIGHT_ON;
if(input == MENU_PLUS) backlight_state = BACKLIGHT_ON;
{ status = 255;
backlight = BACKLIGHT_ON; }
backlight_state = BACKLIGHT_ON; if (input == MENU_MINUS) {
status = 255; backlight = BACKLIGHT_OFF;
} backlight_state = BACKLIGHT_OFF;
if(input == MENU_MINUS) status = 0;
{ }
backlight = BACKLIGHT_OFF; break;
backlight_state = BACKLIGHT_OFF;
status = 0;
}
break;
} }
/* /*
if(input == MENU_READ) return (backlight != BACKLIGHT_OFF); if(input == MENU_READ) return (backlight != BACKLIGHT_OFF);
if(input == MENU_CHECK) if(input == MENU_CHECK)
{ {
if(backlight) backlight = BACKLIGHT_OFF; if(backlight) backlight = BACKLIGHT_OFF;
else backlight = BACKLIGHT_OPEN; else backlight = BACKLIGHT_OPEN;
} }
*/ */
lcd.backlight(backlight_state & BACKLIGHT_ON); lcd.backlight (backlight_state & BACKLIGHT_ON);
return (status | MENU_OK); return (status | MENU_OK);
} }
int Server_screen_func(int input) int
Server_screen_func (int input)
{ {
if(input == MENU_READ) return (server_screen->priority < 256); if (input == MENU_READ)
if(input == MENU_CHECK) return (server_screen->priority < 256);
{ if (input == MENU_CHECK) {
if(server_screen->priority < 256) server_screen->priority = 256; if (server_screen->priority < 256)
else server_screen->priority = 128; server_screen->priority = 256;
else
server_screen->priority = 128;
} }
return (MENU_OK | (server_screen->priority < 256)); return (MENU_OK | (server_screen->priority < 256));
} }
int Contrast_func(int input) int
Contrast_func (int input)
{ {
int status; int status;
status=lcd.contrast(-1); status = lcd.contrast (-1);
if(input == MENU_READ) return status; if (input == MENU_READ)
if(input == MENU_PLUS) status+=5; // does something. return status;
if(input == MENU_MINUS) status-=5; // does something. if (input == MENU_PLUS)
status += 5; // does something.
if (input == MENU_MINUS)
status -= 5; // does something.
if(status<0) status=0; if (status < 0)
if(status>255) status=255; status = 0;
lcd.contrast(status); if (status > 255)
status = 255;
return (status | MENU_OK); lcd.contrast (status);
return (status | MENU_OK);
} }
void server_menu() void
server_menu ()
{ {
debug("server_menu()\n"); debug ("server_menu()\n");
do_menu(main_menu); do_menu (main_menu);
} }
int Backlight_Brightness_func(int input) int
Backlight_Brightness_func (int input)
{ {
int status = backlight_brightness; int status = backlight_brightness;
if(input == MENU_READ) return status; if (input == MENU_READ)
if(input == MENU_PLUS) status+=5; // does something. return status;
if(input == MENU_MINUS) status-=5; // does something. if (input == MENU_PLUS)
status += 5; // does something.
if (input == MENU_MINUS)
status -= 5; // does something.
if (status < 0)
status = 0;
if (status > 255)
status = 255;
lcd.backlight (status);
if(status<0) status=0;
if(status>255) status=255;
lcd.backlight(status);
backlight_brightness = status; backlight_brightness = status;
return (status | MENU_OK); return (status | MENU_OK);
} }
int Backlight_Off_Brightness_func(int input) int
Backlight_Off_Brightness_func (int input)
{ {
int status = backlight_off_brightness; int status = backlight_off_brightness;
if(input == MENU_READ) return status; if (input == MENU_READ)
if(input == MENU_PLUS) status+=5; // does something. return status;
if(input == MENU_MINUS) status-=5; // does something. if (input == MENU_PLUS)
status += 5; // does something.
if (input == MENU_MINUS)
status -= 5; // does something.
if (status < 0)
status = 0;
if (status > 255)
status = 255;
lcd.backlight (status);
if(status<0) status=0;
if(status>255) status=255;
lcd.backlight(status);
backlight_off_brightness = status; backlight_off_brightness = status;
return (status | MENU_OK); return (status | MENU_OK);
} }
int Backlight_Off_func() int
Backlight_Off_func ()
{ {
backlight_state = BACKLIGHT_OFF; backlight_state = BACKLIGHT_OFF;
backlight = BACKLIGHT_OFF; backlight = BACKLIGHT_OFF;
lcd.backlight(backlight_off_brightness); lcd.backlight (backlight_off_brightness);
return MENU_OK; return MENU_OK;
} }
int Backlight_On_func() int
Backlight_On_func ()
{ {
backlight_state = BACKLIGHT_ON; backlight_state = BACKLIGHT_ON;
backlight = BACKLIGHT_ON; backlight = BACKLIGHT_ON;
lcd.backlight(backlight_brightness * (backlight_state & BACKLIGHT_ON)); lcd.backlight (backlight_brightness * (backlight_state & BACKLIGHT_ON));
return MENU_OK; return MENU_OK;
} }
int Backlight_Open_func() int
Backlight_Open_func ()
{ {
backlight = BACKLIGHT_OPEN; backlight = BACKLIGHT_OPEN;
return MENU_OK; return MENU_OK;
} }
+1 -1
View File
@@ -11,6 +11,6 @@ extern menu_item shutdown_menu[];
extern menu_item Backlight_menu[]; extern menu_item Backlight_menu[];
// Brings up the main menu... // Brings up the main menu...
void server_menu(); void server_menu ();
#endif #endif
+46 -61
View File
@@ -23,7 +23,8 @@
int parse_all_client_messages() int
parse_all_client_messages ()
{ {
int i, j; int i, j;
int newtoken, inquote; int newtoken, inquote;
@@ -33,78 +34,64 @@ int parse_all_client_messages()
int argc; int argc;
char *argv[256]; char *argv[256];
char delimiters[] = " \0"; char delimiters[] = " \0";
char leftquote[] = "\0\"'`([{\0"; char leftquote[] = "\0\"'`([{\0";
char rightquote[] = "\0\"'`)]}\0"; char rightquote[] = "\0\"'`)]}\0";
char errmsg[256]; char errmsg[256];
int invalid=0; int invalid = 0;
//debug("parse: Rewinding list...\n"); //debug("parse: Rewinding list...\n");
LL_Rewind(clients); LL_Rewind (clients);
do { do {
// Get the next client... // Get the next client...
//debug("parse: Getting client...\n"); //debug("parse: Getting client...\n");
c = LL_Get(clients); c = LL_Get (clients);
if(c) if (c) {
{
// And parse all its messages... // And parse all its messages...
//debug("parse: Getting messages...\n"); //debug("parse: Getting messages...\n");
for(str = client_get_message(c); str; str = client_get_message(c)) for (str = client_get_message (c); str; str = client_get_message (c)) {
{ debug ("parse: ...%s\n", str);
debug("parse: ...%s\n", str);
// Now, split up the string... // Now, split up the string...
//len = strlen(str); //len = strlen(str);
argc=0; argc = 0;
newtoken=1; newtoken = 1;
inquote=0; inquote = 0;
for(i=0; str[i]; i++) for (i = 0; str[i]; i++) {
{ if (inquote) // Scan for the end of the quote
if(inquote) // Scan for the end of the quote
{ {
if(str[i] == rightquote[inquote]) if (str[i] == rightquote[inquote]) { // Found the end of the quote
{ // Found the end of the quote inquote = 0;
inquote=0;
str[i] = 0; str[i] = 0;
newtoken=1; newtoken = 1;
} }
} } else // Normal operation; split at delimiters
else // Normal operation; split at delimiters
{ {
for(j=1; leftquote[j]; j++) for (j = 1; leftquote[j]; j++) {
{
// Found the beginning of a new quote... // Found the beginning of a new quote...
if(str[i] == leftquote[j]) if (str[i] == leftquote[j]) {
{
inquote = j; inquote = j;
str[i] = 0; str[i] = 0;
continue; continue;
} }
} }
for(j=0; delimiters[j]; j++) for (j = 0; delimiters[j]; j++) {
{
// Break into a new string... // Break into a new string...
if(str[i] == delimiters[j]) if (str[i] == delimiters[j]) {
{
str[i] = 0; str[i] = 0;
newtoken = 1; newtoken = 1;
continue; continue;
} }
} }
} }
if(newtoken && str[i]) if (newtoken && str[i]) {
{ newtoken = 0;
newtoken=0;
argv[argc] = str + i; argv[argc] = str + i;
argc++; argc++;
} } else {
else
{
} }
} }
if(inquote) if (inquote) {
{ sprintf (errmsg, "huh? Unterminated string: missing %c\n", rightquote[inquote]);
sprintf(errmsg, "huh? Unterminated string: missing %c\n", sock_send_string (c->sock, errmsg);
rightquote[inquote]);
sock_send_string(c->sock, errmsg);
continue; continue;
} }
/* /*
@@ -117,32 +104,30 @@ int parse_all_client_messages()
} }
*/ */
argv[argc] = NULL; argv[argc] = NULL;
if(argc < 1) continue; if (argc < 1)
continue;
// Now find and call the appropriate function... // Now find and call the appropriate function...
// debug("parse: Finding function...\n"); // debug("parse: Finding function...\n");
invalid = 1; invalid = 1;
for(i=0; commands[i].keyword; i++) for (i = 0; commands[i].keyword; i++) {
{ // debug("(checking %s)\n", commands[i].keyword);
// debug("(checking %s)\n", commands[i].keyword); if (0 == strcmp (argv[0], commands[i].keyword)) {
if(0 == strcmp(argv[0], commands[i].keyword)) // debug("(FOUND %s)\n", commands[i].keyword);
{ invalid = commands[i].function (c, argc, argv);
// debug("(FOUND %s)\n", commands[i].keyword); // debug("parse: Returned %i...\n", err);
invalid = commands[i].function(c, argc, argv);
// debug("parse: Returned %i...\n", err);
} }
} }
if(invalid) if (invalid) {
{
// FIXME: Check for buffer overflows here... // FIXME: Check for buffer overflows here...
sprintf(errmsg, "huh? Invalid command \"%s\"\n", argv[0]); sprintf (errmsg, "huh? Invalid command \"%s\"\n", argv[0]);
sock_send_string(c->sock, errmsg); sock_send_string (c->sock, errmsg);
} }
free(str); // fixed memory leak? free (str); // fixed memory leak?
} // end for(str...) } // end for(str...)
} // end if (c) } // end if (c)
} while (LL_Next(clients) == 0); } while (LL_Next (clients) == 0);
return 0; return 0;
} }
+1 -1
View File
@@ -2,6 +2,6 @@
#define PARSE_H #define PARSE_H
// This should be pretty self-explanatory... // This should be pretty self-explanatory...
int parse_all_client_messages(); int parse_all_client_messages ();
#endif #endif
+333 -412
View File
@@ -30,461 +30,390 @@
int heartbeat=HEART_OPEN; int heartbeat = HEART_OPEN;
int backlight=BACKLIGHT_OPEN; int backlight = BACKLIGHT_OPEN;
int backlight_state = BACKLIGHT_OPEN; int backlight_state = BACKLIGHT_OPEN;
int backlight_brightness=255; int backlight_brightness = 255;
int backlight_off_brightness=0; int backlight_off_brightness = 0;
int output_state = 0; int output_state = 0;
static int reset; static int reset;
#define BUFSIZE 1024 #define BUFSIZE 1024
static int draw_frame(LL *list, char fscroll, static int draw_frame (LL * list, char fscroll, int left, int top, int right, int bottom, int fwid, int fhgt, int fspeed, int timer);
int left, int top, int right, int bottom,
int fwid, int fhgt,
int fspeed, int timer);
int draw_screen(screen *s, int timer) int
draw_screen (screen * s, int timer)
{ {
static screen *old_s=NULL; static screen *old_s = NULL;
int tmp=0; int tmp = 0;
//debug("Render...\n"); //debug("Render...\n");
//return 0; //return 0;
reset = 1; reset = 1;
//debug("draw_screen: %8x, %i\n", (int)s, timer); //debug("draw_screen: %8x, %i\n", (int)s, timer);
if(!s) return -1;
if(s == old_s) reset = 0; if (!s)
return -1;
if (s == old_s)
reset = 0;
old_s = s; old_s = s;
lcd.clear(); lcd.clear ();
switch(backlight_state) switch (backlight_state) {
{ case BACKLIGHT_OFF:
case BACKLIGHT_OFF: lcd.backlight (backlight_off_brightness);
lcd.backlight(backlight_off_brightness); break;
break; case BACKLIGHT_ON:
case BACKLIGHT_ON: lcd.backlight (backlight_brightness);
lcd.backlight(backlight_brightness); break;
break; default:
default: if (backlight_state & BACKLIGHT_FLASH) {
if(backlight_state & BACKLIGHT_FLASH) tmp = (!((timer & 7) == 7));
{ if (backlight_state & 1)
tmp = (!((timer&7) == 7)); lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness);
if(backlight_state & 1) //lcd.backlight(backlight_brightness * (!((timer&7) == 7)));
lcd.backlight(tmp?backlight_brightness:backlight_off_brightness); else
//lcd.backlight(backlight_brightness * (!((timer&7) == 7))); lcd.backlight (!tmp ? backlight_brightness : backlight_off_brightness);
else //lcd.backlight(backlight_brightness * ((timer&7) == 7));
lcd.backlight(!tmp?backlight_brightness:backlight_off_brightness); } else if (backlight_state & BACKLIGHT_BLINK) {
//lcd.backlight(backlight_brightness * ((timer&7) == 7)); tmp = (!((timer & 14) == 14));
} if (backlight_state & 1)
else if(backlight_state & BACKLIGHT_BLINK) lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness);
{ //lcd.backlight(backlight_brightness * (!((timer&14) == 14)));
tmp = (!((timer&14) == 14)); else
if(backlight_state & 1) lcd.backlight (!tmp ? backlight_brightness : backlight_off_brightness);
lcd.backlight(tmp?backlight_brightness:backlight_off_brightness); //lcd.backlight(backlight_brightness * ((timer&14) == 14));
//lcd.backlight(backlight_brightness * (!((timer&14) == 14))); }
else break;
lcd.backlight(!tmp?backlight_brightness:backlight_off_brightness);
//lcd.backlight(backlight_brightness * ((timer&14) == 14));
}
break;
} }
lcd.output(output_state); lcd.output (output_state);
draw_frame (s->widgets, 'v', 0, 0, lcd.wid, lcd.hgt, s->wid, s->hgt, s->duration / s->hgt, timer);
draw_frame(s->widgets, 'v',
0, 0, lcd.wid, lcd.hgt,
s->wid, s->hgt,
s->duration/s->hgt, timer);
//debug("draw_screen done\n"); //debug("draw_screen done\n");
if(heartbeat) if (heartbeat) {
{ if ((s->heartbeat == 1) || heartbeat == HEART_ON) {
if((s->heartbeat==1) || heartbeat == HEART_ON)
{
// Set this to pulsate like a real heart beat... // Set this to pulsate like a real heart beat...
// (binary is fun... :) // (binary is fun... :)
lcd.icon(!((timer+4)&5), 0); lcd.icon (!((timer + 4) & 5), 0);
lcd.chr(lcd.wid, 1, 0); lcd.chr (lcd.wid, 1, 0);
} }
if((s->heartbeat==2) && heartbeat != HEART_OFF) if ((s->heartbeat == 2) && heartbeat != HEART_OFF) {
{
char *phases = "-\\|/"; char *phases = "-\\|/";
lcd.chr(lcd.wid, 1, phases[timer&3]); lcd.chr (lcd.wid, 1, phases[timer & 3]);
} }
} }
lcd.flush(); lcd.flush ();
//debug("draw_screen: %8x, %i\n", s, timer); //debug("draw_screen: %8x, %i\n", s, timer);
return 0; return 0;
} }
static int draw_frame(LL *list, char fscroll, static int
int left, int top, int right, int bottom, draw_frame (LL * list, char fscroll, int left, int top, int right, int bottom, int fwid, int fhgt, int fspeed, int timer)
int fwid, int fhgt,
int fspeed, int timer)
{ {
char str[BUFSIZE]; // scratch buffer char str[BUFSIZE]; // scratch buffer
widget *w; widget *w;
int wid, hgt; // Width and height of visible frame area int wid, hgt; // Width and height of visible frame area
int x, y; int x, y;
int fx, fy; // Scrolling offset for the frame... int fx, fy; // Scrolling offset for the frame...
int length, speed; int length, speed;
//int lines; //int lines;
int reset = 1; int reset = 1;
wid = right - left; // This is the size of the visible frame area wid = right - left; // This is the size of the visible frame area
hgt = bottom - top; hgt = bottom - top;
fx = 0; fx = 0;
fy = 0; fy = 0;
if(fscroll == 'v') if (fscroll == 'v') {
{
if (fspeed > 0)
if(fspeed > 0) fy = (timer - fspeed) / fspeed;
fy = (timer-fspeed) / fspeed; if (fspeed < 0)
if(fspeed < 0)
fy = (-fspeed) * timer; fy = (-fspeed) * timer;
if(fy < 0) fy = 0; if (fy < 0)
fy = 0;
// Make sure the whole frame gets displayed, at least... // Make sure the whole frame gets displayed, at least...
if(!screenlist_action) screenlist_action = RENDER_HOLD; if (!screenlist_action)
if((fy) > fhgt - 1) screenlist_action = RENDER_HOLD;
{ if ((fy) > fhgt - 1) {
// Release hold after it has been displayed // Release hold after it has been displayed
if(!screenlist_action || screenlist_action == RENDER_HOLD) if (!screenlist_action || screenlist_action == RENDER_HOLD)
screenlist_action = 0; screenlist_action = 0;
} }
fy %= fhgt; fy %= fhgt;
if(fy > fhgt - hgt) fy = fhgt - hgt; if (fy > fhgt - hgt)
fy = fhgt - hgt;
} else if (fscroll == 'h') { // TODO: Frames don't scroll horizontally yet!
} }
else if (fscroll == 'h')
{ // TODO: Frames don't scroll horizontally yet!
}
//debug("draw_screen: %8x, %i\n", s, timer); //debug("draw_screen: %8x, %i\n", s, timer);
if(!list) return -1; if (!list)
return -1;
//debug("draw_frame: %8x, %i\n", frame, timer); //debug("draw_frame: %8x, %i\n", frame, timer);
LL_Rewind(list); LL_Rewind (list);
do { do {
w = (widget *)LL_Get(list); w = (widget *) LL_Get (list);
if(!w) return -1; if (!w)
return -1;
// TODO: Make this cleaner and more flexible! // TODO: Make this cleaner and more flexible!
switch(w->type) switch (w->type) {
{ case WID_STRING:
case WID_STRING: if ((w->x > 0) && (w->y > 0) && (w->text)) {
if((w->x > 0) && (w->y > 0) && (w->text)) if ((w->y <= hgt + fy) && (w->y > fy)) {
{ strncpy (str, w->text, wid - w->x + 1);
if((w->y <= hgt + fy) && str[wid - w->x + 1] = 0;
(w->y > fy)) lcd.string (w->x + left, w->y + top - fy, str);
{
strncpy(str, w->text, wid - w->x + 1);
str[wid - w->x + 1] = 0;
lcd.string(w->x + left,
w->y + top - fy,
str);
}
} }
break; }
case WID_HBAR: break;
if(reset) case WID_HBAR:
{ if (reset) {
lcd.init_hbar(); lcd.init_hbar ();
reset = 0; reset = 0;
} }
if((w->x > 0) && (w->y > 0)) if ((w->x > 0) && (w->y > 0)) {
{ if ((w->y <= hgt + fy) && (w->y > fy)) {
if((w->y <= hgt + fy) && if (w->length > 0) {
(w->y > fy)) if ((w->length / lcd.cellwid) < wid - w->x + 1)
{ lcd.hbar (w->x + left, w->y + top - fy, w->length);
if(w->length > 0) else
{ lcd.hbar (w->x + left, w->y + top - fy, wid * lcd.cellwid);
if((w->length / lcd.cellwid) < wid - w->x + 1) } else if (w->length < 0) {
lcd.hbar(w->x + left, // TODO: Rearrange stuff to get left-extending
w->y + top - fy, // hbars to draw correctly...
w->length);
else
lcd.hbar(w->x + left,
w->y + top - fy,
wid * lcd.cellwid);
}
else if(w->length < 0)
{
// TODO: Rearrange stuff to get left-extending
// hbars to draw correctly...
// .. er, this'll require driver modifications,
// so I'll leave it out for now.
}
}
}
break;
case WID_VBAR: // FIXME: Vbars don't work in frames!
if(reset)
{
lcd.init_vbar();
reset = 0;
}
if((w->x > 0) && (w->y > 0))
{
if(w->length > 0)
{
lcd.vbar(w->x, w->length);
}
else if(w->length < 0)
{
// TODO: Rearrange stuff to get down-extending
// vbars to draw correctly...
// .. er, this'll require driver modifications, // .. er, this'll require driver modifications,
// so I'll leave it out for now. // so I'll leave it out for now.
} }
} }
break;
case WID_ICON: // FIXME: Not implemented
break;
case WID_TITLE: // FIXME: Doesn't work quite right in frames...
if(!w->text) break;
if(wid < 8) break;
memset(str, 255, wid);
str[2] = ' ';
length = strlen(w->text);
if(length <= wid-6)
{
memcpy(str+3, w->text, length);
str[length+3] = ' ';
}
else // Scroll the title, if it doesn't fit...
{
speed = 1;
x = timer / speed;
y = x / length;
// Make sure the whole title gets displayed, at least...
if(!screenlist_action) screenlist_action = RENDER_HOLD;
if(x > length - 6)
{
// Release hold after it has been displayed
if(!screenlist_action || screenlist_action == RENDER_HOLD)
screenlist_action = 0;
}
x %= (length);
x -= 3;
if(x < 0) x = 0;
if(x > length - (wid-6)) x = length - (wid-6);
if(y&1) // Scrolling backwards...
{
x = (length-(wid-6)) - x;
}
strncpy(str+3, w->text+x, (wid-6));
str[wid-3] = ' ';
}
str[wid] = 0;
lcd.string(1 + left, 1 + top, str);
break;
case WID_SCROLLER: // FIXME: doesn't work in frames...
{
int offset;
int screen_width;
if (!w->text) break;
if (w->right < w->left) break;
//printf("rendering: %s %d\n",w->text,timer);
screen_width = w->right - w->left + 1;
switch (w->length)
{ // actually, direction...
// FIXED: Horz scrollers don't show the
// last letter in the string... (1-off error?)
case 'h':
length = strlen(w->text) + 1;
if (length <= screen_width)
{
/* it fits within the box, just render it */
lcd.string(w->left,w->top,w->text);
}
else
{
int effLength = length - screen_width;
int necessaryTimeUnits = 0;
if (!screenlist_action) screenlist_action = RENDER_HOLD;
if (w->speed > 0) {
necessaryTimeUnits = effLength * w->speed;
if (((timer / (effLength*w->speed)) % 2) == 0) {
//wiggle one way
offset = (timer % (effLength*w->speed))
/ w->speed;
}
else
{
//wiggle the other
offset = (((timer % (effLength*w->speed))
- (effLength*w->speed) + 1)
/ w->speed) * -1;
}
}
else if (w->speed < 0)
{
necessaryTimeUnits = effLength / (w->speed * -1);
if (((timer / (effLength/(w->speed*-1))) % 2) == 0)
{
offset = (timer % (effLength/(w->speed*-1)))
* w->speed * -1;
}
else
{
offset = (((timer % (effLength/(w->speed*-1)))
* w->speed * -1) - effLength + 1) * -1;
}
}
else
{
offset = 0;
if(screenlist_action == RENDER_HOLD)
screenlist_action = 0;
}
if (timer > necessaryTimeUnits)
{
if(screenlist_action == RENDER_HOLD)
screenlist_action = 0;
}
if (offset <= length)
{
strncpy(str,&((w->text)[offset]),screen_width);
str[screen_width] = '\0';
//printf("%s : %d\n",str,length-offset);
}
else
{
str[0] = '\0';
}
lcd.string(w->left,w->top,str);
}
break;
// FIXME: Vert scrollers don't always seem to scroll
// back up after hitting the bottom. They jump back to
// the top instead... (nevermind?)
case 'v':
{
int i=0;
length = strlen(w->text);
if (length <= screen_width)
{
/* no scrolling required...*/
lcd.string(w->left,w->top,w->text);
}
else
{
int lines_required =
(length / screen_width)
+ (length % screen_width ? 1 : 0);
int available_lines = (w->bottom - w->top + 1);
if (lines_required <= available_lines)
{
// easy...
for(i=0;i<lines_required;i++)
{
strncpy(str,
&((w->text)[i*screen_width]),
screen_width);
str[screen_width] = '\0';
lcd.string(w->left,w->top + i,str);
}
}
else
{
int necessaryTimeUnits = 0;
int effLines = lines_required - available_lines + 1;
int begin = 0;
if (!screenlist_action)
screenlist_action = RENDER_HOLD;
//printf("length: %d sw: %d lines req: %d avail lines: %d effLines: %d \n",length,screen_width,lines_required,available_lines,effLines);
if (w->speed > 0)
{
necessaryTimeUnits = effLines * w->speed;
if (((timer / (effLines*w->speed)) % 2) == 0)
{
//printf("up ");
begin = (timer % (effLines*w->speed))
/ w->speed;
}
else
{
//printf("down ");
begin = (((timer % (effLines*w->speed))
- (effLines*w->speed) + 1)/w->speed)
* -1;
}
}
else if (w->speed < 0)
{
necessaryTimeUnits = effLines / (w->speed * -1);
if (((timer / (effLines/(w->speed*-1))) % 2) == 0)
{
begin = (timer % (effLines/(w->speed*-1)))
* w->speed * -1;
}
else
{
begin = (((timer % (effLines/(w->speed*-1)))
* w->speed * -1) - effLines + 1)
* -1;
}
}
else
{
begin = 0;
}
//printf("rendering begin: %d timer: %d effLines: %d\n",begin,timer,effLines);
for(i=begin;i<begin+available_lines;i++)
{
strncpy(str,
&((w->text)[i*(screen_width)]),
screen_width);
str[screen_width] = '\0';
//printf("rendering: '%s' of %s\n",
//str,w->text);
lcd.string(w->left,w->top + (i-begin),str);
}
if (timer > necessaryTimeUnits)
{
if(screenlist_action == RENDER_HOLD)
screenlist_action = 0;
}
}
}
break;
}
}
break;
} }
case WID_FRAME: break;
case WID_VBAR: // FIXME: Vbars don't work in frames!
if (reset) {
lcd.init_vbar ();
reset = 0;
}
if ((w->x > 0) && (w->y > 0)) {
if (w->length > 0) {
lcd.vbar (w->x, w->length);
} else if (w->length < 0) {
// TODO: Rearrange stuff to get down-extending
// vbars to draw correctly...
// .. er, this'll require driver modifications,
// so I'll leave it out for now.
}
}
break;
case WID_ICON: // FIXME: Not implemented
break;
case WID_TITLE: // FIXME: Doesn't work quite right in frames...
if (!w->text)
break;
if (wid < 8)
break;
memset (str, 255, wid);
str[2] = ' ';
length = strlen (w->text);
if (length <= wid - 6) {
memcpy (str + 3, w->text, length);
str[length + 3] = ' ';
} else // Scroll the title, if it doesn't fit...
{
speed = 1;
x = timer / speed;
y = x / length;
// Make sure the whole title gets displayed, at least...
if (!screenlist_action)
screenlist_action = RENDER_HOLD;
if (x > length - 6) {
// Release hold after it has been displayed
if (!screenlist_action || screenlist_action == RENDER_HOLD)
screenlist_action = 0;
}
x %= (length);
x -= 3;
if (x < 0)
x = 0;
if (x > length - (wid - 6))
x = length - (wid - 6);
if (y & 1) // Scrolling backwards...
{
x = (length - (wid - 6)) - x;
}
strncpy (str + 3, w->text + x, (wid - 6));
str[wid - 3] = ' ';
}
str[wid] = 0;
lcd.string (1 + left, 1 + top, str);
break;
case WID_SCROLLER: // FIXME: doesn't work in frames...
{
int offset;
int screen_width;
if (!w->text)
break;
if (w->right < w->left)
break;
//printf("rendering: %s %d\n",w->text,timer);
screen_width = w->right - w->left + 1;
switch (w->length) { // actually, direction...
// FIXED: Horz scrollers don't show the
// last letter in the string... (1-off error?)
case 'h':
length = strlen (w->text) + 1;
if (length <= screen_width) {
/* it fits within the box, just render it */
lcd.string (w->left, w->top, w->text);
} else {
int effLength = length - screen_width;
int necessaryTimeUnits = 0;
if (!screenlist_action)
screenlist_action = RENDER_HOLD;
if (w->speed > 0) {
necessaryTimeUnits = effLength * w->speed;
if (((timer / (effLength * w->speed)) % 2) == 0) {
//wiggle one way
offset = (timer % (effLength * w->speed))
/ w->speed;
} else {
//wiggle the other
offset = (((timer % (effLength * w->speed))
- (effLength * w->speed) + 1)
/ w->speed) * -1;
}
} else if (w->speed < 0) {
necessaryTimeUnits = effLength / (w->speed * -1);
if (((timer / (effLength / (w->speed * -1))) % 2) == 0) {
offset = (timer % (effLength / (w->speed * -1)))
* w->speed * -1;
} else {
offset = (((timer % (effLength / (w->speed * -1)))
* w->speed * -1) - effLength + 1) * -1;
}
} else {
offset = 0;
if (screenlist_action == RENDER_HOLD)
screenlist_action = 0;
}
if (timer > necessaryTimeUnits) {
if (screenlist_action == RENDER_HOLD)
screenlist_action = 0;
}
if (offset <= length) {
strncpy (str, &((w->text)[offset]), screen_width);
str[screen_width] = '\0';
//printf("%s : %d\n",str,length-offset);
} else {
str[0] = '\0';
}
lcd.string (w->left, w->top, str);
}
break;
// FIXME: Vert scrollers don't always seem to scroll
// back up after hitting the bottom. They jump back to
// the top instead... (nevermind?)
case 'v':
{
int i = 0;
length = strlen (w->text);
if (length <= screen_width) {
/* no scrolling required... */
lcd.string (w->left, w->top, w->text);
} else {
int lines_required = (length / screen_width)
+ (length % screen_width ? 1 : 0);
int available_lines = (w->bottom - w->top + 1);
if (lines_required <= available_lines) {
// easy...
for (i = 0; i < lines_required; i++) {
strncpy (str, &((w->text)[i * screen_width]), screen_width);
str[screen_width] = '\0';
lcd.string (w->left, w->top + i, str);
}
} else {
int necessaryTimeUnits = 0;
int effLines = lines_required - available_lines + 1;
int begin = 0;
if (!screenlist_action)
screenlist_action = RENDER_HOLD;
//printf("length: %d sw: %d lines req: %d avail lines: %d effLines: %d \n",length,screen_width,lines_required,available_lines,effLines);
if (w->speed > 0) {
necessaryTimeUnits = effLines * w->speed;
if (((timer / (effLines * w->speed)) % 2) == 0) {
//printf("up ");
begin = (timer % (effLines * w->speed))
/ w->speed;
} else {
//printf("down ");
begin = (((timer % (effLines * w->speed))
- (effLines * w->speed) + 1) / w->speed)
* -1;
}
} else if (w->speed < 0) {
necessaryTimeUnits = effLines / (w->speed * -1);
if (((timer / (effLines / (w->speed * -1))) % 2) == 0) {
begin = (timer % (effLines / (w->speed * -1)))
* w->speed * -1;
} else {
begin = (((timer % (effLines / (w->speed * -1)))
* w->speed * -1) - effLines + 1)
* -1;
}
} else {
begin = 0;
}
//printf("rendering begin: %d timer: %d effLines: %d\n",begin,timer,effLines);
for (i = begin; i < begin + available_lines; i++) {
strncpy (str, &((w->text)[i * (screen_width)]), screen_width);
str[screen_width] = '\0';
//printf("rendering: '%s' of %s\n",
//str,w->text);
lcd.string (w->left, w->top + (i - begin), str);
}
if (timer > necessaryTimeUnits) {
if (screenlist_action == RENDER_HOLD)
screenlist_action = 0;
}
}
}
break;
}
}
break;
}
case WID_FRAME:
{ {
// FIXME: doesn't handle nested frames quite right! // FIXME: doesn't handle nested frames quite right!
// doesn't handle scrolling in nested frames at all... // doesn't handle scrolling in nested frames at all...
@@ -493,39 +422,31 @@ static int draw_frame(LL *list, char fscroll,
new_top = top + w->top - 1; new_top = top + w->top - 1;
new_right = left + w->right; new_right = left + w->right;
new_bottom = top + w->bottom; new_bottom = top + w->bottom;
if(new_right > right) new_right = right; if (new_right > right)
if(new_bottom > bottom) new_bottom = bottom; new_right = right;
if(new_left >= right || if (new_bottom > bottom)
new_top >= bottom) new_bottom = bottom;
{ // Do nothing if it's invisible... if (new_left >= right || new_top >= bottom) { // Do nothing if it's invisible...
} } else {
else draw_frame (w->kids, w->length, new_left, new_top, new_right, new_bottom, w->wid, w->hgt, w->speed, timer);
{
draw_frame(w->kids, w->length,
new_left, new_top, new_right, new_bottom,
w->wid, w->hgt,
w->speed, timer);
} }
} }
break; break;
case WID_NUM: // FIXME: doesn't work in frames... case WID_NUM: // FIXME: doesn't work in frames...
if((w->x > 0) && (w->y >= 0) && (w->y <= 9)) if ((w->x > 0) && (w->y >= 0) && (w->y <= 9)) {
{ if (reset) {
if(reset) lcd.init_num ();
{ reset = 0;
lcd.init_num();
reset = 0;
}
lcd.num(w->x + left, w->y);
} }
break; lcd.num (w->x + left, w->y);
case WID_NONE: }
default: break;
break; case WID_NONE:
default:
break;
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
return 0; return 0;
} }
+1 -1
View File
@@ -23,7 +23,7 @@ extern int backlight_state;
extern int backlight_brightness; extern int backlight_brightness;
extern int backlight_off_brightness; extern int backlight_off_brightness;
extern int output_state; extern int output_state;
int draw_screen(screen *s, int timer); int draw_screen (screen * s, int timer);
#endif #endif
+77 -76
View File
@@ -13,159 +13,160 @@
#include "screen.h" #include "screen.h"
screen * screen_create() screen *
screen_create ()
{ {
screen *s; screen *s;
s = malloc(sizeof(screen)); s = malloc (sizeof (screen));
if(!s) if (!s) {
{ fprintf (stderr, "screen_create: Error allocating new screen\n");
fprintf(stderr, "screen_create: Error allocating new screen\n");
return NULL; return NULL;
} }
s->id=NULL; s->id = NULL;
s->name=NULL; s->name = NULL;
s->priority=128; s->priority = 128;
// TODO: Make the screen duration configurable! // TODO: Make the screen duration configurable!
s->duration = 32; s->duration = 32;
s->heartbeat = 1; s->heartbeat = 1;
s->wid = lcd.wid; s->wid = lcd.wid;
s->hgt = lcd.hgt; s->hgt = lcd.hgt;
s->parent = NULL; s->parent = NULL;
s->widgets=NULL; s->widgets = NULL;
s->widgets = LL_new(); s->widgets = LL_new ();
if(!s->widgets) if (!s->widgets) {
{ fprintf (stderr, "screen_create: Error allocating widget list\n");
fprintf(stderr, "screen_create: Error allocating widget list\n");
return NULL; return NULL;
} }
return s; return s;
} }
int screen_destroy(screen *s) int
screen_destroy (screen * s)
{ {
widget *w; widget *w;
if(!s) return -1; if (!s)
return -1;
LL_Rewind(s->widgets);
LL_Rewind (s->widgets);
do { do {
// Free a widget... // Free a widget...
w = LL_Get(s->widgets); w = LL_Get (s->widgets);
widget_destroy(w); widget_destroy (w);
} while (LL_Next(s->widgets) == 0); } while (LL_Next (s->widgets) == 0);
LL_Destroy(s->widgets); LL_Destroy (s->widgets);
if(s->id) if (s->id)
free(s->id); free (s->id);
if(s->name) if (s->name)
free(s->name); free (s->name);
free(s); free (s);
return 0; return 0;
} }
screen *screen_find(client *c, char *id) screen *
screen_find (client * c, char *id)
{ {
screen *s; screen *s;
if(!c) return NULL; if (!c)
if(!id) return NULL; return NULL;
if (!id)
return NULL;
debug("client_find_screen(%s)\n", id); debug ("client_find_screen(%s)\n", id);
LL_Rewind(c->data->screenlist); LL_Rewind (c->data->screenlist);
do { do {
s = LL_Get(c->data->screenlist); s = LL_Get (c->data->screenlist);
if( (s) && (0 == strcmp(s->id, id))) if ((s) && (0 == strcmp (s->id, id))) {
{ debug ("client_find_screen: Found %s\n", id);
debug("client_find_screen: Found %s\n", id);
return s; return s;
} }
} while(LL_Next(c->data->screenlist) == 0); } while (LL_Next (c->data->screenlist) == 0);
return NULL; return NULL;
} }
int screen_add(client *c, char *id) int
screen_add (client * c, char *id)
{ {
screen *s; screen *s;
if(!c) return -1; if (!c)
if(!id) return -1; return -1;
if (!id)
return -1;
// Make sure this screen doesn't already exist... // Make sure this screen doesn't already exist...
s = screen_find(c, id); s = screen_find (c, id);
if(s) if (s) {
{
return 1; return 1;
} }
s = screen_create(); s = screen_create ();
if(!s) if (!s) {
{ fprintf (stderr, "screen_add: Error creating screen\n");
fprintf(stderr, "screen_add: Error creating screen\n");
return -1; return -1;
} }
s->parent = c; s->parent = c;
s->id = strdup(id); s->id = strdup (id);
if(!s->id) if (!s->id) {
{ fprintf (stderr, "screen_add: Error allocating name\n");
fprintf(stderr, "screen_add: Error allocating name\n");
return -1; return -1;
} }
// TODO: Check for errors here? // TODO: Check for errors here?
LL_Push(c->data->screenlist, (void *)s); LL_Push (c->data->screenlist, (void *) s);
// Now, add it to the screenlist... // Now, add it to the screenlist...
if(screenlist_add(s) < 0) if (screenlist_add (s) < 0) {
{ fprintf (stderr, "screen_add: Error queueing new screen\n");
fprintf(stderr, "screen_add: Error queueing new screen\n");
return -1; return -1;
} }
return 0; return 0;
} }
int screen_remove(client *c, char *id) int
screen_remove (client * c, char *id)
{ {
screen *s; screen *s;
if(!c) return -1; if (!c)
if(!id) return -1; return -1;
if (!id)
return -1;
// Make sure this screen *does* exist... // Make sure this screen *does* exist...
s = screen_find(c, id); s = screen_find (c, id);
if(!s) if (!s) {
{ fprintf (stderr, "screen_remove: Error finding screen %s\n", id);
fprintf(stderr, "screen_remove: Error finding screen %s\n", id);
return 1; return 1;
} }
// TODO: Check for errors here? // TODO: Check for errors here?
LL_Remove(c->data->screenlist, (void *)s); LL_Remove (c->data->screenlist, (void *) s);
// ... and here? // ... and here?
screen_destroy(s); screen_destroy (s);
// Now, remove it from the screenlist... // Now, remove it from the screenlist...
if(screenlist_remove_all(s) < 0) if (screenlist_remove_all (s) < 0) {
{
// Not a serious error.. // Not a serious error..
fprintf(stderr, "screen_remove: Error dequeueing screen\n"); fprintf (stderr, "screen_remove: Error dequeueing screen\n");
return 0; return 0;
} }
return 0; return 0;
} }
+14 -15
View File
@@ -4,26 +4,25 @@
#include "../shared/LL.h" #include "../shared/LL.h"
#include "clients.h" #include "clients.h"
typedef struct screen typedef struct screen {
{ char *id;
char *id; char *name;
char *name; int wid, hgt;
int wid, hgt; int priority;
int priority; int duration;
int duration; int heartbeat;
int heartbeat; LL *widgets;
LL * widgets; client *parent;
client *parent;
} screen; } screen;
screen * screen_create(); screen *screen_create ();
int screen_destroy(screen *s); int screen_destroy (screen * s);
screen * screen_find(client *c, char *id); screen *screen_find (client * c, char *id);
int screen_add(client *c, char *id); int screen_add (client * c, char *id);
int screen_remove(client *c, char *id); int screen_remove (client * c, char *id);
#endif #endif
+125 -108
View File
@@ -10,79 +10,85 @@
int screenlist_action=0; int screenlist_action = 0;
int timer=0; int timer = 0;
LL * screenlist; LL *screenlist;
int screenlist_add_end(screen *screen); int screenlist_add_end (screen * screen);
screen * screenlist_next_roll(); screen *screenlist_next_roll ();
screen * screenlist_prev_roll(); screen *screenlist_prev_roll ();
screen * screenlist_next_priority(); screen *screenlist_next_priority ();
int compare_priority(void *one, void *two); int compare_priority (void *one, void *two);
int compare_addresses(void *one, void *two); int compare_addresses (void *one, void *two);
int screenlist_init() int
screenlist_init ()
{ {
debug("screenlist_init()\n"); debug ("screenlist_init()\n");
screenlist = LL_new(); screenlist = LL_new ();
if(!screenlist) if (!screenlist) {
{ fprintf (stderr, "screenlist_init: Error allocating list\n");
fprintf(stderr, "screenlist_init: Error allocating list\n");
return -1; return -1;
} }
screenlist_action = 0; screenlist_action = 0;
timer = 0; timer = 0;
return 0; return 0;
} }
int screenlist_shutdown() int
screenlist_shutdown ()
{ {
debug("screenlist_shutdown()\n"); debug ("screenlist_shutdown()\n");
LL_Destroy(screenlist); LL_Destroy (screenlist);
return 0; return 0;
} }
int screenlist_remove(screen *s) int
screenlist_remove (screen * s)
{ {
debug("screenlist_remove()\n"); debug ("screenlist_remove()\n");
if(!LL_Remove(screenlist, s)) if (!LL_Remove (screenlist, s))
return -1; return -1;
else return 0; else
return 0;
} }
int screenlist_remove_all(screen *s) int
screenlist_remove_all (screen * s)
{ {
int i=0; int i = 0;
debug("screenlist_remove_all()\n"); debug ("screenlist_remove_all()\n");
while(LL_Remove(screenlist, s)) while (LL_Remove (screenlist, s))
i++; i++;
debug("screenlist_remove_all()... got %i\n", i); debug ("screenlist_remove_all()... got %i\n", i);
return i; return i;
} }
LL * screenlist_getlist() LL *
screenlist_getlist ()
{ {
debug("screenlist_getlist()\n"); debug ("screenlist_getlist()\n");
return screenlist; return screenlist;
} }
screen * screenlist_current() screen *
screenlist_current ()
{ {
char str[256]; char str[256];
screen *s; screen *s;
@@ -92,55 +98,48 @@ screen * screenlist_current()
//debug("screenlist_current:\n"); //debug("screenlist_current:\n");
//LL_dprint(screenlist); //LL_dprint(screenlist);
s = (screen *)LL_GetFirst(screenlist);
s = (screen *) LL_GetFirst (screenlist);
// FIXME: Make sure the screen/client exists! // FIXME: Make sure the screen/client exists!
if(s != old_s) if (s != old_s) {
{ debug ("screenlist_current: new screen\n");
debug("screenlist_current: new screen\n");
timer = 0; timer = 0;
// Tell the client we're done with the current screen // Tell the client we're done with the current screen
if(old_s) if (old_s) {
{
//debug("screenlist_current: ignoring old screen\n"); //debug("screenlist_current: ignoring old screen\n");
LL_Rewind(screenlist); LL_Rewind (screenlist);
if(old_s != LL_Find(screenlist, compare_addresses, old_s)) if (old_s != LL_Find (screenlist, compare_addresses, old_s)) {
{ debug ("screenlist: Didn't find screen 0x%8x!\n", (int) old_s);
debug("screenlist: Didn't find screen 0x%8x!\n", (int)old_s); } else {
}
else {
//debug("screenlist_current: ... sending ignore\n"); //debug("screenlist_current: ... sending ignore\n");
c = old_s->parent; c = old_s->parent;
if(c) // Tell the client we're not listening any more... if (c) // Tell the client we're not listening any more...
{ {
sprintf(str, "ignore %s\n", old_s->id); sprintf (str, "ignore %s\n", old_s->id);
sock_send_string(c->sock, str); sock_send_string (c->sock, str);
} } else // The server has the display, so do nothing
else // The server has the display, so do nothing
{ {
} }
//debug("screenlist_current: ... sent ignore\n"); //debug("screenlist_current: ... sent ignore\n");
} }
} }
if(s) if (s) {
{
//debug("screenlist_current: listening to new screen\n"); //debug("screenlist_current: listening to new screen\n");
c = s->parent; c = s->parent;
if(c) // Tell the client we're paying attention... if (c) // Tell the client we're paying attention...
{ {
sprintf(str, "listen %s\n", s->id); sprintf (str, "listen %s\n", s->id);
sock_send_string(c->sock, str); sock_send_string (c->sock, str);
} } else // The server has the display, so do nothing
else // The server has the display, so do nothing
{ {
} }
} }
} }
old_s = s; old_s = s;
@@ -149,33 +148,37 @@ screen * screenlist_current()
return s; return s;
} }
int screenlist_add(screen *s) int
screenlist_add (screen * s)
{ {
// TODO: Different queueing modes... // TODO: Different queueing modes...
return screenlist_add_end(s); return screenlist_add_end (s);
} }
screen * screenlist_next() screen *
screenlist_next ()
{ {
screen *s; screen *s;
//debug("Screenlist_next()\n"); //debug("Screenlist_next()\n");
s = screenlist_current(); s = screenlist_current ();
// If we're on hold, don't advance! // If we're on hold, don't advance!
if(screenlist_action == SCR_HOLD) return s; if (screenlist_action == SCR_HOLD)
if(screenlist_action == RENDER_HOLD) return s; return s;
if (screenlist_action == RENDER_HOLD)
return s;
// Otherwise, reset it to regular operation // Otherwise, reset it to regular operation
screenlist_action = 0; screenlist_action = 0;
//debug("Screenlist_next: calling handler...\n"); //debug("Screenlist_next: calling handler...\n");
// Call the selected queuing function... // Call the selected queuing function...
// TODO: Different queueing modes... // TODO: Different queueing modes...
s = screenlist_next_priority(); s = screenlist_next_priority ();
//s = screenlist_next_roll(); //s = screenlist_next_roll();
//debug("Screenlist_next() done\n"); //debug("Screenlist_next() done\n");
@@ -183,88 +186,102 @@ screen * screenlist_next()
return s; return s;
} }
screen * screenlist_prev() screen *
screenlist_prev ()
{ {
screen *s; screen *s;
s = screenlist_current(); s = screenlist_current ();
// If we're on hold, don't advance! // If we're on hold, don't advance!
if(screenlist_action == SCR_HOLD) return s; if (screenlist_action == SCR_HOLD)
if(screenlist_action == RENDER_HOLD) return s; return s;
if (screenlist_action == RENDER_HOLD)
return s;
// Otherwise, reset it no regular operation // Otherwise, reset it no regular operation
screenlist_action = 0; screenlist_action = 0;
// Call the selected queuing function... // Call the selected queuing function...
// TODO: Different queueing modes... // TODO: Different queueing modes...
s = screenlist_prev_roll(); s = screenlist_prev_roll ();
return s; return s;
} }
// Adds new screens to the end of the screenlist... // Adds new screens to the end of the screenlist...
int screenlist_add_end(screen *screen) int
screenlist_add_end (screen * screen)
{ {
debug("screenlist_add_end()\n"); debug ("screenlist_add_end()\n");
return LL_Push(screenlist, (void *)screen); return LL_Push (screenlist, (void *) screen);
} }
// Simple round-robin approach to screen cycling... // Simple round-robin approach to screen cycling...
screen * screenlist_next_roll() screen *
screenlist_next_roll ()
{ {
//debug("screenlist_next_roll()\n"); //debug("screenlist_next_roll()\n");
if(LL_UnRoll(screenlist) != 0) return NULL;
return screenlist_current(); if (LL_UnRoll (screenlist) != 0)
return NULL;
return screenlist_current ();
} }
// Strict priority queue approach... // Strict priority queue approach...
screen * screenlist_next_priority() screen *
screenlist_next_priority ()
{ {
//screen *s, *t; //screen *s, *t;
//debug("screenlist_next_priority\n"); //debug("screenlist_next_priority\n");
if(LL_UnRoll(screenlist) != 0) return NULL; if (LL_UnRoll (screenlist) != 0)
return NULL;
LL_Sort(screenlist, compare_priority); LL_Sort (screenlist, compare_priority);
return screenlist_current(); return screenlist_current ();
} }
// Simple round-robin approach to screen cycling... // Simple round-robin approach to screen cycling...
screen * screenlist_prev_roll() screen *
screenlist_prev_roll ()
{ {
//debug("screenlist_prev_roll()\n"); //debug("screenlist_prev_roll()\n");
if(LL_Roll(screenlist) != 0) return NULL;
return screenlist_current(); if (LL_Roll (screenlist) != 0)
return NULL;
return screenlist_current ();
} }
int compare_priority(void *one, void *two) int
compare_priority (void *one, void *two)
{ {
screen *a, *b; screen *a, *b;
//debug("compare_priority: %8x %8x\n", one, two); //debug("compare_priority: %8x %8x\n", one, two);
if(!one) return 0; if (!one)
if(!two) return 0; return 0;
if (!two)
a = (screen *)one; return 0;
b = (screen *)two;
a = (screen *) one;
b = (screen *) two;
//debug("compare_priority: done?\n"); //debug("compare_priority: done?\n");
return (a->priority - b->priority); return (a->priority - b->priority);
} }
int compare_addresses(void *one, void *two) int
compare_addresses (void *one, void *two)
{ {
//printf("compare_addresses: 0x%x == 0x%x ???\n", one, two); //printf("compare_addresses: 0x%x == 0x%x ???\n", one, two);
//if(one == two) printf("Yes!\n"); //if(one == two) printf("Yes!\n");
+9 -9
View File
@@ -14,18 +14,18 @@
extern int screenlist_action; extern int screenlist_action;
extern int timer; extern int timer;
int screenlist_init(); int screenlist_init ();
int screenlist_shutdown(); int screenlist_shutdown ();
LL * screenlist_getlist(); LL *screenlist_getlist ();
screen * screenlist_current(); screen *screenlist_current ();
int screenlist_add(screen *s); int screenlist_add (screen * s);
screen * screenlist_next(); screen *screenlist_next ();
screen * screenlist_prev(); screen *screenlist_prev ();
int screenlist_remove(screen *s); int screenlist_remove (screen * s);
int screenlist_remove_all(screen *s); int screenlist_remove_all (screen * s);
#endif #endif
+102 -131
View File
@@ -23,210 +23,181 @@ char *id = "ClientList";
char *name = "Client List"; char *name = "Client List";
char title[256] = "LCDproc Server"; char title[256] = "LCDproc Server";
char one[256] = ""; char one[256] = "";
char two[256] = ""; char two[256] = "";
char three[256] = ""; char three[256] = "";
int server_screen_init() int
server_screen_init ()
{ {
widget *w; widget *w;
debug("server_screen_init\n"); debug ("server_screen_init\n");
server_screen = screen_create();
if(!server_screen) server_screen = screen_create ();
{
fprintf(stderr, "server_screen_init: Error allocating screen\n"); if (!server_screen) {
fprintf (stderr, "server_screen_init: Error allocating screen\n");
return -1; return -1;
} }
server_screen->id = id; server_screen->id = id;
server_screen->name = name; server_screen->name = name;
server_screen->duration = 8; // 1 second, instead of 4... server_screen->duration = 8; // 1 second, instead of 4...
// TODO: Error-checking? // TODO: Error-checking?
widget_add(server_screen, "title", "title", NULL, 1); widget_add (server_screen, "title", "title", NULL, 1);
widget_add(server_screen, "one" , "string", NULL, 1); widget_add (server_screen, "one", "string", NULL, 1);
widget_add(server_screen, "two" , "string", NULL, 1); widget_add (server_screen, "two", "string", NULL, 1);
widget_add(server_screen, "three", "string", NULL, 1); widget_add (server_screen, "three", "string", NULL, 1);
// Now, initialize all the widgets... // Now, initialize all the widgets...
w = widget_find(server_screen, "title"); w = widget_find (server_screen, "title");
if(w) if (w) {
{
w->text = title; w->text = title;
} else {
fprintf (stderr, "server_screen_init: Can't find title\n");
} }
else
{ w = widget_find (server_screen, "one");
fprintf(stderr, "server_screen_init: Can't find title\n"); if (w) {
}
w = widget_find(server_screen, "one");
if(w)
{
w->x = 1; w->x = 1;
w->y = 2; w->y = 2;
w->text = one; w->text = one;
} else {
fprintf (stderr, "server_screen_init: Can't find widget one\n");
} }
else
{ w = widget_find (server_screen, "two");
fprintf(stderr, "server_screen_init: Can't find widget one\n"); if (w) {
}
w = widget_find(server_screen, "two");
if(w)
{
w->x = 1; w->x = 1;
w->y = 3; w->y = 3;
w->text = two; w->text = two;
} else {
fprintf (stderr, "server_screen_init: Can't find widget two\n");
} }
else
{ w = widget_find (server_screen, "three");
fprintf(stderr, "server_screen_init: Can't find widget two\n"); if (w) {
}
w = widget_find(server_screen, "three");
if(w)
{
w->x = 1; w->x = 1;
w->y = 4; w->y = 4;
w->text = three; w->text = three;
} else {
fprintf (stderr, "server_screen_init: Can't find widget three\n");
} }
else
{
fprintf(stderr, "server_screen_init: Can't find widget three\n");
}
// And enqueue the screen // And enqueue the screen
screenlist_add(server_screen); screenlist_add (server_screen);
debug ("server_screen_init done\n");
debug("server_screen_init done\n");
return 0; return 0;
} }
int update_server_screen(int timer) int
update_server_screen (int timer)
{ {
client *c; client *c;
int num_clients; int num_clients;
screen *s; screen *s;
int num_screens; int num_screens;
// Draw a title... // Draw a title...
//strcpy(title, "LCDproc Server"); //strcpy(title, "LCDproc Server");
// Now get info on the number of connected clients... // Now get info on the number of connected clients...
num_clients=0; num_screens=0; num_clients = 0;
LL_Rewind(clients); num_screens = 0;
LL_Rewind (clients);
do { do {
c = LL_Get(clients); c = LL_Get (clients);
if(c) if (c) {
{
num_clients++; num_clients++;
LL_Rewind(c->data->screenlist); LL_Rewind (c->data->screenlist);
do { do {
s = LL_Get(c->data->screenlist); s = LL_Get (c->data->screenlist);
if(s) if (s) {
{
num_screens++; num_screens++;
} }
} while(LL_Next(c->data->screenlist) == 0); } while (LL_Next (c->data->screenlist) == 0);
} }
} while(LL_Next(clients) == 0); } while (LL_Next (clients) == 0);
if(lcd.hgt >= 3) if (lcd.hgt >= 3) {
{ sprintf (one, "Clients: %i", num_clients);
sprintf(one, "Clients: %i", num_clients); sprintf (two, "Screens: %i", num_screens);
sprintf(two, "Screens: %i", num_screens); } else {
if (lcd.wid >= 20)
sprintf (one, "%i Client%s, %i Screen%s", num_clients, (num_clients == 1) ? "" : "s", num_screens, (num_screens == 1) ? "" : "s");
else // 16x2 size
sprintf (one, "%i Cli%s, %i Scr%s", num_clients, (num_clients == 1) ? "" : "s", num_screens, (num_screens == 1) ? "" : "s");
} }
else
{
if(lcd.wid >= 20)
sprintf(one, "%i Client%s, %i Screen%s",
num_clients, (num_clients==1)?"":"s",
num_screens, (num_screens==1)?"":"s");
else // 16x2 size
sprintf(one, "%i Cli%s, %i Scr%s",
num_clients, (num_clients==1)?"":"s",
num_screens, (num_screens==1)?"":"s");
}
return 0; return 0;
} }
int no_screen_screen(int timer) int
no_screen_screen (int timer)
{ {
lcd.clear();
lcd.string(1, 1, "Error: No screen!"); lcd.clear ();
lcd.flush(); lcd.string (1, 1, "Error: No screen!");
lcd.flush ();
return 0; return 0;
} }
int goodbye_screen() int
goodbye_screen ()
{ {
char char
*b20 = " ", *b20 = " ", *t20 = " Thanks for using ",
*t20 = " Thanks for using ",
#ifdef LINUX #ifdef LINUX
*l20 = " LCDproc and Linux! ", *l20 = " LCDproc and Linux! ",
#else #else
*l20 = " LCDproc! ", *l20 = " LCDproc! ",
#endif #endif
*b16 = " ", *b16 = " ", *t16 = "Thanks for using",
*t16 = "Thanks for using",
#ifdef LINUX #ifdef LINUX
*l16 = " LCDproc+Linux! ", *l16 = " LCDproc+Linux! ",
#else #else
*l16 = " LCDproc! ", *l16 = " LCDproc! ",
#endif #endif
*nil = ""; *nil = "";
lcd.clear();
if(lcd.hgt >= 4) lcd.clear ();
{
if(lcd.wid >= 20) if (lcd.hgt >= 4) {
{ if (lcd.wid >= 20) {
lcd.string(1, 1, b20); lcd.string (1, 1, b20);
lcd.string(1, 2, t20); lcd.string (1, 2, t20);
lcd.string(1, 3, l20); lcd.string (1, 3, l20);
lcd.string(1, 4, b20); lcd.string (1, 4, b20);
} else {
lcd.string (1, 1, b16);
lcd.string (1, 2, t16);
lcd.string (1, 3, l16);
lcd.string (1, 4, b16);
} }
else } else {
{ if (lcd.wid >= 20) {
lcd.string(1, 1, b16); lcd.string (1, 1, t20);
lcd.string(1, 2, t16); lcd.string (1, 2, l20);
lcd.string(1, 3, l16); } else {
lcd.string(1, 4, b16); lcd.string (1, 1, t16);
lcd.string (1, 2, l16);
} }
} }
else
{ lcd.flush ();
if(lcd.wid >= 20)
{
lcd.string(1, 1, t20);
lcd.string(1, 2, l20);
}
else
{
lcd.string(1, 1, t16);
lcd.string(1, 2, l16);
}
}
lcd.flush();
return 0; return 0;
} }
+4 -4
View File
@@ -6,9 +6,9 @@
extern screen *server_screen; extern screen *server_screen;
int server_screen_init(); int server_screen_init ();
int update_server_screen(int timer); int update_server_screen (int timer);
int no_screen_screen(int timer); int no_screen_screen (int timer);
int goodbye_screen(); int goodbye_screen ();
#endif #endif
+110 -131
View File
@@ -36,65 +36,63 @@ int read_from_client (int filedes);
// Creates a socket in internet space // Creates a socket in internet space
int sock_create_inet_socket(unsigned short int port) int
sock_create_inet_socket (unsigned short int port)
{ {
struct sockaddr_in name; struct sockaddr_in name;
int sock; int sock;
debug ("sock_create_inet_socket(%i)\n", port);
/* Create the socket. */
//debug("Creating Inet Socket\n");
sock = socket (PF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror ("Error creating socket");
return -1;
}
/* Give the socket a name. */
//debug("Binding Inet Socket\n");
name.sin_family = AF_INET;
name.sin_port = htons (port);
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) {
perror ("Error binding socket");
return -1;
}
return sock;
debug("sock_create_inet_socket(%i)\n", port);
/* Create the socket. */
//debug("Creating Inet Socket\n");
sock = socket (PF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
perror("Error creating socket");
return -1;
}
/* Give the socket a name. */
//debug("Binding Inet Socket\n");
name.sin_family = AF_INET;
name.sin_port = htons (port);
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
{
perror("Error binding socket");
return -1;
}
return sock;
} }
//int StartSocketServer() //int StartSocketServer()
int sock_create_server() int
sock_create_server ()
{ {
int sock; int sock;
debug("sock_create_server()\n");
/* Create the socket and set it up to accept connections. */
sock = sock_create_inet_socket(LCDPORT);
if(sock < 0)
{
perror("sock_create_server: Error creating socket");
return -1;
}
if (listen (sock, 1) < 0)
{
perror("sock_create_server: Listen error");
return -1;
}
/* Initialize the set of active sockets. */
FD_ZERO (&active_fd_set);
FD_SET (sock, &active_fd_set);
orig_sock = sock; debug ("sock_create_server()\n");
/* Create the socket and set it up to accept connections. */
sock = sock_create_inet_socket (LCDPORT);
if (sock < 0) {
perror ("sock_create_server: Error creating socket");
return -1;
}
if (listen (sock, 1) < 0) {
perror ("sock_create_server: Listen error");
return -1;
}
/* Initialize the set of active sockets. */
FD_ZERO (&active_fd_set);
FD_SET (sock, &active_fd_set);
orig_sock = sock;
/* /*
{ {
int val, len, sock; int val, len, sock;
@@ -110,11 +108,12 @@ int sock_create_server()
} }
*/ */
return sock; return sock;
} }
int sock_poll_clients() int
sock_poll_clients ()
{ {
int i; int i;
int err; int err;
@@ -122,82 +121,64 @@ int sock_poll_clients()
size_t size; size_t size;
struct timeval t; struct timeval t;
client *c; client *c;
//debug("sock_poll_clients()\n"); //debug("sock_poll_clients()\n");
t.tv_sec = 0; t.tv_sec = 0;
t.tv_usec = 0; t.tv_usec = 0;
/* Block until input arrives on one or more active sockets. */ /* Block until input arrives on one or more active sockets. */
read_fd_set = active_fd_set; read_fd_set = active_fd_set;
if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, &t) < 0) if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, &t) < 0) {
{ perror ("sock_poll_clients: Select error");
perror("sock_poll_clients: Select error");
return -1; return -1;
} }
/* Service all the sockets with input pending. */ /* Service all the sockets with input pending. */
for (i = 0; i < FD_SETSIZE; ++i) for (i = 0; i < FD_SETSIZE; ++i) {
{ if (FD_ISSET (i, &read_fd_set)) {
if (FD_ISSET (i, &read_fd_set)) if (i == orig_sock) {
{
if (i == orig_sock)
{
/* Connection request on original socket. */ /* Connection request on original socket. */
int new; int new;
size = sizeof (clientname); size = sizeof (clientname);
new = accept (orig_sock, new = accept (orig_sock, (struct sockaddr *) &clientname, &size);
(struct sockaddr *) &clientname, if (new < 0) {
&size); perror ("sock_poll_clients: Accept error");
if (new < 0)
{
perror("sock_poll_clients: Accept error");
return -1; return -1;
} }
debug("sock_poll_clients: connect from host %s, port %hd.\n", debug ("sock_poll_clients: connect from host %s, port %hd.\n", inet_ntoa (clientname.sin_addr), ntohs (clientname.sin_port));
inet_ntoa (clientname.sin_addr),
ntohs (clientname.sin_port));
FD_SET (new, &active_fd_set); FD_SET (new, &active_fd_set);
fcntl(new, F_SETFL, O_NONBLOCK); fcntl (new, F_SETFL, O_NONBLOCK);
// TODO: Create new "client" here... (done?)
if ( client_create(new) == NULL) // TODO: Create new "client" here... (done?)
{ if (client_create (new) == NULL) {
fprintf(stderr, fprintf (stderr, "sock_poll_clients: error creating client %i\n", i);
"sock_poll_clients: error creating client %i\n",
i);
return -1; return -1;
} }
} } else {
else
{
/* Data arriving on an already-connected socket. */ /* Data arriving on an already-connected socket. */
err = 0; err = 0;
do { do {
debug("sock_poll_clients: reading...\n"); debug ("sock_poll_clients: reading...\n");
err = read_from_client(i); err = read_from_client (i);
debug("sock_poll_clients: ...done\n"); debug ("sock_poll_clients: ...done\n");
if (err < 0) if (err < 0) {
{
// TODO: Destroy a "client" here... (done?) // TODO: Destroy a "client" here... (done?)
c = client_find_sock(i); c = client_find_sock (i);
if(c) if (c) {
{
//sock_send_string(i, "bye\n"); //sock_send_string(i, "bye\n");
client_destroy(c); client_destroy (c);
close (i); close (i);
FD_CLR (i, &active_fd_set); FD_CLR (i, &active_fd_set);
debug("sock_poll_clients: Closed connection %i\n", i); debug ("sock_poll_clients: Closed connection %i\n", i);
} } else
else fprintf(stderr, fprintf (stderr, "sock_poll_clients: Can't find client %i\n", i);
"sock_poll_clients: Can't find client %i\n",
i);
} }
} while (err > 0); } while (err > 0);
} }
} }
} }
@@ -205,48 +186,46 @@ int sock_poll_clients()
} }
int read_from_client (int filedes) int
read_from_client (int filedes)
{ {
char buffer[MAXMSG]; char buffer[MAXMSG];
int nbytes, i; int nbytes, i;
client *c; client *c;
// nbytes = read (filedes, buffer, MAXMSG); // nbytes = read (filedes, buffer, MAXMSG);
//debug("read_from_client(%i): reading...\n", filedes); //debug("read_from_client(%i): reading...\n", filedes);
nbytes = sock_recv (filedes, buffer, MAXMSG); nbytes = sock_recv (filedes, buffer, MAXMSG);
//debug("read_from_client(%i): ...done\n", filedes); //debug("read_from_client(%i): ...done\n", filedes);
debug("read_from_client(%i): %i bytes\n", filedes, nbytes); debug ("read_from_client(%i): %i bytes\n", filedes, nbytes);
if (nbytes < 0) // Read error? No data available? if (nbytes < 0) // Read error? No data available?
{ {
// TODO: check errno here! // TODO: check errno here!
//fprintf (stderr,"read_from_client: Read error\n"); //fprintf (stderr,"read_from_client: Read error\n");
return 0; return 0;
} } else if (nbytes == 0) // EOF
else if (nbytes == 0) // EOF
return -1; return -1;
else if (nbytes > (MAXMSG - (MAXMSG / 8))) // Very noisy client... else if (nbytes > (MAXMSG - (MAXMSG / 8))) // Very noisy client...
{ {
sock_send_string(filedes, "huh? Shut up!\n"); sock_send_string (filedes, "huh? Shut up!\n");
return -1; return -1;
} } else // Data Read
else // Data Read
{ {
buffer[nbytes] = 0; buffer[nbytes] = 0;
// Now, replace zeros with linefeeds... // Now, replace zeros with linefeeds...
for(i=0; i<nbytes; i++) for (i = 0; i < nbytes; i++)
if(buffer[i] == 0) buffer[i] = '\n'; if (buffer[i] == 0)
buffer[i] = '\n';
// Enqueue a "client message" here... // Enqueue a "client message" here...
c = client_find_sock(filedes); c = client_find_sock (filedes);
if(c) if (c) {
{ client_add_message (c, buffer);
client_add_message(c, buffer); } else
} fprintf (stderr, "read_from_client: Can't find client %i\n", filedes);
else fprintf(stderr, "read_from_client: Can't find client %i\n",
filedes); debug ("read_from_client: got message: `%s'\n", buffer);
debug("read_from_client: got message: `%s'\n", buffer);
return nbytes; return nbytes;
} }
return nbytes; return nbytes;
@@ -255,21 +234,21 @@ int read_from_client (int filedes)
// FIXME: This talks to all open files, including // FIXME: This talks to all open files, including
// stdin, stdout, stderr, the LCD, etc... // stdin, stdout, stderr, the LCD, etc...
// BUT it should only talk to sockets! // BUT it should only talk to sockets!
int sock_close_all() int
sock_close_all ()
{ {
int i; int i;
debug("sock_close_all()\n"); debug ("sock_close_all()\n");
for (i = 0; i < FD_SETSIZE; i++) for (i = 0; i < FD_SETSIZE; i++) {
{
// TODO: Destroy a "client" here...? Nope. // TODO: Destroy a "client" here...? Nope.
sock_send_string(i, "bye\n"); sock_send_string (i, "bye\n");
close (i); close (i);
FD_CLR (i, &active_fd_set); FD_CLR (i, &active_fd_set);
debug("sock_close_all: Closed connection %i\n", i); debug ("sock_close_all: Closed connection %i\n", i);
} }
return 0; return 0;
} }
+4 -4
View File
@@ -9,10 +9,10 @@ typedef struct sockaddr_in sockaddr_in;
// Server functions... // Server functions...
int sock_create_server(); int sock_create_server ();
int sock_create_inet_socket(unsigned short int port); int sock_create_inet_socket (unsigned short int port);
int sock_poll_clients(); int sock_poll_clients ();
int sock_close_all(); int sock_close_all ();
int read_from_client (int filedes); int read_from_client (int filedes);
#endif #endif
+175 -193
View File
@@ -9,34 +9,34 @@
#include "widget.h" #include "widget.h"
char *types[] = {"none", char *types[] = { "none",
"string", "string",
"hbar", "hbar",
"vbar", "vbar",
"icon", "icon",
"title", "title",
"scroller", "scroller",
"frame", "frame",
"num", "num",
//"", //"",
NULL, NULL,
}; };
static widget * widget_finder(LL *list, char *id);
static int widget_remover(LL *list, widget *w);
widget * widget_create() static widget *widget_finder (LL * list, char *id);
static int widget_remover (LL * list, widget * w);
widget *
widget_create ()
{ {
widget *w; widget *w;
debug("widget_create()\n"); debug ("widget_create()\n");
w = malloc(sizeof(widget)); w = malloc (sizeof (widget));
if(!w) if (!w) {
{ fprintf (stderr, "widget_create: Error allocating widget\n");
fprintf(stderr, "widget_create: Error allocating widget\n");
return NULL; return NULL;
} }
@@ -54,55 +54,61 @@ widget * widget_create()
w->speed = 1; w->speed = 1;
w->text = NULL; w->text = NULL;
w->kids = NULL; w->kids = NULL;
return w; return w;
} }
int widget_destroy(widget *w) int
widget_destroy (widget * w)
{ {
LL * list; LL *list;
widget *foo; widget *foo;
if(!w) return -1;
debug("widget_destroy(%s)\n", w->id); if (!w)
return -1;
if(w->id) free(w->id);
debug ("widget_destroy(%s)\n", w->id);
if (w->id)
free (w->id);
//debug("widget_destroy: id...\n"); //debug("widget_destroy: id...\n");
if(w->text) free(w->text); if (w->text)
free (w->text);
//debug("widget_destroy: text...\n"); //debug("widget_destroy: text...\n");
// TODO: Free kids! // TODO: Free kids!
if(w->kids) if (w->kids) {
{
list = w->kids; list = w->kids;
LL_Rewind(list); LL_Rewind (list);
do { do {
foo = LL_Get(list); foo = LL_Get (list);
if(foo) if (foo)
widget_destroy(foo); widget_destroy (foo);
} while( 0 == LL_Next(list) ); } while (0 == LL_Next (list));
LL_Destroy(list); LL_Destroy (list);
w->kids = NULL; w->kids = NULL;
} }
free(w); free (w);
//debug("widget_destroy: widget...\n"); //debug("widget_destroy: widget...\n");
return 0; return 0;
} }
widget * widget_find(screen *s, char *id) widget *
widget_find (screen * s, char *id)
{ {
//widget *w, *err; //widget *w, *err;
if(!s) return NULL; if (!s)
if(!id) return NULL; return NULL;
if (!id)
return NULL;
debug("widget_find(%s)\n", id); debug ("widget_find(%s)\n", id);
return widget_finder(s->widgets, id); return widget_finder (s->widgets, id);
/* /*
LL_Rewind(s->widgets); LL_Rewind(s->widgets);
do { do {
@@ -125,186 +131,168 @@ widget * widget_find(screen *s, char *id)
*/ */
} }
widget * widget_finder(LL *list, char *id) widget *
widget_finder (LL * list, char *id)
{ {
widget *w, *err; widget *w, *err;
if(!list) return NULL; if (!list)
if(!id) return NULL; return NULL;
if (!id)
return NULL;
debug("widget_finder(%s)\n", id); debug ("widget_finder(%s)\n", id);
LL_Rewind(list); LL_Rewind (list);
do { do {
//debug("widget_finder: Iteration\n"); //debug("widget_finder: Iteration\n");
w = LL_Get(list); w = LL_Get (list);
if(w) if (w) {
{
//debug("widget_finder: ...\n"); //debug("widget_finder: ...\n");
if(0 == strcmp(w->id, id)) if (0 == strcmp (w->id, id)) {
{ debug ("widget_finder: Found %s\n", id);
debug("widget_finder: Found %s\n", id);
return w; return w;
} }
// Search kids recursively // Search kids recursively
//debug("widget_finder: ...\n"); //debug("widget_finder: ...\n");
if( w->type == WID_FRAME ) if (w->type == WID_FRAME) {
{ err = widget_finder (w->kids, id);
err = widget_finder(w->kids, id); if (err)
if(err) return err; return err;
} }
//debug("widget_finder: ...\n"); //debug("widget_finder: ...\n");
} }
} while(LL_Next(list) == 0); } while (LL_Next (list) == 0);
return NULL; return NULL;
} }
int widget_add(screen *s, char *id, char *type, char *in, int sock) int
widget_add (screen * s, char *id, char *type, char *in, int sock)
{ {
int i; int i;
int valid=0; int valid = 0;
int wid_type=0; int wid_type = 0;
widget *w, *parent; widget *w, *parent;
LL *list; LL *list;
debug("widget_add(%s, %s, %s)\n", id, type, in);
if(!s) return -1; debug ("widget_add(%s, %s, %s)\n", id, type, in);
if(!id) return -1;
if (!s)
return -1;
if (!id)
return -1;
list = s->widgets; list = s->widgets;
if(0 == strcmp(id, "heartbeat")) if (0 == strcmp (id, "heartbeat")) {
{
s->heartbeat = 1; s->heartbeat = 1;
return 0; return 0;
} }
// Make sure this screen doesn't already exist... // Make sure this screen doesn't already exist...
w = widget_find(s, id); w = widget_find (s, id);
if(w) if (w) {
{
// already exists // already exists
sock_send_string(sock, sock_send_string (sock, "huh? You already have a widget with that id#\n");
"huh? You already have a widget with that id#\n");
return 1; return 1;
} }
// Make sure the container, if any, is real // Make sure the container, if any, is real
if(in) if (in) {
{ parent = widget_find (s, in);
parent = widget_find(s, in); if (!parent) {
if(!parent)
{
// no frame to use as parent // no frame to use as parent
sock_send_string(sock, "huh? Frame doesn't exist\n"); sock_send_string (sock, "huh? Frame doesn't exist\n");
return 3; return 3;
} } else {
else if (parent->type == WID_FRAME) {
{
if(parent->type == WID_FRAME)
{
list = parent->kids; list = parent->kids;
if(!list) fprintf(stderr, "widget_add: Parent has no kids\n"); if (!list)
} fprintf (stderr, "widget_add: Parent has no kids\n");
else } else {
{
// no frame to use as parent // no frame to use as parent
sock_send_string(sock, "huh? Not a frame\n"); sock_send_string (sock, "huh? Not a frame\n");
return 4; return 4;
} }
} }
} }
// Make sure it's a valid widget type // Make sure it's a valid widget type
for(i=1; types[i]; i++) for (i = 1; types[i]; i++) {
{ if (0 == strcmp (types[i], type)) {
if(0 == strcmp(types[i], type)) valid = 1;
{ wid_type = i;
valid=1;
wid_type=i;
} }
} }
if(!valid) if (!valid) {
{
// invalid widget type // invalid widget type
sock_send_string(sock, "huh? Invalid widget type\n"); sock_send_string (sock, "huh? Invalid widget type\n");
return 2; return 2;
} }
debug("widget_add: making widget\n"); debug ("widget_add: making widget\n");
// Now, make it... // Now, make it...
w = widget_create(); w = widget_create ();
if(!w) if (!w) {
{ fprintf (stderr, "widget_add: Error creating widget\n");
fprintf(stderr, "widget_add: Error creating widget\n");
return -1; return -1;
} }
w->id = strdup(id); w->id = strdup (id);
if(!w->id) if (!w->id) {
{ fprintf (stderr, "widget_add: Error allocating id\n");
fprintf(stderr, "widget_add: Error allocating id\n");
return -1; return -1;
} }
w->type = wid_type; w->type = wid_type;
// Set up the container's widget list... // Set up the container's widget list...
if(w->type == WID_FRAME) if (w->type == WID_FRAME) {
{ if (!w->kids) {
if(!w->kids) w->kids = LL_new ();
{ if (!w->kids) {
w->kids = LL_new(); fprintf (stderr, "widget_add: error allocating kids for frame\n");
if(!w->kids)
{
fprintf(stderr, "widget_add: error allocating kids for frame\n");
return -1; return -1;
} }
} }
} }
// TODO: Check for errors here? // TODO: Check for errors here?
LL_Push(list, (void *)w); LL_Push (list, (void *) w);
return 0; return 0;
} }
int widget_remove(screen *s, char *id, int sock) int
widget_remove (screen * s, char *id, int sock)
{ {
widget *w; widget *w;
LL *list; LL *list;
debug("widget_remove(%s)\n", id); debug ("widget_remove(%s)\n", id);
if(!s) return -1; if (!s)
if(!id) return -1; return -1;
if (!id)
return -1;
list = s->widgets; list = s->widgets;
if(0 == strcmp(id, "heartbeat")) if (0 == strcmp (id, "heartbeat")) {
{
s->heartbeat = 0; s->heartbeat = 0;
return 0; return 0;
} }
// Make sure this screen *does* exist... // Make sure this screen *does* exist...
w = widget_find(s, id); w = widget_find (s, id);
if(!w) if (!w) {
{ sock_send_string (sock, "huh? You don't have a widget with that id#\n");
sock_send_string(sock, debug ("widget_remove: Error finding widget %s\n", id);
"huh? You don't have a widget with that id#\n");
debug("widget_remove: Error finding widget %s\n", id);
return 1; return 1;
} }
@@ -318,74 +306,68 @@ int widget_remove(screen *s, char *id, int sock)
// widget_destroy(w); // widget_destroy(w);
*/ */
return widget_remover(list, w); return widget_remover (list, w);
// return 0; // return 0;
} }
int widget_remover(LL *list, widget *w) int
widget_remover (LL * list, widget * w)
{ {
widget *foo, *bar; widget *foo, *bar;
int err; int err;
debug("widget_remover\n"); debug ("widget_remover\n");
if(!list) return 0; if (!list)
if(!w) return 0; return 0;
if (!w)
return 0;
// Search through the list... // Search through the list...
LL_Rewind(list); LL_Rewind (list);
do { do {
// Test each item // Test each item
foo = LL_Get(list); foo = LL_Get (list);
if(foo) if (foo) {
{
// Frames require recursion to search and/or destroy // Frames require recursion to search and/or destroy
if(foo->type == WID_FRAME) if (foo->type == WID_FRAME) {
{
// If removing a frame, kill all its kids, too... // If removing a frame, kill all its kids, too...
if(foo == w) if (foo == w) {
{ if (!foo->kids) {
if(!foo->kids) fprintf (stderr, "widget_remover: frame has no kids\n");
} else // Kill the kids...
{ {
fprintf(stderr, "widget_remover: frame has no kids\n"); LL_Rewind (foo->kids);
}
else // Kill the kids...
{
LL_Rewind(foo->kids);
do { do {
bar = LL_Get(foo->kids); bar = LL_Get (foo->kids);
err = widget_remover(foo->kids, bar); err = widget_remover (foo->kids, bar);
} while(0 == LL_Next(foo->kids)); } while (0 == LL_Next (foo->kids));
// Then kill the parent... // Then kill the parent...
LL_Remove(list, (void *)w); LL_Remove (list, (void *) w);
widget_destroy(w); widget_destroy (w);
} }
} } else // Otherwise, search the frame recursively...
else // Otherwise, search the frame recursively...
{ {
if(!foo->kids) if (!foo->kids) {
{ fprintf (stderr, "widget_remover: frame has no kids\n");
fprintf(stderr, "widget_remover: frame has no kids\n"); } else
} err = widget_remover (foo->kids, w);
else err = widget_remover(foo->kids, w);
} }
} } else // If not a frame, remove it if it matches...
else // If not a frame, remove it if it matches...
{ {
if(foo == w) if (foo == w) {
{ LL_Remove (list, (void *) w);
LL_Remove(list, (void *)w); widget_destroy (w);
widget_destroy(w);
} }
} }
} }
} while(0 == LL_Next(list)); } while (0 == LL_Next (list));
return 0; return 0;
} }
+16 -17
View File
@@ -3,18 +3,17 @@
#include "screen.h" #include "screen.h"
typedef struct widget typedef struct widget {
{ char *id;
char *id; int type;
int type; // some sort of data here...
// some sort of data here... int x, y; // Position
int x, y; // Position int wid, hgt; // Size
int wid, hgt; // Size int left, top, right, bottom; // bounding rectangle
int left, top, right, bottom; // bounding rectangle int length; // size or direction
int length; // size or direction int speed; // For scroller...
int speed; // For scroller... char *text; // text or binary data
char *text; // text or binary data LL *kids; // Frames can contain more widgets...
LL *kids; // Frames can contain more widgets...
} widget; } widget;
// These correspond to the index into the "types" array... // These correspond to the index into the "types" array...
@@ -33,13 +32,13 @@ typedef struct widget
extern char *types[]; extern char *types[];
widget * widget_create(); widget *widget_create ();
int widget_destroy(widget *w); int widget_destroy (widget * w);
widget * widget_find(screen *s, char *id); widget *widget_find (screen * s, char *id);
int widget_add(screen *s, char *id, char *type, char *in, int sock); int widget_add (screen * s, char *id, char *type, char *in, int sock);
int widget_remove(screen *s, char *id, int sock); int widget_remove (screen * s, char *id, int sock);
#endif #endif