source: npl/mediabox/lcdproc_edwin/src/server/drivers/debug.c @ 0105685

gcc484ntopperl-5.22
Last change on this file since 0105685 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: 5.2 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 "debug.h"
11
12
13//////////////////////////////////////////////////////////////////////////
14////////////////////// For Debugging Output //////////////////////////////
15//////////////////////////////////////////////////////////////////////////
16
17// TODO: somehow allow access to the driver->framebuffer to each
18// function...
19
20
21int debug_init(struct lcd_logical_driver *driver, char *args)
22{
23  printf("debug_init(%s)\n", device);
24 
25  if(!driver->framebuf)
26    {
27      printf("Allocating frame buffer (%ix%i)\n", lcd.wid, lcd.hgt);
28      driver->framebuf = malloc(lcd.wid * lcd.hgt);
29    }
30 
31
32  if(!driver->framebuf)
33    {
34      debug_close();
35      return -1;
36    }
37
38  if(driver->framebuf) printf("Frame buffer: %i\n", (int)driver->framebuf);
39
40  debug_clear();
41
42  driver->clear = debug_clear;
43  driver->string = debug_string;
44  driver->chr = debug_chr;
45  driver->vbar = debug_vbar;
46  driver->hbar = debug_hbar;
47  driver->init_num = debug_init_num;
48  driver->num = debug_num;
49 
50  driver->init = debug_init;
51  driver->close = debug_close;
52  driver->flush = debug_flush;
53  driver->flush_box = debug_flush_box;
54  driver->contrast = debug_contrast;
55  driver->backlight = debug_backlight;
56  driver->set_char = debug_set_char;
57  driver->icon = debug_icon;
58  driver->init_vbar = debug_init_vbar;
59  driver->init_hbar = debug_init_hbar;
60  driver->draw_frame = debug_draw_frame;
61
62  driver->getkey = debug_getkey;
63 
64 
65  return 200;  // 200 is arbitrary.  (must be 1 or more)
66}
67
68void debug_close()
69{
70// Ack!  This shouldn't crash the program, but does..  Why??
71
72
73  printf("debug_close()\n");
74
75// This is the line which crashes.
76  if(driver->framebuf) free(driver->framebuf);
77
78  if(driver->framebuf) printf("Frame buffer: %i\n", (int)driver->framebuf);
79  driver->framebuf = NULL;
80//  printf("debug_close() finished\n");
81}
82
83/////////////////////////////////////////////////////////////////
84// Clears the LCD screen
85//
86void debug_clear()
87{
88  printf("clear()\n");
89 
90  memset(driver->framebuf, ' ', lcd.wid*lcd.hgt);
91 
92}
93
94
95//////////////////////////////////////////////////////////////////
96// Flushes all output to the lcd...
97//
98void debug_flush()
99{
100  printf("flush()\n");
101 
102  lcd.draw_frame();
103}
104
105
106/////////////////////////////////////////////////////////////////
107// Prints a string on the lcd display, at position (x,y).  The
108// upper-left is (1,1), and the lower right should be (20,4).
109//
110void debug_string(int x, int y, char string[])
111{
112
113  int i;
114
115  printf("string(%i, %i):%s \n", x, y, string);
116 
117
118  x -= 1;  // Convert 1-based coords to 0-based...
119  y -= 1;
120 
121  for(i=0; string[i]; i++)
122    {
123      driver->framebuf[(y*lcd.wid) + x + i] = string[i];
124    }
125}
126
127/////////////////////////////////////////////////////////////////
128// Prints a character on the lcd display, at position (x,y).  The
129// upper-left is (1,1), and the lower right should be (20,4).
130//
131void debug_chr(int x, int y, char c)
132{
133  printf("character(%i, %i):%c\n", x, y, c);
134 
135
136  y--;
137  x--;
138 
139  lcd.framebuf[(y*lcd.wid) + x] = c;
140}
141
142
143
144void debug_contrast(int contrast)
145{
146  printf("Contrast: %i\n", contrast);
147}
148
149void debug_backlight(int on)
150{
151  if(on)
152  {
153    printf("Backlight ON\n");
154  }
155  else
156  {
157    printf("Backlight OFF\n");
158  }
159}
160
161void debug_init_vbar()
162{
163  printf("Vertical bars.\n");
164}
165
166void debug_init_hbar()
167{
168  printf("Horizontal bars.\n");
169}
170
171void debug_init_num()
172{
173  printf("Big Numbers.\n");
174}
175
176void debug_num(int x, int num)
177{
178  printf("BigNum(%i, %i)\n", x, num);
179}
180
181void debug_set_char(int n, char *dat)
182{
183  printf("Set Character %i\n", n);
184}
185
186/////////////////////////////////////////////////////////////////
187// Draws a vertical bar; erases entire column onscreen.
188//
189void debug_vbar(int x, int len)
190{
191  int y;
192
193  printf("Vbar(%i, %i)\n", x, len);
194 
195
196  for(y=lcd.hgt; y > 0 && len>0; y--)
197    {
198      debug_chr(x, y, '|');
199
200      len -= lcd.cellhgt;
201    }
202 
203}
204
205/////////////////////////////////////////////////////////////////
206// Draws a horizontal bar to the right.
207//
208void debug_hbar(int x, int y, int len)
209{
210  printf("Hbar(%i, %i, %i)\n", x, y, len);
211 
212 
213  for(; x<lcd.wid && len>0; x++)
214    {
215      debug_chr(x,y,'-');
216     
217      len -= lcd.cellwid;
218    }
219 
220}
221
222
223/////////////////////////////////////////////////////////////////
224// Sets character 0 to an icon...
225//
226void debug_icon(int which, char dest)
227{
228  printf("Char %i is icon %i\n", dest, which);
229}
230
231
232void debug_flush_box(int lft, int top, int rgt, int bot)
233{
234  printf("Flush Box(%i, %i)-(%i, %i)\n", lft, top, rgt, bot);
235 
236
237  debug_flush();
238 
239}
240
241
242void debug_draw_frame(char *dat)
243{
244  int i, j;
245
246  char out[LCD_MAX_WIDTH];
247
248  printf("draw_frame()\n");
249 
250
251  if(!dat) return;
252
253//  printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat);
254
255  for(i=0; i<lcd.wid; i++)
256    {
257      out[i] = '-';
258    }
259  out[lcd.wid] = 0;
260  printf("+%s+\n", out);
261 
262 
263  for(i=0; i<lcd.hgt; i++)
264    {
265      for(j=0; j<lcd.wid; j++)
266        {
267          out[j] = dat[j+(i*lcd.wid)];
268        }
269      out[lcd.wid] = 0;
270      printf("|%s|\n", out);
271     
272    }
273 
274  for(i=0; i<lcd.wid; i++)
275    {
276      out[i] = '-';
277    }
278  out[lcd.wid] = 0;
279  printf("+%s+\n", out);
280
281}
282
283
284char debug_getkey()
285{
286  printf("Trying to grab keypress.\n");
287  return 0;
288}
Note: See TracBrowser for help on using the repository browser.