Added support for DE200C VFD
[lcdproc-de200c.git] / server / drivers / de200c-vfd / test / main.c
blob286829fe1bf796ec2d834d6050726049e42deaf7
1 // ****************************************************************************
2 // main.c (C) 1992-2003 Christophe de Dinechin (ddd)
3 // VFD800 project
4 // ****************************************************************************
5 //
6 // File Description:
7 //
8 // Main entry point of the VFD800 control program
9 //
10 //
11 //
12 //
13 //
14 //
15 //
16 //
17 // ****************************************************************************
18 // This document is confidential.
19 // Do not redistribute without written permission
20 // ****************************************************************************
21 // * File : $RCSFile$
22 // * Revision : $Revision$
23 // * Date : $Date$
24 // ****************************************************************************
26 #include "vfd.h"
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <time.h>
30 #include <string.h>
33 int main(int argc, char **argv)
34 // ----------------------------------------------------------------------------
35 // Entry point for the program
36 // ----------------------------------------------------------------------------
38 int x, y, d;
39 float bright;
40 FILE *fortune = NULL;
41 int fscroll = 0;
42 char fbytes[160];
43 char *fptr;
44 int c;
47 VFD_Init();
49 for (d = 0; d <= 256; d++)
51 VFD_Brightness(.5 + .5 * d / 256.0);
52 for (y = 0; y < 4; y++)
54 VFD_SetXY(0, y);
55 VFD_Command(AUTOINCX);
56 for (x = 0; x < 160; x++)
57 VFD_Data(d);
61 for (bright = 1.0; bright >= 0.0; bright -= 0.1)
63 VFD_Brightness(bright);
64 usleep(10 MS);
67 VFD_SetXY(0, 1);
68 VFD_Text("abcdefghijklmnopqrstuvwxyz");
70 VFD_SetXY(0,3);
71 VFD_Text("J'aime Christine a la folie!");
73 for (bright = 0.0; bright <= 1.0; bright += 0.1)
75 VFD_Brightness(bright);
76 usleep(10 MS);
78 usleep(500 MS);
80 VFD_Brightness(.3);
81 x = d = 0;
82 while (1)
84 time_t t = time(NULL);
85 float load1, load2, load3;
86 int l, l1, l2, l3, s;
87 FILE *f = fopen("/proc/loadavg", "r");
89 // Display oscillating date/time
90 d++;
91 if (d & 16)
92 x--;
93 else
94 x++;
95 VFD_SetXY(x, 0);
96 VFD_Data(0);
97 VFD_Text(ctime(&t));
99 // Display load averages
100 fscanf(f, "%f %f %f", &load1, &load2, &load3);
101 fclose(f);
102 l1 = load1 * 120;
103 l2 = load2 * 120;
104 l3 = load3 * 120;
106 VFD_SetXY(0, 2);
107 VFD_Text("Load: ");
108 for (l = 0; l < 120; l++)
110 int b = 0;
111 if (l1 >= l) b |= 0x07;
112 if (l2 >= l) b |= 0x1C;
113 if (l3 >= l) b |= 0x70;
114 VFD_Data(b);
117 // Display current fortune
118 for (s = 0; s < 2; s++)
120 if (!fortune)
122 system ("/usr/games/fortune > /tmp/glop");
123 fortune = fopen("/tmp/glop", "r");
125 if (fscroll == 0)
127 c = fgetc(fortune);
128 if (c == EOF)
130 fclose (fortune);
131 fortune = NULL;
132 c = 0;
133 fscroll = 80;
135 else
137 fscroll = 6;
139 fptr = VFD_Font[c];
141 memmove(fbytes, fbytes+1, 159);
142 fbytes[159] = *fptr++;
143 fscroll--;
144 VFD_SetXY(0, 1);
146 for (l = 0; l < 160; l++)
147 VFD_Data(fbytes[l]);
149 usleep(30 MS);
154 return 0;
159 int showchars()
160 // ----------------------------------------------------------------------------
161 // Show the character map
162 // ----------------------------------------------------------------------------
164 int x, y, d;
165 for (x = 0; x < 256; x++)
167 printf("{ ");
168 for (y = 0; y < 6; y++)
170 int byte = VFD_Font[x][y];
171 unsigned char z = byte;
172 if (0) for (d = 0; d < 8; d++)
174 z <<= 1;
175 if (byte & 1)
176 z |= 1;
177 byte >>= 1;
179 printf("0x%02X%s ", z, y < 5 ? "," : "");
181 printf("}%s /* 0x%02X %c */\n",
182 x < 255 ? "," : " ", x, isprint(x) ? x : ' ');