Files
lcdproc/server/drivers/debug.c
T

274 lines
5.2 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>
2001-09-25 07:19:08 +00:00
#include <syslog.h>
1999-12-09 23:15:14 +00:00
#include "lcd.h"
1999-12-09 23:15:14 +00:00
#include "debug.h"
//////////////////////////////////////////////////////////////////////////
////////////////////// 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-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "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-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "debug_close()");
1999-12-09 23:15:14 +00:00
2001-09-25 07:19:08 +00:00
if (debug_drv->framebuf) {
printf ("frame buffer: %010X", (int) debug_drv->framebuf);
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-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "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-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "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;
2001-09-25 07:19:08 +00:00
char buf[64];
1999-12-09 23:15:14 +00:00
2001-09-25 07:19:08 +00:00
snprintf(buf, sizeof(buf), "string(%i,%i): %s", x, y, string);
syslog (LOG_DEBUG, buf);
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-09-25 07:19:08 +00:00
char buf[64];
1999-12-09 23:15:14 +00:00
2001-09-25 07:19:08 +00:00
snprintf(buf, sizeof(buf), "character(%i,%i): %c", x, y, c);
syslog (LOG_DEBUG, buf);
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-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "contrast: %i", contrast);
return 0;
1999-12-09 23:15:14 +00:00
}
void
debug_backlight (int on)
1999-12-09 23:15:14 +00:00
{
2001-09-25 07:19:08 +00:00
if (on)
syslog(LOG_DEBUG, "backlight turned on");
else
syslog(LOG_DEBUG, "backlight turned off");
1999-12-09 23:15:14 +00:00
}
void
debug_init_vbar ()
1999-12-09 23:15:14 +00:00
{
2001-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "Init vertical bars");
1999-12-09 23:15:14 +00:00
}
void
debug_init_hbar ()
1999-12-09 23:15:14 +00:00
{
2001-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "Init horizontal bars");
1999-12-09 23:15:14 +00:00
}
void
debug_init_num ()
1999-12-09 23:15:14 +00:00
{
2001-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "Big numbers");
1999-12-09 23:15:14 +00:00
}
void
debug_num (int x, int num)
1999-12-09 23:15:14 +00:00
{
2001-09-25 07:19:08 +00:00
char buf[64];
snprintf(buf, sizeof(buf), "big number(%i): %i", x, num);
syslog (LOG_DEBUG, buf);
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-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "set character %i", 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-09-25 07:19:08 +00:00
syslog (LOG_DEBUG, "vbar(%i): len = %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-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "hbar(%i,%i): len = %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-09-25 07:19:08 +00:00
syslog (LOG_DEBUG, "char %i = icon %i", dest, which);
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-09-25 07:19:08 +00:00
syslog (LOG_DEBUG, "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-09-25 07:19:08 +00:00
syslog (LOG_DEBUG, "draw_frame()");
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-09-25 16:47:02 +00:00
// printf("Frame (%ix%i): \n%s\n", 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-09-25 07:19:08 +00:00
//printf ("+%s+\n", 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-09-25 07:19:08 +00:00
//printf ("|%s|\n", 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-09-25 07:19:08 +00:00
//printf ("+%s+\n", out);
1999-12-09 23:15:14 +00:00
}
char
debug_getkey ()
1999-12-09 23:15:14 +00:00
{
2001-09-25 07:19:08 +00:00
syslog(LOG_DEBUG, "getkey");
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}