~benklop/+junk/lcdproc

« back to all changes in this revision

Viewing changes to server/drivers/text.c

  • Committer: Bazaar Package Importer
  • Author(s): Noel Koethe
  • Date: 2002-04-18 18:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20020418180500-94iz2toqhzm3zvna
Tags: 0.4.3-10
* updated code from cvs to get all drivers updated.
  upstream maintainer asked for this for woody release
  this version will the 0.4.3 upstream release
* small changes in description
* added some upstream Docs which are not in the source

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "lcd.h"
19
19
#include "text.h"
20
20
#include "drv_base.h"
 
21
#include "shared/report.h"
 
22
#include "configfile.h"
 
23
 
 
24
/* Character used for title bars... */
 
25
#define PAD '#'
21
26
 
22
27
static void text_close ();
23
28
static void text_clear ();
26
31
static void text_chr (int x, int y, char c);
27
32
static int text_contrast (int contrast);
28
33
static void text_backlight (int on);
29
 
//static void text_init_vbar ();
30
 
//static void text_init_hbar ();
31
 
//static void text_init_num ();
 
34
/* static void text_init_vbar ();
 
35
 * static void text_init_hbar ();
 
36
 * static void text_init_num ();
 
37
 */
32
38
static void text_vbar (int x, int len);
33
39
static void text_hbar (int x, int y, int len);
34
40
static void text_num (int x, int num);
35
 
//static void text_set_char (int n, char *dat);
36
 
//static void text_flush_box (int lft, int top, int rgt, int bot);
 
41
/* static void text_set_char (int n, char *dat);
 
42
 * static void text_flush_box (int lft, int top, int rgt, int bot);
 
43
 */
37
44
static void text_draw_frame (char *dat);
38
45
 
39
46
/* Ugly code extracted by David GLAUDE from lcdm001.c ;)*/
81
88
 
82
89
lcd_logical_driver *text;
83
90
 
84
 
//////////////////////////////////////////////////////////////////////////
85
 
////////////////////// For Text-Mode Output //////////////////////////////
86
 
//////////////////////////////////////////////////////////////////////////
87
 
 
88
 
#define LCD_DEFAULT_WIDTH 20
89
 
#define LCD_DEFAULT_HEIGHT 4
90
 
// The two value below are fake, we don't support custom char.
 
91
/*
 
92
 * For Text-Mode Output 
 
93
 */
 
94
 
 
95
                                
 
96
#define TEXTDRV_DEF_SIZE  "20x4"
 
97
                                
 
98
/* The two value below are fake, we don't support custom char. */
91
99
#define LCD_DEFAULT_CELL_WIDTH 5
92
100
#define LCD_DEFAULT_CELL_HEIGHT 8
93
101
 
94
 
// TODO: When using the text driver, ^C fails to interrupt!
95
 
// Why?  Fix it...
96
 
// DONE??? Are you sure, not in my Konsole. David GLAUDE
97
 
 
 
