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>
|
|
|
|
|
|
1999-12-11 19:21:29 +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...
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
int
|
|
|
|
|
debug_init (struct lcd_logical_driver *driver, char *args)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("debug_init(%s)\n", device);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
if (!driver->framebuf) {
|
|
|
|
|
printf ("Allocating frame buffer (%ix%i)\n", lcd.wid, lcd.hgt);
|
|
|
|
|
driver->framebuf = malloc (lcd.wid * lcd.hgt);
|
|
|
|
|
}
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
if (!driver->framebuf) {
|
|
|
|
|
debug_close ();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
if (driver->framebuf)
|
|
|
|
|
printf ("Frame buffer: %i\n", (int) driver->framebuf);
|
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
|
|
|
|
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-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
driver->getkey = debug_getkey;
|
2000-03-30 20:20:41 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_close ()
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
|
|
|
|
// Ack! This shouldn't crash the program, but does.. Why??
|
|
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("debug_close()\n");
|
1999-12-09 23:15:14 +00:00
|
|
|
|
|
|
|
|
// This is the line which crashes.
|
2000-04-03 22:13:57 +00:00
|
|
|
if (driver->framebuf)
|
|
|
|
|
free (driver->framebuf);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
if (driver->framebuf)
|
|
|
|
|
printf ("Frame buffer: %i\n", (int) driver->framebuf);
|
|
|
|
|
driver->framebuf = NULL;
|
1999-12-09 23:15:14 +00:00
|
|
|
// printf("debug_close() finished\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
// Clears the LCD screen
|
|
|
|
|
//
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_clear ()
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("clear()\n");
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
memset (driver->framebuf, ' ', lcd.wid * lcd.hgt);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
// Flushes all output to the lcd...
|
|
|
|
|
//
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_flush ()
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("flush()\n");
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
lcd.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).
|
|
|
|
|
//
|
2000-03-30 20:20:41 +00:00
|
|
|
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
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("string(%i, %i):%s \n", x, y, string);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
x -= 1; // Convert 1-based coords to 0-based...
|
|
|
|
|
y -= 1;
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
for (i = 0; string[i]; i++) {
|
|
|
|
|
driver->framebuf[(y * lcd.wid) + x + i] = string[i];
|
|
|
|
|
}
|
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).
|
|
|
|
|
//
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_chr (int x, int y, char c)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("character(%i, %i):%c\n", x, y, c);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
y--;
|
|
|
|
|
x--;
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
lcd.framebuf[(y * lcd.wid) + x] = c;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_contrast (int contrast)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Contrast: %i\n", contrast);
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_backlight (int on)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
if (on) {
|
|
|
|
|
printf ("Backlight ON\n");
|
|
|
|
|
} else {
|
|
|
|
|
printf ("Backlight OFF\n");
|
|
|
|
|
}
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_init_vbar ()
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Vertical bars.\n");
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_init_hbar ()
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Horizontal bars.\n");
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_init_num ()
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Big Numbers.\n");
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_num (int x, int num)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("BigNum(%i, %i)\n", x, num);
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_set_char (int n, char *dat)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Set Character %i\n", n);
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
// Draws a vertical bar; erases entire column onscreen.
|
|
|
|
|
//
|
2000-03-30 20:20:41 +00:00
|
|
|
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
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Vbar(%i, %i)\n", x, len);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
for (y = lcd.hgt; y > 0 && len > 0; y--) {
|
|
|
|
|
debug_chr (x, y, '|');
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
len -= lcd.cellhgt;
|
|
|
|
|
}
|
2000-03-30 20:20:41 +00:00
|
|
|
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
// Draws a horizontal bar to the right.
|
|
|
|
|
//
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_hbar (int x, int y, int len)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Hbar(%i, %i, %i)\n", x, y, len);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
for (; x < lcd.wid && len > 0; x++) {
|
|
|
|
|
debug_chr (x, y, '-');
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
len -= lcd.cellwid;
|
|
|
|
|
}
|
2000-03-30 20:20:41 +00:00
|
|
|
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
// Sets character 0 to an icon...
|
|
|
|
|
//
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_icon (int which, char dest)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Char %i is icon %i\n", dest, which);
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
void
|
|
|
|
|
debug_flush_box (int lft, int top, int rgt, int bot)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Flush Box(%i, %i)-(%i, %i)\n", lft, top, rgt, bot);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
debug_flush ();
|
1999-12-09 23:15:14 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +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
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("draw_frame()\n");
|
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
|
|
|
|
|
|
|
|
// printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat);
|
|
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
for (i = 0; i < lcd.wid; i++) {
|
|
|
|
|
out[i] = '-';
|
|
|
|
|
}
|
|
|
|
|
out[lcd.wid] = 0;
|
|
|
|
|
printf ("+%s+\n", out);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
for (i = 0; i < lcd.hgt; i++) {
|
|
|
|
|
for (j = 0; j < lcd.wid; j++) {
|
|
|
|
|
out[j] = dat[j + (i * lcd.wid)];
|
|
|
|
|
}
|
|
|
|
|
out[lcd.wid] = 0;
|
|
|
|
|
printf ("|%s|\n", out);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
}
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
for (i = 0; i < lcd.wid; i++) {
|
|
|
|
|
out[i] = '-';
|
|
|
|
|
}
|
|
|
|
|
out[lcd.wid] = 0;
|
|
|
|
|
printf ("+%s+\n", out);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
char
|
|
|
|
|
debug_getkey ()
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
printf ("Trying to grab keypress.\n");
|
|
|
|
|
return 0;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|