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,
+73 -67
View File
@@ -14,24 +14,25 @@
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) if (!batt_fd)
batt_fd = open ("/proc/apm", O_RDONLY); batt_fd = open ("/proc/apm", O_RDONLY);
if(batt_fd <= 0) return -1; if (batt_fd <= 0)
return -1;
if(lseek(batt_fd, 0, 0) != 0) return -1; if (lseek (batt_fd, 0, 0) != 0)
return -1;
if(read(batt_fd, str, sizeof(str)-1) < 0) return -1; if (read (batt_fd, str, sizeof (str) - 1) < 0)
return -1;
if(3 > sscanf(str+13, "0x%x 0x%x 0x%x %d", if (3 > sscanf (str + 13, "0x%x 0x%x 0x%x %d", acstat, battstat, battflag, percent))
acstat, battstat, battflag, percent))
return -1; return -1;
return 0; return 0;
@@ -40,12 +41,12 @@ static int get_batt_stat(int *acstat, int *battstat,
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");
} }
@@ -53,9 +54,11 @@ int batt_init()
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,15 +75,15 @@ 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);
@@ -89,77 +92,80 @@ int battery_screen(int rep, int display)
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, sock_send_string (sock, "widget_set B one 1 2 {AC: Unknown}\n");
"widget_set B one 1 2 {AC: Unknown}\n"); sock_send_string (sock, "widget_set B two 1 3 {Batt: Unknown}\n");
sock_send_string(sock, sock_send_string (sock, "widget_set B three 1 4 {E F}\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"); 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);
else
sprintf (buffer, "??%%");
sprintf (tmp, "widget_set B title {Batt: %s: %s}\n", buffer, host); sprintf (tmp, "widget_set B title {Batt: %s: %s}\n", buffer, host);
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
if (lcd_hgt >= 4) // 4-line version of the screen 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:
sprintf (tmp + strlen (tmp), "AC: On}\n");
break; break;
case 2: sprintf(tmp+strlen(tmp), "AC: Backup}\n"); case 2:
sprintf (tmp + strlen (tmp), "AC: Backup}\n");
break; break;
default: sprintf(tmp+strlen(tmp), "AC: Unknown}\n"); default:
sprintf (tmp + strlen (tmp), "AC: Unknown}\n");
break; break;
} }
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
sprintf (tmp, "widget_set B two 1 3 {"); sprintf (tmp, "widget_set B two 1 3 {");
if(battflag == 0xff) if (battflag == 0xff) {
{
sprintf (tmp + strlen (tmp), "Battery Stat Unknown"); sprintf (tmp + strlen (tmp), "Battery Stat Unknown");
} } else {
else
{
sprintf (tmp + strlen (tmp), "Batt:"); sprintf (tmp + strlen (tmp), "Batt:");
if(battflag & 1) sprintf(tmp+strlen(tmp), " High"); if (battflag & 1)
if(battflag & 2) sprintf(tmp+strlen(tmp), " Low"); sprintf (tmp + strlen (tmp), " High");
if(battflag & 4) sprintf(tmp+strlen(tmp), " Critical"); if (battflag & 2)
if(battflag & 8 sprintf (tmp + strlen (tmp), " Low");
||battstat == 3) sprintf(tmp+strlen(tmp), " Charging"); if (battflag & 4)
if(battflag & 128) sprintf(tmp+strlen(tmp), " (NONE)"); 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"); sprintf (tmp + strlen (tmp), "}\n");
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
if(percent > 0) if (percent > 0) {
{ sprintf (tmp, "widget_set B gauge 2 4 %i\n", (percent * ((lcd_wid - 2) * lcd_cellwid) / 100));
sprintf(tmp, "widget_set B gauge 2 4 %i\n", if (display)
(percent * ((lcd_wid-2)*lcd_cellwid)/100)); sock_send_string (sock, tmp);
if(display) sock_send_string(sock, tmp);
} }
} // end if(lcd_hgt >= 4) } // end if(lcd_hgt >= 4)
else // two-line version of the screen else // two-line version of the screen
@@ -168,26 +174,26 @@ int battery_screen(int rep, int display)
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 {
else
{
sprintf (tmp + strlen (tmp), "Batt:"); sprintf (tmp + strlen (tmp), "Batt:");
if(battflag & 1) sprintf(tmp+strlen(tmp), " High"); if (battflag & 1)
if(battflag & 2) sprintf(tmp+strlen(tmp), " Low"); sprintf (tmp + strlen (tmp), " High");
if(battflag & 4) sprintf(tmp+strlen(tmp), " Critical"); if (battflag & 2)
if(battflag & 8 sprintf (tmp + strlen (tmp), " Low");
||battstat == 3) sprintf(tmp+strlen(tmp), " Charging"); if (battflag & 4)
if(battflag & 128) sprintf(tmp+strlen(tmp), " (NONE)"); 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"); sprintf (tmp + strlen (tmp), "}\n");
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
} }
return 0; return 0;
} }
+93 -114
View File
@@ -21,7 +21,8 @@ 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;
@@ -85,12 +86,12 @@ static char *shortmonths[] = {
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);
@@ -120,7 +121,8 @@ int chrono_init()
} }
int chrono_close() int
chrono_close ()
{ {
if (uptime_fd) if (uptime_fd)
close (uptime_fd); close (uptime_fd);
@@ -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];
@@ -157,8 +160,7 @@ int time_screen(int rep, int display)
if(first) if (first) {
{
first = 0; first = 0;
sock_send_string (sock, "screen_add T\n"); sock_send_string (sock, "screen_add T\n");
@@ -167,13 +169,10 @@ int time_screen(int rep, int display)
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 {
else
{
sprintf (buffer, "widget_set T title {TIME: %s}\n", host); sprintf (buffer, "widget_set T title {TIME: %s}\n", host);
sock_send_string (sock, buffer); sock_send_string (sock, buffer);
} }
@@ -190,27 +189,24 @@ int time_screen(int rep, int display)
rtime = localtime (&thetime); rtime = localtime (&thetime);
if(TwentyFourHour) if (TwentyFourHour) {
{ 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); 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)
{
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 sprintf(ampm, "%s", "A");
sprintf (min, "%02d", rtime->tm_min); sprintf (min, "%02d", rtime->tm_min);
sprintf (sec, "%02d", rtime->tm_sec); sprintf (sec, "%02d", rtime->tm_sec);
@@ -223,39 +219,35 @@ int time_screen(int rep, int display)
///////////////////// 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", sprintf (tmp + strlen (tmp), "%s %s: %s}\n", sysname, kver, host);
sysname, kver, host); if (display)
if(display) sock_send_string(sock, tmp); 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) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
/////////////////////// Display the uptime... /////////////////////// Display the uptime...
@@ -274,24 +266,23 @@ int time_screen(int rep, int display)
//// 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 ", sprintf (tmp + strlen (tmp), "%02d/%02d ", rtime->tm_mon + 1, rtime->tm_mday);
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) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
} }
@@ -306,7 +297,8 @@ int time_screen(int rep, int display)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// 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];
@@ -317,10 +309,10 @@ int clock_screen(int rep, int display)
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");
@@ -328,16 +320,13 @@ int clock_screen(int rep, int display)
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 {
else
{
sprintf (buffer, "widget_set O title {TIME: %s}\n", host); sprintf (buffer, "widget_set O title {TIME: %s}\n", host);
sock_send_string (sock, buffer); sock_send_string (sock, buffer);
} }
@@ -354,26 +343,26 @@ int clock_screen(int rep, int display)
strcpy (day, days[rtime->tm_wday]); strcpy (day, days[rtime->tm_wday]);
if(TwentyFourHour) 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); 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 == 12)
{ i = 1;
i = 0; sprintf(hr, "%02d", rtime->tm_hour);
}
}
if(rtime->tm_hour == 12) i=1;
sprintf (min, "%02d", rtime->tm_min); sprintf (min, "%02d", rtime->tm_min);
sprintf (sec, "%02d", rtime->tm_sec); sprintf (sec, "%02d", rtime->tm_sec);
if (i == 1) { sprintf(ampm, "%s", "P"); } if (i == 1) {
else { sprintf(ampm, "%s", "A"); } sprintf (ampm, "%s", "P");
} else {
sprintf (ampm, "%s", "A");
}
strcpy (month, months[rtime->tm_mon]); strcpy (month, months[rtime->tm_mon]);
@@ -381,34 +370,30 @@ int clock_screen(int rep, int display)
{ {
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) sock_send_string(sock, tmp); if (display)
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",
month,
rtime->tm_mday,
(rtime->tm_year + 1900));
sprintf (tmp + strlen (tmp), "}\n"); sprintf (tmp + strlen (tmp), "}\n");
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
} // end if(lcd_hgt >= 4) } // end if(lcd_hgt >= 4)
else // 20x2 version of the screen 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) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
} }
colons = colons ^ 1; colons = colons ^ 1;
@@ -421,7 +406,8 @@ int clock_screen(int rep, int display)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// 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,16 +416,14 @@ 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");
@@ -449,11 +433,8 @@ int uptime_screen(int rep, int display)
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);
{
sprintf(tmp, "widget_set U title {%s %s: %s}\n",
sysname, kver, host);
sock_send_string (sock, tmp); sock_send_string (sock, tmp);
sock_send_string (sock, "widget_add U one string\n"); sock_send_string (sock, "widget_add U one string\n");
} }
@@ -480,7 +461,8 @@ int uptime_screen(int rep, int display)
sprintf (buffer, "widget_set U two %i 3 {%s}\n", i, tmp); 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;
@@ -500,7 +482,8 @@ 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;
@@ -512,10 +495,10 @@ int big_clock_screen(int rep, int display)
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");
@@ -547,12 +530,10 @@ int big_clock_screen(int rep, int display)
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", sprintf (tmp + strlen (tmp), "widget_set K d%d %d %c\n", j, pos[j], fulltxt[j]);
j, pos[j], fulltxt[j]);
old_fulltxt[j] = fulltxt[j]; old_fulltxt[j] = fulltxt[j];
} }
} }
@@ -562,5 +543,3 @@ int big_clock_screen(int rep, int display)
return 0; return 0;
} // End big_clock_screen() } // End big_clock_screen()
+107 -100
View File
@@ -11,26 +11,23 @@
#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,
&curr_load.system,
&curr_load.idle);
curr_load.total = curr_load.user
+ curr_load.nice
+ curr_load.system
+ curr_load.idle;
result->total = curr_load.total - last_load.total; result->total = curr_load.total - last_load.total;
result->user = curr_load.user - last_load.user; result->user = curr_load.user - last_load.user;
result->nice = curr_load.nice - last_load.nice; result->nice = curr_load.nice - last_load.nice;
@@ -45,17 +42,18 @@ static void get_load(struct load * result)
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);
@@ -69,7 +67,8 @@ 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
@@ -80,37 +79,29 @@ int cpu_screen(int rep, int display)
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, sock_send_string (sock, "widget_set C one 1 2 {0 1 Sys 0.0%}\n");
"widget_set C one 1 2 {0 1 Sys 0.0%}\n");
sock_send_string (sock, "widget_add C two string\n"); sock_send_string (sock, "widget_add C two string\n");
sock_send_string (sock, "widget_add C three string\n"); sock_send_string (sock, "widget_add C three string\n");
sock_send_string(sock, sock_send_string (sock, "widget_set C one 1 2 {Usr 0.0% Nice 0.0%}\n");
"widget_set C one 1 2 {Usr 0.0% Nice 0.0%}\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 two 1 3 {Sys 0.0% Idle 0.0%}\n");
sock_send_string(sock,
"widget_set C three 1 4 {0% 100%}\n");
sock_send_string (sock, "widget_add C usr string\n"); sock_send_string (sock, "widget_add C usr string\n");
sock_send_string (sock, "widget_add C nice string\n"); sock_send_string (sock, "widget_add C nice string\n");
sock_send_string (sock, "widget_add C idle string\n"); sock_send_string (sock, "widget_add C idle string\n");
sock_send_string (sock, "widget_add C sys string\n"); sock_send_string (sock, "widget_add C sys string\n");
sock_send_string (sock, "widget_add C bar hbar\n"); sock_send_string (sock, "widget_add C bar hbar\n");
sock_send_string (sock, "widget_set C bar 3 4 0\n"); sock_send_string (sock, "widget_set C bar 3 4 0\n");
} } else {
else
{
sock_send_string (sock, "widget_add C cpu0 string\n"); sock_send_string (sock, "widget_add C cpu0 string\n");
if (lcd_wid >= 20) if (lcd_wid >= 20)
sock_send_string (sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n"); sock_send_string (sock, "widget_set C cpu0 1 1 {CPU0[ ]}\n");
@@ -120,8 +111,7 @@ int cpu_screen(int rep, int display)
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");
@@ -146,12 +136,10 @@ int cpu_screen(int rep, int display)
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++)
@@ -161,13 +149,10 @@ int cpu_screen(int rep, int display)
} }
// 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,75 +160,104 @@ 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%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C title {CPU %s: %s}\n", tmp, host); sprintf (buffer, "widget_set C title {CPU %s: %s}\n", tmp, host);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][0]; value = cpu[CPU_BUF_SIZE][0];
if (value >= 99.9) { sprintf(tmp, " 100%%"); } if (value >= 99.9) {
else { sprintf(tmp, "%4.1f%%", value); } sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C usr 5 2 {%s}\n", tmp); sprintf (buffer, "widget_set C usr 5 2 {%s}\n", tmp);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][1]; value = cpu[CPU_BUF_SIZE][1];
if (value >= 99.9) { sprintf(tmp, " 100%%"); } if (value >= 99.9) {
else { sprintf(tmp, "%4.1f%%", value); } sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C sys 5 3 {%s}\n", tmp); sprintf (buffer, "widget_set C sys 5 3 {%s}\n", tmp);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][2]; value = cpu[CPU_BUF_SIZE][2];
if (value >= 99.9) { sprintf(tmp, " 100%%"); } if (value >= 99.9) {
else { sprintf(tmp, "%4.1f%%", value); } sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C nice 16 2 {%s}\n", tmp); sprintf (buffer, "widget_set C nice 16 2 {%s}\n", tmp);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][3]; value = cpu[CPU_BUF_SIZE][3];
if (value >= 99.9) { sprintf(tmp, " 100%%"); } if (value >= 99.9) {
else { sprintf(tmp, "%4.1f%%", value); } sprintf (tmp, " 100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C idle 16 3 {%s}\n", tmp); sprintf (buffer, "widget_set C idle 16 3 {%s}\n", tmp);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
value = cpu[CPU_BUF_SIZE][4]; value = cpu[CPU_BUF_SIZE][4];
n = (int) (value * (lcd_cellwid * 14) / 100.0); n = (int) (value * (lcd_cellwid * 14) / 100.0);
sprintf (buffer, "widget_set C bar 3 4 %i\n", n); sprintf (buffer, "widget_set C bar 3 4 %i\n", n);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
} // end if(lcd_hgt >= 4) } // end if(lcd_hgt >= 4)
else // 20x2 version else // 20x2 version
{ {
value = cpu[CPU_BUF_SIZE][4]; value = cpu[CPU_BUF_SIZE][4];
if (value >= 99.9) { sprintf(tmp, "100%%"); } if (value >= 99.9) {
else { sprintf(tmp, "%4.1f%%", value); } sprintf (tmp, "100%%");
} else {
sprintf (tmp, "%4.1f%%", value);
}
sprintf (buffer, "widget_set C cpu0%% %i 1 {%s}\n", lcd_wid - 4, tmp); sprintf (buffer, "widget_set C cpu0%% %i 1 {%s}\n", lcd_wid - 4, tmp);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
n = (float) (value * lcd_cellwid * (float) (lcd_wid - 11)) / 100.0; n = (float) (value * lcd_cellwid * (float) (lcd_wid - 11)) / 100.0;
sprintf (buffer, "widget_set C total 6 1 %i\n", n); sprintf (buffer, "widget_set C total 6 1 %i\n", n);
if(display) sock_send_string(sock, buffer); 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; n = (float) (value * lcd_cellwid * 4.0) / 100.0;
sprintf (buffer, "widget_set C usr 1 2 %i\n", n); sprintf (buffer, "widget_set C usr 1 2 %i\n", n);
if(display) sock_send_string(sock, buffer); 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; n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C sys 7 2 %i\n", n); sprintf (buffer, "widget_set C sys 7 2 %i\n", n);
if(display) sock_send_string(sock, buffer); 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; n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C nice 12 2 %i\n", n); sprintf (buffer, "widget_set C nice 12 2 %i\n", n);
if(display) sock_send_string(sock, buffer); 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; n = (float) (value * lcd_cellwid * 3.0) / 100.0;
sprintf (buffer, "widget_set C idle 17 2 %i\n", n); sprintf (buffer, "widget_set C idle 17 2 %i\n", n);
if(display) sock_send_string(sock, buffer); if (display)
sock_send_string (sock, buffer);
} }
@@ -255,7 +269,8 @@ int cpu_screen(int rep, int display)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// 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;
@@ -268,26 +283,21 @@ int cpu_graph_screen(int rep, int display)
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 {
else
{
sock_send_string (sock, "widget_add G title string\n"); sock_send_string (sock, "widget_add G title string\n");
sprintf (buffer, "widget_set G title 1 1 {CPU: %s}\n", host); sprintf (buffer, "widget_set G title 1 1 {CPU: %s}\n", host);
} }
sock_send_string (sock, buffer); 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);
@@ -302,13 +312,11 @@ int cpu_graph_screen(int rep, int display)
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++)
@@ -316,11 +324,9 @@ int cpu_graph_screen(int rep, int display)
*/ */
} }
// 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;
@@ -328,16 +334,16 @@ int cpu_graph_screen(int rep, int display)
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];
@@ -347,19 +353,20 @@ int cpu_graph_screen(int rep, int display)
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 (cpu_past[lcd_wid - 1] > 0)
if(maxload < 1) status = BACKLIGHT_OFF; 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()
+15 -22
View File
@@ -58,7 +58,9 @@
#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;
@@ -81,16 +83,9 @@ get_load(struct load *result, int *numcpus)
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].system,
&curr_load[*numcpus].idle);
curr_load[*numcpus].total = curr_load[*numcpus].user curr_load[*numcpus].total = curr_load[*numcpus].user + curr_load[*numcpus].nice + curr_load[*numcpus].system + curr_load[*numcpus].idle;
+ curr_load[*numcpus].nice
+ curr_load[*numcpus].system
+ curr_load[*numcpus].idle;
result[*numcpus].total = curr_load[*numcpus].total - last_load[*numcpus].total; result[*numcpus].total = curr_load[*numcpus].total - last_load[*numcpus].total;
result[*numcpus].user = curr_load[*numcpus].user - last_load[*numcpus].user; result[*numcpus].user = curr_load[*numcpus].user - last_load[*numcpus].user;
result[*numcpus].nice = curr_load[*numcpus].nice - last_load[*numcpus].nice; result[*numcpus].nice = curr_load[*numcpus].nice - last_load[*numcpus].nice;
@@ -151,8 +146,7 @@ cpu_smp_screen(int rep, int display)
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);
@@ -166,7 +160,8 @@ cpu_smp_screen(int rep, int display)
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] = ' ';
@@ -174,7 +169,8 @@ cpu_smp_screen(int rep, int display)
} }
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);
@@ -207,7 +203,6 @@ cpu_smp_screen(int rep, int display)
if (load[z].total == 0) { if (load[z].total == 0) {
continue; continue;
} }
// Read new data // Read new data
#if 0 // we're only using 4 right now #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][0] = ((float) load[z].user / (float) load[z].total) * 100.0;
@@ -215,16 +210,13 @@ cpu_smp_screen(int rep, int display)
cpu[z][CPU_BUF_SIZE - 1][2] = ((float) load[z].nice / (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; 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; value /= CPU_BUF_SIZE;
@@ -242,7 +234,8 @@ cpu_smp_screen(int rep, int display)
} }
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;
+38 -65
View File
@@ -37,15 +37,15 @@
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;
@@ -60,10 +60,8 @@ static int get_fs(mounts fs[])
// Get rid of old, unmounted filesystems... // Get rid of old, unmounted filesystems...
memset (fs, 0, sizeof (mounts) * 256); memset (fs, 0, sizeof (mounts) * 256);
while (x < 256) while (x < 256) {
{ if (fgets (line, 256, mtab_fd) == NULL) {
if(fgets(line, 256, mtab_fd) == NULL)
{
fclose (mtab_fd); fclose (mtab_fd);
return x; return x;
} }
@@ -77,8 +75,7 @@ static int get_fs(mounts fs[])
#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
@@ -90,8 +87,7 @@ static int get_fs(mounts fs[])
#endif #endif
fs[x].blocks = fsinfo.f_blocks; fs[x].blocks = fsinfo.f_blocks;
if(fs[x].blocks > 0) if (fs[x].blocks > 0) {
{
fs[x].bsize = fsinfo.f_bsize; fs[x].bsize = fsinfo.f_bsize;
fs[x].bfree = fsinfo.f_bfree; fs[x].bfree = fsinfo.f_bfree;
fs[x].files = fsinfo.f_files; fs[x].files = fsinfo.f_files;
@@ -105,13 +101,15 @@ static int get_fs(mounts fs[])
return x; return x;
} }
int disk_init() int
disk_init ()
{ {
return 0; return 0;
} }
int disk_close() int
disk_close ()
{ {
return 0; return 0;
@@ -126,14 +124,14 @@ 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;
@@ -146,8 +144,7 @@ int disk_screen(int rep, int display)
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");
@@ -158,8 +155,7 @@ int disk_screen(int rep, int display)
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");
@@ -168,7 +164,6 @@ int disk_screen(int rep, int display)
} }
// 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);
@@ -177,19 +172,13 @@ int disk_screen(int rep, int display)
first = 0; first = 0;
// Fill the display structure... // Fill the display structure...
if(count) if (count) {
{
sock_send_string (sock, "widget_set D err1 30 5 .\n"); sock_send_string (sock, "widget_set D err1 30 5 .\n");
sock_send_string (sock, "widget_set D err2 30 5 .\n"); sock_send_string (sock, "widget_set D err2 30 5 .\n");
for(i=0; i<count; i++) for (i = 0; i < count; i++) {
{ if (strlen (mnt[i].mpoint) > 6) {
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, "%c%s", ELLIPSIS,
(mnt[i].mpoint)+(strlen(mnt[i].mpoint)-5));
}
else
{
sprintf (table[i].dev, "%s", mnt[i].mpoint); sprintf (table[i].dev, "%s", mnt[i].mpoint);
} }
@@ -203,53 +192,41 @@ int disk_screen(int rep, int display)
// 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);
@@ -258,17 +235,14 @@ int disk_screen(int rep, int display)
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", sprintf (tmp, "widget_set D h%i 16 %i %i\n", i, i + 1, table[i].full);
i, i+1, table[i].full);
sock_send_string (sock, tmp); 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);
@@ -288,4 +262,3 @@ int disk_screen(int rep, int display)
*/ */
return 0; return 0;
} }
+30 -36
View File
@@ -14,7 +14,8 @@ 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;
@@ -24,7 +25,8 @@ static double get_loadavg(void)
} }
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);
@@ -32,7 +34,8 @@ int load_init()
return 0; return 0;
} }
int load_close() int
load_close ()
{ {
if (loadavg_fd) if (loadavg_fd)
close (loadavg_fd); close (loadavg_fd);
@@ -47,7 +50,8 @@ 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];
@@ -65,21 +69,17 @@ int xload_screen(int rep, int display)
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 {
else
{
sock_send_string (sock, "widget_add X title string\n"); 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_set X title 1 1 {LOAD}\n");
sock_send_string (sock, "widget_del X heartbeat\n"); sock_send_string (sock, "widget_del X heartbeat\n");
@@ -88,32 +88,35 @@ int xload_screen(int rep, int display)
sock_send_string (sock, "widget_add X top 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); sprintf (tmp, "widget_set X zero %i %i 0\n", lcd_wid, lcd_hgt);
sock_send_string (sock, tmp); sock_send_string (sock, tmp);
sprintf(tmp, "widget_set X top %i %i 1\n", sprintf (tmp, "widget_set X top %i %i 1\n", lcd_wid, (lcd_hgt == 2) ? 1 : 2);
lcd_wid, (lcd_hgt==2)?1:2);
sock_send_string (sock, tmp); 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[n] = loads[n + 1];
loads[lcd_wid - 2] = get_loadavg (); 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); if (loadmax < 1.0)
else factor = (float)(lcd_cellhgt) * ((lcd_hgt==2)?2.0:3.0) / (float)n; 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++) 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);
@@ -121,32 +124,23 @@ int xload_screen(int rep, int display)
sock_send_string (sock, tmp); sock_send_string (sock, tmp);
} }
if(loadmax < LOAD_MIN) if (loadmax < LOAD_MIN) {
{
status = BACKLIGHT_OFF; status = BACKLIGHT_OFF;
} }
if(loadmax > LOAD_MIN) if (loadmax > LOAD_MIN) {
{
status = BACKLIGHT_ON; status = BACKLIGHT_ON;
} }
if(loads[lcd_wid-2] > LOAD_MAX) if (loads[lcd_wid - 2] > LOAD_MAX) {
{
status = BLINK_ON; 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()
+63 -94
View File
@@ -49,8 +49,7 @@ 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
@@ -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";
@@ -101,52 +101,55 @@ int main(int argc, char **argv)
// 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':
if (argc < i + 1)
HelpScreen ();
strcpy (server, argv[++i]); 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':
if (argc < i + 1)
HelpScreen ();
port = atoi (argv[++i]); port = atoi (argv[++i]);
if (port < 1 && port > 0xffff) if (port < 1 && port > 0xffff)
fprintf(stderr, "Warning: Port %i outside of standard range\n", fprintf (stderr, "Warning: Port %i outside of standard range\n", port);
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)); memcpy (&sequence[j], &default_sequence[k], sizeof (mode));
tmp = 1; 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]);
@@ -158,10 +161,8 @@ int main(int argc, char **argv)
// 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");
@@ -186,7 +187,8 @@ int main(int argc, char **argv)
} }
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");
@@ -205,7 +207,8 @@ void HelpScreen()
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// 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);
@@ -217,7 +220,8 @@ void exit_program(int val)
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// 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;
@@ -229,23 +233,20 @@ void main_loop(mode *sequence)
// 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;
@@ -253,54 +254,37 @@ void main_loop(mode *sequence)
case '\n': case '\n':
buf[i] = 0; buf[i] = 0;
default: default:
if(newtoken) if (newtoken) {
{
argv[argc] = buf + i; argv[argc] = buf + i;
argc++; argc++;
} }
newtoken = 0; newtoken = 0;
break; 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]); debug ("Key %s\n", argv[1]);
} } else if (0 == strcmp (argv[0], "menu")) {
else if(0 == strcmp(argv[0], "menu")) } else if (0 == strcmp (argv[0], "connect")) {
{
}
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"))
@@ -311,14 +295,10 @@ void main_loop(mode *sequence)
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]);
@@ -326,7 +306,8 @@ void main_loop(mode *sequence)
} }
} }
argc = 0; newtoken = 1; argc = 0;
newtoken = 1;
} }
} }
@@ -336,33 +317,23 @@ void main_loop(mode *sequence)
// 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);
@@ -442,5 +413,3 @@ void main_loop(mode *sequence)
*/ */
} }
} }
+104 -141
View File
@@ -15,13 +15,16 @@
#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;
@@ -36,17 +39,18 @@ static void get_mem_info(struct meminfo *result)
} }
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);
@@ -60,7 +64,8 @@ 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];
@@ -68,16 +73,14 @@ int mem_screen(int rep, int display)
static int which_title = 0; static int which_title = 0;
float value; float value;
if(first) if (first) {
{
first = 0; first = 0;
sock_send_string (sock, "screen_add M\n"); sock_send_string (sock, "screen_add M\n");
sprintf (buffer, "screen_set M -name {Memory & Swap: %s}\n", host); sprintf (buffer, "screen_set M -name {Memory & Swap: %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 M title title\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_set M title { MEM -==- SWAP}\n");
sock_send_string (sock, "widget_add M totl string\n"); sock_send_string (sock, "widget_add M totl string\n");
@@ -90,18 +93,13 @@ int mem_screen(int rep, int display)
sock_send_string (sock, "widget_add M swapused 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 memgauge 2 4 0\n");
//sock_send_string(sock, "widget_set M swapgauge 13 4 0\n"); //sock_send_string(sock, "widget_set M swapgauge 13 4 0\n");
} } else {
else
{
sock_send_string (sock, "widget_add M m string\n"); sock_send_string (sock, "widget_add M m string\n");
sock_send_string (sock, "widget_add M s string\n"); sock_send_string (sock, "widget_add M s string\n");
if(lcd_wid >= 20) if (lcd_wid >= 20) {
{
sock_send_string (sock, "widget_set M m 1 1 {M [ ]}\n"); 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_set M s 1 2 {S [ ]}\n");
} } else {
else
{
sock_send_string (sock, "widget_set M m 1 1 {M [ ]}\n"); sock_send_string (sock, "widget_set M m 1 1 {M [ ]}\n");
sock_send_string (sock, "widget_set M s 1 2 {S [ ]}\n"); sock_send_string (sock, "widget_set M s 1 2 {S [ ]}\n");
} }
@@ -128,61 +126,58 @@ int mem_screen(int rep, int display)
// flip the title back and forth... // flip the title back and forth...
if(lcd_hgt >= 4) if (lcd_hgt >= 4) {
{ if (which_title & 4) {
if(which_title & 4)
{
sprintf (buffer, "widget_set M title {%s}\n", host); sprintf (buffer, "widget_set M title {%s}\n", host);
sock_send_string (sock, buffer); sock_send_string (sock, buffer);
} } else
else sock_send_string(sock, "widget_set M title { MEM -==- SWAP}\n"); sock_send_string (sock, "widget_set M title { MEM -==- SWAP}\n");
which_title = (which_title + 1) & 7; which_title = (which_title + 1) & 7;
// Total memory // Total memory
sprintf (tmp, "widget_set M memtotl 1 2 {%6dk}\n", mem[0].total); sprintf (tmp, "widget_set M memtotl 1 2 {%6dk}\n", mem[0].total);
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
// Free memory (plus buffers and cache) // Free memory (plus buffers and cache)
sprintf(tmp, "widget_set M memused 1 3 {%6dk}\n", sprintf (tmp, "widget_set M memused 1 3 {%6dk}\n", mem[0].free + mem[0].buffers + mem[0].cache);
mem[0].free + mem[0].buffers + mem[0].cache); if (display)
if(display) sock_send_string(sock, tmp); sock_send_string (sock, tmp);
// Total swap // Total swap
sprintf (tmp, "widget_set M swaptotl 14 2 {%6dk}\n", mem[1].total); sprintf (tmp, "widget_set M swaptotl 14 2 {%6dk}\n", mem[1].total);
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
// Free swap // Free swap
sprintf (tmp, "widget_set M swapused 14 3 {%6dk}\n", mem[1].free); sprintf (tmp, "widget_set M swapused 14 3 {%6dk}\n", mem[1].free);
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
// Free memory graph // Free memory graph
n = (int)(35.0 - n = (int) (35.0 - ((float) mem[0].free + (float) mem[0].buffers + (float) mem[0].cache)
((float)mem[0].free + (float)mem[0].buffers + (float)mem[0].cache) / (float) mem[0].total * 35.0);
/ (float)mem[0].total
* 35.0);
sprintf (tmp, "widget_set M memgauge 2 4 %i\n", n); sprintf (tmp, "widget_set M memgauge 2 4 %i\n", n);
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
// Free swap graph // Free swap graph
n = (int)(35.0 - n = (int) (35.0 - (float) mem[1].free / (float) mem[1].total * 35.0);
(float)mem[1].free / (float)mem[1].total
* 35.0);
sprintf (tmp, "widget_set M swapgauge 13 4 %i\n", n); sprintf (tmp, "widget_set M swapgauge 13 4 %i\n", n);
if(display) sock_send_string(sock, tmp); if (display)
} sock_send_string (sock, tmp);
else } else {
{
// Total memory // Total memory
sprintf(tmp, "widget_set M memtotl 2 1 {%4dM}\n", sprintf (tmp, "widget_set M memtotl 2 1 {%4dM}\n", (int) (mem[0].total / 1024.0));
(int)(mem[0].total / 1024.0)); if (display)
if(display) sock_send_string(sock, tmp); sock_send_string (sock, tmp);
// Total swap // Total swap
sprintf(tmp, "widget_set M swaptotl 2 2 {%4dM}\n", sprintf (tmp, "widget_set M swaptotl 2 2 {%4dM}\n", (int) (mem[1].total / 1024.0));
(int)(mem[1].total / 1024.0)); if (display)
if(display) sock_send_string(sock, tmp); sock_send_string (sock, tmp);
// Free memory graph // Free memory graph
@@ -191,26 +186,36 @@ int mem_screen(int rep, int display)
value = 1.0 - value; value = 1.0 - value;
n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value)); n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value));
sprintf (tmp, "widget_set M memgauge 8 1 %i\n", n); sprintf (tmp, "widget_set M memgauge 8 1 %i\n", n);
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
value *= 100.0; value *= 100.0;
if (value >= 99.9) { sprintf(buffer, "100%%"); } if (value >= 99.9) {
else { sprintf(buffer, "%4.1f%%", value); } sprintf (buffer, "100%%");
} else {
sprintf (buffer, "%4.1f%%", value);
}
sprintf (tmp, "widget_set M mem%% %i 1 {%s}\n", lcd_wid - 4, buffer); sprintf (tmp, "widget_set M mem%% %i 1 {%s}\n", lcd_wid - 4, buffer);
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
// Free swap graph // Free swap graph
value = ((float) mem[1].free / (float) mem[1].total); value = ((float) mem[1].free / (float) mem[1].total);
value = 1.0 - value; value = 1.0 - value;
n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value)); n = (int) ((lcd_cellwid * (float) (lcd_wid - 13)) * (value));
sprintf (tmp, "widget_set M swapgauge 8 2 %i\n", n); sprintf (tmp, "widget_set M swapgauge 8 2 %i\n", n);
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
value *= 100.0; value *= 100.0;
if (value >= 99.9) { sprintf(buffer, "100%%"); } if (value >= 99.9) {
else { sprintf(buffer, "%4.1f%%", value); } sprintf (buffer, "100%%");
} else {
sprintf (buffer, "%4.1f%%", value);
}
sprintf (tmp, "widget_set M swap%% %i 2 {%s}\n", lcd_wid - 4, buffer); sprintf (tmp, "widget_set M swap%% %i 2 {%s}\n", lcd_wid - 4, buffer);
if(display) sock_send_string(sock, tmp); if (display)
sock_send_string (sock, tmp);
} }
@@ -222,8 +227,7 @@ int mem_screen(int rep, int display)
typedef struct proc_mem_info typedef struct proc_mem_info {
{
char name[16]; // Is this really long enough? char name[16]; // Is this really long enough?
// Size isn't used any more... // Size isn't used any more...
// Totl stores the "size" of the program now... // Totl stores the "size" of the program now...
@@ -232,12 +236,15 @@ typedef struct proc_mem_info
} 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 (!a)
if(!b) return 0; return 0;
if (!b)
return 0;
one = (proc_mem_info *) a; one = (proc_mem_info *) a;
two = (proc_mem_info *) b; two = (proc_mem_info *) b;
@@ -246,7 +253,8 @@ static int sort_procs(void *a, void *b)
} }
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];
@@ -257,25 +265,11 @@ int mem_top_screen(int rep, int display)
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;
@@ -284,8 +278,7 @@ int mem_top_screen(int rep, int display)
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");
@@ -299,8 +292,7 @@ int mem_top_screen(int rep, int display)
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);
} }
@@ -309,29 +301,24 @@ int mem_top_screen(int rep, int display)
procs = LL_new (); procs = LL_new ();
if(!procs) 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" ,
@@ -340,51 +327,36 @@ int mem_top_screen(int rep, int display)
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 */ /* Name: procName */
sscanf (buf, "%*s %s", procName); sscanf (buf, "%*s %s", procName);
} } else if (!strncmp (buf, VmSizeLine, VmSizeLineLen)) {
else if ( !strncmp ( buf , VmSizeLine , VmSizeLineLen ) )
{
/* VmSize: procSize kB */ /* VmSize: procSize kB */
sscanf (buf, "%*s %d", &procSize); sscanf (buf, "%*s %d", &procSize);
} } else if (!strncmp (buf, VmRSSLine, VmRSSLineLen)) {
else if ( !strncmp ( buf , VmRSSLine , VmRSSLineLen ) )
{
/* VmRSS: procRSS kB */ /* VmRSS: procRSS kB */
sscanf (buf, "%*s %d", &procRSS); sscanf (buf, "%*s %d", &procRSS);
} } else if (!strncmp (buf, VmDataLine, VmDataLineLen)) {
else if ( !strncmp ( buf , VmDataLine , VmDataLineLen ) )
{
/* VmData: procData kB */ /* VmData: procData kB */
sscanf (buf, "%*s %d", &procData); sscanf (buf, "%*s %d", &procData);
} } else if (!strncmp (buf, VmStkLine, VmStkLineLen)) {
else if ( !strncmp ( buf , VmStkLine , VmStkLineLen ) )
{
/* VmStk: procStk kB */ /* VmStk: procStk kB */
sscanf (buf, "%*s %d", &procStk); sscanf (buf, "%*s %d", &procStk);
} } else if (!strncmp (buf, VmExeLine, VmExeLineLen)) {
else if ( !strncmp ( buf , VmExeLine , VmExeLineLen ) )
{
/* VmExe: procExe kB */ /* VmExe: procExe kB */
sscanf (buf, "%*s %d", &procExe); 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;
@@ -393,13 +365,10 @@ int mem_top_screen(int rep, int display)
} 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");
fprintf(stderr,
"mem_top_screen: Error allocating process entry\n");
goto end; // Ack! I hate goto's! goto end; // Ack! I hate goto's!
} }
strcpy (p->name, procName); strcpy (p->name, procName);
@@ -419,25 +388,21 @@ int mem_top_screen(int rep, int display)
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);
@@ -451,8 +416,7 @@ int mem_top_screen(int rep, int display)
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);
} }
@@ -463,4 +427,3 @@ int mem_top_screen(int rep, int display)
return 0; return 0;
} // End mem_top_screen() } // End mem_top_screen()
+83 -72
View File
@@ -41,32 +41,29 @@ 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 {
else
{
strncpy (host, Uname.nodename, 15); strncpy (host, Uname.nodename, 15);
host[16] = 0; host[16] = 0;
if (index (host, '.')) // truncate at the first dot if (index (host, '.')) // truncate at the first dot
*(index (host, '.')) = '\0'; *(index (host, '.')) = '\0';
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
if(host[i] == '\n') host[i]=0; 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':
case 'G': // cpu_graph_screen case 'G': // cpu_graph_screen
cpu_init (); cpu_init ();
@@ -118,7 +115,8 @@ int mode_init(mode *sequence)
case 'P': // cpu_smp_screen case 'P': // cpu_smp_screen
cpu_smp_init (); cpu_smp_init ();
break; break;
default: break; default:
break;
} }
} }
@@ -127,7 +125,8 @@ int mode_init(mode *sequence)
return 0; return 0;
} }
void mode_close() void
mode_close ()
{ {
batt_close (); batt_close ();
chrono_close (); chrono_close ();
@@ -139,42 +138,68 @@ void mode_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); break; case 'G':
status = cpu_graph_screen (m->timer, display);
break;
case 'c': case 'c':
case 'C': status = cpu_screen(m->timer, display); break; case 'C':
status = cpu_screen (m->timer, display);
break;
case 'o': case 'o':
case 'O': status = clock_screen(m->timer, display); break; case 'O':
status = clock_screen (m->timer, display);
break;
case 'k': case 'k':
case 'K': status = big_clock_screen(m->timer, display); break; case 'K':
status = big_clock_screen (m->timer, display);
break;
case 'm': case 'm':
case 'M': status = mem_screen(m->timer, display); break; case 'M':
status = mem_screen (m->timer, display);
break;
case 's': case 's':
case 'S': status = mem_top_screen(m->timer, display); break; case 'S':
status = mem_top_screen (m->timer, display);
break;
case 'u': case 'u':
case 'U': status = uptime_screen(m->timer, display); break; case 'U':
status = uptime_screen (m->timer, display);
break;
case 't': case 't':
case 'T': status = time_screen(m->timer, display); break; case 'T':
status = time_screen (m->timer, display);
break;
case 'd': case 'd':
case 'D': status = disk_screen(m->timer, display); break; case 'D':
status = disk_screen (m->timer, display);
break;
case 'x': case 'x':
case 'X': status = xload_screen(m->timer, display); break; case 'X':
status = xload_screen (m->timer, display);
break;
case 'b': case 'b':
case 'B': status = battery_screen(m->timer, display); break; case 'B':
status = battery_screen (m->timer, display);
break;
case 'a': case 'a':
case 'A': status = credit_screen(m->timer, display); break; case 'A':
status = credit_screen (m->timer, display);
break;
case 'p': case 'p':
case 'P': status = cpu_smp_screen (m->timer, display); break; case 'P':
default: break; status = cpu_smp_screen (m->timer, display);
break;
default:
break;
} }
/* Debugging tool... /* Debugging tool...
if(display) if(display)
@@ -184,18 +209,14 @@ int update_screen(mode *m, int display)
*/ */
} }
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");
} }
} }
@@ -204,7 +225,8 @@ int update_screen(mode *m, int display)
} }
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;
@@ -212,19 +234,21 @@ void reread(int f, char *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) return -1; if (tail == bufptr + len)
else return retval; return -1;
else
return retval;
} }
bufptr = strchr (bufptr, '\n'); bufptr = strchr (bufptr, '\n');
} }
@@ -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 one string\n");
sock_send_string (sock, "widget_add A two string\n"); sock_send_string (sock, "widget_add A two string\n");
sock_send_string (sock, "widget_add A three string\n"); sock_send_string (sock, "widget_add A three string\n");
sock_send_string(sock, sock_send_string (sock, "widget_set A one 1 2 { for Linux }\n");
"widget_set A one 1 2 { for Linux }\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 two 1 3 { by William Ferrell}\n"); } else {
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_add A text scroller\n");
sock_send_string(sock, sock_send_string (sock, "widget_set A text 1 2 20 2 v 8 { for Linux by William Ferrell and Scott Scriven}\n");
"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()
+11 -13
View File
@@ -19,16 +19,17 @@
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;
} }
@@ -43,13 +44,15 @@ int client_data_init(client_data *d)
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;
@@ -62,19 +65,16 @@ int client_data_destroy(client_data *d)
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);
} }
@@ -85,5 +85,3 @@ int client_data_destroy(client_data *d)
return 0; return 0;
} }
+1 -2
View File
@@ -6,8 +6,7 @@
#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
+168 -264
View File
@@ -61,13 +61,13 @@ client_function commands[] = {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Debugging only.. prints out a list of arguments it receives // Debugging only.. prints out a list of arguments it receives
// //
int test_func_func(client *c, int argc, char **argv) int
test_func_func (client * c, int argc, char **argv)
{ {
int i; int i;
char str[256]; char str[256];
for(i=0; i<argc; i++) for (i = 0; i < argc; i++) {
{
sprintf (str, "test_func_func: %i -> %s\n", i, argv[i]); sprintf (str, "test_func_func: %i -> %s\n", i, argv[i]);
printf (str); printf (str);
sock_send_string (c->sock, str); sock_send_string (c->sock, str);
@@ -81,7 +81,8 @@ int test_func_func(client *c, int argc, char **argv)
// //
// It returns a string of info about the server to the client // It returns a string of info about the server to the client
// //
int hello_func(client *c, int argc, char **argv) int
hello_func (client * c, int argc, char **argv)
{ {
char str[256]; char str[256];
@@ -89,10 +90,7 @@ int hello_func(client *c, int argc, char **argv)
debug ("Hello!\n"); debug ("Hello!\n");
sprintf(str, sprintf (str, "connect LCDproc %s protocol %s lcd wid %i hgt %i cellwid %i cellhgt %i\n", version, protocol_version, lcd.wid, lcd.hgt, lcd.cellwid, lcd.cellhgt);
"connect LCDproc %s protocol %s lcd wid %i hgt %i cellwid %i cellhgt %i\n",
version, protocol_version,
lcd.wid, lcd.hgt, lcd.cellwid, lcd.cellhgt);
sock_send_string (c->sock, str); sock_send_string (c->sock, str);
if (c->data) if (c->data)
@@ -104,19 +102,18 @@ int hello_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// sets info about the client, such as its name // sets info about the client, such as its name
// //
int client_set_func(client *c, int argc, char **argv) int
client_set_func (client * c, int argc, char **argv)
{ {
int i; int i;
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
for(i=1; i<argc; i++) for (i = 1; i < argc; i++) {
{
// Handle the "name" parameter // Handle the "name" parameter
if(0 == strcmp(argv[i], "-name")) if (0 == strcmp (argv[i], "-name")) {
{ if (argc > i + 1) {
if(argc > i+1)
{
i++; i++;
debug ("client_set: name=\"%s\"\n", argv[i]); debug ("client_set: name=\"%s\"\n", argv[i]);
@@ -124,14 +121,10 @@ int client_set_func(client *c, int argc, char **argv)
if (c->data->name) if (c->data->name)
free (c->data->name); free (c->data->name);
c->data->name = strdup (argv[i]); c->data->name = strdup (argv[i]);
} } else {
else
{
sock_send_string (c->sock, "huh? name requires a parameter\n"); sock_send_string (c->sock, "huh? name requires a parameter\n");
} }
} } else {
else
{
sock_send_string (c->sock, "huh? invalid parameter\n"); sock_send_string (c->sock, "huh? invalid parameter\n");
} }
} }
@@ -147,11 +140,13 @@ int client_set_func(client *c, int argc, char **argv)
// Tells the server the client would like to accept keypresses // Tells the server the client would like to accept keypresses
// of a particular type // of a particular type
// //
int client_add_key_func(client *c, int argc, char **argv) int
client_add_key_func (client * c, int argc, char **argv)
{ {
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet.\n");
@@ -162,11 +157,13 @@ int client_add_key_func(client *c, int argc, char **argv)
// Tells the server the client would NOT like to accept keypresses // Tells the server the client would NOT like to accept keypresses
// of a particular type // of a particular type
// //
int client_del_key_func(client *c, int argc, char **argv) int
client_del_key_func (client * c, int argc, char **argv)
{ {
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet.\n");
@@ -176,19 +173,19 @@ int client_del_key_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Tells the server the client has another screen to offer // Tells the server the client has another screen to offer
// //
int screen_add_func(client *c, int argc, char **argv) int
screen_add_func (client * c, int argc, char **argv)
{ {
int err = 0; int err = 0;
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
if(argc < 2) if (argc < 2) {
{
sock_send_string (c->sock, "huh? Specify a screen #id\n"); sock_send_string (c->sock, "huh? Specify a screen #id\n");
return 0; return 0;
} }
if(argc > 2) if (argc > 2) {
{
sock_send_string (c->sock, "huh? Too many parameters...\n"); sock_send_string (c->sock, "huh? Too many parameters...\n");
return 0; return 0;
} }
@@ -199,8 +196,7 @@ int screen_add_func(client *c, int argc, char **argv)
if (err < 0) if (err < 0)
fprintf (stderr, "screen_add_func: Error adding screen\n"); fprintf (stderr, "screen_add_func: Error adding screen\n");
if (err > 0) if (err > 0)
sock_send_string(c->sock, sock_send_string (c->sock, "huh? You already have a screen with that id#\n");
"huh? You already have a screen with that id#\n");
return 0; return 0;
} }
@@ -208,19 +204,19 @@ int screen_add_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Client requests that the server forget about a screen // Client requests that the server forget about a screen
// //
int screen_del_func(client *c, int argc, char **argv) int
screen_del_func (client * c, int argc, char **argv)
{ {
int err = 0; int err = 0;
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
if(argc < 2) if (argc < 2) {
{
sock_send_string (c->sock, "huh? Specify a screen #id\n"); sock_send_string (c->sock, "huh? Specify a screen #id\n");
return 0; return 0;
} }
if(argc > 2) if (argc > 2) {
{
sock_send_string (c->sock, "huh? Too many parameters...\n"); sock_send_string (c->sock, "huh? Too many parameters...\n");
return 0; return 0;
} }
@@ -231,8 +227,7 @@ int screen_del_func(client *c, int argc, char **argv)
if (err < 0) if (err < 0)
fprintf (stderr, "screen_del_func: Error removing screen\n"); fprintf (stderr, "screen_del_func: Error removing screen\n");
if (err > 0) if (err > 0)
sock_send_string(c->sock, sock_send_string (c->sock, "huh? You don't have a screen with that id#\n");
"huh? You don't have a screen with that id#\n");
return 0; return 0;
} }
@@ -241,7 +236,8 @@ int screen_del_func(client *c, int argc, char **argv)
// Configures info about a particular screen, such as its // Configures info about a particular screen, such as its
// name, priority, or duration // name, priority, or duration
// //
int screen_set_func(client *c, int argc, char **argv) int
screen_set_func (client * c, int argc, char **argv)
{ {
int i; int i;
@@ -249,18 +245,17 @@ int screen_set_func(client *c, int argc, char **argv)
char *id; char *id;
screen *s; screen *s;
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
// If there weren't enough parameters... // If there weren't enough parameters...
if(argc < 2) if (argc < 2) {
{
sock_send_string (c->sock, "huh? You must specify a screen id\n"); sock_send_string (c->sock, "huh? You must specify a screen id\n");
return 0; return 0;
} }
if(argc == 2) if (argc == 2) {
{
sock_send_string (c->sock, "huh? What do you want to set?\n"); sock_send_string (c->sock, "huh? What do you want to set?\n");
return 0; return 0;
} }
@@ -268,20 +263,15 @@ int screen_set_func(client *c, int argc, char **argv)
id = argv[1]; id = argv[1];
s = screen_find (c, id); s = screen_find (c, id);
if(!s) if (!s) {
{
sock_send_string (c->sock, "huh? Invalid screen id\n"); sock_send_string (c->sock, "huh? Invalid screen id\n");
return 0; return 0;
} }
// Handle the rest of the parameters // Handle the rest of the parameters
for(i=2; i<argc; i++) for (i = 2; i < argc; i++) {
{
// Handle the "name" parameter // Handle the "name" parameter
if(0 == strcmp(argv[i], "-name")) if (0 == strcmp (argv[i], "-name")) {
{ if (argc > i + 1) {
if(argc > i+1)
{
i++; i++;
debug ("screen_set: name=\"%s\"\n", argv[i]); debug ("screen_set: name=\"%s\"\n", argv[i]);
@@ -289,17 +279,13 @@ int screen_set_func(client *c, int argc, char **argv)
if (s->name) if (s->name)
free (s->name); free (s->name);
s->name = strdup (argv[i]); s->name = strdup (argv[i]);
} } else {
else
{
sock_send_string (c->sock, "huh? -name requires a parameter\n"); sock_send_string (c->sock, "huh? -name requires a parameter\n");
} }
} }
// Handle the "priority" parameter // Handle the "priority" parameter
else if(0 == strcmp(argv[i], "-priority")) else if (0 == strcmp (argv[i], "-priority")) {
{ if (argc > i + 1) {
if(argc > i+1)
{
i++; i++;
debug ("screen_set: priority=\"%s\"\n", argv[i]); debug ("screen_set: priority=\"%s\"\n", argv[i]);
@@ -307,17 +293,13 @@ int screen_set_func(client *c, int argc, char **argv)
number = atoi (argv[i]); number = atoi (argv[i]);
if (number > 0) if (number > 0)
s->priority = number; s->priority = number;
} } else {
else
{
sock_send_string (c->sock, "huh? -priority requires a parameter\n"); sock_send_string (c->sock, "huh? -priority requires a parameter\n");
} }
} }
// Handle the "duration" parameter // Handle the "duration" parameter
else if(0 == strcmp(argv[i], "-duration")) else if (0 == strcmp (argv[i], "-duration")) {
{ if (argc > i + 1) {
if(argc > i+1)
{
i++; i++;
debug ("screen_set: duration=\"%s\"\n", argv[i]); debug ("screen_set: duration=\"%s\"\n", argv[i]);
@@ -325,17 +307,13 @@ int screen_set_func(client *c, int argc, char **argv)
number = atoi (argv[i]); number = atoi (argv[i]);
if (number > 0) if (number > 0)
s->duration = number; s->duration = number;
} } else {
else
{
sock_send_string (c->sock, "huh? -duration requires a parameter\n"); sock_send_string (c->sock, "huh? -duration requires a parameter\n");
} }
} }
// Handle the "heartbeat" parameter // Handle the "heartbeat" parameter
else if(0 == strcmp(argv[i], "-heartbeat")) else if (0 == strcmp (argv[i], "-heartbeat")) {
{ if (argc > i + 1) {
if(argc > i+1)
{
i++; i++;
debug ("screen_set: heartbeat=\"%s\"\n", argv[i]); debug ("screen_set: heartbeat=\"%s\"\n", argv[i]);
@@ -354,17 +332,13 @@ int screen_set_func(client *c, int argc, char **argv)
s->heartbeat = 0; s->heartbeat = 0;
if (0 == strcmp (argv[i], "slash")) if (0 == strcmp (argv[i], "slash"))
s->heartbeat = 2; s->heartbeat = 2;
} } else {
else
{
sock_send_string (c->sock, "huh? -heartbeat requires a parameter\n"); sock_send_string (c->sock, "huh? -heartbeat requires a parameter\n");
} }
} }
// Handle the "wid" parameter // Handle the "wid" parameter
else if(0 == strcmp(argv[i], "-wid")) else if (0 == strcmp (argv[i], "-wid")) {
{ if (argc > i + 1) {
if(argc > i+1)
{
i++; i++;
debug ("screen_set: wid=\"%s\"\n", argv[i]); debug ("screen_set: wid=\"%s\"\n", argv[i]);
@@ -372,17 +346,13 @@ int screen_set_func(client *c, int argc, char **argv)
number = atoi (argv[i]); number = atoi (argv[i]);
if (number > 0) if (number > 0)
s->wid = number; s->wid = number;
} } else {
else
{
sock_send_string (c->sock, "huh? -wid requires a parameter\n"); sock_send_string (c->sock, "huh? -wid requires a parameter\n");
} }
} }
// Handle the "hgt" parameter // Handle the "hgt" parameter
else if(0 == strcmp(argv[i], "-hgt")) else if (0 == strcmp (argv[i], "-hgt")) {
{ if (argc > i + 1) {
if(argc > i+1)
{
i++; i++;
debug ("screen_set: hgt=\"%s\"\n", argv[i]); debug ("screen_set: hgt=\"%s\"\n", argv[i]);
@@ -390,14 +360,10 @@ int screen_set_func(client *c, int argc, char **argv)
number = atoi (argv[i]); number = atoi (argv[i]);
if (number > 0) if (number > 0)
s->hgt = number; s->hgt = number;
} } else {
else
{
sock_send_string (c->sock, "huh? -hgt requires a parameter\n"); sock_send_string (c->sock, "huh? -hgt requires a parameter\n");
} }
} } else {
else
{
sock_send_string (c->sock, "huh? invalid parameter\n"); sock_send_string (c->sock, "huh? invalid parameter\n");
} }
} // done checking argv } // done checking argv
@@ -408,7 +374,8 @@ int screen_set_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Adds a widget to a screen, but doesn't give it a value // Adds a widget to a screen, but doesn't give it a value
// //
int widget_add_func(client *c, int argc, char **argv) int
widget_add_func (client * c, int argc, char **argv)
{ {
int err; int err;
@@ -419,27 +386,24 @@ int widget_add_func(client *c, int argc, char **argv)
screen *s; screen *s;
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
// If there weren't enough parameters... // If there weren't enough parameters...
if(argc < 2) if (argc < 2) {
{
sock_send_string (c->sock, "huh? You must specify a screen id\n"); sock_send_string (c->sock, "huh? You must specify a screen id\n");
return 0; return 0;
} }
if(argc < 3) if (argc < 3) {
{
sock_send_string (c->sock, "huh? You must specify a widget id\n"); sock_send_string (c->sock, "huh? You must specify a widget id\n");
return 0; return 0;
} }
if(argc < 4) if (argc < 4) {
{
sock_send_string (c->sock, "huh? You must specify a widget type\n"); sock_send_string (c->sock, "huh? You must specify a widget type\n");
return 0; return 0;
} }
if(argc > 6) if (argc > 6) {
{
sock_send_string (c->sock, "huh? Too many parameters\n"); sock_send_string (c->sock, "huh? Too many parameters\n");
return 0; return 0;
} }
@@ -449,8 +413,7 @@ int widget_add_func(client *c, int argc, char **argv)
wid = argv[2]; wid = argv[2];
s = screen_find (c, sid); s = screen_find (c, sid);
if(!s) if (!s) {
{
sock_send_string (c->sock, "huh? Invalid screen id\n"); sock_send_string (c->sock, "huh? Invalid screen id\n");
return 0; return 0;
} }
@@ -458,22 +421,17 @@ int widget_add_func(client *c, int argc, char **argv)
type = argv[3]; type = argv[3];
// Check for additional flags... // Check for additional flags...
if(argc > 4) if (argc > 4) {
{
// Handle the "-in" flag to place widgets in a container... // Handle the "-in" flag to place widgets in a container...
if(0 == strcmp(argv[4], "-in")) if (0 == strcmp (argv[4], "-in")) {
{ if (argc < 6) {
if(argc < 6) sock_send_string (c->sock, "huh? Specify a frame to place widget in\n");
{
sock_send_string(c->sock,
"huh? Specify a frame to place widget in\n");
return 0; return 0;
} }
in = argv[5]; in = argv[5];
} }
} }
// Add the widget and set its type... // Add the widget and set its type...
err = widget_add (s, wid, type, in, c->sock); err = widget_add (s, wid, type, in, c->sock);
if (err < 0) if (err < 0)
@@ -485,7 +443,8 @@ int widget_add_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Removes a widget from a screen, and forgets about it // Removes a widget from a screen, and forgets about it
// //
int widget_del_func(client *c, int argc, char **argv) int
widget_del_func (client * c, int argc, char **argv)
{ {
int err = 0; int err = 0;
@@ -493,21 +452,19 @@ int widget_del_func(client *c, int argc, char **argv)
char *wid; char *wid;
screen *s; screen *s;
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
// Check the number of parameters... // Check the number of parameters...
if(argc < 2) if (argc < 2) {
{
sock_send_string (c->sock, "huh? Specify a screen #id\n"); sock_send_string (c->sock, "huh? Specify a screen #id\n");
return 0; return 0;
} }
if(argc < 3) if (argc < 3) {
{
sock_send_string (c->sock, "huh? Specify a widget #id\n"); sock_send_string (c->sock, "huh? Specify a widget #id\n");
return 0; return 0;
} }
if(argc > 3) if (argc > 3) {
{
sock_send_string (c->sock, "huh? Too many parameters...\n"); sock_send_string (c->sock, "huh? Too many parameters...\n");
return 0; return 0;
} }
@@ -519,8 +476,7 @@ int widget_del_func(client *c, int argc, char **argv)
debug ("screen_del: Deleting widget %s.%s\n", sid, wid); debug ("screen_del: Deleting widget %s.%s\n", sid, wid);
s = screen_find (c, sid); s = screen_find (c, sid);
if(!s) if (!s) {
{
sock_send_string (c->sock, "huh? Invalid screen id\n"); sock_send_string (c->sock, "huh? Invalid screen id\n");
} }
@@ -536,7 +492,8 @@ int widget_del_func(client *c, int argc, char **argv)
// contents, position, speed, etc... // contents, position, speed, etc...
// //
// Ack! This is long! // Ack! This is long!
int widget_set_func(client *c, int argc, char **argv) int
widget_set_func (client * c, int argc, char **argv)
{ {
int i; int i;
@@ -549,22 +506,20 @@ int widget_set_func(client *c, int argc, char **argv)
screen *s; screen *s;
widget *w; widget *w;
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
// If there weren't enough parameters... // If there weren't enough parameters...
if(argc < 2) if (argc < 2) {
{
sock_send_string (c->sock, "huh? You must specify a screen id\n"); sock_send_string (c->sock, "huh? You must specify a screen id\n");
return 0; return 0;
} }
if(argc < 3) if (argc < 3) {
{
sock_send_string (c->sock, "huh? You must specify a widget id\n"); sock_send_string (c->sock, "huh? You must specify a widget id\n");
return 0; return 0;
} }
if(argc < 4) if (argc < 4) {
{
sock_send_string (c->sock, "huh? You must send some widget data\n"); sock_send_string (c->sock, "huh? You must send some widget data\n");
return 0; return 0;
} }
@@ -573,14 +528,12 @@ int widget_set_func(client *c, int argc, char **argv)
sid = argv[1]; sid = argv[1];
wid = argv[2]; wid = argv[2];
s = screen_find (c, sid); s = screen_find (c, sid);
if(!s) if (!s) {
{
sock_send_string (c->sock, "huh? Invalid screen id\n"); sock_send_string (c->sock, "huh? Invalid screen id\n");
return 0; return 0;
} }
w = widget_find (s, wid); w = widget_find (s, wid);
if(!w) if (!w) {
{
sock_send_string (c->sock, "huh? Invalid widget id\n"); sock_send_string (c->sock, "huh? Invalid widget id\n");
// Client Debugging... // Client Debugging...
{ {
@@ -593,21 +546,16 @@ int widget_set_func(client *c, int argc, char **argv)
return 0; return 0;
} }
// FIXME? Shouldn't this be handled in widget.c? // FIXME? Shouldn't this be handled in widget.c?
i = 3; i = 3;
switch(w->type) switch (w->type) {
{
case WID_STRING: // String takes "x y text" case WID_STRING: // String takes "x y text"
if (argc != i + 3) if (argc != i + 3)
sock_send_string (c->sock, "huh? Wrong number of arguments\n"); sock_send_string (c->sock, "huh? Wrong number of arguments\n");
else else {
{ if ((!isdigit (argv[i][0])) || (!isdigit (argv[i + 1][0]))) {
if((!isdigit(argv[i][0])) || (!isdigit(argv[i+1][0])))
{
sock_send_string (c->sock, "huh? Invalid coordinates\n"); sock_send_string (c->sock, "huh? Invalid coordinates\n");
} } else // Set all the data...
else // Set all the data...
{ {
x = atoi (argv[i]); x = atoi (argv[i]);
y = atoi (argv[i + 1]); y = atoi (argv[i + 1]);
@@ -616,10 +564,8 @@ int widget_set_func(client *c, int argc, char **argv)
if (w->text) if (w->text)
free (w->text); free (w->text);
w->text = strdup (argv[i + 2]); w->text = strdup (argv[i + 2]);
if(!w->text) if (!w->text) {
{ fprintf (stderr, "widget_set_func: Error allocating string\n");
fprintf(stderr,
"widget_set_func: Error allocating string\n");
return -1; return -1;
} }
debug ("Widget %s set to %s\n", wid, w->text); debug ("Widget %s set to %s\n", wid, w->text);
@@ -629,14 +575,10 @@ int widget_set_func(client *c, int argc, char **argv)
case WID_HBAR: // Hbar takes "x y length" case WID_HBAR: // Hbar takes "x y length"
if (argc != i + 3) if (argc != i + 3)
sock_send_string (c->sock, "huh? Wrong number of arguments\n"); sock_send_string (c->sock, "huh? Wrong number of arguments\n");
else else {
{ if ((!isdigit (argv[i][0])) || (!isdigit (argv[i + 1][0]))) {
if((!isdigit(argv[i][0])) || (!isdigit(argv[i+1][0])))
{
sock_send_string (c->sock, "huh? Invalid coordinates\n"); sock_send_string (c->sock, "huh? Invalid coordinates\n");
} } else {
else
{
x = atoi (argv[i]); x = atoi (argv[i]);
y = atoi (argv[i + 1]); y = atoi (argv[i + 1]);
length = atoi (argv[i + 2]); length = atoi (argv[i + 2]);
@@ -650,14 +592,10 @@ int widget_set_func(client *c, int argc, char **argv)
case WID_VBAR: // Vbar takes "x y length" case WID_VBAR: // Vbar takes "x y length"
if (argc != i + 3) if (argc != i + 3)
sock_send_string (c->sock, "huh? Wrong number of arguments\n"); sock_send_string (c->sock, "huh? Wrong number of arguments\n");
else else {
{ if ((!isdigit (argv[i][0])) || (!isdigit (argv[i + 1][0]))) {
if((!isdigit(argv[i][0])) || (!isdigit(argv[i+1][0])))
{
sock_send_string (c->sock, "huh? Invalid coordinates\n"); sock_send_string (c->sock, "huh? Invalid coordinates\n");
} } else {
else
{
x = atoi (argv[i]); x = atoi (argv[i]);
y = atoi (argv[i + 1]); y = atoi (argv[i + 1]);
length = atoi (argv[i + 2]); length = atoi (argv[i + 2]);
@@ -671,14 +609,10 @@ int widget_set_func(client *c, int argc, char **argv)
case WID_ICON: // Icon takes "x y binary_data" case WID_ICON: // Icon takes "x y binary_data"
if (argc != i + 3) if (argc != i + 3)
sock_send_string (c->sock, "huh? Wrong number of arguments\n"); sock_send_string (c->sock, "huh? Wrong number of arguments\n");
else else {
{ if ((!isdigit (argv[i][0])) || (!isdigit (argv[i + 1][0]))) {
if((!isdigit(argv[i][0])) || (!isdigit(argv[i+1][0])))
{
sock_send_string (c->sock, "huh? Invalid coordinates\n"); sock_send_string (c->sock, "huh? Invalid coordinates\n");
} } else {
else
{
x = atoi (argv[i]); x = atoi (argv[i]);
y = atoi (argv[i + 1]); y = atoi (argv[i + 1]);
w->x = x; w->x = x;
@@ -691,15 +625,12 @@ int widget_set_func(client *c, int argc, char **argv)
case WID_TITLE: // title takes "text" case WID_TITLE: // title takes "text"
if (argc != i + 1) if (argc != i + 1)
sock_send_string (c->sock, "huh? Wrong number of arguments\n"); sock_send_string (c->sock, "huh? Wrong number of arguments\n");
else else {
{
if (w->text) if (w->text)
free (w->text); free (w->text);
w->text = strdup (argv[i]); w->text = strdup (argv[i]);
if(!w->text) if (!w->text) {
{ fprintf (stderr, "widget_set_func: Error allocating string\n");
fprintf(stderr,
"widget_set_func: Error allocating string\n");
return -1; return -1;
} }
debug ("Widget %s set to %s\n", wid, w->text); debug ("Widget %s set to %s\n", wid, w->text);
@@ -708,18 +639,10 @@ int widget_set_func(client *c, int argc, char **argv)
case WID_SCROLLER: // Scroller takes "left top right bottom direction speed text" case WID_SCROLLER: // Scroller takes "left top right bottom direction speed text"
if (argc != i + 7) { if (argc != i + 7) {
sock_send_string (c->sock, "huh? Wrong number of arguments\n"); sock_send_string (c->sock, "huh? Wrong number of arguments\n");
} } else {
else if ((!isdigit (argv[i][0])) || (!isdigit (argv[i + 1][0])) || (!isdigit (argv[i + 2][0])) || (!isdigit (argv[i + 3][0]))) {
{
if((!isdigit(argv[i][0])) ||
(!isdigit(argv[i+1][0])) ||
(!isdigit(argv[i+2][0])) ||
(!isdigit(argv[i+3][0])))
{
sock_send_string (c->sock, "huh? Invalid coordinates\n"); sock_send_string (c->sock, "huh? Invalid coordinates\n");
} } else {
else
{
left = atoi (argv[i]); left = atoi (argv[i]);
//debug("left: %d\n",left); //debug("left: %d\n",left);
top = atoi (argv[i + 1]); top = atoi (argv[i + 1]);
@@ -733,12 +656,9 @@ int widget_set_func(client *c, int argc, char **argv)
speed = atoi (argv[i + 5]); speed = atoi (argv[i + 5]);
//debug("speed: %d\n",speed); //debug("speed: %d\n",speed);
// Direction must be v or h // Direction must be v or h
if(((char)direction != 'h') && ((char)direction != 'v')) if (((char) direction != 'h') && ((char) direction != 'v')) {
{
sock_send_string (c->sock, "huh? Invalid direction\n"); sock_send_string (c->sock, "huh? Invalid direction\n");
} } else {
else
{
w->left = left; w->left = left;
w->top = top; w->top = top;
w->right = right; w->right = right;
@@ -748,8 +668,7 @@ int widget_set_func(client *c, int argc, char **argv)
if (w->text) if (w->text)
free (w->text); free (w->text);
w->text = strdup (argv[i + 6]); w->text = strdup (argv[i + 6]);
if(!w->text) if (!w->text) {
{
fprintf (stderr, "widget_set_func: Error allocating string\n"); fprintf (stderr, "widget_set_func: Error allocating string\n");
return -1; return -1;
} }
@@ -761,20 +680,10 @@ int widget_set_func(client *c, int argc, char **argv)
case WID_FRAME: // Frame takes "left top right bottom wid hgt direction speed" case WID_FRAME: // Frame takes "left top right bottom wid hgt direction speed"
if (argc != i + 8) { if (argc != i + 8) {
sock_send_string (c->sock, "huh? Wrong number of arguments\n"); sock_send_string (c->sock, "huh? Wrong number of arguments\n");
} } else {
else if ((!isdigit (argv[i][0])) || (!isdigit (argv[i + 1][0])) || (!isdigit (argv[i + 2][0])) || (!isdigit (argv[i + 3][0])) || (!isdigit (argv[i + 4][0])) || (!isdigit (argv[i + 5][0]))) {
{
if((!isdigit(argv[i][0])) ||
(!isdigit(argv[i+1][0])) ||
(!isdigit(argv[i+2][0])) ||
(!isdigit(argv[i+3][0])) ||
(!isdigit(argv[i+4][0])) ||
(!isdigit(argv[i+5][0])))
{
sock_send_string (c->sock, "huh? Invalid coordinates\n"); sock_send_string (c->sock, "huh? Invalid coordinates\n");
} } else {
else
{
left = atoi (argv[i]); left = atoi (argv[i]);
//debug("left: %d\n",left); //debug("left: %d\n",left);
top = atoi (argv[i + 1]); top = atoi (argv[i + 1]);
@@ -792,12 +701,9 @@ int widget_set_func(client *c, int argc, char **argv)
speed = atoi (argv[i + 7]); speed = atoi (argv[i + 7]);
//debug("speed: %d\n",speed); //debug("speed: %d\n",speed);
// Direction must be v or h // Direction must be v or h
if(((char)direction != 'h') && ((char)direction != 'v')) if (((char) direction != 'h') && ((char) direction != 'v')) {
{
sock_send_string (c->sock, "huh? Invalid direction\n"); sock_send_string (c->sock, "huh? Invalid direction\n");
} } else {
else
{
w->left = left; w->left = left;
w->top = top; w->top = top;
w->right = right; w->right = right;
@@ -806,8 +712,7 @@ int widget_set_func(client *c, int argc, char **argv)
w->hgt = height; w->hgt = height;
w->length = direction; w->length = direction;
w->speed = speed; w->speed = speed;
debug("Widget %s set to (%i,%i)-(%i,%i) %ix%i\n", debug ("Widget %s set to (%i,%i)-(%i,%i) %ix%i\n", wid, left, top, right, bottom, width, height);
wid, left, top, right, bottom, width, height);
} }
} }
} }
@@ -815,16 +720,12 @@ int widget_set_func(client *c, int argc, char **argv)
case WID_NUM: // Num takes "x num" case WID_NUM: // Num takes "x num"
if (argc != i + 2) if (argc != i + 2)
sock_send_string (c->sock, "huh? Wrong number of arguments\n"); sock_send_string (c->sock, "huh? Wrong number of arguments\n");
else else {
{ if (!isdigit (argv[i][0])) {
if(!isdigit(argv[i][0]))
{
sock_send_string (c->sock, "huh? Invalid coordinates\n"); sock_send_string (c->sock, "huh? Invalid coordinates\n");
} else if(!isdigit(argv[i+1][0])) } else if (!isdigit (argv[i + 1][0])) {
{
sock_send_string (c->sock, "huh? Invalid number\n"); sock_send_string (c->sock, "huh? Invalid number\n");
} else } else {
{
x = atoi (argv[i]); x = atoi (argv[i]);
y = atoi (argv[i + 1]); y = atoi (argv[i + 1]);
w->x = x; w->x = x;
@@ -845,11 +746,13 @@ int widget_set_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Adds a menu to the client; handled by the server... // Adds a menu to the client; handled by the server...
// //
int menu_add_func(client *c, int argc, char **argv) int
menu_add_func (client * c, int argc, char **argv)
{ {
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet.\n");
@@ -859,11 +762,13 @@ int menu_add_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Removes a client's menu and all contents from the server // Removes a client's menu and all contents from the server
// //
int menu_del_func(client *c, int argc, char **argv) int
menu_del_func (client * c, int argc, char **argv)
{ {
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet.\n");
@@ -875,11 +780,13 @@ int menu_del_func(client *c, int argc, char **argv)
// //
// For example, should the menu be top-level, or buried somewhere? // For example, should the menu be top-level, or buried somewhere?
// //
int menu_set_func(client *c, int argc, char **argv) int
menu_set_func (client * c, int argc, char **argv)
{ {
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet.\n");
@@ -889,11 +796,13 @@ int menu_set_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Adds an item to a menu // Adds an item to a menu
// //
int menu_item_add_func(client *c, int argc, char **argv) int
menu_item_add_func (client * c, int argc, char **argv)
{ {
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet.\n");
@@ -903,11 +812,13 @@ int menu_item_add_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Deletes an item from a menu // Deletes an item from a menu
// //
int menu_item_del_func(client *c, int argc, char **argv) int
menu_item_del_func (client * c, int argc, char **argv)
{ {
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet.\n");
@@ -919,11 +830,13 @@ int menu_item_del_func(client *c, int argc, char **argv)
// //
// For example, text displayed, widget type, value, etc... // For example, text displayed, widget type, value, etc...
// //
int menu_item_set_func(client *c, int argc, char **argv) int
menu_item_set_func (client * c, int argc, char **argv)
{ {
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
sock_send_string (c->sock, "huh? Not implemented yet.\n"); sock_send_string (c->sock, "huh? Not implemented yet.\n");
@@ -933,19 +846,19 @@ int menu_item_set_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Toggles the backlight, if enabled. // Toggles the backlight, if enabled.
// //
int backlight_func(client *c, int argc, char **argv) int
backlight_func (client * c, int argc, char **argv)
{ {
if(!c->data->ack) return 1; if (!c->data->ack)
return 1;
// Check the number of parameters... // Check the number of parameters...
if(argc < 2) if (argc < 2) {
{
sock_send_string (c->sock, "huh? Specify a screen #id\n"); sock_send_string (c->sock, "huh? Specify a screen #id\n");
return 0; return 0;
} }
if(argc > 2) if (argc > 2) {
{
sock_send_string (c->sock, "huh? Too many parameters...\n"); sock_send_string (c->sock, "huh? Too many parameters...\n");
return 0; return 0;
} }
@@ -954,30 +867,24 @@ int backlight_func(client *c, int argc, char **argv)
debug ("backlight(%s)\n", argv[1]); debug ("backlight(%s)\n", argv[1]);
switch(backlight) switch (backlight) {
{
case BACKLIGHT_OPEN: case BACKLIGHT_OPEN:
if(0 == strcmp("on", argv[1])) if (0 == strcmp ("on", argv[1])) {
{
backlight_state = BACKLIGHT_ON; backlight_state = BACKLIGHT_ON;
} }
if(0 == strcmp("off", argv[1])) if (0 == strcmp ("off", argv[1])) {
{
backlight_state = BACKLIGHT_OFF; backlight_state = BACKLIGHT_OFF;
} }
if(0 == strcmp("toggle", argv[1])) if (0 == strcmp ("toggle", argv[1])) {
{
if (backlight_state == BACKLIGHT_ON) if (backlight_state == BACKLIGHT_ON)
backlight_state = BACKLIGHT_OFF; backlight_state = BACKLIGHT_OFF;
else if (backlight_state == BACKLIGHT_OFF) else if (backlight_state == BACKLIGHT_OFF)
backlight_state = BACKLIGHT_ON; backlight_state = BACKLIGHT_ON;
} }
if(0 == strcmp("blink", argv[1])) if (0 == strcmp ("blink", argv[1])) {
{
backlight_state |= BACKLIGHT_BLINK; backlight_state |= BACKLIGHT_BLINK;
} }
if(0 == strcmp("flash", argv[1])) if (0 == strcmp ("flash", argv[1])) {
{
backlight_state |= BACKLIGHT_FLASH; backlight_state |= BACKLIGHT_FLASH;
} }
break; break;
@@ -991,14 +898,12 @@ int backlight_func(client *c, int argc, char **argv)
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Sets the output port on MtxOrb LCDs // Sets the output port on MtxOrb LCDs
int output_func(client *c, int argc, char **argv) int
{ output_func (client * c, int argc, char **argv)
if(argc != 2)
{ {
if (argc != 2) {
sock_send_string (c->sock, "huh? Too many parameters...\n"); sock_send_string (c->sock, "huh? Too many parameters...\n");
} } else {
else
{
if (0 == strcmp (argv[1], "on")) if (0 == strcmp (argv[1], "on"))
output_state = 1; output_state = 1;
else else
@@ -1013,4 +918,3 @@ int output_func(client *c, int argc, char **argv)
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
+1 -2
View File
@@ -7,8 +7,7 @@
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;
+2 -4
View File
@@ -8,14 +8,12 @@
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...
+43 -50
View File
@@ -25,13 +25,13 @@
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;
} }
@@ -39,7 +39,8 @@ int client_init()
return 0; return 0;
} }
int client_shutdown() int
client_shutdown ()
{ {
// TODO: Close all connections first... // TODO: Close all connections first...
client *c; client *c;
@@ -50,25 +51,16 @@ int client_shutdown()
// 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;
c = LL_Pop(clients))
{
debug ("client_shutdown: ...\n"); debug ("client_shutdown: ...\n");
if(c) if (c) {
{
debug ("client_shutdown: ... %i ...\n", c->sock); debug ("client_shutdown: ... %i ...\n", c->sock);
if(0 != client_destroy(c)) if (0 != client_destroy (c)) {
{
fprintf (stderr, "client_shutdown: Error freeing client\n"); fprintf (stderr, "client_shutdown: Error freeing client\n");
} } else {
else
{
debug ("client_shutdown: Freed client...\n"); debug ("client_shutdown: Freed client...\n");
} }
} } else {
else
{
debug ("client_shutdown: No client!\n"); debug ("client_shutdown: No client!\n");
} }
} }
@@ -83,7 +75,8 @@ int client_shutdown()
// Create and destroy clients.... // Create and destroy clients....
client * client_create(int sock) client *
client_create (int sock)
{ {
client *c; client *c;
@@ -91,12 +84,10 @@ client * client_create(int 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;
@@ -107,33 +98,29 @@ client * client_create(int 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; return NULL;
} } else if (client_data_init (c->data) < 0) {
else if(client_data_init(c->data) < 0)
{
return NULL; 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;
@@ -142,12 +129,12 @@ int client_destroy(client *c)
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);
@@ -174,7 +161,8 @@ 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)
{ {
int err = 0; int err = 0;
char *dup; char *dup;
@@ -184,23 +172,22 @@ int client_add_message(client *c, char *message)
//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);
@@ -213,14 +200,17 @@ int client_add_message(client *c, char *message)
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);
@@ -230,12 +220,15 @@ char * client_get_message(client *c)
} }
// 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,7 +236,8 @@ void * client_get(client *c)
} }
client * client_find_sock(int sock) client *
client_find_sock (int sock)
{ {
client *c; client *c;
@@ -253,8 +247,7 @@ client * client_find_sock(int sock)
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;
} }
+1 -2
View File
@@ -4,8 +4,7 @@
#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;
+107 -126
View File
@@ -19,7 +19,8 @@ typedef enum {
hbar = 1, hbar = 1,
vbar = 2, vbar = 2,
bign = 4, bign = 4,
beat = 8 } custom_type; beat = 8
} custom_type;
@@ -37,7 +38,8 @@ lcd_logical_driver *CFontz;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly... // Opens com port and sets baud correctly...
// //
int CFontz_init(lcd_logical_driver *driver, char *args) int
CFontz_init (lcd_logical_driver * driver, char *args)
{ {
char *argv[64]; char *argv[64];
int argc; int argc;
@@ -63,101 +65,68 @@ int CFontz_init(lcd_logical_driver *driver, char *args)
} }
*/ */
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) { if (i + 1 > argc) {
fprintf(stderr, "CFontz_init: %s requires an argument\n", fprintf (stderr, "CFontz_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} }
strcpy (device, argv[++i]); strcpy (device, argv[++i]);
} } else if (0 == strcmp (argv[i], "-c") || 0 == strcmp (argv[i], "--contrast")) {
else if(0 == strcmp(argv[i], "-c") ||
0 == strcmp(argv[i], "--contrast"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "CFontz_init: %s requires an argument\n", fprintf (stderr, "CFontz_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} }
tmp = atoi (argv[++i]); tmp = atoi (argv[++i]);
if ((tmp < 0) || (tmp > 255)) { if ((tmp < 0) || (tmp > 255)) {
fprintf(stderr, "CFontz_init: %s argument must between 0 and 255. Using default value.\n", fprintf (stderr, "CFontz_init: %s argument must between 0 and 255. Using default value.\n", argv[i]);
argv[i]); } else
} else contrast = tmp; contrast = tmp;
} } else if (0 == strcmp (argv[i], "-b") || 0 == strcmp (argv[i], "--brightness")) {
else if(0 == strcmp(argv[i], "-b") ||
0 == strcmp(argv[i], "--brightness"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "CFontz_init: %s requires an argument\n", fprintf (stderr, "CFontz_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} }
tmp = atoi (argv[++i]); tmp = atoi (argv[++i]);
if ((tmp < 0) || (tmp > 255)) { if ((tmp < 0) || (tmp > 255)) {
fprintf(stderr, "CFontz_init: %s argument must between 0 and 255. Using default value.\n", fprintf (stderr, "CFontz_init: %s argument must between 0 and 255. Using default value.\n", argv[i]);
argv[i]); } else
} else backlight_brightness = tmp; backlight_brightness = tmp;
} } else if (0 == strcmp (argv[i], "-o") || 0 == strcmp (argv[i], "--off-bright")) {
else if(0 == strcmp(argv[i], "-o") ||
0 == strcmp(argv[i], "--off-bright"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "CFontz_init: %s requires an argument\n", fprintf (stderr, "CFontz_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} }
tmp = atoi (argv[++i]); tmp = atoi (argv[++i]);
if ((tmp < 0) || (tmp > 255)) { if ((tmp < 0) || (tmp > 255)) {
fprintf(stderr, "CFontz_init: %s argument must between 0 and 255. Using default value.\n", fprintf (stderr, "CFontz_init: %s argument must between 0 and 255. Using default value.\n", argv[i]);
argv[i]); } else
} else backlight_off_brightness = tmp; backlight_off_brightness = tmp;
} } else if (0 == strcmp (argv[i], "-s") || 0 == strcmp (argv[i], "--speed")) {
else if(0 == strcmp(argv[i], "-s") ||
0 == strcmp(argv[i], "--speed"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "CFontz_init: %s requires an argument\n", fprintf (stderr, "CFontz_init: %s requires an argument\n", argv[i]);
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 == 9600)
speed = B9600;
else if (tmp == 19200)
speed = B19200;
else { else {
fprintf(stderr, "CFontz_init: %s argument must be 1200, 2400, or 9600. Using default value.\n", fprintf (stderr, "CFontz_init: %s argument must be 1200, 2400, or 9600. Using default value.\n", argv[i]);
argv[i]);
} }
} } else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
else if(0 == strcmp(argv[i], "-h") || printf ("LCDproc CrystalFontz LCD driver\n" "\t-d\t--device\tSelect the output device to use [/dev/lcd]\n" "\t-t\t--type\t\tSelect the LCD type (size) [20x4]\n" "\t-c\t--contrast\tSet the initial contrast [140]\n" "\t-b\t--brightness\tSet the initial brightness [255]\n" "\t-o\t--off-bright\tSet the initial brightness [0]\n" "\t-s\t--speed\t\tSet the communication speed [9600]\n" "\t-r\t--reboot\tReinitialize the LCD's BIOS\n" "\t-h\t--help\t\tShow this help information\n");
0 == strcmp(argv[i], "--help"))
{
printf("LCDproc CrystalFontz LCD driver\n"
"\t-d\t--device\tSelect the output device to use [/dev/lcd]\n"
"\t-t\t--type\t\tSelect the LCD type (size) [20x4]\n"
"\t-c\t--contrast\tSet the initial contrast [140]\n"
"\t-b\t--brightness\tSet the initial brightness [255]\n"
"\t-o\t--off-bright\tSet the initial brightness [0]\n"
"\t-s\t--speed\t\tSet the communication speed [9600]\n"
"\t-r\t--reboot\tReinitialize the LCD's BIOS\n"
"\t-h\t--help\t\tShow this help information\n");
return -1; return -1;
} } else if (0 == strcmp (argv[i], "-r") || 0 == strcmp (argv[i], "--reboot")) {
else if(0 == strcmp(argv[i], "-r") ||
0 == strcmp(argv[i], "--reboot"))
{
printf ("LCDd: rebooting CrystalFontz LCD...\n"); printf ("LCDd: rebooting CrystalFontz LCD...\n");
reboot = 1; reboot = 1;
} } else {
else
{
printf ("Invalid parameter: %s\n", argv[i]); printf ("Invalid parameter: %s\n", argv[i]);
} }
@@ -165,8 +134,7 @@ int CFontz_init(lcd_logical_driver *driver, char *args)
// 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, "CFontz_init: failed (%s)\n", strerror (errno)); fprintf (stderr, "CFontz_init: failed (%s)\n", strerror (errno));
return -1; return -1;
} }
@@ -182,8 +150,7 @@ int CFontz_init(lcd_logical_driver *driver, char *args)
// Set display-specific stuff.. // Set display-specific stuff..
if(reboot) if (reboot) {
{
CFontz_reboot (); CFontz_reboot ();
sleep (4); sleep (4);
reboot = 0; reboot = 0;
@@ -195,14 +162,12 @@ int CFontz_init(lcd_logical_driver *driver, char *args)
CFontz_backlight (backlight_brightness); CFontz_backlight (backlight_brightness);
if(!driver->framebuf) if (!driver->framebuf) {
{
fprintf (stderr, "CFontz_init: No frame buffer.\n"); fprintf (stderr, "CFontz_init: No frame buffer.\n");
driver->close (); driver->close ();
return -1; return -1;
} }
// Set the functions the driver supports... // Set the functions the driver supports...
driver->clear = (void *) -1; driver->clear = (void *) -1;
@@ -241,24 +206,28 @@ int CFontz_init(lcd_logical_driver *driver, char *args)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clean-up // Clean-up
// //
void CFontz_close() void
CFontz_close ()
{ {
close (fd); close (fd);
if(CFontz->framebuf) free(CFontz->framebuf); if (CFontz->framebuf)
free (CFontz->framebuf);
CFontz->framebuf = NULL; CFontz->framebuf = NULL;
} }
void CFontz_flush() void
CFontz_flush ()
{ {
CFontz_draw_frame (lcd.framebuf); CFontz_draw_frame (lcd.framebuf);
} }
void CFontz_flush_box(int lft, int top, int rgt, int bot) void
CFontz_flush_box (int lft, int top, int rgt, int bot)
{ {
int y; int y;
char out[LCD_MAX_WIDTH]; char out[LCD_MAX_WIDTH];
@@ -266,8 +235,7 @@ void CFontz_flush_box(int lft, int top, int rgt, int bot)
// printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot); // printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot);
for(y=top; y<=bot; y++) for (y = top; y <= bot; y++) {
{
sprintf (out, "%c%c%c", 17, lft, y); sprintf (out, "%c%c%c", 17, lft, y);
write (fd, out, 4); write (fd, out, 4);
write (fd, lcd.framebuf + (y * lcd.wid) + lft, rgt - lft + 1); write (fd, lcd.framebuf + (y * lcd.wid) + lft, rgt - lft + 1);
@@ -282,12 +250,14 @@ void CFontz_flush_box(int lft, int top, int rgt, int bot)
// 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 CFontz_chr(int x, int y, char c) void
CFontz_chr (int x, int y, char c)
{ {
y--; y--;
x--; x--;
if(c < 32 && c >= 0) c += 128; if (c < 32 && c >= 0)
c += 128;
lcd.framebuf[(y * lcd.wid) + x] = c; lcd.framebuf[(y * lcd.wid) + x] = c;
} }
@@ -295,14 +265,14 @@ void CFontz_chr(int x, int y, char c)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Changes screen contrast (0-255; 140 seems good) // Changes screen contrast (0-255; 140 seems good)
// //
int CFontz_contrast(int contrast) int
CFontz_contrast (int contrast)
{ {
int realcontrast; int realcontrast;
char out[4]; char out[4];
static int status = 140; static int status = 140;
if(contrast > 0) if (contrast > 0) {
{
status = contrast; status = contrast;
realcontrast = (((int) (status)) * 100) / 255; realcontrast = (((int) (status)) * 100) / 255;
sprintf (out, "%c%c", 15, realcontrast); sprintf (out, "%c%c", 15, realcontrast);
@@ -317,16 +287,14 @@ int CFontz_contrast(int contrast)
// Sets the backlight on or off -- can be done quickly for // Sets the backlight on or off -- can be done quickly for
// an intermediate brightness... // an intermediate brightness...
// //
void CFontz_backlight(int on) void
CFontz_backlight (int on)
{ {
char out[4]; char out[4];
if(on) if (on) {
{
sprintf (out, "%c%c", 14, (unsigned char) (on * 100 / 255)); sprintf (out, "%c%c", 14, (unsigned char) (on * 100 / 255));
//sprintf(out, "%c%c", 14, 100); //sprintf(out, "%c%c", 14, 100);
} } else {
else
{
sprintf (out, "%c%c", 14, 0); sprintf (out, "%c%c", 14, 0);
} }
write (fd, out, 3); write (fd, out, 3);
@@ -336,7 +304,8 @@ void CFontz_backlight(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Toggle the built-in linewrapping feature // Toggle the built-in linewrapping feature
// //
static void CFontz_linewrap(int on) static void
CFontz_linewrap (int on)
{ {
char out[4]; char out[4];
if (on) if (on)
@@ -349,7 +318,8 @@ static void CFontz_linewrap(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Toggle the built-in automatic scrolling feature // Toggle the built-in automatic scrolling feature
// //
static void CFontz_autoscroll(int on) static void
CFontz_autoscroll (int on)
{ {
char out[4]; char out[4];
if (on) if (on)
@@ -363,7 +333,8 @@ static void CFontz_autoscroll(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Get rid of the blinking curson // Get rid of the blinking curson
// //
static void CFontz_hidecursor() static void
CFontz_hidecursor ()
{ {
char out[4]; char out[4];
sprintf (out, "%c", 4); sprintf (out, "%c", 4);
@@ -373,7 +344,8 @@ static void CFontz_hidecursor()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Reset the display bios // Reset the display bios
// //
static void CFontz_reboot() static void
CFontz_reboot ()
{ {
char out[4]; char out[4];
sprintf (out, "%c", 26); sprintf (out, "%c", 26);
@@ -384,7 +356,8 @@ static void CFontz_reboot()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for vertical bars. Call before lcd.vbar() // Sets up for vertical bars. Call before lcd.vbar()
// //
void CFontz_init_vbar() void
CFontz_init_vbar ()
{ {
char a[] = { char a[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -472,7 +445,8 @@ void CFontz_init_vbar()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Inits horizontal bars... // Inits horizontal bars...
// //
void CFontz_init_hbar() void
CFontz_init_hbar ()
{ {
char a[] = { char a[] = {
@@ -550,16 +524,18 @@ void CFontz_init_hbar()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar... // Draws a vertical bar...
// //
void CFontz_vbar(int x, int len) void
CFontz_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; 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) CFontz_chr(x, y, 255); CFontz_chr (x, y, 255);
else CFontz_chr(x, y, map[len]); else
CFontz_chr (x, y, map[len]);
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
@@ -569,14 +545,16 @@ void CFontz_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void CFontz_hbar(int x, int y, int len) void
CFontz_hbar (int x, int y, int len)
{ {
char map[7] = { 32, 1, 2, 3, 4, 5, 6 }; char map[7] = { 32, 1, 2, 3, 4, 5, 6 };
for(; x<=lcd.wid && len>0; x++) for (; x <= lcd.wid && len > 0; x++) {
{ if (len >= lcd.cellwid)
if(len >= lcd.cellwid) CFontz_chr(x,y,map[6]); CFontz_chr (x, y, map[6]);
else CFontz_chr(x, y, map[len]); else
CFontz_chr (x, y, map[len]);
len -= lcd.cellwid; len -= lcd.cellwid;
@@ -588,7 +566,8 @@ void CFontz_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for big numbers. // Sets up for big numbers.
// //
void CFontz_init_num() void
CFontz_init_num ()
{ {
} }
@@ -596,7 +575,8 @@ void CFontz_init_num()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. // Writes a big number.
// //
void CFontz_num(int x, int num) void
CFontz_num (int x, int num)
{ {
char out[5]; char out[5];
sprintf (out, "%c%c%c", 28, x, num); sprintf (out, "%c%c%c", 28, x, num);
@@ -611,24 +591,25 @@ void CFontz_num(int x, int num)
// //
// The input is just an array of characters... // The input is just an array of characters...
// //
void CFontz_set_char(int n, char *dat) void
CFontz_set_char (int n, char *dat)
{ {
char out[4]; char out[4];
int row, col; int row, col;
int letter; int letter;
if(n < 0 || n > 7) return; if (n < 0 || n > 7)
if(!dat) return; return;
if (!dat)
return;
sprintf (out, "%c%c", 25, n); sprintf (out, "%c%c", 25, 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 <<= 1;
letter |= (dat[(row * lcd.cellwid) + col] > 0); letter |= (dat[(row * lcd.cellwid) + col] > 0);
} }
@@ -637,7 +618,8 @@ void CFontz_set_char(int n, char *dat)
} }
void CFontz_icon(int which, char dest) void
CFontz_icon (int which, char dest)
{ {
char icons[3][6 * 8] = { char icons[3][6 * 8] = {
{ {
@@ -675,7 +657,8 @@ void CFontz_icon(int which, char dest)
}; };
if(custom==bign) custom=beat; if (custom == bign)
custom = beat;
CFontz_set_char (dest, &icons[which][0]); CFontz_set_char (dest, &icons[which][0]);
} }
@@ -685,12 +668,14 @@ void CFontz_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 CFontz_draw_frame(char *dat) void
CFontz_draw_frame (char *dat)
{ {
char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT]; char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i; int i;
if(!dat) return; if (!dat)
return;
// Custom characters start at 128, not at 0. // Custom characters start at 128, not at 0.
/* /*
@@ -700,8 +685,7 @@ void CFontz_draw_frame(char *dat)
} }
*/ */
for(i=0; i<lcd.hgt; i++) for (i = 0; i < lcd.hgt; i++) {
{
sprintf (out, "%c%c%c", 17, 0, i); sprintf (out, "%c%c%c", 17, 0, i);
write (fd, out, 3); write (fd, out, 3);
write (fd, dat + (lcd.wid * i), lcd.wid); write (fd, dat + (lcd.wid * i), lcd.wid);
@@ -713,6 +697,3 @@ void CFontz_draw_frame(char *dat)
*/ */
} }
+205 -152
View File
@@ -19,7 +19,8 @@ typedef enum {
hbar = 1, hbar = 1,
vbar = 2, vbar = 2,
bign = 4, bign = 4,
beat = 8 } custom_type; beat = 8
} custom_type;
// TODO: This is my ugglyest piece of code. // TODO: This is my ugglyest piece of code.
typedef enum { typedef enum {
@@ -46,7 +47,8 @@ typedef enum {
barl3 = 20, barl3 = 20,
barl4 = 21, barl4 = 21,
barw = 32, barw = 32,
barb = 255} bar_type; barb = 255
} bar_type;
static int fd; static int fd;
static int clear = 1; static int clear = 1;
@@ -67,7 +69,8 @@ lcd_logical_driver *MtxOrb;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly... // Opens com port and sets baud correctly...
// //
int MtxOrb_init(lcd_logical_driver *driver, char *args) int
MtxOrb_init (lcd_logical_driver * driver, char *args)
{ {
char *argv[64]; char *argv[64];
int argc; int argc;
@@ -94,64 +97,47 @@ int MtxOrb_init(lcd_logical_driver *driver, char *args)
} }
*/ */
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) { if (i + 1 > argc) {
fprintf(stderr, "MtxOrb_init: %s requires an argument\n", fprintf (stderr, "MtxOrb_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} }
strcpy (device, argv[++i]); strcpy (device, argv[++i]);
} } else if (0 == strcmp (argv[i], "-c") || 0 == strcmp (argv[i], "--contrast")) {
else if(0 == strcmp(argv[i], "-c") ||
0 == strcmp(argv[i], "--contrast"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "MtxOrb_init: %s requires an argument\n", fprintf (stderr, "MtxOrb_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} }
tmp = atoi (argv[++i]); tmp = atoi (argv[++i]);
if ((tmp < 0) || (tmp > 255)) { if ((tmp < 0) || (tmp > 255)) {
fprintf(stderr, "MtxOrb_init: %s argument must between 0 and 255. Ussing default value.\n", fprintf (stderr, "MtxOrb_init: %s argument must between 0 and 255. Ussing default value.\n", argv[i]);
argv[i]); } else
} else contrast = tmp; contrast = tmp;
} } else if (0 == strcmp (argv[i], "-s") || 0 == strcmp (argv[i], "--speed")) {
else if(0 == strcmp(argv[i], "-s") ||
0 == strcmp(argv[i], "--speed"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "MtxOrb_init: %s requires an argument\n", fprintf (stderr, "MtxOrb_init: %s requires an argument\n", argv[i]);
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 == 9600)
speed = B9600;
else if (tmp == 19200)
speed = B19200;
else { else {
fprintf(stderr, "MtxOrb_init: %s argument must be 1200, 2400, 9600 or 19200. Ussing default value.\n", fprintf (stderr, "MtxOrb_init: %s argument must be 1200, 2400, 9600 or 19200. Ussing default value.\n", argv[i]);
argv[i]);
} }
} } else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
else if(0 == strcmp(argv[i], "-h") || printf ("LCDproc Matrix-Orbital LCD driver\n" "\t-d\t--device\tSelect the output device to use [/dev/lcd]\n"
0 == strcmp(argv[i], "--help"))
{
printf("LCDproc Matrix-Orbital LCD driver\n"
"\t-d\t--device\tSelect the output device to use [/dev/lcd]\n"
// "\t-t\t--type\t\tSelect the LCD type (size) [20x4]\n" // "\t-t\t--type\t\tSelect the LCD type (size) [20x4]\n"
"\t-c\t--contrast\tSet the initial contrast [140]\n" "\t-c\t--contrast\tSet the initial contrast [140]\n" "\t-s\t--speed\t\tSet the communication speed [19200]\n" "\t-h\t--help\t\tShow this help information\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 {
else
{
printf ("Invalid parameter: %s\n", argv[i]); printf ("Invalid parameter: %s\n", argv[i]);
} }
@@ -159,8 +145,7 @@ int MtxOrb_init(lcd_logical_driver *driver, char *args)
// 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, "MtxOrb_init: failed (%s)\n", strerror (errno)); fprintf (stderr, "MtxOrb_init: failed (%s)\n", strerror (errno));
return -1; return -1;
} }
@@ -181,14 +166,12 @@ int MtxOrb_init(lcd_logical_driver *driver, char *args)
MtxOrb_cursorblink (0); MtxOrb_cursorblink (0);
if(!driver->framebuf) if (!driver->framebuf) {
{
fprintf (stderr, "MtxOrb_init: No frame buffer.\n"); fprintf (stderr, "MtxOrb_init: No frame buffer.\n");
driver->close (); driver->close ();
return -1; return -1;
} }
// Set the functions the driver supports... // Set the functions the driver supports...
// driver->clear = (void *)-1; // driver->clear = (void *)-1;
@@ -230,7 +213,8 @@ int MtxOrb_init(lcd_logical_driver *driver, char *args)
// forget bar caracter not in use anymore and reuse the // forget bar caracter not in use anymore and reuse the
// slot for another bar caracter. // slot for another bar caracter.
// //
void MtxOrb_clear() void
MtxOrb_clear ()
{ {
// REMOVE: fprintf(stderr, "GLU: MtxOrb_clear.\n"); // REMOVE: fprintf(stderr, "GLU: MtxOrb_clear.\n");
drv_base_clear (); drv_base_clear ();
@@ -241,23 +225,27 @@ void MtxOrb_clear()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clean-up // Clean-up
// //
void MtxOrb_close() void
MtxOrb_close ()
{ {
close (fd); close (fd);
if(MtxOrb->framebuf) free(MtxOrb->framebuf); if (MtxOrb->framebuf)
free (MtxOrb->framebuf);
MtxOrb->framebuf = NULL; MtxOrb->framebuf = NULL;
} }
void MtxOrb_flush() void
MtxOrb_flush ()
{ {
MtxOrb_draw_frame (lcd.framebuf); MtxOrb_draw_frame (lcd.framebuf);
} }
void MtxOrb_flush_box(int lft, int top, int rgt, int bot) void
MtxOrb_flush_box (int lft, int top, int rgt, int bot)
{ {
int y; int y;
char out[LCD_MAX_WIDTH]; char out[LCD_MAX_WIDTH];
@@ -265,8 +253,7 @@ void MtxOrb_flush_box(int lft, int top, int rgt, int bot)
// printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot); // printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot);
for(y=top; y<=bot; y++) for (y = top; y <= bot; y++) {
{
sprintf (out, "%cG%c%c", 254, lft, y); sprintf (out, "%cG%c%c", 254, lft, y);
write (fd, out, 4); write (fd, out, 4);
write (fd, lcd.framebuf + (y * lcd.wid) + lft, rgt - lft + 1); write (fd, lcd.framebuf + (y * lcd.wid) + lft, rgt - lft + 1);
@@ -281,7 +268,8 @@ void MtxOrb_flush_box(int lft, int top, int rgt, int bot)
// 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 MtxOrb_chr(int x, int y, char c) void
MtxOrb_chr (int x, int y, char c)
{ {
y--; y--;
x--; x--;
@@ -293,13 +281,13 @@ void MtxOrb_chr(int x, int y, char c)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Changes screen contrast (0-255; 140 seems good) // Changes screen contrast (0-255; 140 seems good)
// //
int MtxOrb_contrast(int contrast) int
MtxOrb_contrast (int contrast)
{ {
char out[4]; char out[4];
static int status = 140; static int status = 140;
if(contrast > 0) if (contrast > 0) {
{
status = contrast; status = contrast;
sprintf (out, "%cP%c", 254, status); sprintf (out, "%cP%c", 254, status);
write (fd, out, 3); write (fd, out, 3);
@@ -313,16 +301,14 @@ int MtxOrb_contrast(int contrast)
// Sets the backlight on or off -- can be done quickly for // Sets the backlight on or off -- can be done quickly for
// an intermediate brightness... // an intermediate brightness...
// //
void MtxOrb_backlight(int on) void
MtxOrb_backlight (int on)
{ {
char out[4]; char out[4];
if(on) if (on) {
{
sprintf (out, "%cB%c", 254, 0); sprintf (out, "%cB%c", 254, 0);
write (fd, out, 3); write (fd, out, 3);
} } else {
else
{
sprintf (out, "%cF", 254); sprintf (out, "%cF", 254);
write (fd, out, 2); write (fd, out, 2);
} }
@@ -331,16 +317,14 @@ void MtxOrb_backlight(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets output port on or off // Sets output port on or off
void MtxOrb_output(int on) void
MtxOrb_output (int on)
{ {
char out[4]; char out[4];
if(on) if (on) {
{
sprintf (out, "%cW", 254); sprintf (out, "%cW", 254);
write (fd, out, 2); write (fd, out, 2);
} } else {
else
{
sprintf (out, "%cV", 254); sprintf (out, "%cV", 254);
write (fd, out, 2); write (fd, out, 2);
} }
@@ -350,7 +334,8 @@ void MtxOrb_output(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Toggle the built-in linewrapping feature // Toggle the built-in linewrapping feature
// //
static void MtxOrb_linewrap(int on) static void
MtxOrb_linewrap (int on)
{ {
char out[4]; char out[4];
if (on) if (on)
@@ -364,7 +349,8 @@ static void MtxOrb_linewrap(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Toggle the built-in automatic scrolling feature // Toggle the built-in automatic scrolling feature
// //
static void MtxOrb_autoscroll(int on) static void
MtxOrb_autoscroll (int on)
{ {
char out[4]; char out[4];
if (on) if (on)
@@ -379,7 +365,8 @@ static void MtxOrb_autoscroll(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Toggle cursor blink on/off // Toggle cursor blink on/off
// //
static void MtxOrb_cursorblink(int on) static void
MtxOrb_cursorblink (int on)
{ {
char out[4]; char out[4];
if (on) if (on)
@@ -394,7 +381,8 @@ static void MtxOrb_cursorblink(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for vertical bars. Call before lcd.vbar() // Sets up for vertical bars. Call before lcd.vbar()
// //
void MtxOrb_init_vbar() void
MtxOrb_init_vbar ()
{ {
MtxOrb_init_all (vbar); MtxOrb_init_all (vbar);
} }
@@ -403,7 +391,8 @@ void MtxOrb_init_vbar()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Inits horizontal bars... // Inits horizontal bars...
// //
void MtxOrb_init_hbar() void
MtxOrb_init_hbar ()
{ {
MtxOrb_init_all (hbar); MtxOrb_init_all (hbar);
} }
@@ -414,7 +403,8 @@ void MtxOrb_init_hbar()
// Draws a vertical bar... // Draws a vertical bar...
// This is the new version ussing dynamic icon alocation // This is the new version ussing dynamic icon alocation
// //
void MtxOrb_vbar(int x, int len) void
MtxOrb_vbar (int x, int len)
{ {
unsigned char mapu[9] = { barw, baru1, baru2, baru3, baru4, baru5, baru6, baru7, barb }; unsigned char mapu[9] = { barw, baru1, baru2, baru3, baru4, baru5, baru6, baru7, barb };
unsigned char mapd[9] = { barw, bard1, bard2, bard3, bard4, bard5, bard6, bard7, barb }; unsigned char mapd[9] = { barw, bard1, bard2, bard3, bard4, bard5, bard6, bard7, barb };
@@ -426,19 +416,21 @@ void MtxOrb_vbar(int x, int len)
// TODO: REMOVE THE PREVIOUS LINE FOR TESTING ONLY... // TODO: REMOVE THE PREVIOUS LINE FOR TESTING ONLY...
if (len > 0) { if (len > 0) {
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) MtxOrb_chr(x, y, 255); MtxOrb_chr (x, y, 255);
else MtxOrb_chr(x, y, MtxOrb_ask_bar(mapu[len])); else
MtxOrb_chr (x, y, MtxOrb_ask_bar (mapu[len]));
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
} else { } else {
len = -len; len = -len;
for(y=2; y <= lcd.hgt && len>0; y++) for (y = 2; y <= lcd.hgt && len > 0; y++) {
{ if (len >= lcd.cellhgt)
if(len >= lcd.cellhgt) MtxOrb_chr(x, y, 255); MtxOrb_chr (x, y, 255);
else MtxOrb_chr(x, y, MtxOrb_ask_bar(mapd[len])); else
MtxOrb_chr (x, y, MtxOrb_ask_bar (mapd[len]));
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
@@ -451,29 +443,29 @@ void MtxOrb_vbar(int x, int len)
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// This is the new version ussing dynamic icon alocation // This is the new version ussing dynamic icon alocation
// //
void MtxOrb_hbar(int x, int y, int len) void
MtxOrb_hbar (int x, int y, int len)
{ {
unsigned char mapr[6] = { barw, barr1, barr2, barr3, barr4, barb }; unsigned char mapr[6] = { barw, barr1, barr2, barr3, barr4, barb };
unsigned char mapl[6] = { barw, barl1, barl2, barl3, barl4, barb }; unsigned char mapl[6] = { barw, barl1, barl2, barl3, barl4, barb };
if(len>0) if (len > 0) {
{ for (; x <= lcd.wid && len > 0; x++) {
for(; x<=lcd.wid && len>0; x++) if (len >= lcd.cellwid)
{ MtxOrb_chr (x, y, 255);
if(len >= lcd.cellwid) MtxOrb_chr(x,y,255); else
else MtxOrb_chr(x, y, MtxOrb_ask_bar(mapr[len])); MtxOrb_chr (x, y, MtxOrb_ask_bar (mapr[len]));
len -= lcd.cellwid; len -= lcd.cellwid;
} }
} } else {
else
{
len = -len; len = -len;
for(; x>0 && len>0; x--) for (; x > 0 && len > 0; x--) {
{ if (len >= lcd.cellwid)
if(len >= lcd.cellwid) MtxOrb_chr(x,y,255); MtxOrb_chr (x, y, 255);
else MtxOrb_chr(x, y, MtxOrb_ask_bar(mapl[len])); else
MtxOrb_chr (x, y, MtxOrb_ask_bar (mapl[len]));
len -= lcd.cellwid; len -= lcd.cellwid;
@@ -487,7 +479,8 @@ void MtxOrb_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for big numbers. // Sets up for big numbers.
// //
void MtxOrb_init_num() void
MtxOrb_init_num ()
{ {
char out[3]; char out[3];
if (custom != bign) { if (custom != bign) {
@@ -502,7 +495,8 @@ void MtxOrb_init_num()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. // Writes a big number.
// //
void MtxOrb_num(int x, int num) void
MtxOrb_num (int x, int num)
{ {
char out[5]; char out[5];
sprintf (out, "%c#%c%c", 254, x, num); sprintf (out, "%c#%c%c", 254, x, num);
@@ -519,23 +513,24 @@ void MtxOrb_num(int x, int num)
// //
// The input is just an array of characters... // The input is just an array of characters...
// //
void MtxOrb_set_char(int n, char *dat) void
MtxOrb_set_char (int n, char *dat)
{ {
char out[4]; char out[4];
int row, col; int row, col;
int letter; int letter;
if(n < 0 || n > 7) return; if (n < 0 || n > 7)
if(!dat) return; return;
if (!dat)
return;
sprintf (out, "%cN%c", 254, n); sprintf (out, "%cN%c", 254, n);
write (fd, out, 3); write (fd, out, 3);
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 <<= 1;
letter |= (dat[(row * lcd.cellwid) + col] > 0); letter |= (dat[(row * lcd.cellwid) + col] > 0);
} }
@@ -544,7 +539,8 @@ void MtxOrb_set_char(int n, char *dat)
} }
void MtxOrb_icon(int which, char dest) void
MtxOrb_icon (int which, char dest)
{ {
char icons[3][5 * 8] = { char icons[3][5 * 8] = {
{ {
@@ -582,7 +578,8 @@ void MtxOrb_icon(int which, char dest)
}; };
if(custom==bign) custom=beat; if (custom == bign)
custom = beat;
MtxOrb_set_char (dest, &icons[which][0]); MtxOrb_set_char (dest, &icons[which][0]);
} }
@@ -591,15 +588,16 @@ void MtxOrb_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 MtxOrb_draw_frame(char *dat) void
MtxOrb_draw_frame (char *dat)
{ {
char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT]; char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i; int i;
if(!dat) return; if (!dat)
return;
for(i=0; i<lcd.hgt; i++) for (i = 0; i < lcd.hgt; i++) {
{
sprintf (out, "%cG%c%c", 254, 1, i + 1); sprintf (out, "%cG%c%c", 254, 1, i + 1);
write (fd, out, 4); write (fd, out, 4);
write (fd, dat + (lcd.wid * i), lcd.wid); write (fd, dat + (lcd.wid * i), lcd.wid);
@@ -613,18 +611,21 @@ void MtxOrb_draw_frame(char *dat)
// returns one character from the keypad... // returns one character from the keypad...
// (A-Z) on success, 0 on failure... // (A-Z) on success, 0 on failure...
// //
char MtxOrb_getkey() char
MtxOrb_getkey ()
{ {
char in = 0; char in = 0;
read (fd, &in, 1); read (fd, &in, 1);
return in; return in;
} }
void MtxOrb_led(int which, int on) void
MtxOrb_led (int which, int on)
{ {
char out[4]; char out[4];
if(which < 0 || which > 7) return; if (which < 0 || which > 7)
return;
if (!which) { if (!which) {
if (on) if (on)
@@ -632,8 +633,7 @@ void MtxOrb_led(int which, int on)
else else
sprintf (out, "%cW", 254); sprintf (out, "%cW", 254);
write (fd, out, 2); write (fd, out, 2);
} } else {
else{
if (on) if (on)
sprintf (out, "%cV%c", 254, which); sprintf (out, "%cV%c", 254, which);
else else
@@ -652,7 +652,8 @@ void MtxOrb_led(int which, int on)
// I really hope it is working and bug-less because it is not // I really hope it is working and bug-less because it is not
// completely tested, just a quick hack. // completely tested, just a quick hack.
// //
int MtxOrb_ask_bar(int type) int
MtxOrb_ask_bar (int type)
{ {
int i; int i;
int last_not_in_use; int last_not_in_use;
@@ -676,8 +677,10 @@ int MtxOrb_ask_bar(int type)
pos = 8; // Not found. pos = 8; // Not found.
last_not_in_use = 8; // No empty slot to reuse. last_not_in_use = 8; // No empty slot to reuse.
for (i = 1; i < 8; i++) { // For all but first (heartbeat). for (i = 1; i < 8; i++) { // For all but first (heartbeat).
if(!use[i]) last_not_in_use=i; // New empty slot. if (!use[i])
if(def[i]==type) pos=i; // Founded (should break now). last_not_in_use = i; // New empty slot.
if (def[i] == type)
pos = i; // Founded (should break now).
} }
if (pos == 8) { if (pos == 8) {
@@ -700,39 +703,88 @@ int MtxOrb_ask_bar(int type)
if (pos == 8) // TODO: Choose a character to approximate the graph if (pos == 8) // TODO: Choose a character to approximate the graph
{ {
//pos=65; // ("A")? //pos=65; // ("A")?
switch(type) switch (type) {
{ case baru1:
case baru1: pos='_'; break; pos = '_';
case baru2: pos='.'; break; break;
case baru3: pos=','; break; case baru2:
case baru4: pos='o'; break; pos = '.';
case baru5: pos='o'; break; break;
case baru6: pos='O'; break; case baru3:
case baru7: pos='8'; break; pos = ',';
break;
case baru4:
pos = 'o';
break;
case baru5:
pos = 'o';
break;
case baru6:
pos = 'O';
break;
case baru7:
pos = '8';
break;
case bard1: pos='\''; break; case bard1:
case bard2: pos='"'; break; pos = '\'';
case bard3: pos='^'; break; break;
case bard4: pos='^'; break; case bard2:
case bard5: pos='*'; break; pos = '"';
case bard6: pos='O'; break; break;
case bard7: pos='8'; break; case bard3:
pos = '^';
break;
case bard4:
pos = '^';
break;
case bard5:
pos = '*';
break;
case bard6:
pos = 'O';
break;
case bard7:
pos = '8';
break;
case barr1: pos='-'; break; case barr1:
case barr2: pos='-'; break; pos = '-';
case barr3: pos='='; break; break;
case barr4: pos='='; break; case barr2:
pos = '-';
break;
case barr3:
pos = '=';
break;
case barr4:
pos = '=';
break;
case barl1: pos='-'; break; case barl1:
case barl2: pos='-'; break; pos = '-';
case barl3: pos='='; break; break;
case barl4: pos='='; break; case barl2:
pos = '-';
break;
case barl3:
pos = '=';
break;
case barl4:
pos = '=';
break;
case barw: pos=' '; break; case barw:
pos = ' ';
break;
case barb: pos=255; break; case barb:
pos = 255;
break;
default: pos='?'; break; default:
pos = '?';
break;
} }
} }
@@ -743,7 +795,8 @@ int MtxOrb_ask_bar(int type)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up a well known character for use. // Sets up a well known character for use.
// //
void MtxOrb_set_known_char(int car, int type) void
MtxOrb_set_known_char (int car, int type)
{ {
char all_bar[25][5 * 8] = { char all_bar[25][5 * 8] = {
{ {
@@ -985,7 +1038,7 @@ MtxOrb_set_char(car, &all_bar[type][0]);
// TODO: Remove this code wich was use for developpement. // TODO: Remove this code wich was use for developpement.
// PS: There might be reference to this code left, so keep it for some time. // PS: There might be reference to this code left, so keep it for some time.
void MtxOrb_init_all(int type) void
MtxOrb_init_all (int type)
{ {
} }
+81 -73
View File
@@ -34,7 +34,8 @@ 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;
@@ -43,56 +44,35 @@ int curses_drv_init(struct lcd_logical_driver *driver, char *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++) {
{ if (0 == strcmp (argv[i], "-f") || 0 == strcmp (argv[i], "--forecolor")) {
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") ||
0 == strcmp(argv[i], "--backcolor"))
{
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], "--backlight")) {
else if(0 == strcmp(argv[i], "-B") ||
0 == strcmp(argv[i], "--backlight"))
{
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], "-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 {
else
{
printf ("Invalid parameter: %s\n", argv[i]); printf ("Invalid parameter: %s\n", argv[i]);
} }
@@ -143,7 +123,8 @@ int curses_drv_init(struct lcd_logical_driver *driver, char *args)
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 ();
@@ -158,7 +139,8 @@ void curses_drv_close()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void curses_drv_clear() void
curses_drv_clear ()
{ {
clear (); clear ();
@@ -169,18 +151,21 @@ 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);
@@ -190,12 +175,16 @@ void curses_drv_string(int x, int y, char 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);
@@ -204,14 +193,16 @@ void curses_drv_chr(int x, int y, char 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;
@@ -228,15 +219,17 @@ void curses_drv_num(int x, int num)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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;
} }
@@ -249,10 +242,10 @@ void curses_drv_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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
@@ -271,14 +264,20 @@ 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;
} }
} }
@@ -286,19 +285,22 @@ void curses_drv_icon(int which, char dest)
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// 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);
@@ -308,19 +310,25 @@ void curses_drv_draw_frame(char *dat)
char curses_drv_getkey() char
curses_drv_getkey ()
{ {
int i; int i;
i = getch (); i = getch ();
if(i == KEY_LEFT) return 'D'; if (i == KEY_LEFT)
if(i == KEY_UP) return 'B'; return 'D';
if(i == KEY_DOWN) return 'C'; if (i == KEY_UP)
if(i == KEY_RIGHT) return 'A'; return 'B';
if (i == KEY_DOWN)
return 'C';
if (i == KEY_RIGHT)
return 'A';
if(i != ERR) return i; if (i != ERR)
else return 0; return i;
else
return 0;
} }
+57 -46
View File
@@ -18,24 +18,24 @@
// 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) if (!driver->framebuf) {
{
printf ("Allocating frame buffer (%ix%i)\n", lcd.wid, lcd.hgt); printf ("Allocating frame buffer (%ix%i)\n", lcd.wid, lcd.hgt);
driver->framebuf = malloc (lcd.wid * lcd.hgt); driver->framebuf = malloc (lcd.wid * lcd.hgt);
} }
if(!driver->framebuf) if (!driver->framebuf) {
{
debug_close (); 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 ();
@@ -65,7 +65,8 @@ int debug_init(struct lcd_logical_driver *driver, char *args)
return 200; // 200 is arbitrary. (must be 1 or more) 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??
@@ -73,9 +74,11 @@ void debug_close()
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)
printf ("Frame buffer: %i\n", (int) driver->framebuf);
driver->framebuf = NULL; driver->framebuf = NULL;
// printf("debug_close() finished\n"); // printf("debug_close() finished\n");
} }
@@ -83,7 +86,8 @@ void debug_close()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Clears the LCD screen // Clears the LCD screen
// //
void debug_clear() void
debug_clear ()
{ {
printf ("clear()\n"); printf ("clear()\n");
@@ -95,7 +99,8 @@ void debug_clear()
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Flushes all output to the lcd... // Flushes all output to the lcd...
// //
void debug_flush() void
debug_flush ()
{ {
printf ("flush()\n"); printf ("flush()\n");
@@ -107,7 +112,8 @@ 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;
@@ -118,8 +124,7 @@ void debug_string(int x, int y, char string[])
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++) {
{
driver->framebuf[(y * lcd.wid) + x + i] = string[i]; driver->framebuf[(y * lcd.wid) + x + i] = string[i];
} }
} }
@@ -128,7 +133,8 @@ void debug_string(int x, int y, char 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 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);
@@ -141,44 +147,48 @@ void debug_chr(int x, int y, char 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 {
else
{
printf ("Backlight OFF\n"); 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);
} }
@@ -186,15 +196,15 @@ void debug_set_char(int n, char *dat)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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;
@@ -205,13 +215,13 @@ void debug_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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;
@@ -223,13 +233,15 @@ void debug_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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);
@@ -239,7 +251,8 @@ void debug_flush_box(int lft, int top, int rgt, int bot)
} }
void debug_draw_frame(char *dat) void
debug_draw_frame (char *dat)
{ {
int i, j; int i, j;
@@ -248,22 +261,20 @@ void debug_draw_frame(char *dat)
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;
@@ -271,8 +282,7 @@ void debug_draw_frame(char *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;
@@ -281,7 +291,8 @@ void debug_draw_frame(char *dat)
} }
char debug_getkey() char
debug_getkey ()
{ {
printf ("Trying to grab keypress.\n"); printf ("Trying to grab keypress.\n");
return 0; return 0;
+46 -30
View File
@@ -22,7 +22,8 @@ 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");
@@ -35,8 +36,7 @@ int drv_base_init(struct lcd_logical_driver *driver, char *args)
if (!driver->framebuf) if (!driver->framebuf)
driver->framebuf = malloc (driver->wid * driver->hgt); driver->framebuf = malloc (driver->wid * driver->hgt);
if(!driver->framebuf) if (!driver->framebuf) {
{
drv_base_close (); drv_base_close ();
return -1; return -1;
} }
@@ -80,9 +80,11 @@ 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;
} }
@@ -90,7 +92,8 @@ void drv_base_close()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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);
@@ -100,7 +103,8 @@ void drv_base_clear()
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// 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,17 +114,18 @@ 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)) break; if ((y * lcd.wid) + x + i > (lcd.wid * lcd.hgt))
break;
lcd.framebuf[(y * lcd.wid) + x + i] = string[i]; lcd.framebuf[(y * lcd.wid) + x + i] = string[i];
} }
} }
@@ -129,7 +134,8 @@ void drv_base_string(int x, int y, char 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 drv_base_chr(int x, int y, char c) void
drv_base_chr (int x, int y, char c)
{ {
y--; y--;
x--; x--;
@@ -142,7 +148,8 @@ 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;
@@ -151,7 +158,8 @@ int drv_base_contrast(int contrast)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// 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)
@@ -168,7 +176,8 @@ void drv_base_backlight(int on)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// 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,11 +221,11 @@ 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;
@@ -223,10 +236,10 @@ void drv_base_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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;
@@ -238,7 +251,8 @@ void drv_base_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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,7 +264,8 @@ 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;
} }
+26 -33
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
@@ -67,10 +65,8 @@ 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];
@@ -85,11 +81,8 @@ int hd_init_4bit(HD44780_functions *hd44780_functions,
// 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 ||
strcmp(argv[i], "--extended") == 0)
{
extIF = 1; extIF = 1;
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));
@@ -99,43 +92,46 @@ int hd_init_4bit(HD44780_functions *hd44780_functions,
} }
// powerup the lcd now // powerup the lcd now
if (extIF) if (extIF) {
{
displayID |= EN3; displayID |= EN3;
port_out (lptPort + 2, 0 ^ OUTMASK); port_out (lptPort + 2, 0 ^ OUTMASK);
} }
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)
port_out (lptPort + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (4100); 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)
port_out (lptPort + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (100); hd44780_functions->uPause (100);
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)
port_out (lptPort + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (40); hd44780_functions->uPause (40);
// now in 8-bit mode... set 4-bit mode // now in 8-bit mode... set 4-bit mode
port_out (lptPort, displayID | 0x02); port_out (lptPort, displayID | 0x02);
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, 0x02); port_out (lptPort, 0x02);
if (extIF) port_out(lptPort + 2, 0 ^ OUTMASK); if (extIF)
port_out (lptPort + 2, 0 ^ OUTMASK);
hd44780_functions->uPause (40); hd44780_functions->uPause (40);
common_init (IF_4bit); common_init (IF_4bit);
@@ -144,9 +140,8 @@ int hd_init_4bit(HD44780_functions *hd44780_functions,
// 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
@@ -157,8 +152,7 @@ void lcdstat_HD44780_senddata(unsigned char displayID,
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
@@ -175,8 +169,7 @@ void lcdstat_HD44780_senddata(unsigned char displayID,
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
+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
+11 -17
View File
@@ -20,34 +20,28 @@
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, int (*init_fn) (HD44780_functions * hd44780_functions, lcd_logical_driver * driver, char *args, unsigned int port);
lcd_logical_driver *driver,
char *args,
unsigned int port);
const char *helpMsg; 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" },
{ HD_winamp, "winamp", hd_init_winamp,
"\t-e\t--extended\tEnable three or more displays\n" },
// add new connection types and their string specifier here // add new connection types and their string specifier here
// default, end of structure element (do not delete) // default, end of structure element (do not delete)
{ HD_unknown, "", NULL, "" } {
HD_unknown, "", NULL, ""}
}; };
#endif #endif
+5 -10
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,10 +60,8 @@ 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 ();
@@ -83,9 +79,8 @@ int hd_init_ext8bit(HD44780_functions *hd44780_functions,
// 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;
+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
+1 -4
View File
@@ -9,8 +9,7 @@ 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);
@@ -98,5 +97,3 @@ extern HD44780_functions *hd44780_functions;
#define INMASK 0x48 #define INMASK 0x48
#endif #endif
+16 -27
View File
@@ -31,9 +31,7 @@
#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);
@@ -51,10 +49,8 @@ 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;
@@ -79,30 +75,22 @@ int hd_init_serialLpt(HD44780_functions *hd44780_functions,
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,
FUNCSET | IF_4BIT | TWOLINE | SMALLCHAR);
// clear // clear
lcdserLpt_HD44780_senddata (0, RS_INSTR, CLEAR); lcdserLpt_HD44780_senddata (0, RS_INSTR, CLEAR);
hd44780_functions->uPause (1600); hd44780_functions->uPause (1600);
// Now turn on the display // Now turn on the display
lcdserLpt_HD44780_senddata(displayID, lcdserLpt_HD44780_senddata (displayID, RS_INSTR, ONOFFCTRL | DISPON | CURSOROFF | CURSORNOBLINK);
RS_INSTR,
ONOFFCTRL | DISPON | CURSOROFF | CURSORNOBLINK);
hd44780_functions->uPause (1600); 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;
@@ -122,7 +110,8 @@ void lcdserLpt_HD44780_senddata(unsigned char displayID,
/* 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
@@ -134,8 +123,7 @@ char lcdserLpt_HD44780_getkey()
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);
@@ -154,18 +142,19 @@ char lcdserLpt_HD44780_getkey()
} }
/* 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); rawshift (r);
port_out (lp, displayID); //latch it, to correct display port_out (lp, displayID); //latch it, to correct display
+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_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
+6 -13
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
@@ -53,10 +51,8 @@ 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];
@@ -70,8 +66,7 @@ int hd_init_winamp(HD44780_functions *hd44780_functions,
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 || if (strcmp (argv[i], "-e") == 0 || strcmp (argv[i], "--extended") == 0)
strcmp(argv[i], "--extended") == 0)
extIF = 1; extIF = 1;
if ((ioperm (lptPort + 2, 1, 255)) == -1) { if ((ioperm (lptPort + 2, 1, 255)) == -1) {
@@ -85,9 +80,8 @@ int hd_init_winamp(HD44780_functions *hd44780_functions,
// 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;
@@ -106,4 +100,3 @@ void lcdwinamp_HD44780_senddata(unsigned char displayID,
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
+99 -152
View File
@@ -95,18 +95,15 @@ static void HD44780_position(int x, int y);
static void common_position (int display, int DDaddr); static void common_position (int display, int DDaddr);
static void common_autoscroll (int on); static void common_autoscroll (int on);
static void uPause (int delayCalls); static void uPause (int delayCalls);
static void HD44780_senddata(unsigned char displayID, static void HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch);
unsigned char flags,
unsigned char ch);
static int parse_span_list(int *spanListArray[], int *spLsize, static int parse_span_list (int *spanListArray[], int *spLsize, int *dispOffsets[], int *dOffsize, int *dispSizeArray[], char *spanlist);
int *dispOffsets[], int *dOffsize,
int *dispSizeArray[], char *spanlist);
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly... // Opens com port and sets baud correctly...
// //
int HD44780_init(lcd_logical_driver *driver, char *args) int
HD44780_init (lcd_logical_driver * driver, char *args)
{ {
// TODO: remove the two magic numbers below // TODO: remove the two magic numbers below
// TODO: single point of return // TODO: single point of return
@@ -119,105 +116,69 @@ int HD44780_init(lcd_logical_driver *driver, char *args)
if (args) if (args)
if ((str = (char *) malloc (strlen (args) + 1))) if ((str = (char *) malloc (strlen (args) + 1)))
strcpy (str, args); strcpy (str, args);
else else {
{
fprintf (stderr, "Error mallocing\n"); fprintf (stderr, "Error mallocing\n");
return -1; return -1;
} } else
else
str = NULL; str = NULL;
argc = get_args (argv, args, 64); argc = get_args (argv, args, 64);
// arguments are passed in with -d HD44780 "-p 0x278" // arguments are passed in with -d HD44780 "-p 0x278"
// getopt will work well here // getopt will work well here
for(i=0; i<argc; i++) for (i = 0; i < argc; i++) {
{ if (0 == strcmp (argv[i], "-p") || 0 == strcmp (argv[i], "--port")) {
if(0 == strcmp(argv[i], "-p") ||
0 == strcmp(argv[i], "--port"))
{
if (i + 1 >= argc) { if (i + 1 >= argc) {
fprintf(stderr, "HD44780_init: %s requires an argument\n", fprintf (stderr, "HD44780_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} else { } else {
int myport; int myport;
if (sscanf (argv[i + 1], "%i", &myport) != 1) { if (sscanf (argv[i + 1], "%i", &myport) != 1) {
fprintf(stderr, "HD44780_init: Couldn't read port address -" fprintf (stderr, "HD44780_init: Couldn't read port address -" " using default value 0x%x\n", port);
" using default value 0x%x\n", port);
return -1; return -1;
} else { } else {
port = myport; port = myport;
++i; ++i;
} }
} }
} } else if (0 == strcmp (argv[i], "-c") || 0 == strcmp (argv[i], "--connect")) {
else if(0 == strcmp(argv[i], "-c") ||
0 == strcmp(argv[i], "--connect"))
{
int j = 0; int j = 0;
if (i + 1 >= argc) { if (i + 1 >= argc) {
fprintf(stderr, "HD44780_init: %s requires an argument\n", fprintf (stderr, "HD44780_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} }
// search the next argument for the connection type // search the next argument for the connection type
for (j = 0; for (j = 0; strcmp (argv[i + 1], connectionMapping[j].connectionTypeStr) != 0 && connectionMapping[j].type != HD_unknown; ++j);
strcmp(argv[i + 1], connectionMapping[j].connectionTypeStr) != 0
&& connectionMapping[j].type != HD_unknown;
++j)
;
if (connectionMapping[j].type == HD_unknown) if (connectionMapping[j].type == HD_unknown) {
{ fprintf (stderr, "HD44780_init: Unknown connection type - using default %s driver\n", connectionMapping[0].connectionTypeStr);
fprintf(stderr,
"HD44780_init: Unknown connection type - using default %s driver\n",
connectionMapping[0].connectionTypeStr);
connection = connectionMapping[0].type; connection = connectionMapping[0].type;
j = 0; j = 0;
} } else
else
connection = connectionMapping[j].type; connection = connectionMapping[j].type;
connIdx = j; connIdx = j;
++i; ++i;
} } else if (0 == strcmp (argv[i], "-v") || 0 == strcmp (argv[i], "--vspan")) {
else if(0 == strcmp(argv[i], "-v") ||
0 == strcmp(argv[i], "--vspan"))
{
int j = 0; int j = 0;
if (i + 1 >= argc) { if (i + 1 >= argc) {
fprintf(stderr, "HD44780_init: %s requires an argument\n", fprintf (stderr, "HD44780_init: %s requires an argument\n", argv[i]);
argv[i]);
return -1; return -1;
} }
if (parse_span_list(&spanList, &numLines, if (parse_span_list (&spanList, &numLines, &dispVOffset, &numDisplays, &dispSizes, argv[i + 1]) == -1) {
&dispVOffset, &numDisplays,
&dispSizes, argv[i + 1]) == -1)
{
fprintf (stderr, "HD44780_init: invalid vspan argument\n"); fprintf (stderr, "HD44780_init: invalid vspan argument\n");
return -1; return -1;
} }
++i; ++i;
} } else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
else if(0 == strcmp(argv[i], "-h") ||
0 == strcmp(argv[i], "--help"))
{
int i; int i;
printf("LCDproc HD44780 driver\n" printf ("LCDproc HD44780 driver\n" "\t-p n\t--port n\tSelect the output device to use port n\n" "\t-c type\t--connect type\tSet the connection type (default 4 bit)\n" "\t\t\t\ttype = %s", connectionMapping[0].connectionTypeStr);
"\t-p n\t--port n\tSelect the output device to use port n\n"
"\t-c type\t--connect type\tSet the connection type (default 4 bit)\n"
"\t\t\t\ttype = %s", connectionMapping[0].connectionTypeStr);
for (i = 1; connectionMapping[i].type != HD_unknown; ++i) for (i = 1; connectionMapping[i].type != HD_unknown; ++i)
printf (" | %s", connectionMapping[i].connectionTypeStr); printf (" | %s", connectionMapping[i].connectionTypeStr);
printf("\n\t-v spanlist\t--vspan spanlist\tvertical span n{,m}\n" printf ("\n\t-v spanlist\t--vspan spanlist\tvertical span n{,m}\n" "\t-h\t--help\t\tShow this help information\n" "\n\tNote that the '-t' option should precede the '-d' option\n");
"\t-h\t--help\t\tShow this help information\n"
"\n\tNote that the '-t' option should precede the '-d' option\n");
if (connectionMapping[connIdx].type != HD_unknown) if (connectionMapping[connIdx].type != HD_unknown) {
{ printf ("\n Parameters for %s driver\n", connectionMapping[connIdx].connectionTypeStr);
printf("\n Parameters for %s driver\n",
connectionMapping[connIdx].connectionTypeStr);
printf ("%s", connectionMapping[connIdx].helpMsg); printf ("%s", connectionMapping[connIdx].helpMsg);
} }
return -1; return -1;
@@ -233,39 +194,29 @@ int HD44780_init(lcd_logical_driver *driver, char *args)
// default case for when spans aren't indicated // default case for when spans aren't indicated
// - add a sanity check against lcd.hgt ?? // - add a sanity check against lcd.hgt ??
// - this only works if the -t option is specified before -d // - this only works if the -t option is specified before -d
if (numLines == 0) if (numLines == 0) {
{ if ((spanList = (int *) malloc (sizeof (int) * lcd.hgt))) {
if ((spanList = (int *) malloc(sizeof(int) * lcd.hgt)))
{
int i; int i;
for (i = 0; i < lcd.hgt; ++i) for (i = 0; i < lcd.hgt; ++i) {
{
spanList[i] = 1; spanList[i] = 1;
numLines = lcd.hgt; numLines = lcd.hgt;
} }
} } else
else
fprintf (stderr, "Error mallocing for span list\n"); fprintf (stderr, "Error mallocing for span list\n");
} }
if (numDisplays == 0) if (numDisplays == 0) {
{ if ((dispVOffset = (int *) malloc (sizeof (int))) && (dispSizes = (int *) malloc (sizeof (int)))) {
if ((dispVOffset = (int *) malloc(sizeof(int))) &&
(dispSizes = (int *) malloc(sizeof(int))))
{
dispVOffset[0] = 0; dispVOffset[0] = 0;
dispSizes[0] = lcd.hgt; dispSizes[0] = lcd.hgt;
numDisplays = 1; numDisplays = 1;
} } else
else
fprintf (stderr, "Error mallocing for display sizes list\n"); fprintf (stderr, "Error mallocing for display sizes list\n");
} }
// Set up io port correctly, and open it... // Set up io port correctly, and open it...
if ((ioperm (port, 1, 255)) == -1) { if ((ioperm (port, 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;
} }
// Make sure the frame buffer is there... // Make sure the frame buffer is there...
if (!HD44780->framebuf) if (!HD44780->framebuf)
HD44780->framebuf = (unsigned char *) malloc (lcd.wid * lcd.hgt); HD44780->framebuf = (unsigned char *) malloc (lcd.wid * lcd.hgt);
@@ -275,7 +226,6 @@ int HD44780_init(lcd_logical_driver *driver, char *args)
return -1; return -1;
} }
// Set the functions the driver supports... // Set the functions the driver supports...
// These are the default HD44780 functions // These are the default HD44780 functions
driver->clear = (void *) -1; driver->clear = (void *) -1;
@@ -299,9 +249,7 @@ int HD44780_init(lcd_logical_driver *driver, char *args)
driver->draw_frame = HD44780_draw_frame; driver->draw_frame = HD44780_draw_frame;
driver->getkey = NULL; driver->getkey = NULL;
if ((hd44780_functions = if ((hd44780_functions = (HD44780_functions *) malloc (sizeof (HD44780_functions))) == NULL) {
(HD44780_functions *) malloc(sizeof(HD44780_functions))) == NULL)
{
return -1; return -1;
} }
hd44780_functions->uPause = uPause; hd44780_functions->uPause = uPause;
@@ -317,10 +265,10 @@ int HD44780_init(lcd_logical_driver *driver, char *args)
// common initialisation sequence - sets twoline, small characters (5x8), // common initialisation sequence - sets twoline, small characters (5x8),
// cursor off and not blinking, clear display and homecursor // cursor off and not blinking, clear display and homecursor
void common_init(enum ifWidth ifwidth) void
{ common_init (enum ifWidth ifwidth)
if (ifwidth == IF_8bit)
{ {
if (ifwidth == IF_8bit) {
// setup the lcd in 8 bit mode // setup the lcd in 8 bit mode
hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT); hd44780_functions->senddata (0, RS_INSTR, FUNCSET | IF_8BIT);
hd44780_functions->uPause (4100); hd44780_functions->uPause (4100);
@@ -334,16 +282,10 @@ void common_init(enum ifWidth ifwidth)
// properly but it might just work properly anyway .... // properly but it might just work properly anyway ....
// set display type functions // set display type functions
hd44780_functions->senddata(0, hd44780_functions->senddata (0, RS_INSTR, FUNCSET | ((ifwidth == IF_4BIT) ? IF_4BIT : IF_8BIT) | TWOLINE | SMALLCHAR);
RS_INSTR,
FUNCSET |
((ifwidth == IF_4BIT) ? IF_4BIT : IF_8BIT) |
TWOLINE | SMALLCHAR);
hd44780_functions->uPause (40); hd44780_functions->uPause (40);
hd44780_functions->senddata(0, hd44780_functions->senddata (0, RS_INSTR, ONOFFCTRL | DISPON | CURSOROFF | CURSORNOBLINK);
RS_INSTR,
ONOFFCTRL | DISPON | CURSOROFF | CURSORNOBLINK);
hd44780_functions->uPause (40); hd44780_functions->uPause (40);
hd44780_functions->senddata (0, RS_INSTR, CLEAR); hd44780_functions->senddata (0, RS_INSTR, CLEAR);
hd44780_functions->uPause (1600); hd44780_functions->uPause (1600);
@@ -352,7 +294,8 @@ void common_init(enum ifWidth ifwidth)
} }
// IO delay to avoid a task switch // IO delay to avoid a task switch
void uPause(int delayCalls) void
uPause (int delayCalls)
{ {
int i; int i;
for (i = 0; i < delayCalls; ++i) for (i = 0; i < delayCalls; ++i)
@@ -362,7 +305,8 @@ void uPause(int delayCalls)
// displayID - ID of display to use (0 = all displays) // displayID - ID of display to use (0 = all displays)
static void HD44780_senddata(unsigned char displayID, unsigned char flags, unsigned char ch) static void
HD44780_senddata (unsigned char displayID, unsigned char flags, unsigned char ch)
{ {
hd44780_functions->senddata (displayID, flags, ch); hd44780_functions->senddata (displayID, flags, ch);
hd44780_functions->uPause (40); hd44780_functions->uPause (40);
@@ -380,7 +324,8 @@ static void HD44780_senddata(unsigned char displayID, unsigned char flags, unsig
*/ */
// x and y here are for the virtual lcd.hgt x lcd.wid display // x and y here are for the virtual lcd.hgt x lcd.wid display
static void HD44780_position(int x, int y) static void
HD44780_position (int x, int y)
{ {
int dispID = spanList[y]; int dispID = spanList[y];
int relY = y - dispVOffset[dispID - 1]; int relY = y - dispVOffset[dispID - 1];
@@ -388,9 +333,9 @@ static void HD44780_position(int x, int y)
// 16x1 is a special case // 16x1 is a special case
if (dispSizes[dispID - 1] == 1 && lcd.wid == 16) if (dispSizes[dispID - 1] == 1 && lcd.wid == 16)
if (x >= 8) if (x >= 8) {
{ x -= 8;
x -= 8; relY = 1; relY = 1;
} }
DDaddr = x + (relY % 2) * 0x40; DDaddr = x + (relY % 2) * 0x40;
@@ -400,19 +345,22 @@ static void HD44780_position(int x, int y)
hd44780_functions->position (dispID, DDaddr); hd44780_functions->position (dispID, DDaddr);
} }
void common_position(int display, int DDaddr) void
common_position (int display, int DDaddr)
{ {
hd44780_functions->senddata (display, RS_INSTR, POSITION | DDaddr); hd44780_functions->senddata (display, RS_INSTR, POSITION | DDaddr);
hd44780_functions->uPause (40); hd44780_functions->uPause (40);
} }
void HD44780_flush() void
HD44780_flush ()
{ {
HD44780_draw_frame (lcd.framebuf); HD44780_draw_frame (lcd.framebuf);
} }
void HD44780_flush_box(int lft, int top, int rgt, int bot) void
HD44780_flush_box (int lft, int top, int rgt, int bot)
{ {
int x, y; int x, y;
@@ -422,8 +370,7 @@ void HD44780_flush_box(int lft, int top, int rgt, int bot)
HD44780_position (lft, y); HD44780_position (lft, y);
//printf("\n%d,%d :",lft,y); //printf("\n%d,%d :",lft,y);
for (x = lft; x <= rgt; x++) { for (x = lft; x <= rgt; x++) {
HD44780_senddata(spanList[y], RS_DATA, HD44780_senddata (spanList[y], RS_DATA, lcd.framebuf[(y * lcd.wid) + x]);
lcd.framebuf[(y*lcd.wid)+x]);
} }
//write(fd, lcd.framebuf[(y*lcd.wid)+lft, rgt-lft+1]); //write(fd, lcd.framebuf[(y*lcd.wid)+lft, rgt-lft+1]);
} }
@@ -434,7 +381,8 @@ void HD44780_flush_box(int lft, int top, int rgt, int bot)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Changes screen contrast (0-255; 140 seems good) // Changes screen contrast (0-255; 140 seems good)
// //
int HD44780_contrast(int contrast) int
HD44780_contrast (int contrast)
{ {
return 0; return 0;
} }
@@ -443,7 +391,8 @@ int HD44780_contrast(int contrast)
// Sets the backlight on or off -- can be done quickly for // Sets the backlight on or off -- can be done quickly for
// an intermediate brightness... // an intermediate brightness...
// //
void HD44780_backlight(int on) void
HD44780_backlight (int on)
{ {
} }
@@ -451,23 +400,24 @@ void HD44780_backlight(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Toggle the built-in linewrapping feature // Toggle the built-in linewrapping feature
// //
static void HD44780_linewrap(int on) static void
HD44780_linewrap (int on)
{ {
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Toggle the built-in automatic scrolling feature // Toggle the built-in automatic scrolling feature
// //
static void HD44780_autoscroll(int on) static void
HD44780_autoscroll (int on)
{ {
hd44780_functions->autoscroll (on); hd44780_functions->autoscroll (on);
} }
void common_autoscroll(int on) void
common_autoscroll (int on)
{ {
hd44780_functions->senddata(0, RS_INSTR, hd44780_functions->senddata (0, RS_INSTR, ENTRYMODE | E_MOVERIGHT | ((on) ? EDGESCROLL : NOSCROLL));
ENTRYMODE | E_MOVERIGHT |
((on) ? EDGESCROLL : NOSCROLL));
hd44780_functions->uPause (1600); hd44780_functions->uPause (1600);
} }
@@ -475,7 +425,8 @@ void common_autoscroll(int on)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for vertical bars. Call before lcd.vbar() // Sets up for vertical bars. Call before lcd.vbar()
// //
void HD44780_init_vbar() void
HD44780_init_vbar ()
{ {
char a[] = { char a[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -560,7 +511,8 @@ void HD44780_init_vbar()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Inits horizontal bars... // Inits horizontal bars...
// //
void HD44780_init_hbar() void
HD44780_init_hbar ()
{ {
char a[] = { char a[] = {
@@ -614,7 +566,8 @@ void HD44780_init_hbar()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a vertical bar... // Draws a vertical bar...
// //
void HD44780_vbar(int x, int len) void
HD44780_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 };
@@ -633,7 +586,8 @@ void HD44780_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right. // Draws a horizontal bar to the right.
// //
void HD44780_hbar(int x, int y, int len) void
HD44780_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 };
@@ -652,7 +606,8 @@ void HD44780_hbar(int x, int y, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Sets up for big numbers. // Sets up for big numbers.
// //
void HD44780_init_num() void
HD44780_init_num ()
{ {
char out[3]; char out[3];
sprintf (out, "%cn", 254); sprintf (out, "%cn", 254);
@@ -663,7 +618,8 @@ void HD44780_init_num()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Writes a big number. // Writes a big number.
// //
void HD44780_num(int x, int num) void
HD44780_num (int x, int num)
{ {
char out[5]; char out[5];
sprintf (out, "%c#%c%c", 254, x, num); sprintf (out, "%c#%c%c", 254, x, num);
@@ -678,21 +634,22 @@ void HD44780_num(int x, int num)
// //
// The input is just an array of characters... // The input is just an array of characters...
// //
void HD44780_set_char(int n, char *dat) void
HD44780_set_char (int n, char *dat)
{ {
int row, col; int row, col;
int letter; int letter;
if (n < 0 || n > 7) return; if (n < 0 || n > 7)
if (!dat) return; return;
if (!dat)
return;
HD44780_senddata (0, RS_INSTR, SETCHAR | n * 8); HD44780_senddata (0, RS_INSTR, SETCHAR | n * 8);
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 <<= 1;
letter |= (dat[(row * lcd.cellwid) + col] > 0); letter |= (dat[(row * lcd.cellwid) + col] > 0);
} }
@@ -701,7 +658,8 @@ void HD44780_set_char(int n, char *dat)
} }
void HD44780_icon(int which, char dest) void
HD44780_icon (int which, char dest)
{ {
char icons[3][5 * 8] = { char icons[3][5 * 8] = {
{ {
@@ -749,11 +707,13 @@ void HD44780_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 HD44780_draw_frame(char *dat) void
HD44780_draw_frame (char *dat)
{ {
int x, y; int x, y;
if (!dat) return; if (!dat)
return;
for (y = 0; y < lcd.hgt; y++) { for (y = 0; y < lcd.hgt; y++) {
HD44780_position (0, y); HD44780_position (0, y);
@@ -776,30 +736,22 @@ void HD44780_draw_frame(char *dat)
// returns number of span elements, -1 on parse error // returns number of span elements, -1 on parse error
int int
parse_span_list(int *spanListArray[], int *spLsize, parse_span_list (int *spanListArray[], int *spLsize, int *dispOffsets[], int *dOffsize, int *dispSizeArray[], char *spanlist)
int *dispOffsets[], int *dOffsize,
int *dispSizeArray[], char *spanlist)
{ {
int j = 0, retVal = 0; int j = 0, retVal = 0;
*spLsize = 0; *spLsize = 0;
*dOffsize = 0; *dOffsize = 0;
while (j < strlen(spanlist)) while (j < strlen (spanlist)) {
{ if (spanlist[j] >= '1' && spanlist[j] <= '9') {
if (spanlist[j] >= '1' && spanlist[j] <= '9')
{
int spansize = spanlist[j] - '0'; int spansize = spanlist[j] - '0';
// add spansize lines to the span list, note the offset to // add spansize lines to the span list, note the offset to
// the previous display and the size of the display // the previous display and the size of the display
if ((*spanListArray = (int *) realloc(*spanListArray, if ((*spanListArray = (int *) realloc (*spanListArray, sizeof (int) * (*spLsize + spansize)))
sizeof(int) * (*spLsize + spansize))) && (*dispOffsets = (int *) realloc (*dispOffsets, sizeof (int) * (*dOffsize + 1)))
&& (*dispOffsets = (int *) realloc(*dispOffsets, && (*dispSizeArray = (int *) realloc (*dispSizeArray, sizeof (int) * (*dOffsize + 1)))) {
sizeof(int) * (*dOffsize + 1)))
&& (*dispSizeArray = (int *) realloc(*dispSizeArray,
sizeof(int) * (*dOffsize + 1))))
{
int k; int k;
for (k = 0; k < spansize; ++k) for (k = 0; k < spansize; ++k)
(*spanListArray)[*spLsize + k] = *dOffsize + 1; (*spanListArray)[*spLsize + k] = *dOffsize + 1;
@@ -811,17 +763,12 @@ parse_span_list(int *spanListArray[], int *spLsize,
retVal = *dOffsize; retVal = *dOffsize;
// find the next number (\0 is also outside this range) // find the next number (\0 is also outside this range)
for ( ++j; spanlist[j] < '1' || spanlist[j] > '9'; ++j) for (++j; spanlist[j] < '1' || spanlist[j] > '9'; ++j);
; } else {
}
else
{
fprintf (stderr, "Error reallocing for span list\n"); fprintf (stderr, "Error reallocing for span list\n");
retVal - 1; retVal - 1;
} }
} } else {
else
{
fprintf (stderr, "Error reading spansize\n"); fprintf (stderr, "Error reading spansize\n");
retVal = -1; retVal = -1;
} }
+16 -28
View File
@@ -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;
@@ -100,42 +101,26 @@ int irmanin_init(struct lcd_logical_driver *driver, char *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]);
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) { if (i + 1 > argc) {
fprintf(stderr, "irmanin_init: %s requires an argument\n", fprintf (stderr, "irmanin_init: %s requires an argument\n", argv[i]);
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") ||
0 == strcmp(argv[i], "--config"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "irmanin_init: %s requires an argument\n", fprintf (stderr, "irmanin_init: %s requires an argument\n", argv[i]);
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 {
else
{
printf ("Invalid parameter: %s\n", argv[i]); printf ("Invalid parameter: %s\n", argv[i]);
} }
} }
@@ -178,9 +163,11 @@ int irmanin_init(struct lcd_logical_driver *driver, char *args)
} }
void irmanin_close() void
irmanin_close ()
{ {
if(irmanin->framebuf != NULL) free(irmanin->framebuf); if (irmanin->framebuf != NULL)
free (irmanin->framebuf);
irmanin->framebuf = NULL; irmanin->framebuf = NULL;
@@ -194,7 +181,8 @@ 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;
+30 -47
View File
@@ -53,7 +53,8 @@ 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];
@@ -66,52 +67,30 @@ int joy_init(struct lcd_logical_driver *driver, char *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]);
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) { if (i + 1 > argc) {
fprintf(stderr, "joy_init: %s requires an argument\n", fprintf (stderr, "joy_init: %s requires an argument\n", argv[i]);
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") ||
0 == strcmp(argv[i], "--axes"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "joy_init: %s requires an argument\n", fprintf (stderr, "joy_init: %s requires an argument\n", argv[i]);
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") ||
0 == strcmp(argv[i], "--buttons"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "joy_init: %s requires an argument\n", fprintf (stderr, "joy_init: %s requires an argument\n", argv[i]);
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 {
else
{
printf ("Invalid parameter: %s\n", argv[i]); printf ("Invalid parameter: %s\n", argv[i]);
} }
@@ -136,16 +115,15 @@ int joy_init(struct lcd_logical_driver *driver, char *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, JSIOCGVERSION, &jsversion);
ioctl (fd, JSIOCGAXES, &axes); ioctl (fd, JSIOCGAXES, &axes);
ioctl (fd, JSIOCGBUTTONS, &buttons); ioctl (fd, JSIOCGBUTTONS, &buttons);
ioctl (fd, JSIOCGNAME (NAME_LENGTH), jsname); ioctl (fd, JSIOCGNAME (NAME_LENGTH), jsname);
debug("Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n", 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);
jsname, axes, buttons,
jsversion >> 16, (jsversion >> 8) & 0xff, jsversion & 0xff);
axis = calloc (axes, sizeof (int)); axis = calloc (axes, sizeof (int));
button = calloc (buttons, sizeof (char)); button = calloc (buttons, sizeof (char));
@@ -154,9 +132,11 @@ int joy_init(struct lcd_logical_driver *driver, char *args)
} }
void joy_close() void
joy_close ()
{ {
if(joy->framebuf != NULL) free(joy->framebuf); if (joy->framebuf != NULL)
free (joy->framebuf);
close (fd); close (fd);
joy->framebuf = NULL; joy->framebuf = NULL;
@@ -173,18 +153,19 @@ 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)
return 0;
if (err != sizeof (struct js_event)) { if (err != sizeof (struct js_event)) {
fprintf (stderr, "\nerror reading joystick\n"); 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) {
@@ -200,17 +181,19 @@ char joy_getkey()
//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)];
} }
} }
+107 -133
View File
@@ -61,8 +61,7 @@
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,},
@@ -103,14 +102,14 @@ 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 (); list = LL_new ();
if(!list) if (!list) {
{
printf ("Error allocating driver list.\n"); printf ("Error allocating driver list.\n");
return -1; return -1;
} }
@@ -144,43 +143,41 @@ int lcd_init(char *args)
// 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); add->framebuf = malloc (add->wid * add->hgt);
if(!add->framebuf) if (!add->framebuf) {
{ printf ("Couldn't allocate framebuffer for driver \"%s\".\n", driver);
printf("Couldn't allocate framebuffer for driver \"%s\".\n",
driver);
free (add); free (add);
return -1; return -1;
} }
@@ -196,7 +193,8 @@ 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;
@@ -204,17 +202,13 @@ int lcd_shutdown()
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) {
else if((int)driver->close == -1)
{
drv_base->close (); drv_base->close ();
} }
@@ -231,7 +225,8 @@ int lcd_shutdown()
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");
@@ -302,7 +297,8 @@ 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;
@@ -311,17 +307,13 @@ void lcd_drv_close()
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) {
else if((int)driver->close == -1)
{
drv_base->close (); drv_base->close ();
} }
} }
@@ -329,21 +321,20 @@ void lcd_drv_close()
} }
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 ();
} }
} }
@@ -352,21 +343,20 @@ void lcd_drv_clear()
} }
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 ();
} }
} }
@@ -374,42 +364,40 @@ void lcd_drv_flush()
} }
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);
} }
} }
@@ -418,7 +406,8 @@ void lcd_drv_chr(int x, int y, char c)
int lcd_drv_contrast(int contrast) int
lcd_drv_contrast (int contrast)
{ {
int res = 0; int res = 0;
@@ -427,14 +416,13 @@ int lcd_drv_contrast(int contrast)
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) return res; if (res >= 0)
return res;
} }
/* /*
else if((int)driver->contrast == -1) else if((int)driver->contrast == -1)
@@ -448,41 +436,38 @@ int lcd_drv_contrast(int contrast)
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);
} }
} }
@@ -490,147 +475,140 @@ void lcd_drv_output(int on)
} }
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);
} }
} }
@@ -638,21 +616,20 @@ 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)
{ {
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);
} }
} }
@@ -660,21 +637,20 @@ 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)
{ {
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);
} }
} }
@@ -685,21 +661,20 @@ void lcd_drv_flush_box(int lft, int top, int rgt, int bot)
// 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);
} }
} }
@@ -708,7 +683,8 @@ void lcd_drv_draw_frame(char *dat)
} }
char lcd_drv_getkey() char
lcd_drv_getkey ()
{ {
lcd_logical_driver *driver; lcd_logical_driver *driver;
@@ -717,19 +693,17 @@ char lcd_drv_getkey()
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) return key; if (key)
} return key;
else if((int)driver->getkey == -1) } else if ((int) driver->getkey == -1) {
{
key = drv_base->getkey (); key = drv_base->getkey ();
if(key) return key; if (key)
return key;
} }
} }
} while (LL_Next (list) == 0); } while (LL_Next (list) == 0);
+2 -5
View File
@@ -20,8 +20,7 @@ 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
@@ -60,8 +59,7 @@ typedef struct lcd_logical_driver
} 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;
@@ -92,4 +90,3 @@ void lcd_drv_draw_frame();
char lcd_drv_getkey (); char lcd_drv_getkey ();
#endif #endif
+9 -22
View File
@@ -68,16 +68,11 @@ 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) {
{
switch (errno)
{
case EEXIST: case EEXIST:
/* semaphore set exists, get id and return it */ /* semaphore set exists, get id and return it */
if ((semid = semget(getkey(SEMAPHORE), SEMCOUNT, if ((semid = semget (getkey (SEMAPHORE), SEMCOUNT, IPC_EXCL | WMODE)) < 0) {
IPC_EXCL | WMODE)) < 0)
{
perror ("semget"); perror ("semget");
exit (1); exit (1);
} }
@@ -93,14 +88,11 @@ sem_get(void)
exit (1); exit (1);
break; break;
} }
} } else {
else
{
/* initialise semaphore to 1 */ /* initialise semaphore to 1 */
semval.val = 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);
} }
@@ -116,8 +108,7 @@ 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);
} }
@@ -132,8 +123,7 @@ 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);
} }
@@ -151,10 +141,8 @@ sem_remove(int sid)
int i; int i;
union semun dummy; union semun dummy;
if ((i = semctl(sid, 0, IPC_RMID, dummy)) < 0) if ((i = semctl (sid, 0, IPC_RMID, dummy)) < 0) {
{ switch (i) {
switch(i)
{
case EIDRM: case EIDRM:
/* semaphore removed */ /* semaphore removed */
return 0; return 0;
@@ -167,4 +155,3 @@ sem_remove(int sid)
return 0; return 0;
} }
-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 */
+10 -9
View File
@@ -49,7 +49,8 @@ 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,17 +62,17 @@ 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())) if (!(ir = lirc_nextir ())) {
{ return 0;
} else {
if (!(cmd = lirc_ir2char (config, ir)))
return 0; return 0;
} else
{
if (!(cmd = lirc_ir2char(config,ir))) return 0;
printf ("lirc: \"%s\"\n", cmd); printf ("lirc: \"%s\"\n", cmd);
sscanf (cmd, "%c", &key); sscanf (cmd, "%c", &key);
@@ -87,7 +88,8 @@ char lircin_getkey()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// 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 */
@@ -119,4 +121,3 @@ int lircin_init(struct lcd_logical_driver *driver, char *args)
return 1; // 200 is arbitrary. (must be 1 or more) return 1; // 200 is arbitrary. (must be 1 or more)
} }
+10 -10
View File
@@ -15,34 +15,34 @@
#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);
} }
+120 -56
View File
@@ -212,8 +212,8 @@ 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;
@@ -240,7 +240,8 @@ unsigned char *p;
} }
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.
// //
@@ -255,7 +256,8 @@ 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;
@@ -321,13 +323,15 @@ int svgalib_drv_init(struct lcd_logical_driver *driver, char *args)
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,16 +342,20 @@ 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);
@@ -358,12 +366,17 @@ void svgalib_drv_string(int x, int y, char 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;
@@ -374,14 +387,16 @@ char buffer[2];
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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;
@@ -397,15 +412,17 @@ void svgalib_drv_num(int x, int num)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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,10 +431,10 @@ 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
@@ -431,34 +448,44 @@ 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;
@@ -472,10 +499,18 @@ FILE* fd;
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:
i = 'B';
break;
case VGAKEY_DOWN:
i = 'C';
break;
case VGAKEY_RIGHT:
i = 'A';
break;
default: default:
i = 0; /* key not recognised */ i = 0; /* key not recognised */
} }
@@ -492,28 +527,57 @@ FILE* fd;
be able to quit LCDproc from the emulation. be able to quit LCDproc from the emulation.
*/ */
case 'j' : i= 'D';break; /* left */ case 'j':
case 'm' : i= 'B';break; /* up */ i = 'D';
case '7' : i= 'C';break; /* down */ break; /* left */
case 'u' : i= 'A';break; /* right */ 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 'v':
case 'c':i='W';break; /* two */ i = 'Q';
case 'z':i='E';break; /* three */ break; /* one */
case '4':i='R';break; /* four */ case 'c':
case '3':i='T';break; /* five */ i = 'W';
case '1':i='Y';break; /* six */ break; /* two */
case 'f':i='U';break; /* seven */ case 'z':
case 'd':i='I';break; /* eight */ i = 'E';
case 'a':i='O';break; /* nine */ break; /* three */
case 'e':i='P';break; /* zero */ case '4':
case 'r':i='L';break; /* 'C' key */ 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: default:
i = 0; i = 0;
} }
} /* if (i) */ }
/* if (i) */
return i; return i;
} }
+44 -35
View File
@@ -17,12 +17,12 @@ 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;
} }
@@ -59,7 +59,8 @@ int text_init(lcd_logical_driver *driver, char *args)
return 200; // 200 is arbitrary. (must be 1 or more) return 200; // 200 is arbitrary. (must be 1 or more)
} }
void text_close() void
text_close ()
{ {
drv_base_close (); drv_base_close ();
} }
@@ -67,7 +68,8 @@ void text_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);
@@ -77,7 +79,8 @@ void text_clear()
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// 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,15 +90,15 @@ 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];
} }
} }
@@ -104,7 +107,8 @@ void text_string(int x, int y, char 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 text_chr(int x, int y, char c) void
text_chr (int x, int y, char c)
{ {
y--; y--;
x--; x--;
@@ -114,13 +118,15 @@ void text_chr(int x, int y, char 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,11 +173,11 @@ 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;
@@ -177,10 +188,10 @@ void text_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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;
@@ -189,35 +200,35 @@ void text_hbar(int x, int y, int len)
} }
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;
@@ -225,12 +236,10 @@ void text_draw_frame(char *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);
} }
+74 -70
View File
@@ -23,7 +23,8 @@ 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;
@@ -58,51 +60,41 @@ int sli_init(lcd_logical_driver *driver, char *args)
} }
*/ */
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) { if (i + 1 > argc) {
fprintf(stderr, "sli_init: %s requires an argument\n", fprintf (stderr, "sli_init: %s requires an argument\n", argv[i]);
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") ||
0 == strcmp(argv[i], "--speed"))
{
if (i + 1 > argc) { if (i + 1 > argc) {
fprintf(stderr, "sli_init: %s requires an argument\n", fprintf (stderr, "sli_init: %s requires an argument\n", argv[i]);
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)
speed = B19200;
else if (tmp == 38400)
speed = B38400;
else if (tmp == 57600)
speed = B57600;
else if (tmp == 115200)
speed = B115200;
else { else {
fprintf(stderr, "sli_init: %s argument must be 1200, 2400, 9600, 19200, 38400, 57600, or 115200. Using default value (19200).\n", fprintf (stderr, "sli_init: %s argument must be 1200, 2400, 9600, 19200, 38400, 57600, or 115200. Using default value (19200).\n", argv[i]);
argv[i]);
} }
} } else if (0 == strcmp (argv[i], "-h") || 0 == strcmp (argv[i], "--help")) {
else if(0 == strcmp(argv[i], "-h") || 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");
0 == strcmp(argv[i], "--help"))
{
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 {
else
{
printf ("Invalid parameter: %s\n", argv[i]); printf ("Invalid parameter: %s\n", argv[i]);
} }
@@ -110,8 +102,7 @@ int sli_init(lcd_logical_driver *driver, char *args)
// 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;
} }
@@ -138,13 +129,11 @@ int sli_init(lcd_logical_driver *driver, char *args)
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...
@@ -181,17 +170,20 @@ int sli_init(lcd_logical_driver *driver, char *args)
/* 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,7 +193,8 @@ 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? */
@@ -216,8 +209,7 @@ void sli_flush_box(int lft, int top, int rgt, int bot)
// 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)
@@ -233,7 +225,8 @@ void sli_flush_box(int lft, int top, int rgt, int bot)
// 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--;
@@ -255,7 +248,8 @@ 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,
@@ -343,7 +337,8 @@ void sli_init_vbar()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Inits horizontal bars... // Inits horizontal bars...
// //
void sli_init_hbar() void
sli_init_hbar ()
{ {
char a[] = { char a[] = {
@@ -405,16 +400,18 @@ 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; 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) sli_chr(x, y, 255); sli_chr (x, y, 255);
else sli_chr(x, y, map[len]); else
sli_chr (x, y, map[len]);
len -= lcd.cellhgt; len -= lcd.cellhgt;
} }
@@ -424,14 +421,16 @@ void sli_vbar(int x, int len)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// 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++) for (; x <= lcd.wid && len > 0; x++) {
{ if (len >= lcd.cellwid)
if(len >= lcd.cellwid) sli_chr(x,y,255); sli_chr (x, y, 255);
else sli_chr(x, y, map[len]); else
sli_chr (x, y, map[len]);
len -= lcd.cellwid; len -= lcd.cellwid;
@@ -447,26 +446,27 @@ 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 <<= 1;
letter |= (dat[(row * lcd.cellwid) + col] > 0); letter |= (dat[(row * lcd.cellwid) + col] > 0);
} }
@@ -481,7 +481,8 @@ void sli_set_char(int n, char *dat)
} }
void sli_icon(int which, char dest) void
sli_icon (int which, char dest)
{ {
char icons[3][5 * 8] = { char icons[3][5 * 8] = {
{ {
@@ -519,7 +520,8 @@ void sli_icon(int which, char dest)
}; };
if(custom==bign) custom=beat; if (custom == bign)
custom = beat;
sli_set_char (dest, &icons[which][0]); sli_set_char (dest, &icons[which][0]);
} }
@@ -529,12 +531,14 @@ 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)
return;
/* /*
out[0]=0x0FE; out[0]=0x0FE;
+14 -20
View File
@@ -47,7 +47,8 @@ int server_input(int key);
// (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;
@@ -56,35 +57,29 @@ int handle_input()
key = lcd.getkey (); key = lcd.getkey ();
if (!key) return 0; if (!key)
return 0;
debug ("handle_input(%c)\n", (char) key); debug ("handle_input(%c)\n", (char) key);
if(key) if (key) {
{
s = screenlist_current (); s = screenlist_current ();
if(s) 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,12 +92,12 @@ 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;
@@ -122,8 +117,7 @@ int server_input(int key)
server_menu (); server_menu ();
break; break;
default: default:
debug("server_input: Invalid key \"%c\" (%i)\n", debug ("server_input: Invalid key \"%c\" (%i)\n", (char) key, key);
(char)key, key);
break; break;
} }
+57 -91
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"},
@@ -69,7 +68,8 @@ 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";
@@ -95,23 +95,19 @@ int main(int argc, char **argv)
// 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 usleep (1500000); // Wait for child to initialize
exit (0); /* PARENT EXITS */ exit (0); /* PARENT EXITS */
} }
@@ -128,53 +124,41 @@ int main(int argc, char **argv)
// 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) || if (!strcmp (argv[i + 1], args[j].sh) || !strcmp (argv[i + 1], args[j].lg))
! strcmp(argv[i+1], args[j].lg)) skip=1; 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; daemon_mode = 0;
} } else if (0 == strcmp (argv[i], "-b") || 0 == strcmp (argv[i], "--backlight")) {
else if(0 == strcmp(argv[i], "-b") || if (argc <= i + 1)
0 == strcmp(argv[i], "--backlight")) HelpScreen ();
{
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;
@@ -182,29 +166,21 @@ int main(int argc, char **argv)
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
} HelpScreen ();
else if(0 == strcmp(argv[i], "-t") || } else if (0 == strcmp (argv[i], "-t") || 0 == strcmp (argv[i], "--type")) {
0 == strcmp(argv[i], "--type"))
{
if (i + 1 > argc) if (i + 1 > argc)
HelpScreen (); HelpScreen ();
else 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;
} }
@@ -228,21 +204,17 @@ 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") ||
0 == strcmp(argv[i], "--serverinfo"))
{
if (i + 1 > argc) if (i + 1 > argc)
HelpScreen (); HelpScreen ();
else 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 ();
@@ -253,42 +225,33 @@ int main(int argc, char **argv)
// 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; return 1;
} }
if(screenlist_init() < 0) if (screenlist_init () < 0) {
{
printf ("Error initializing screen list\n"); printf ("Error initializing screen list\n");
return 1; 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 ();
@@ -299,18 +262,20 @@ 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)
timer = 0;
update_server_screen (timer); update_server_screen (timer);
s = screenlist_current (); 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
no_screen_screen (timer);
usleep (TIME_UNIT); usleep (TIME_UNIT);
} }
@@ -323,7 +288,8 @@ int main(int argc, char **argv)
} }
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...
@@ -345,7 +311,8 @@ void exit_program(int val)
} }
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");
@@ -368,4 +335,3 @@ void HelpScreen()
printf ("\n"); printf ("\n");
exit (0); exit (0);
} }
+2 -4
View File
@@ -21,14 +21,12 @@ void exit_program(int val);
// 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;
+62 -60
View File
@@ -29,7 +29,8 @@
// 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 ();
@@ -37,12 +38,12 @@ void framedelay()
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);
@@ -58,8 +59,7 @@ static int PAD = 255;
typedef struct menu_info typedef struct menu_info {
{
int selected; int selected;
int length; int length;
} menu_info; } menu_info;
@@ -73,7 +73,8 @@ 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;
@@ -84,19 +85,19 @@ int do_menu(Menu menu)
int (*readfunc) (int); int (*readfunc) (int);
if(!menu) return MENU_ERROR; if (!menu)
return MENU_ERROR;
fill_menu_info (menu, &info); fill_menu_info (menu, &info);
while(!done) while (!done) {
{
// Keep the cursor off titles... (?) // Keep the cursor off titles... (?)
while(menu[info.selected].type == TYPE_TITL) while (menu[info.selected].type == TYPE_TITL) {
{
info.selected++; info.selected++;
// If the title is the last thing in the menu... // If the title is the last thing in the menu...
if(!menu[info.selected].text) info.selected -= 2; if (!menu[info.selected].text)
info.selected -= 2;
} }
@@ -105,8 +106,7 @@ int do_menu(Menu menu)
// FIXME: This should use a better keypress interface, which // FIXME: This should use a better keypress interface, which
// FIXME: handles things according to keybindings... // FIXME: handles things according to keybindings...
for(key = lcd.getkey(); key==0; key = lcd.getkey()) for (key = lcd.getkey (); key == 0; key = lcd.getkey ()) {
{
// sleep for 1/8th second... // sleep for 1/8th second...
framedelay (); framedelay ();
// do the heartbeat... // do the heartbeat...
@@ -116,22 +116,28 @@ int do_menu(Menu menu)
// Handle the key according to the keybindings... // Handle the key according to the keybindings...
switch(key) switch (key) {
{ case 'D':
case 'D': done=1; break; done = 1;
case 'B': if(info.selected > 0) info.selected--; break;
while(menu[info.selected].type == TYPE_TITL) case 'B':
{
if (info.selected > 0) if (info.selected > 0)
info.selected--; info.selected--;
else break; while (menu[info.selected].type == TYPE_TITL) {
if (info.selected > 0)
info.selected--;
else
break;
} }
break; break;
case 'C': if(menu[info.selected+1].text) info.selected++; break; case 'C':
if (menu[info.selected + 1].text)
info.selected++;
break;
case 'A': case 'A':
switch(menu[info.selected].type) switch (menu[info.selected].type) {
{ case TYPE_MENU:
case TYPE_MENU: status = do_menu(menu[info.selected].data); status = do_menu (menu[info.selected].data);
break; break;
case TYPE_FUNC: case TYPE_FUNC:
func = menu[info.selected].data; func = menu[info.selected].data;
@@ -153,8 +159,7 @@ int do_menu(Menu menu)
break; break;
} }
switch(status) switch (status) {
{
case MENU_OK: case MENU_OK:
break; break;
case MENU_CLOSE: case MENU_CLOSE:
@@ -171,7 +176,8 @@ int do_menu(Menu menu)
// TODO: It should now do special stuff for "mover" widgets, // TODO: It should now do special stuff for "mover" widgets,
// TODO: and handle the return code appropriately. // TODO: and handle the return code appropriately.
break; break;
default: break; default:
break;
} }
} }
@@ -180,7 +186,8 @@ int do_menu(Menu menu)
} }
static int draw_menu(Menu menu, menu_info *info) static int
draw_menu (Menu menu, menu_info * info)
{ {
int i; int i;
int x = 1, y = 1; int x = 1, y = 1;
@@ -192,28 +199,31 @@ static int draw_menu(Menu menu, menu_info *info)
int wid = lcd.wid, hgt = lcd.hgt; int wid = lcd.wid, hgt = lcd.hgt;
if(!menu) return MENU_ERROR; if (!menu)
return MENU_ERROR;
lcd.clear (); lcd.clear ();
// Scroll down until the selected item is centered, if possible... // Scroll down until the selected item is centered, if possible...
top = info->selected - (hgt / 2); top = info->selected - (hgt / 2);
if(top<0) top=0; if (top < 0)
top = 0;
bottom = top + hgt; bottom = top + hgt;
if(bottom > info->length) bottom=info->length; if (bottom > info->length)
bottom = info->length;
top = bottom - hgt; top = bottom - hgt;
if(top<0) top=0; if (top < 0)
top = 0;
// Draw all visible items... // Draw all visible items...
for(i=top; i<bottom; i++, y++) for (i = top; i < bottom; i++, y++) {
{ if (i == info->selected)
if(i == info->selected) lcd.chr(2,y,'>'); lcd.chr (2, y, '>');
switch(menu[i].type) switch (menu[i].type) {
{
case TYPE_TITL: case TYPE_TITL:
lcd.chr (1, y, PAD); lcd.chr (1, y, PAD);
lcd.chr (2, y, PAD); lcd.chr (2, y, PAD);
@@ -229,8 +239,7 @@ static int draw_menu(Menu menu, menu_info *info)
lcd.string (3, y, menu[i].text); lcd.string (3, y, menu[i].text);
break; break;
case TYPE_CHEK: case TYPE_CHEK:
if(menu[i].data) if (menu[i].data) {
{
readfunc = menu[i].data; readfunc = menu[i].data;
if (readfunc (MENU_READ)) if (readfunc (MENU_READ))
lcd.chr (wid, y, 'Y'); lcd.chr (wid, y, 'Y');
@@ -262,7 +271,8 @@ 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)
{ {
int i; int i;
@@ -277,13 +287,15 @@ 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)
{ {
return MENU_OK; 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;
@@ -295,8 +307,7 @@ static int slid_func(menu_item *item)
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);
@@ -310,22 +321,18 @@ static int slid_func(menu_item *item)
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); lcd.string (17, 2, str);
value = ((lcd.wid - 4) * lcd.cellwid * value / 256); value = ((lcd.wid - 4) * lcd.cellwid * value / 256);
lcd.hbar (1, 2, value); 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...
@@ -333,8 +340,7 @@ static int slid_func(menu_item *item)
// 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;
@@ -343,13 +349,9 @@ static int slid_func(menu_item *item)
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;
} }
+1 -2
View File
@@ -126,8 +126,7 @@ and sliders should return 0-255.
#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;
+105 -67
View File
@@ -99,7 +99,8 @@ menu_item Backlight_menu[] = {
// //
// Exits the program. // Exits the program.
int Shutdown_func() int
Shutdown_func ()
{ {
exit_program (0); exit_program (0);
@@ -107,7 +108,8 @@ int Shutdown_func()
} }
// 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;
@@ -116,18 +118,22 @@ int System_halt_func()
err = system ("init 0"); err = system ("init 0");
if(err < 0) return MENU_KILL; if (err < 0)
if(err == 127) return MENU_KILL; 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;
@@ -136,33 +142,41 @@ int Reboot_func()
err = system ("init 6"); err = system ("init 6");
if(err < 0) return MENU_KILL; if (err < 0)
if(err == 127) return MENU_KILL; 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
@@ -172,57 +186,57 @@ int Time24_func(int input)
// 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) status = 0; if (input == MENU_READ)
if(input == MENU_PLUS) status = 0;
{ 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; break;
case BACKLIGHT_ON: case BACKLIGHT_ON:
if(input == MENU_READ) status = 255; if (input == MENU_READ)
if(input == MENU_PLUS) status = 255;
{ if (input == MENU_PLUS) {
status = 255; status = 255;
} }
if(input == MENU_MINUS) if (input == MENU_MINUS) {
{
backlight = BACKLIGHT_OPEN; backlight = BACKLIGHT_OPEN;
status = 128; status = 128;
} }
break; break;
case BACKLIGHT_OPEN: case BACKLIGHT_OPEN:
if(input == MENU_READ) status = 128; if (input == MENU_READ)
if(input == MENU_PLUS) status = 128;
{ if (input == MENU_PLUS) {
backlight = BACKLIGHT_ON; backlight = BACKLIGHT_ON;
backlight_state = BACKLIGHT_ON; backlight_state = BACKLIGHT_ON;
status = 255; status = 255;
} }
if(input == MENU_MINUS) if (input == MENU_MINUS) {
{
backlight = BACKLIGHT_OFF; backlight = BACKLIGHT_OFF;
backlight_state = BACKLIGHT_OFF; backlight_state = BACKLIGHT_OFF;
status = 0; status = 0;
@@ -243,37 +257,47 @@ int Backlight_func(int input)
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;
if (status > 255)
status = 255;
lcd.contrast (status); lcd.contrast (status);
return (status | MENU_OK); return (status | MENU_OK);
} }
void server_menu() void
server_menu ()
{ {
debug ("server_menu()\n"); debug ("server_menu()\n");
@@ -281,16 +305,22 @@ void server_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 < 0)
if(status>255) status=255; status = 0;
if (status > 255)
status = 255;
lcd.backlight (status); lcd.backlight (status);
backlight_brightness = status; backlight_brightness = status;
@@ -298,16 +328,22 @@ int Backlight_Brightness_func(int input)
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 < 0)
if(status>255) status=255; status = 0;
if (status > 255)
status = 255;
lcd.backlight (status); lcd.backlight (status);
backlight_off_brightness = status; backlight_off_brightness = status;
@@ -315,7 +351,8 @@ int Backlight_Off_Brightness_func(int input)
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;
@@ -323,7 +360,8 @@ int Backlight_Off_func()
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;
@@ -331,9 +369,9 @@ int Backlight_On_func()
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;
} }
+20 -35
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;
@@ -44,66 +45,52 @@ int parse_all_client_messages()
// 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",
rightquote[inquote]);
sock_send_string (c->sock, errmsg); sock_send_string (c->sock, errmsg);
continue; continue;
} }
@@ -117,23 +104,21 @@ 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); // debug("(FOUND %s)\n", commands[i].keyword);
invalid = commands[i].function (c, argc, argv); invalid = commands[i].function (c, argc, argv);
// debug("parse: Returned %i...\n", err); // 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);
+100 -179
View File
@@ -41,13 +41,11 @@ 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;
@@ -59,9 +57,11 @@ int draw_screen(screen *s, int timer)
//debug("draw_screen: %8x, %i\n", (int)s, timer); //debug("draw_screen: %8x, %i\n", (int)s, timer);
if(!s) return -1; if (!s)
return -1;
if(s == old_s) reset = 0; if (s == old_s)
reset = 0;
old_s = s; old_s = s;
@@ -69,8 +69,7 @@ int draw_screen(screen *s, int timer)
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;
@@ -78,8 +77,7 @@ int draw_screen(screen *s, int timer)
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)); tmp = (!((timer & 7) == 7));
if (backlight_state & 1) if (backlight_state & 1)
lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness); lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness);
@@ -87,9 +85,7 @@ int draw_screen(screen *s, int timer)
else else
lcd.backlight (!tmp ? backlight_brightness : backlight_off_brightness); lcd.backlight (!tmp ? backlight_brightness : backlight_off_brightness);
//lcd.backlight(backlight_brightness * ((timer&7) == 7)); //lcd.backlight(backlight_brightness * ((timer&7) == 7));
} } else if (backlight_state & BACKLIGHT_BLINK) {
else if(backlight_state & BACKLIGHT_BLINK)
{
tmp = (!((timer & 14) == 14)); tmp = (!((timer & 14) == 14));
if (backlight_state & 1) if (backlight_state & 1)
lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness); lcd.backlight (tmp ? backlight_brightness : backlight_off_brightness);
@@ -103,26 +99,20 @@ int draw_screen(screen *s, int timer)
lcd.output (output_state); lcd.output (output_state);
draw_frame(s->widgets, 'v', draw_frame (s->widgets, 'v', 0, 0, lcd.wid, lcd.hgt, s->wid, s->hgt, s->duration / s->hgt, timer);
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]);
} }
@@ -136,10 +126,8 @@ int draw_screen(screen *s, int timer)
} }
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;
@@ -157,35 +145,34 @@ static int draw_frame(LL *list, char fscroll,
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') } else if (fscroll == 'h') { // TODO: Frames don't scroll horizontally yet!
{ // 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);
@@ -194,49 +181,33 @@ static int draw_frame(LL *list, char fscroll,
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)) {
if((w->y <= hgt + fy) &&
(w->y > fy))
{
strncpy (str, w->text, wid - w->x + 1); strncpy (str, w->text, wid - w->x + 1);
str[wid - w->x + 1] = 0; str[wid - w->x + 1] = 0;
lcd.string(w->x + left, lcd.string (w->x + left, w->y + top - fy, str);
w->y + top - fy,
str);
} }
} }
break; break;
case WID_HBAR: case WID_HBAR:
if(reset) 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 > 0)
{
if ((w->length / lcd.cellwid) < wid - w->x + 1) if ((w->length / lcd.cellwid) < wid - w->x + 1)
lcd.hbar(w->x + left, lcd.hbar (w->x + left, w->y + top - fy, w->length);
w->y + top - fy,
w->length);
else else
lcd.hbar(w->x + left, lcd.hbar (w->x + left, w->y + top - fy, wid * lcd.cellwid);
w->y + top - fy, } else if (w->length < 0) {
wid * lcd.cellwid);
}
else if(w->length < 0)
{
// TODO: Rearrange stuff to get left-extending // TODO: Rearrange stuff to get left-extending
// hbars to draw correctly... // hbars to draw correctly...
// .. er, this'll require driver modifications, // .. er, this'll require driver modifications,
@@ -246,19 +217,14 @@ static int draw_frame(LL *list, char fscroll,
} }
break; break;
case WID_VBAR: // FIXME: Vbars don't work in frames! case WID_VBAR: // FIXME: Vbars don't work in frames!
if(reset) if (reset) {
{
lcd.init_vbar (); lcd.init_vbar ();
reset = 0; reset = 0;
} }
if((w->x > 0) && (w->y > 0)) if ((w->x > 0) && (w->y > 0)) {
{ if (w->length > 0) {
if(w->length > 0)
{
lcd.vbar (w->x, w->length); lcd.vbar (w->x, w->length);
} } else if (w->length < 0) {
else if(w->length < 0)
{
// TODO: Rearrange stuff to get down-extending // TODO: Rearrange stuff to get down-extending
// vbars to draw correctly... // vbars to draw correctly...
// .. er, this'll require driver modifications, // .. er, this'll require driver modifications,
@@ -269,35 +235,37 @@ static int draw_frame(LL *list, char fscroll,
case WID_ICON: // FIXME: Not implemented case WID_ICON: // FIXME: Not implemented
break; break;
case WID_TITLE: // FIXME: Doesn't work quite right in frames... case WID_TITLE: // FIXME: Doesn't work quite right in frames...
if(!w->text) break; if (!w->text)
if(wid < 8) break; break;
if (wid < 8)
break;
memset (str, 255, wid); memset (str, 255, wid);
str[2] = ' '; str[2] = ' ';
length = strlen (w->text); length = strlen (w->text);
if(length <= wid-6) if (length <= wid - 6) {
{
memcpy (str + 3, w->text, length); memcpy (str + 3, w->text, length);
str[length + 3] = ' '; str[length + 3] = ' ';
} } else // Scroll the title, if it doesn't fit...
else // Scroll the title, if it doesn't fit...
{ {
speed = 1; speed = 1;
x = timer / speed; x = timer / speed;
y = x / length; y = x / length;
// Make sure the whole title gets displayed, at least... // Make sure the whole title gets displayed, at least...
if(!screenlist_action) screenlist_action = RENDER_HOLD; if (!screenlist_action)
if(x > length - 6) screenlist_action = RENDER_HOLD;
{ if (x > length - 6) {
// 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;
} }
x %= (length); x %= (length);
x -= 3; x -= 3;
if(x < 0) x = 0; if (x < 0)
if(x > length - (wid-6)) x = length - (wid-6); x = 0;
if (x > length - (wid - 6))
x = length - (wid - 6);
if (y & 1) // Scrolling backwards... if (y & 1) // Scrolling backwards...
{ {
@@ -314,74 +282,60 @@ static int draw_frame(LL *list, char fscroll,
{ {
int offset; int offset;
int screen_width; int screen_width;
if (!w->text) break; if (!w->text)
if (w->right < w->left) break; break;
if (w->right < w->left)
break;
//printf("rendering: %s %d\n",w->text,timer); //printf("rendering: %s %d\n",w->text,timer);
screen_width = w->right - w->left + 1; screen_width = w->right - w->left + 1;
switch (w->length) switch (w->length) { // actually, direction...
{ // actually, direction...
// FIXED: Horz scrollers don't show the // FIXED: Horz scrollers don't show the
// last letter in the string... (1-off error?) // last letter in the string... (1-off error?)
case 'h': case 'h':
length = strlen (w->text) + 1; length = strlen (w->text) + 1;
if (length <= screen_width) if (length <= screen_width) {
{
/* it fits within the box, just render it */ /* it fits within the box, just render it */
lcd.string (w->left, w->top, w->text); lcd.string (w->left, w->top, w->text);
} } else {
else
{
int effLength = length - screen_width; int effLength = length - screen_width;
int necessaryTimeUnits = 0; int necessaryTimeUnits = 0;
if (!screenlist_action) screenlist_action = RENDER_HOLD; if (!screenlist_action)
screenlist_action = RENDER_HOLD;
if (w->speed > 0) { if (w->speed > 0) {
necessaryTimeUnits = effLength * w->speed; necessaryTimeUnits = effLength * w->speed;
if (((timer / (effLength * w->speed)) % 2) == 0) { if (((timer / (effLength * w->speed)) % 2) == 0) {
//wiggle one way //wiggle one way
offset = (timer % (effLength * w->speed)) offset = (timer % (effLength * w->speed))
/ w->speed; / w->speed;
} } else {
else
{
//wiggle the other //wiggle the other
offset = (((timer % (effLength * w->speed)) offset = (((timer % (effLength * w->speed))
- (effLength * w->speed) + 1) - (effLength * w->speed) + 1)
/ w->speed) * -1; / w->speed) * -1;
} }
} } else if (w->speed < 0) {
else if (w->speed < 0)
{
necessaryTimeUnits = effLength / (w->speed * -1); necessaryTimeUnits = effLength / (w->speed * -1);
if (((timer / (effLength/(w->speed*-1))) % 2) == 0) if (((timer / (effLength / (w->speed * -1))) % 2) == 0) {
{
offset = (timer % (effLength / (w->speed * -1))) offset = (timer % (effLength / (w->speed * -1)))
* w->speed * -1; * w->speed * -1;
} } else {
else
{
offset = (((timer % (effLength / (w->speed * -1))) offset = (((timer % (effLength / (w->speed * -1)))
* w->speed * -1) - effLength + 1) * -1; * w->speed * -1) - effLength + 1) * -1;
} }
} } else {
else
{
offset = 0; offset = 0;
if (screenlist_action == RENDER_HOLD) if (screenlist_action == RENDER_HOLD)
screenlist_action = 0; screenlist_action = 0;
} }
if (timer > necessaryTimeUnits) if (timer > necessaryTimeUnits) {
{
if (screenlist_action == RENDER_HOLD) if (screenlist_action == RENDER_HOLD)
screenlist_action = 0; screenlist_action = 0;
} }
if (offset <= length) if (offset <= length) {
{
strncpy (str, &((w->text)[offset]), screen_width); strncpy (str, &((w->text)[offset]), screen_width);
str[screen_width] = '\0'; str[screen_width] = '\0';
//printf("%s : %d\n",str,length-offset); //printf("%s : %d\n",str,length-offset);
} } else {
else
{
str[0] = '\0'; str[0] = '\0';
} }
lcd.string (w->left, w->top, str); lcd.string (w->left, w->top, str);
@@ -394,86 +348,61 @@ static int draw_frame(LL *list, char fscroll,
{ {
int i = 0; int i = 0;
length = strlen (w->text); length = strlen (w->text);
if (length <= screen_width) if (length <= screen_width) {
{
/* no scrolling required... */ /* no scrolling required... */
lcd.string (w->left, w->top, w->text); lcd.string (w->left, w->top, w->text);
} } else {
else int lines_required = (length / screen_width)
{
int lines_required =
(length / screen_width)
+ (length % screen_width ? 1 : 0); + (length % screen_width ? 1 : 0);
int available_lines = (w->bottom - w->top + 1); int available_lines = (w->bottom - w->top + 1);
if (lines_required <= available_lines) if (lines_required <= available_lines) {
{
// easy... // easy...
for(i=0;i<lines_required;i++) for (i = 0; i < lines_required; i++) {
{ strncpy (str, &((w->text)[i * screen_width]), screen_width);
strncpy(str,
&((w->text)[i*screen_width]),
screen_width);
str[screen_width] = '\0'; str[screen_width] = '\0';
lcd.string (w->left, w->top + i, str); lcd.string (w->left, w->top + i, str);
} }
} } else {
else
{
int necessaryTimeUnits = 0; int necessaryTimeUnits = 0;
int effLines = lines_required - available_lines + 1; int effLines = lines_required - available_lines + 1;
int begin = 0; int begin = 0;
if (!screenlist_action) if (!screenlist_action)
screenlist_action = RENDER_HOLD; 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); //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) if (w->speed > 0) {
{
necessaryTimeUnits = effLines * w->speed; necessaryTimeUnits = effLines * w->speed;
if (((timer / (effLines*w->speed)) % 2) == 0) if (((timer / (effLines * w->speed)) % 2) == 0) {
{
//printf("up "); //printf("up ");
begin = (timer % (effLines * w->speed)) begin = (timer % (effLines * w->speed))
/ w->speed; / w->speed;
} } else {
else
{
//printf("down "); //printf("down ");
begin = (((timer % (effLines * w->speed)) begin = (((timer % (effLines * w->speed))
- (effLines * w->speed) + 1) / w->speed) - (effLines * w->speed) + 1) / w->speed)
* -1; * -1;
} }
} } else if (w->speed < 0) {
else if (w->speed < 0)
{
necessaryTimeUnits = effLines / (w->speed * -1); necessaryTimeUnits = effLines / (w->speed * -1);
if (((timer / (effLines/(w->speed*-1))) % 2) == 0) if (((timer / (effLines / (w->speed * -1))) % 2) == 0) {
{
begin = (timer % (effLines / (w->speed * -1))) begin = (timer % (effLines / (w->speed * -1)))
* w->speed * -1; * w->speed * -1;
} } else {
else
{
begin = (((timer % (effLines / (w->speed * -1))) begin = (((timer % (effLines / (w->speed * -1)))
* w->speed * -1) - effLines + 1) * w->speed * -1) - effLines + 1)
* -1; * -1;
} }
} } else {
else
{
begin = 0; begin = 0;
} }
//printf("rendering begin: %d timer: %d effLines: %d\n",begin,timer,effLines); //printf("rendering begin: %d timer: %d effLines: %d\n",begin,timer,effLines);
for(i=begin;i<begin+available_lines;i++) for (i = begin; i < begin + available_lines; i++) {
{ strncpy (str, &((w->text)[i * (screen_width)]), screen_width);
strncpy(str,
&((w->text)[i*(screen_width)]),
screen_width);
str[screen_width] = '\0'; str[screen_width] = '\0';
//printf("rendering: '%s' of %s\n", //printf("rendering: '%s' of %s\n",
//str,w->text); //str,w->text);
lcd.string (w->left, w->top + (i - begin), str); lcd.string (w->left, w->top + (i - begin), str);
} }
if (timer > necessaryTimeUnits) if (timer > necessaryTimeUnits) {
{
if (screenlist_action == RENDER_HOLD) if (screenlist_action == RENDER_HOLD)
screenlist_action = 0; screenlist_action = 0;
} }
@@ -493,26 +422,19 @@ 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 (); lcd.init_num ();
reset = 0; reset = 0;
} }
@@ -528,4 +450,3 @@ static int draw_frame(LL *list, char fscroll,
return 0; return 0;
} }
+33 -32
View File
@@ -13,13 +13,13 @@
#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;
} }
@@ -36,8 +36,7 @@ screen * screen_create()
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;
} }
@@ -45,11 +44,13 @@ screen * screen_create()
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 {
@@ -71,20 +72,22 @@ int screen_destroy(screen *s)
} }
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;
} }
@@ -94,23 +97,24 @@ screen *screen_find(client *c, char *id)
} }
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;
} }
@@ -118,19 +122,16 @@ int screen_add(client *c, char *id)
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;
} }
@@ -138,21 +139,22 @@ int screen_add(client *c, char *id)
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);
@@ -160,8 +162,7 @@ int screen_remove(client *c, char *id)
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;
+1 -2
View File
@@ -4,8 +4,7 @@
#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;
+58 -41
View File
@@ -26,13 +26,13 @@ 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;
} }
@@ -43,7 +43,8 @@ int screenlist_init()
return 0; return 0;
} }
int screenlist_shutdown() int
screenlist_shutdown ()
{ {
debug ("screenlist_shutdown()\n"); debug ("screenlist_shutdown()\n");
@@ -52,16 +53,19 @@ int screenlist_shutdown()
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;
@@ -75,14 +79,16 @@ int screenlist_remove_all(screen *s)
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;
@@ -97,44 +103,37 @@ screen * screenlist_current()
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
{ {
} }
} }
@@ -149,13 +148,15 @@ 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;
@@ -164,8 +165,10 @@ screen * screenlist_next()
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;
@@ -183,15 +186,18 @@ 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;
@@ -206,7 +212,8 @@ screen * screenlist_prev()
// 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");
@@ -214,22 +221,26 @@ int screenlist_add_end(screen *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; if (LL_UnRoll (screenlist) != 0)
return NULL;
return screenlist_current (); 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);
@@ -237,24 +248,29 @@ screen * screenlist_next_priority()
} }
// 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; if (LL_Roll (screenlist) != 0)
return NULL;
return screenlist_current (); 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)
return 0;
a = (screen *) one; a = (screen *) one;
b = (screen *) two; b = (screen *) two;
@@ -264,7 +280,8 @@ int compare_priority(void *one, void *two)
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");
+33 -62
View File
@@ -27,7 +27,8 @@ 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;
@@ -35,8 +36,7 @@ int server_screen_init()
server_screen = screen_create (); server_screen = screen_create ();
if(!server_screen) if (!server_screen) {
{
fprintf (stderr, "server_screen_init: Error allocating screen\n"); fprintf (stderr, "server_screen_init: Error allocating screen\n");
return -1; return -1;
} }
@@ -54,48 +54,36 @@ int server_screen_init()
// 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 {
else
{
fprintf (stderr, "server_screen_init: Can't find title\n"); fprintf (stderr, "server_screen_init: Can't find title\n");
} }
w = widget_find (server_screen, "one"); w = widget_find (server_screen, "one");
if(w) if (w) {
{
w->x = 1; w->x = 1;
w->y = 2; w->y = 2;
w->text = one; w->text = one;
} } else {
else
{
fprintf (stderr, "server_screen_init: Can't find widget one\n"); fprintf (stderr, "server_screen_init: Can't find widget one\n");
} }
w = widget_find (server_screen, "two"); w = widget_find (server_screen, "two");
if(w) if (w) {
{
w->x = 1; w->x = 1;
w->y = 3; w->y = 3;
w->text = two; w->text = two;
} } else {
else
{
fprintf (stderr, "server_screen_init: Can't find widget two\n"); fprintf (stderr, "server_screen_init: Can't find widget two\n");
} }
w = widget_find (server_screen, "three"); w = widget_find (server_screen, "three");
if(w) if (w) {
{
w->x = 1; w->x = 1;
w->y = 4; w->y = 4;
w->text = three; w->text = three;
} } else {
else
{
fprintf (stderr, "server_screen_init: Can't find widget three\n"); fprintf (stderr, "server_screen_init: Can't find widget three\n");
} }
@@ -110,7 +98,8 @@ int server_screen_init()
} }
int update_server_screen(int timer) int
update_server_screen (int timer)
{ {
client *c; client *c;
int num_clients; int num_clients;
@@ -123,45 +112,38 @@ int update_server_screen(int timer)
// 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;
num_screens = 0;
LL_Rewind (clients); 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 {
else
{
if (lcd.wid >= 20) if (lcd.wid >= 20)
sprintf(one, "%i Client%s, %i Screen%s", sprintf (one, "%i Client%s, %i Screen%s", num_clients, (num_clients == 1) ? "" : "s", num_screens, (num_screens == 1) ? "" : "s");
num_clients, (num_clients==1)?"":"s",
num_screens, (num_screens==1)?"":"s");
else // 16x2 size else // 16x2 size
sprintf(one, "%i Cli%s, %i Scr%s", sprintf (one, "%i Cli%s, %i Scr%s", num_clients, (num_clients == 1) ? "" : "s", num_screens, (num_screens == 1) ? "" : "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.clear ();
@@ -173,18 +155,17 @@ int no_screen_screen(int timer)
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
@@ -194,32 +175,23 @@ int goodbye_screen()
lcd.clear (); lcd.clear ();
if(lcd.hgt >= 4) if (lcd.hgt >= 4) {
{ if (lcd.wid >= 20) {
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 {
else
{
lcd.string (1, 1, b16); lcd.string (1, 1, b16);
lcd.string (1, 2, t16); lcd.string (1, 2, t16);
lcd.string (1, 3, l16); lcd.string (1, 3, l16);
lcd.string (1, 4, b16); lcd.string (1, 4, b16);
} }
} } else {
else if (lcd.wid >= 20) {
{
if(lcd.wid >= 20)
{
lcd.string (1, 1, t20); lcd.string (1, 1, t20);
lcd.string (1, 2, l20); lcd.string (1, 2, l20);
} } else {
else
{
lcd.string (1, 1, t16); lcd.string (1, 1, t16);
lcd.string (1, 2, l16); lcd.string (1, 2, l16);
} }
@@ -229,4 +201,3 @@ int goodbye_screen()
return 0; return 0;
} }
+36 -57
View File
@@ -36,7 +36,8 @@ 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;
@@ -46,8 +47,7 @@ int sock_create_inet_socket(unsigned short int port)
/* Create the socket. */ /* Create the socket. */
//debug("Creating Inet Socket\n"); //debug("Creating Inet Socket\n");
sock = socket (PF_INET, SOCK_STREAM, 0); sock = socket (PF_INET, SOCK_STREAM, 0);
if (sock < 0) if (sock < 0) {
{
perror ("Error creating socket"); perror ("Error creating socket");
return -1; return -1;
} }
@@ -57,8 +57,7 @@ int sock_create_inet_socket(unsigned short int port)
name.sin_family = AF_INET; name.sin_family = AF_INET;
name.sin_port = htons (port); name.sin_port = htons (port);
name.sin_addr.s_addr = htonl (INADDR_ANY); name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) {
{
perror ("Error binding socket"); perror ("Error binding socket");
return -1; return -1;
} }
@@ -68,7 +67,8 @@ int sock_create_inet_socket(unsigned short int port)
} }
//int StartSocketServer() //int StartSocketServer()
int sock_create_server() int
sock_create_server ()
{ {
int sock; int sock;
@@ -76,15 +76,13 @@ int sock_create_server()
/* Create the socket and set it up to accept connections. */ /* Create the socket and set it up to accept connections. */
sock = sock_create_inet_socket (LCDPORT); sock = sock_create_inet_socket (LCDPORT);
if(sock < 0) if (sock < 0) {
{
perror ("sock_create_server: Error creating socket"); perror ("sock_create_server: Error creating socket");
return -1; return -1;
} }
if (listen (sock, 1) < 0) if (listen (sock, 1) < 0) {
{
perror ("sock_create_server: Listen error"); perror ("sock_create_server: Listen error");
return -1; return -1;
} }
@@ -114,7 +112,8 @@ int sock_create_server()
} }
int sock_poll_clients() int
sock_poll_clients ()
{ {
int i; int i;
int err; int err;
@@ -131,70 +130,52 @@ int sock_poll_clients()
/* 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);
if (new < 0)
{
perror ("sock_poll_clients: Accept error"); 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?) // TODO: Create new "client" here... (done?)
if ( client_create(new) == NULL) if (client_create (new) == NULL) {
{ fprintf (stderr, "sock_poll_clients: error creating client %i\n", i);
fprintf(stderr,
"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,7 +186,8 @@ 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;
@@ -223,28 +205,25 @@ int read_from_client (int filedes)
// 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
else fprintf(stderr, "read_from_client: Can't find client %i\n", fprintf (stderr, "read_from_client: Can't find client %i\n", filedes);
filedes);
debug ("read_from_client: got message: `%s'\n", buffer); debug ("read_from_client: got message: `%s'\n", buffer);
return nbytes; return nbytes;
@@ -255,14 +234,14 @@ 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);
+79 -97
View File
@@ -27,15 +27,15 @@ static widget * widget_finder(LL *list, char *id);
static int widget_remover (LL * list, widget * w); static int widget_remover (LL * list, widget * w);
widget * widget_create() 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;
} }
@@ -58,23 +58,26 @@ widget * widget_create()
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; if (!w)
return -1;
debug ("widget_destroy(%s)\n", w->id); debug ("widget_destroy(%s)\n", w->id);
if(w->id) free(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 {
@@ -93,12 +96,15 @@ int widget_destroy(widget *w)
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);
@@ -125,12 +131,15 @@ 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);
@@ -138,20 +147,18 @@ widget * widget_finder(LL *list, char *id)
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) return err; if (err)
return err;
} }
//debug("widget_finder: ...\n"); //debug("widget_finder: ...\n");
} }
@@ -161,7 +168,8 @@ widget * widget_finder(LL *list, char *id)
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;
@@ -172,65 +180,52 @@ int widget_add(screen *s, char *id, char *type, char *in, int sock)
debug ("widget_add(%s, %s, %s)\n", id, type, in); debug ("widget_add(%s, %s, %s)\n", id, type, in);
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 = 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; valid = 1;
wid_type = i; 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;
@@ -242,15 +237,13 @@ int widget_add(screen *s, char *id, char *type, char *in, int sock)
// 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;
} }
@@ -258,20 +251,16 @@ int widget_add(screen *s, char *id, char *type, char *in, int sock)
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 (); w->kids = LL_new ();
if(!w->kids) if (!w->kids) {
{
fprintf (stderr, "widget_add: error allocating kids for frame\n"); 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);
@@ -279,31 +268,30 @@ int widget_add(screen *s, char *id, char *type, char *in, int sock)
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,
"huh? You don't have a widget with that id#\n");
debug ("widget_remove: Error finding widget %s\n", id); debug ("widget_remove: Error finding widget %s\n", id);
return 1; return 1;
} }
@@ -324,15 +312,18 @@ int widget_remove(screen *s, char *id, int sock)
} }
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...
@@ -340,19 +331,14 @@ int widget_remover(LL *list, widget *w)
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"); fprintf (stderr, "widget_remover: frame has no kids\n");
} } else // Kill the kids...
else // Kill the kids...
{ {
LL_Rewind (foo->kids); LL_Rewind (foo->kids);
do { do {
@@ -365,21 +351,17 @@ int widget_remover(LL *list, widget *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
else err = widget_remover(foo->kids, w); 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);
} }
+1 -2
View File
@@ -3,8 +3,7 @@
#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...