102
/* To verify: When using the text driver, ^C fails to interrupt!  */ 
98
103
int
99
104
text_init (lcd_logical_driver * driver, char *args)
100
105
{
 
106
        char buf[256];
 
107
        int wid=0, hgt=0;
 
108
 
101
109
        text = driver;
102
110
 
103
 
        // Make sure the frame buffer is there...
 
111
        /* TODO?: replace DriverName with driver->name when that field exists.*/
 
112
        #define DriverName "text"
 
113
 
 
114
        /*Get settings from config file*/
 
115
 
 
116
        /*Get size settings*/
 
117
        strncpy(buf, config_get_string ( DriverName , "Size" , 0 , TEXTDRV_DEF_SIZE), sizeof(buf));
 
118
        buf[sizeof(buf)-1]=0;
 
119
        if( sscanf(buf , "%dx%d", &wid, &hgt ) != 2
 
120
        || (wid <= 0)
 
121
        || (hgt <= 0)) {
 
122
                report (RPT_WARNING, "TEXT: Cannot read size: %s. Using default value %s.\n", buf, TEXTDRV_DEF_SIZE);
 
123
                sscanf( TEXTDRV_DEF_SIZE , "%dx%d", &wid, &hgt );
 
124
        }
 
125
        text->wid = wid;
 
126
        text->hgt = hgt;
 
127
 
 
128
        /* Make sure the frame buffer is there... */
104
129
        if (!text->framebuf)
105
130
                text->framebuf = (unsigned char *)
106
131
                        malloc (text->wid * text->hgt);
107
132
        memset (text->framebuf, ' ', text->wid * text->hgt);
108
133
 
109
134
 
110
 
        // Set the functions the driver supports
 
135
        /* Set the functions the driver supports */
111
136
 
112
 
        text->wid = LCD_DEFAULT_WIDTH;
113
 
        text->hgt = LCD_DEFAULT_HEIGHT;
114
137
        text->cellwid = LCD_DEFAULT_CELL_WIDTH;
115
138
        text->cellhgt = LCD_DEFAULT_CELL_HEIGHT;
116
139
 
118
141
        text->string = text_string;
119
142
        text->chr = text_chr;
120
143
        text->vbar = text_vbar;
121
 
        //text->init_vbar = NULL;
 
144
        /* text->init_vbar = NULL; */
122
145
        text->hbar = text_hbar;
123
 
        //text->init_hbar = NULL;
 
146
        /* text->init_hbar = NULL; */
124
147
        text->num = text_num;
125
 
        //text->init_num = NULL;
 
148
        /* text->init_num = NULL; */
126
149
 
127
150
        text->init = text_init;
128
151
        text->close = text_close;
129
152
        text->flush = text_flush;
130
 
        //text->flush_box = NULL;
131
 
        //text->contrast = NULL;
132
 
        //text->backlight = NULL;
133
 
        //text->set_char = NULL;
134
 
        //text->icon = NULL;
 
153
        /* text->flush_box = NULL; */ 
 
154
        /* text->contrast = NULL; */ 
 
155
        /* text->backlight = NULL; */
 
156
        /* text->set_char = NULL; */
 
157
        /* text->icon = NULL; */
135
158
        text->draw_frame = text_draw_frame;
136
159
 
137
 
        //text->getkey = NULL;
 
160
        /* text->getkey = NULL; */
138
161
 
139
 
        return 200;                                               // 200 is arbitrary.  (must be 1 or more)
 
162
        return 200;              /* 200 is arbitrary.  (must be 1 or more) */
140
163
}
141
164
 
142
165
static void
148
171
        text->framebuf = NULL;
149
172
}
150
173
 
151
 
/////////////////////////////////////////////////////////////////
152
 
// Clears the LCD screen
153
 
//
 
174
/* Clears the LCD screen */
154
175
static void
155
176
text_clear ()
156
177
{
157
178
        memset (text->framebuf, ' ', text->wid * text->hgt);
158
179
}
159
180
 
160
 
//////////////////////////////////////////////////////////////////
161
 
// Flushes all output to the lcd...
162
 
//
 
181
/* Flushes all output to the lcd...  */
163
182
static void
164
183
text_flush ()
165
184
{
166
185
        text_draw_frame (text->framebuf);
167
186
}
168
187
 
169
 
/////////////////////////////////////////////////////////////////
170
 
// Prints a string on the lcd display, at position (x,y).  The
171
 
// upper-left is (1,1), and the lower right should be (20,4).
172
 
//
 
188
/* Prints a string on the lcd display, at position (x,y).  The
 
189
   upper-left is (1,1), and the lower right should be (20,4).  */
173
190
static void
174
191
text_string (int x, int y, char string[])
175
192
{
176
193
        int i;
177
194
 
178
 
        x--; y--; // Convert 1-based coords to 0-based...
 
195
        x--; y--; /* Convert 1-based coords to 0-based... */ 
179
196
 
 
197
        /* Convert NULLs and 0xFF in string to valid printables... */
 
198
         
180
199
        for (i = 0; string[i]; i++) {
 
200
                switch (string[i]) {
 
201
                        /* case 0: -- can never happen?
 
202
                         *      *p = icon_char;
 
203
                         *      break;
 
204
                         */
 
205
                        case -1:   /* This magicaly translate to 255 */
 
206
                                string[i] = PAD;
 
207
                                break;
 
208
                }
181
209
                text->framebuf[(y * text->wid) + x + i] = string[i];
182
210
        }
183
211
}
184
212
 
