source: npl/mediabox/lcdproc_edwin/src/server/drivers/text.c @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c 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: 4.0 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 "text.h"
11#include "drv_base.h"
12
13
14lcd_logical_driver *text;
15
16//////////////////////////////////////////////////////////////////////////
17////////////////////// For Text-Mode Output //////////////////////////////
18//////////////////////////////////////////////////////////////////////////
19
20int text_init(lcd_logical_driver *driver, char *args)
21{
22   text = driver;
23   
24   if(!driver->framebuf)
25    {
26      driver->close();
27      return -1;
28    }
29 
30
31  driver->wid = 20;
32  driver->hgt = 4;
33  driver->cellwid = 5;
34  driver->cellhgt = 8;
35 
36  driver->clear = (void *)-1;
37  driver->string = (void *)-1;
38  driver->chr = (void *)-1;
39  driver->vbar = text_vbar;
40  driver->init_vbar = NULL;
41  driver->hbar = text_hbar;
42  driver->init_hbar = NULL;
43  driver->num = (void *)-1;
44  driver->init_num = NULL;
45 
46  driver->init = text_init;
47  driver->close = text_close;
48  driver->flush = text_flush;
49  driver->flush_box = NULL;
50  driver->contrast = NULL;
51  driver->backlight = NULL;
52  driver->set_char = NULL;
53  driver->icon = NULL;
54  driver->draw_frame = text_draw_frame;
55
56  driver->getkey = NULL;
57
58
59  return 200;  // 200 is arbitrary.  (must be 1 or more)
60}
61
62void text_close()
63{
64  drv_base_close();
65}
66
67/////////////////////////////////////////////////////////////////
68// Clears the LCD screen
69//
70void text_clear()
71{
72  memset(lcd.framebuf, ' ', lcd.wid*lcd.hgt);
73 
74}
75
76
77//////////////////////////////////////////////////////////////////
78// Flushes all output to the lcd...
79//
80void text_flush()
81{
82  text_draw_frame(lcd.framebuf);
83}
84
85
86/////////////////////////////////////////////////////////////////
87// Prints a string on the lcd display, at position (x,y).  The
88// upper-left is (1,1), and the lower right should be (20,4).
89//
90void text_string(int x, int y, char string[])
91{
92  int i;
93
94  x -= 1;  // Convert 1-based coords to 0-based...
95  y -= 1;
96 
97  for(i=0; string[i]; i++)
98    {
99      lcd.framebuf[(y*lcd.wid) + x + i] = string[i];
100    }
101}
102
103/////////////////////////////////////////////////////////////////
104// Prints a character on the lcd display, at position (x,y).  The
105// upper-left is (1,1), and the lower right should be (20,4).
106//
107void text_chr(int x, int y, char c)
108{
109  y--;
110  x--;
111 
112  lcd.framebuf[(y*lcd.wid) + x] = c;
113}
114
115
116
117int text_contrast(int contrast)
118{
119//  printf("Contrast: %i\n", contrast);
120   return 0;
121}
122
123void text_backlight(int on)
124{
125/*
126  if(on)
127  {
128    printf("Backlight ON\n");
129  }
130  else
131  {
132    printf("Backlight OFF\n");
133  }
134*/
135}
136
137void text_init_vbar()
138{
139//  printf("Vertical bars.\n");
140}
141
142void text_init_hbar()
143{
144//  printf("Horizontal bars.\n");
145}
146
147void text_init_num()
148{
149//  printf("Big Numbers.\n");
150}
151
152void text_num(int x, int num)
153{
154//  printf("BigNum(%i, %i)\n", x, num);
155}
156
157void text_set_char(int n, char *dat)
158{
159//  printf("Set Character %i\n", n);
160}
161
162/////////////////////////////////////////////////////////////////
163// Draws a vertical bar; erases entire column onscreen.
164//
165void text_vbar(int x, int len)
166{
167  int y;
168  for(y=lcd.hgt; y > 0 && len>0; y--)
169    {
170      text_chr(x, y, '|');
171
172      len -= lcd.cellhgt;
173    }
174 
175}
176
177/////////////////////////////////////////////////////////////////
178// Draws a horizontal bar to the right.
179//
180void text_hbar(int x, int y, int len)
181{
182  for(; x<=lcd.wid && len>0; x++)
183    {
184      text_chr(x,y,'-');
185     
186      len -= lcd.cellwid;
187    }
188 
189}
190
191
192void text_flush_box(int lft, int top, int rgt, int bot)
193{
194  text_flush();
195 
196}
197
198
199void text_draw_frame(char *dat)
200{
201  int i, j;
202
203  char out[LCD_MAX_WIDTH];
204
205  if(!dat) return;
206
207//  printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat);
208
209  for(i=0; i<lcd.wid; i++)
210    {
211      out[i] = '-';
212    }
213  out[lcd.wid] = 0;
214  printf("+%s+\n", out);
215 
216 
217  for(i=0; i<lcd.hgt; i++)
218    {
219      for(j=0; j<lcd.wid; j++)
220        {
221          out[j] = dat[j+(i*lcd.wid)];
222        }
223      out[lcd.wid] = 0;
224      printf("|%s|\n", out);
225     
226    }
227 
228  for(i=0; i<lcd.wid; i++)
229    {
230      out[i] = '-';
231    }
232  out[lcd.wid] = 0;
233  printf("+%s+\n", out);
234
235}
236
Note: See TracBrowser for help on using the repository browser.