Files
lcdproc/server/drivers/drv_base.c
T

318 lines
6.7 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"
#include "drv_base.h"
//////////////////////////////////////////////////////////////////////////
////////////////////// Base "class" to derive from ///////////////////////
//////////////////////////////////////////////////////////////////////////
lcd_logical_driver *drv_base;
// TODO: Get lcd.framebuf to properly work as whatever driver is running...
////////////////////////////////////////////////////////////
// init() should set up any device-specific stuff, and
// point all the function pointers.
int
drv_base_init (struct lcd_logical_driver *driver, char *args)
1999-12-09 23:15:14 +00:00
{
// printf("drv_base_init()\n");
2000-04-03 22:13:57 +00:00
drv_base = driver;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
driver->wid = 20;
driver->hgt = 4;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
// You must use driver->framebuf here, but may use lcd.framebuf later.
if (!driver->framebuf)
driver->framebuf = malloc (driver->wid * driver->hgt);
2000-04-03 22:13:57 +00:00
if (!driver->framebuf) {
drv_base_close ();
return -1;
}
1999-12-09 23:15:14 +00:00
// Debugging...
// if(lcd.framebuf) printf("Frame buffer: %i\n", (int)lcd.framebuf);
2000-04-03 22:13:57 +00:00
memset (driver->framebuf, ' ', driver->wid * driver->hgt);
1999-12-09 23:15:14 +00:00
// drv_base_clear();
2000-04-03 22:13:57 +00:00
driver->cellwid = 5;
driver->cellhgt = 8;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
driver->clear = drv_base_clear;
driver->string = drv_base_string;
driver->chr = drv_base_chr;
driver->vbar = drv_base_vbar;
driver->init_vbar = drv_base_init_vbar;
driver->hbar = drv_base_hbar;
driver->init_hbar = drv_base_init_hbar;
driver->num = drv_base_num;
driver->init_num = drv_base_init_num;
2000-04-03 22:13:57 +00:00
driver->init = drv_base_init;
driver->close = drv_base_close;
driver->flush = drv_base_flush;
driver->flush_box = drv_base_flush_box;
driver->contrast = drv_base_contrast;
driver->backlight = drv_base_backlight;
driver->set_char = drv_base_set_char;
driver->icon = drv_base_icon;
driver->draw_frame = drv_base_draw_frame;
2000-04-03 22:13:57 +00:00
driver->getkey = drv_base_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
}
// Below here, you may use either lcd.framebuf or driver->framebuf..
// lcd.framebuf will be set to the appropriate buffer before calling
// your driver.
void
drv_base_close ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
if (lcd.framebuf != NULL)
free (lcd.framebuf);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
lcd.framebuf = NULL;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Clears the LCD screen
//
void
drv_base_clear ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
memset (lcd.framebuf, ' ', lcd.wid * lcd.hgt);
1999-12-09 23:15:14 +00:00
}
//////////////////////////////////////////////////////////////////
// Flushes all output to the lcd...
//
void
drv_base_flush ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
//lcd.draw_frame(lcd.framebuf);
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
drv_base_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
x -= 1; // Convert 1-based coords to 0-based...
y -= 1;
2000-04-03 22:13:57 +00:00
for (i = 0; string[i]; i++) {
// Check for buffer overflows...
if ((y * lcd.wid) + x + i > (lcd.wid * lcd.hgt))
break;
lcd.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).
//
void
drv_base_chr (int x, int y, char c)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
y--;
x--;
1999-12-09 23:15:14 +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
}
//////////////////////////////////////////////////////////////////////
// Sets the contrast of the display. Value is 0-255, where 140 is
// what I consider "just right".
//
int
drv_base_contrast (int contrast)
1999-12-09 23:15:14 +00:00
{
// printf("Contrast: %i\n", contrast);
2000-04-03 22:13:57 +00:00
return -1;
1999-12-09 23:15:14 +00:00
}
//////////////////////////////////////////////////////////////////////
// Turns the lcd backlight on or off...
//
void
drv_base_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
}
//////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for vertical bargraphs.
//
void
drv_base_init_vbar ()
1999-12-09 23:15:14 +00:00
{
// printf("Vertical bars.\n");
}
//////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for horizontal bargraphs.
//
void
drv_base_init_hbar ()
1999-12-09 23:15:14 +00:00
{
// printf("Horizontal bars.\n");
}
//////////////////////////////////////////////////////////////////////
// Tells the driver to get ready for big numbers, if possible.
//
void
drv_base_init_num ()
1999-12-09 23:15:14 +00:00
{
// printf("Big Numbers.\n");
}
//////////////////////////////////////////////////////////////////////
// Draws a big (4-row) number.
//
void
drv_base_num (int x, int num)
1999-12-09 23:15:14 +00:00
{
// printf("BigNum(%i, %i)\n", x, num);
}
//////////////////////////////////////////////////////////////////////
// Changes the font data of character n.
//
void
drv_base_set_char (int n, char *dat)
1999-12-09 23:15:14 +00:00
{
// printf("Set Character %i\n", n);
}
/////////////////////////////////////////////////////////////////
// Draws a vertical bar, from the bottom of the screen up.
//
void
drv_base_vbar (int x, int len)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
int y;
for (y = lcd.hgt; y > 0 && len > 0; y--) {
drv_base_chr (x, y, '|');
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
len -= lcd.cellhgt;
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right.
//
void
drv_base_hbar (int x, int y, int len)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
for (; x <= lcd.wid && len > 0; x++) {
drv_base_chr (x, y, '-');
2000-04-03 22:13:57 +00:00
len -= lcd.cellwid;
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Sets character 0 to an icon...
//
void
drv_base_icon (int which, char dest)
1999-12-09 23:15:14 +00:00
{
// printf("Char %i set to icon %i\n", dest, which);
}
//////////////////////////////////////////////////////////////////////
// Send a rectangular area to the display.
//
// I've just called drv_base_flush() because there's not much point yet
// in flushing less than the entire framebuffer.
//
void
drv_base_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
//drv_base_flush();
1999-12-09 23:15:14 +00:00
}
//////////////////////////////////////////////////////////////////////
// Draws the framebuffer on the display.
//
// The commented-out code is from the text driver.
//
void
drv_base_draw_frame (char *dat)
1999-12-09 23:15:14 +00:00
{
/*
int i, j;
char out[LCD_MAX_WIDTH];
if(!dat) return;
for(i=0; i<lcd.wid; i++)
{
out[i] = '-';
}
out[lcd.wid] = 0;
printf("+%s+\n", out);
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);
}
for(i=0; i<lcd.wid; i++)
{
out[i] = '-';
}
out[lcd.wid] = 0;
printf("+%s+\n", out);
*/
}
//////////////////////////////////////////////////////////////////////
// Tries to read a character from an input device...
//
// Return 0 for "nothing available".
//
char
drv_base_getkey ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}