185
 
/////////////////////////////////////////////////////////////////
186
 
// Prints a character on the lcd display, at position (x,y).  The
187
 
// upper-left is (1,1), and the lower right should be (20,4).
188
 
//
 
213
 
 
214
/* Prints a character on the lcd display, at position (x,y).  The
 
215
   upper-left is (1,1), and the lower right should be (20,4).  */
189
216
static void
190
217
text_chr (int x, int y, char c)
191
218
{
192
219
        y--; x--;
193
220
 
 
221
        switch (c) {
 
222
 
 
223
/*
 
224
                case 0:
 
225
                        c = icon_char;
 
226
                        break;
 
227
*/
 
228
                case -1:        /* translates to 255 (ouch!) */
 
229
                        c = PAD;
 
230
                        break;
 
231
/*
 
232
                default:
 
233
                        normal character...
 
234
*/
 
235
        }
 
236
 
194
237
        text->framebuf[(y * text->wid) + x] = c;
 
238
 
195
239
}
196
240
 
 
241
 
 
242
 
 
243
 
 
244
 
197
245
static int
198
246
text_contrast (int contrast)
199
247
{
200
 
//  printf("Contrast: %i\n", contrast);
201
248
        return 0;
202
249
}
203
250
 
204
251
static void
205
252
text_backlight (int on)
206
253
{
207
 
/*
208
 
  if(on)
209
 
  {
210
 
    printf("Backlight ON\n");
211
 
  }
212
 
  else
213
 
  {
214
 
    printf("Backlight OFF\n");
215
 
  }
216
 
*/
217
254
}
218
255
 
219
 
//void
220
 
//text_init_vbar ()
221
 
//{
222
 
////  printf("Vertical bars.\n");
223
 
//}
224
 
 
225
 
//void
226
 
//text_init_hbar ()
227
 
//{
228
 
////  printf("Horizontal bars.\n");
229
 
//}
230
 
 
231
 
//void
232
 
//text_init_num ()
233
 
//{
234
 
////  printf("Big Numbers.\n");
235
 
//}
236
 
 
237
 
/////////////////////////////////////////////////////////////////
238
 
// Writes a big number. (by Rene Wagner from lcdm001.c)
239
 
//
 
256
/* Writes a big number. (by Rene Wagner from lcdm001.c) */
240
257
static void text_num (int x, int num)
241
258
{
242
259
        int y, dx;
243
260
 
244
 
//  printf("BigNum(%i, %i)\n", x, num);
245
261
        for (y = 1; y < 5; y++)
246
262
                for (dx = 0; dx < 3; dx++)
247
263
                        text_chr (x + dx, y, num_icon[num][y-1][dx]);
248
264
}
249
265
 
250
 
//void
251
 
//text_set_char (int n, char *dat)
252
 
//{
253
 
////  printf("Set Character %i\n", n);
254
 
//}
255
 
 
256
 
/////////////////////////////////////////////////////////////////
257
 
// Draws a vertical bar; erases entire column onscreen.
258
 
//
 
266
/* Draws a vertical bar; erases entire column onscreen.  */
259
267
static void
260
268
text_vbar (int x, int len)
261
269
{
268
276
 
269
277
}
270
278
 
271
 
/////////////////////////////////////////////////////////////////
272
 
// Draws a horizontal bar to the right.
273
 
//
 
279
/* Draws a horizontal bar to the right.  */
274
280
static void
275
281
text_hbar (int x, int y, int len)
276
282
{
298
304
        if (!dat)
299
305
                return;
300
306
 
301
 
//  printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat);
302
 
 
303
307
        for (i = 0; i < text->wid; i++) {
304
308
                out[i] = '-';
305
309
        }
323
327
 
324
328
}
325
329
 
326