source: npl/mediabox/lcdproc_edwin/src/server/drivers/drv_base.c

Last change on this file was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 6.8 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <termios.h>
5#include <fcntl.h>
6#include <string.h>
7#include <sys/errno.h>
8
9#include "lcd.h"
10#include "drv_base.h"
11
12
13//////////////////////////////////////////////////////////////////////////
14////////////////////// Base "class" to derive from ///////////////////////
15//////////////////////////////////////////////////////////////////////////
16
17lcd_logical_driver *drv_base;
18
19// TODO: Get lcd.framebuf to properly work as whatever driver is running...
20
21
22////////////////////////////////////////////////////////////
23// init() should set up any device-specific stuff, and
24// point all the function pointers.
25int drv_base_init(struct lcd_logical_driver *driver, char *args)
26{
27//  printf("drv_base_init()\n");
28
29   drv_base = driver;
30   
31  driver->wid = 20;
32  driver->hgt = 4;
33
34  // You must use driver->framebuf here, but may use lcd.framebuf later.
35  if(!driver->framebuf)
36    driver->framebuf = malloc(driver->wid * driver->hgt);
37
38  if(!driver->framebuf)
39    {
40      drv_base_close();
41      return -1;
42    }
43// Debugging...
44//  if(lcd.framebuf) printf("Frame buffer: %i\n", (int)lcd.framebuf);
45
46  memset(driver->framebuf, ' ', driver->wid*driver->hgt);
47//  drv_base_clear();
48
49  driver->cellwid = 5;
50  driver->cellhgt = 8;
51 
52  driver->clear = drv_base_clear;
53  driver->string = drv_base_string;
54  driver->chr = drv_base_chr;
55  driver->vbar = drv_base_vbar;
56  driver->init_vbar = drv_base_init_vbar;
57  driver->hbar = drv_base_hbar;
58  driver->init_hbar = drv_base_init_hbar;
59  driver->num = drv_base_num;
60  driver->init_num = drv_base_init_num;
61 
62  driver->init = drv_base_init;
63  driver->close = drv_base_close;
64  driver->flush = drv_base_flush;
65  driver->flush_box = drv_base_flush_box;
66  driver->contrast = drv_base_contrast;
67  driver->backlight = drv_base_backlight;
68  driver->set_char = drv_base_set_char;
69  driver->icon = drv_base_icon;
70  driver->draw_frame = drv_base_draw_frame;
71
72  driver->getkey = drv_base_getkey;
73 
74 
75  return 200;  // 200 is arbitrary.  (must be 1 or more)
76}
77
78
79// Below here, you may use either lcd.framebuf or driver->framebuf..
80// lcd.framebuf will be set to the appropriate buffer before calling
81// your driver.
82
83void drv_base_close()
84{
85  if(lcd.framebuf != NULL) free(lcd.framebuf);
86
87  lcd.framebuf = NULL;
88}
89
90/////////////////////////////////////////////////////////////////
91// Clears the LCD screen
92//
93void drv_base_clear()
94{
95  memset(lcd.framebuf, ' ', lcd.wid*lcd.hgt);
96 
97}
98
99
100//////////////////////////////////////////////////////////////////
101// Flushes all output to the lcd...
102//
103void drv_base_flush()
104{
105   //lcd.draw_frame(lcd.framebuf);
106}
107
108
109/////////////////////////////////////////////////////////////////
110// Prints a string on the lcd display, at position (x,y).  The
111// upper-left is (1,1), and the lower right should be (20,4).
112//
113void drv_base_string(int x, int y, char string[])
114{
115  int i;
116
117  x -= 1;  // Convert 1-based coords to 0-based...
118  y -= 1;
119 
120  for(i=0; string[i]; i++)
121  {
122     // Check for buffer overflows...
123     if((y*lcd.wid) + x + i  >  (lcd.wid*lcd.hgt)) break;
124     lcd.framebuf[(y*lcd.wid) + x + i] = string[i];
125  }
126}
127
128/////////////////////////////////////////////////////////////////
129// Prints a character on the lcd display, at position (x,y).  The
130// upper-left is (1,1), and the lower right should be (20,4).
131//
132void drv_base_chr(int x, int y, char c)
133{
134  y--;
135  x--;
136
137  lcd.framebuf[(y*lcd.wid) + x] = c;
138}
139
140
141//////////////////////////////////////////////////////////////////////
142// Sets the contrast of the display.  Value is 0-255, where 140 is
143// what I consider "just right".
144//
145int drv_base_contrast(int contrast)
146{
147//  printf("Contrast: %i\n", contrast);
148  return -1;
149}
150
151//////////////////////////////////////////////////////////////////////
152// Turns the lcd backlight on or off...
153//
154void drv_base_backlight(int on)
155{
156  /*
157  if(on)
158  {
159    printf("Backlight ON\n");
160  }
161  else
162  {
163    printf("Backlight OFF\n");
164  }
165  */
166}
167
168//////////////////////////////////////////////////////////////////////
169// Tells the driver to get ready for vertical bargraphs.
170//
171void drv_base_init_vbar()
172{
173//  printf("Vertical bars.\n");
174}
175
176//////////////////////////////////////////////////////////////////////
177// Tells the driver to get ready for horizontal bargraphs.
178//
179void drv_base_init_hbar()
180{
181//  printf("Horizontal bars.\n");
182}
183
184//////////////////////////////////////////////////////////////////////
185// Tells the driver to get ready for big numbers, if possible.
186//
187void drv_base_init_num()
188{
189//  printf("Big Numbers.\n");
190}
191
192//////////////////////////////////////////////////////////////////////
193// Draws a big (4-row) number.
194//
195void drv_base_num(int x, int num)
196{
197//  printf("BigNum(%i, %i)\n", x, num);
198}
199
200//////////////////////////////////////////////////////////////////////
201// Changes the font data of character n.
202//
203void drv_base_set_char(int n, char *dat)
204{
205//  printf("Set Character %i\n", n);
206}
207
208/////////////////////////////////////////////////////////////////
209// Draws a vertical bar, from the bottom of the screen up.
210//
211void drv_base_vbar(int x, int len)
212{
213  int y;
214  for(y=lcd.hgt; y > 0 && len>0; y--)
215    {
216      drv_base_chr(x, y, '|');
217
218      len -= lcd.cellhgt;
219    }
220 
221}
222
223/////////////////////////////////////////////////////////////////
224// Draws a horizontal bar to the right.
225//
226void drv_base_hbar(int x, int y, int len)
227{
228  for(; x<=lcd.wid && len>0; x++)
229    {
230      drv_base_chr(x,y,'-');
231     
232      len -= lcd.cellwid;
233    }
234 
235}
236
237
238/////////////////////////////////////////////////////////////////
239// Sets character 0 to an icon...
240//
241void drv_base_icon(int which, char dest)
242{
243//  printf("Char %i set to icon %i\n", dest, which);
244}
245
246
247//////////////////////////////////////////////////////////////////////
248// Send a rectangular area to the display.
249//
250// I've just called drv_base_flush() because there's not much point yet
251// in flushing less than the entire framebuffer.
252//
253void drv_base_flush_box(int lft, int top, int rgt, int bot)
254{
255   //drv_base_flush();
256 
257}
258
259//////////////////////////////////////////////////////////////////////
260// Draws the framebuffer on the display.
261//
262// The commented-out code is from the text driver.
263//
264void drv_base_draw_frame(char *dat)
265{
266/*
267   int i, j;
268
269   char out[LCD_MAX_WIDTH];
270
271   if(!dat) return;
272
273   for(i=0; i<lcd.wid; i++)
274   {
275      out[i] = '-';
276   }
277   out[lcd.wid] = 0;
278   printf("+%s+\n", out);
279 
280 
281   for(i=0; i<lcd.hgt; i++)
282   {
283      for(j=0; j<lcd.wid; j++)
284      {
285         out[j] = dat[j+(i*lcd.wid)];
286      }
287      out[lcd.wid] = 0;
288      printf("|%s|\n", out);
289     
290   }
291 
292   for(i=0; i<lcd.wid; i++)
293   {
294      out[i] = '-';
295   }
296   out[lcd.wid] = 0;
297   printf("+%s+\n", out);
298*/
299}
300
301
302//////////////////////////////////////////////////////////////////////
303// Tries to read a character from an input device...
304//
305// Return 0 for "nothing available".
306//
307char drv_base_getkey()
308{
309  return 0;
310}
311
Note: See TracBrowser for help on using the repository browser.