Files
lcdproc/server/drivers/debug.c
T

263 lines
5.0 KiB
C
Raw Normal View History

1999-12-09 23:15:14 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <sys/errno.h>
#include "lcd.h"
1999-12-09 23:15:14 +00:00
#include "debug.h"
2001-11-29 14:09:13 +00:00
#include "shared/report.h"
1999-12-09 23:15:14 +00:00
//////////////////////////////////////////////////////////////////////////
////////////////////// For Debugging Output //////////////////////////////
//////////////////////////////////////////////////////////////////////////
// TODO: somehow allow access to the driver->framebuffer to each
// function...
2001-09-25 07:19:08 +00:00
static lcd_logical_driver *debug_drv;
int
debug_init (struct lcd_logical_driver *driver, char *args)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "debug_init()");
1999-12-09 23:15:14 +00:00
2001-09-25 07:19:08 +00:00
debug_drv = driver;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
debug_clear ();
1999-12-09 23:15:14 +00:00
driver->daemonize = 0;
2000-04-03 22:13:57 +00:00
driver->clear = debug_clear;
driver->string = debug_string;
driver->chr = debug_chr;
driver->vbar = debug_vbar;
driver->hbar = debug_hbar;
driver->init_num = debug_init_num;
driver->num = debug_num;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
driver->init = debug_init;
driver->close = debug_close;
driver->flush = debug_flush;
driver->flush_box = debug_flush_box;
driver->contrast = debug_contrast;
driver->backlight = debug_backlight;
driver->set_char = debug_set_char;
driver->icon = debug_icon;
driver->init_vbar = debug_init_vbar;
driver->init_hbar = debug_init_hbar;
driver->draw_frame = debug_draw_frame;
2000-04-03 22:13:57 +00:00
driver->getkey = debug_getkey;
2000-04-03 22:13:57 +00:00
return 200; // 200 is arbitrary. (must be 1 or more)
1999-12-09 23:15:14 +00:00
}
void
debug_close ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "debug_close()");
1999-12-09 23:15:14 +00:00
2001-09-25 07:19:08 +00:00
if (debug_drv->framebuf) {
2001-11-29 14:09:13 +00:00
report (RPT_DEBUG, "frame buffer: %010X", (int) debug_drv->framebuf);
2001-09-25 07:19:08 +00:00
free (debug_drv->framebuf);
}
1999-12-09 23:15:14 +00:00
2001-09-25 07:19:08 +00:00
debug_drv->framebuf = NULL;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Clears the LCD screen
//
void
debug_clear ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "clear()");
2001-09-25 16:47:02 +00:00
memset (debug_drv->framebuf, ' ', debug_drv->wid * debug_drv->hgt);
1999-12-09 23:15:14 +00:00
}
//////////////////////////////////////////////////////////////////
// Flushes all output to the lcd...
//
void
debug_flush ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "flush()");
2001-09-25 16:47:02 +00:00
debug_drv->draw_frame ();
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Prints a string on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4).
//
void
debug_string (int x, int y, char string[])
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
int i;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
report(RPT_INFO, "string(%i,%i,%.40s)", x, y, string);
1999-12-09 23:15:14 +00:00
2001-09-25 07:19:08 +00:00
y --; x --; // Convert 1-based coords to 0-based...
2000-04-03 22:13:57 +00:00
for (i = 0; string[i]; i++) {
2001-09-25 16:47:02 +00:00
debug_drv->framebuf[(y * debug_drv->wid) + x + i] = string[i];
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4).
//
void
debug_chr (int x, int y, char c)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_DEBUG, "char(%i,%i,%c)", x, y, c);
2001-09-25 07:19:08 +00:00
x--; y--;
2001-09-25 16:47:02 +00:00
debug_drv->framebuf[(y * debug_drv->wid) + x] = c;
1999-12-09 23:15:14 +00:00
}
2001-09-25 07:19:08 +00:00
int
debug_contrast (int contrast)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "contrast(%i)", contrast);
2001-09-25 07:19:08 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
void
debug_backlight (int on)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "backlight(%i)", on);
1999-12-09 23:15:14 +00:00
}
void
debug_init_vbar ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (LOG_INFO, "init_vbar()");
1999-12-09 23:15:14 +00:00
}
void
debug_init_hbar ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "init_hbar()");
1999-12-09 23:15:14 +00:00
}
void
debug_init_num ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "init_bignum()");
1999-12-09 23:15:14 +00:00
}
void
debug_num (int x, int num)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "big number(%i,%i)", x, num);
1999-12-09 23:15:14 +00:00
}
void
debug_set_char (int n, char *dat)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "set_char(%i,data)", n);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen.
//
void
debug_vbar (int x, int len)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
int y;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "vbar(%i,%i)", x, len);
1999-12-09 23:15:14 +00:00
2001-09-25 16:47:02 +00:00
for (y = debug_drv->hgt; y > 0 && len > 0; y--) {
2000-04-03 22:13:57 +00:00
debug_chr (x, y, '|');
1999-12-09 23:15:14 +00:00
2001-09-25 16:47:02 +00:00
len -= debug_drv->cellhgt;
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right.
//
void
debug_hbar (int x, int y, int len)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "hbar(%i,%i,%i)", x, y, len);
2001-09-25 16:47:02 +00:00
for (; x < debug_drv->wid && len > 0; x++) {
2000-04-03 22:13:57 +00:00
debug_chr (x, y, '-');
2001-09-25 16:47:02 +00:00
len -= debug_drv->cellwid;
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Sets character 0 to an icon...
//
void
debug_icon (int which, char dest)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "icon(%i,%i", which, dest);
1999-12-09 23:15:14 +00:00
}
void
debug_flush_box (int lft, int top, int rgt, int bot)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "flush_box(%i,%i,%i,%i)", lft, top, rgt, bot);
2000-04-03 22:13:57 +00:00
debug_flush ();
1999-12-09 23:15:14 +00:00
}
void
debug_draw_frame (char *dat)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
int i, j;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
char out[LCD_MAX_WIDTH];
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "draw_frame(data)");
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if (!dat)
return;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
// report (RPT_DEBUG, "Frame (%ix%i): %s", debug_drv->wid, debug_drv->hgt, dat);
1999-12-09 23:15:14 +00:00
2001-09-25 16:47:02 +00:00
for (i = 0; i < debug_drv->wid; i++) {
2000-04-03 22:13:57 +00:00
out[i] = '-';
}
2001-09-25 16:47:02 +00:00
out[debug_drv->wid] = 0;
2001-11-29 14:09:13 +00:00
//report (RPT_DEBUG, "+%s+", out);
2001-09-25 16:47:02 +00:00
for (i = 0; i < debug_drv->hgt; i++) {
for (j = 0; j < debug_drv->wid; j++) {
out[j] = dat[j + (i * debug_drv->wid)];
2000-04-03 22:13:57 +00:00
}
2001-09-25 16:47:02 +00:00
out[debug_drv->wid] = 0;
2001-11-29 14:09:13 +00:00
//report (RPT_DEBUG, "|%s|", out);
2000-04-03 22:13:57 +00:00
}
2001-09-25 16:47:02 +00:00
for (i = 0; i < debug_drv->wid; i++) {
2000-04-03 22:13:57 +00:00
out[i] = '-';
}
2001-09-25 16:47:02 +00:00
out[debug_drv->wid] = 0;
2001-11-29 14:09:13 +00:00
//report (RPT_DEBUG, "+%s+", out);
1999-12-09 23:15:14 +00:00
}
char
debug_getkey ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "getkey()");
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}