[lcd4linux @ 2000-03-18 08:07:04 by reinelt]

vertical bars implemented
bar compaction improved
memory information implemented

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@12 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
reinelt
2000-03-18 08:07:04 +00:00
parent db5e3666b5
commit 0ec6be5c53
5 changed files with 157 additions and 63 deletions
+86 -24
View File
@@ -1,4 +1,4 @@
/* $Id: MatrixOrbital.c,v 1.6 2000/03/17 09:21:42 reinelt Exp $
/* $Id: MatrixOrbital.c,v 1.7 2000/03/18 08:07:04 reinelt Exp $
*
* driver for Matrix Orbital serial display modules
*
@@ -20,6 +20,12 @@
*
*
* $Log: MatrixOrbital.c,v $
* Revision 1.7 2000/03/18 08:07:04 reinelt
*
* vertical bars implemented
* bar compaction improved
* memory information implemented
*
* Revision 1.6 2000/03/17 09:21:42 reinelt
*
* various memory statistics added
@@ -59,8 +65,7 @@
#define XRES 5
#define YRES 8
#define CHARS 8
#define BARS ( BAR_L | BAR_R | BAR_H2 )
// Fixme: BAR_U, BAR_D
#define BARS ( BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2 )
static DISPLAY Display;
static char *Port=NULL;
@@ -86,8 +91,8 @@ static char Txt[4][40];
static BAR Bar[4][40];
static int nSegment=2;
static SEGMENT Segment[256] = {{ len1: 0, len2: 0, type:255, used:0, ascii:32 },
{ len1:XRES, len2:XRES, type:255, used:0, ascii:255 }};
static SEGMENT Segment[256] = {{ len1:0, len2:0, type:255, used:0, ascii:32 },
{ len1:255, len2:255, type:255, used:0, ascii:255 }};
static int MO_open (void)
@@ -170,35 +175,49 @@ static void MO_process_bars (void)
}
}
#define sqr(x) ((x)*(x))
static int MO_segment_diff (int i, int j)
{
int RES;
int i1, i2, j1, j2;
if (i==j) return 65535;
if (!(Segment[i].type & Segment[j].type)) return 65535;
if (Segment[i].len1==0 && Segment[j].len1!=0) return 65535;
if (Segment[i].len2==0 && Segment[j].len2!=0) return 65535;
RES=Segment[i].type & BAR_H ? XRES:YRES;
if (Segment[i].len1>=RES && Segment[j].len1<RES) return 65535;
if (Segment[i].len2>=RES && Segment[j].len2<RES) return 65535;
if (Segment[i].len1==Segment[i].len2 && Segment[j].len1!=Segment[j].len2) return 65535;
i1=Segment[i].len1; if (i1>RES) i1=RES;
i2=Segment[i].len2; if (i2>RES) i2=RES;
j1=Segment[j].len1; if (j1>RES) i1=RES;
j2=Segment[j].len2; if (j2>RES) i2=RES;
return (i1-i2)*(i1-i2)+(j1-j2)*(j1-j2);
}
static void MO_compact_bars (void)
{
int i, j, r, c, min;
int pack_i, pack_j;
int pass1=1;
int error[nSegment][nSegment];
if (nSegment>CHARS+2) {
for (i=2; i<nSegment; i++) {
for (j=0; j<nSegment; j++) {
error[i][j]=65535;
if (i==j) continue;
if (Segment[i].used) continue;
if (!(Segment[i].type & Segment[j].type)) continue;
if (Segment[i].len1==0 && Segment[j].len1!=0) continue;
if (Segment[i].len2==0 && Segment[j].len2!=0) continue;
if (Segment[i].len1==XRES && Segment[j].len1!=XRES) continue;
if (Segment[i].len2==XRES && Segment[j].len2!=XRES) continue;
if (Segment[i].len1==Segment[i].len2 && Segment[j].len1!=Segment[j].len2) continue;
error[i][j]=sqr(Segment[i].len1-Segment[j].len1)+sqr(Segment[i].len2-Segment[j].len2);
error[i][j]=MO_segment_diff(i,j);
}
}
while (nSegment>CHARS+2) {
min=65535;
pack_i=-1;
pack_j=-1;
for (i=2; i<nSegment; i++) {
if (pass1 && Segment[i].used) continue;
for (j=0; j<nSegment; j++) {
if (error[i][j]<min) {
min=error[i][j];
@@ -208,11 +227,16 @@ static void MO_compact_bars (void)
}
}
if (pack_i==-1) {
fprintf (stderr, "MatrixOrbital: unable to compact bar characters\n");
nSegment=CHARS;
break;
if (pass1) {
pass1=0;
continue;
} else {
fprintf (stderr, "MatrixOrbital: unable to compact bar characters\n");
nSegment=CHARS;
break;
}
}
nSegment--;
Segment[pack_i]=Segment[nSegment];
@@ -220,7 +244,7 @@ static void MO_compact_bars (void)
error[pack_i][i]=error[nSegment][i];
error[i][pack_i]=error[i][nSegment];
}
for (r=0; r<Display.rows; r++) {
for (c=0; c<Display.cols; c++) {
if (Bar[r][c].segment==pack_i)
@@ -264,6 +288,22 @@ static void MO_define_chars (void)
buffer[j+7]=Pixel[Segment[i].len2];
}
break;
case BAR_U:
for (j=0; j<Segment[i].len1; j++) {
buffer[10-j]=31;
}
for (; j<YRES; j++) {
buffer[10-j]=0;
}
break;
case BAR_D:
for (j=0; j<Segment[i].len1; j++) {
buffer[j+3]=31;
}
for (; j<YRES; j++) {
buffer[j+3]=0;
}
break;
}
MO_write (buffer, 11);
}
@@ -393,9 +433,31 @@ int MO_bar (int type, int row, int col, int max, int len1, int len2)
break;
case BAR_U:
break;
len1=max-len1;
len2=max-len2;
rev=1;
case BAR_D:
while (max>0 && row<=Display.rows) {
Bar[row][col].type=type;
Bar[row][col].segment=-1;
if (len1>=YRES) {
Bar[row][col].len1=rev?0:YRES;
len1-=YRES;
} else {
Bar[row][col].len1=rev?YRES-len1:len1;
len1=0;
}
if (len2>=YRES) {
Bar[row][col].len2=rev?0:YRES;
len2-=YRES;
} else {
Bar[row][col].len2=rev?YRES-len2:len2;
len2=0;
}
max-=YRES;
row++;
}
break;
}
+7 -2
View File
@@ -1,4 +1,4 @@
/* $Id: display.c,v 1.6 2000/03/17 09:21:42 reinelt Exp $
/* $Id: display.c,v 1.7 2000/03/18 08:07:04 reinelt Exp $
*
* framework for device drivers
*
@@ -20,6 +20,12 @@
*
*
* $Log: display.c,v $
* Revision 1.7 2000/03/18 08:07:04 reinelt
*
* vertical bars implemented
* bar compaction improved
* memory information implemented
*
* Revision 1.6 2000/03/17 09:21:42 reinelt
*
* various memory statistics added
@@ -141,4 +147,3 @@ int lcd_flush (void)
{
return Display->flush();
}
+36 -17
View File
@@ -1,4 +1,4 @@
/* $Id: lcd4linux.c,v 1.4 2000/03/17 09:21:42 reinelt Exp $
/* $Id: lcd4linux.c,v 1.5 2000/03/18 08:07:04 reinelt Exp $
*
* LCD4Linux
*
@@ -20,6 +20,12 @@
*
*
* $Log: lcd4linux.c,v $
* Revision 1.5 2000/03/18 08:07:04 reinelt
*
* vertical bars implemented
* bar compaction improved
* memory information implemented
*
* Revision 1.4 2000/03/17 09:21:42 reinelt
*
* various memory statistics added
@@ -34,7 +40,6 @@
*
* first unstable but running release
*
*
*/
#include <stdlib.h>
@@ -250,14 +255,9 @@ void print_token (int token, char **p)
case T_MEM_APP:
*p+=sprintf (*p, "%6.0f", query(token));
break;
case T_CPU_USER:
case T_CPU_NICE:
case T_CPU_SYSTEM:
case T_CPU_BUSY:
case T_CPU_IDLE:
*p+=sprintf (*p, "%3.0f", 100.0*query(token));
break;
default:
case T_LOAD_1:
case T_LOAD_2:
case T_LOAD_3:
val=query(token);
if (val<10.0) {
*p+=sprintf (*p, "%4.2f", val);
@@ -266,6 +266,25 @@ void print_token (int token, char **p)
} else {
*p+=sprintf (*p, "%4.0f", val);
}
break;
case T_CPU_USER:
case T_CPU_NICE:
case T_CPU_SYSTEM:
case T_CPU_BUSY:
case T_CPU_IDLE:
*p+=sprintf (*p, "%3.0f", 100.0*query(token));
break;
case T_ISDN_IN:
case T_ISDN_OUT:
case T_ISDN_MAX:
case T_ISDN_TOTAL:
if (isdn.usage)
*p+=sprintf (*p, "%4.0f", query(token));
else
*p+=sprintf (*p, "----");
break;
default:
*p+=sprintf (*p, "%4.0f", query(token));
}
}
@@ -283,13 +302,14 @@ char *process_row (int r, char *s)
int type=*++s;
int len=*++s;
double val1=query_bar(*(unsigned char*)++s);
double val2;
double val2=val1;
if (type & (BAR_H2 | BAR_V2))
val2=query_bar(*(unsigned char*)++s);
if (type & BAR_H)
lcd_bar (type, r, p-buffer+1, len*xres, val1*len*xres, val2*len*xres);
else
val2=val1;
lcd_bar (type, r, p-buffer+1, len*xres, val1*len*xres, val2*len*xres);
lcd_bar (type, r, p-buffer+1, len*yres, val1*len*yres, val2*len*yres);
if (type & BAR_H) {
for (i=0; i<len && p-buffer<cols; i++)
*p++='\t';
@@ -313,7 +333,7 @@ void main (int argc, char *argv[])
char *display;
char *row[ROWS];
int i, smooth;
if (argc>2) {
usage();
exit (2);
@@ -360,7 +380,6 @@ void main (int argc, char *argv[])
}
lcd_clear();
lcd_put (1, 1, "** LCD4Linux V" VERSION " **");
lcd_put (2, 1, " (c) 2000 M.Reinelt");
lcd_flush();
@@ -379,6 +398,6 @@ void main (int argc, char *argv[])
lcd_flush();
smooth+=tick;
if (smooth>tack) smooth=0;
usleep(1000*tick);
usleep(tick*1000);
}
}
+6 -12
View File
@@ -8,21 +8,15 @@ Contrast 160
#Row3 "Busy %cu%% $r10cs+cb"
#Row4 "Load %l1%L$r10l1"
Row1 "CPU %cu%% $r10cs+cb"
Row2 "%mf %ms %ma"
#Row2 "Disk %dm $R10dr+dw"
Row1 "Load %l1%L$r10cs+cb"
Row2 "Disk %dm $R10dr+dw"
Row3 "Net %nm $R10nr+nw"
Row4 "ISDN %im $r10ii+io"
#Row1 "CPU $l6cs+cb$R6dr+dw I/O"
#Row2 "I/O $R16dr+dw"
#Row3 "LAN $R16nr+nw"
#Row4 "WAN $r16ii+io"
#Row1 ""
#Row2 ""
#Row3 "$u3cs $u3cb "
#Row4 "CPU I/O LAN WAN"
#Row1 "$u3l1$u3cb$u3cs $u3mu$u3ma$u3ms $u3dr$u3dw $u3nr$u3nw $u3ii$u3io"
#Row2 " "
#Row3 " "
#Row4 "CPU MEM IO IP"
Tick 100
Tack 400
+22 -8
View File
@@ -1,4 +1,4 @@
/* $Id: system.c,v 1.6 2000/03/17 09:21:42 reinelt Exp $
/* $Id: system.c,v 1.7 2000/03/18 08:07:04 reinelt Exp $
*
* system status retreivement
*
@@ -20,6 +20,12 @@
*
*
* $Log: system.c,v $
* Revision 1.7 2000/03/18 08:07:04 reinelt
*
* vertical bars implemented
* bar compaction improved
* memory information implemented
*
* Revision 1.6 2000/03/17 09:21:42 reinelt
*
* various memory statistics added
@@ -107,7 +113,7 @@
#include <linux/sys.h>
#endif
static unsigned long parse_meminfo (char *tag, char *buffer)
static int parse_meminfo (char *tag, char *buffer)
{
char *p;
unsigned long val;
@@ -190,18 +196,26 @@ int Memory(void)
int Ram (int *total, int *free, int *shared, int *buffered, int *cached)
{
static time_t now=0;
static int fd=-2;
unsigned long v1, v2, v3, v4, v5;
static int v1=0;
static int v2=0;
static int v3=0;
static int v4=0;
static int v5=0;
char buffer[4096];
*total=0;
*free=0;
*shared=0;
*buffered=0;
*cached=0;
*total=v1;
*free=v2;
*shared=v3;
*buffered=v4;
*cached=v5;
if (fd==-1) return -1;
if (time(NULL)==now) return 0;
time(&now);
if (fd==-2) {
fd = open("/proc/meminfo", O_RDONLY | O_NDELAY);
if (fd==-1) {