v0.5 kick-off

This commit is contained in:
robijn
2001-12-30 00:15:25 +00:00
parent c28d25b795
commit 71056ec551
88 changed files with 6638 additions and 5469 deletions
+144 -119
View File
@@ -26,18 +26,17 @@
# include "config.h"
#endif
#ifdef HAVE_NCURSES_H
# include <ncurses.h>
#else
# include <curses.h>
#endif
//#ifdef HAVE_NCURSES_H
//# include <ncurses.h>
//#else
//# include <curses.h>
//#endif
#include "shared/str.h"
#include "shared/debug.h"
#include "lcd.h"
#include "lb216.h"
#include "drv_base.h"
#include "render.h"
#include "shared/str.h"
#include "report.h"
//#include "drv_base.h"
static int custom=0;
typedef enum {
@@ -47,20 +46,30 @@ typedef enum {
beat = 8 } custom_type;
static int fd;
static char *framebuf = NULL;
static int width = LCD_DEFAULT_WIDTH;
static int height = LCD_DEFAULT_HEIGHT;
static int cellwidth = LCD_DEFAULT_CELLWIDTH;
static int cellheight = LCD_DEFAULT_CELLHEIGHT;
static void LB216_hidecursor();
static void LB216_reboot();
// TODO: Get rid of this variable?
lcd_logical_driver *LB216;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "LB216_";
// TODO: Get the frame buffers working right
/////////////////////////////////////////////////////////////////
// Opens com port and sets baud correctly...
//
int LB216_init(lcd_logical_driver *driver, char *args)
int
LB216_init(Driver * drvthis, char *args)
{
char *argv[64];
int argc;
@@ -71,8 +80,8 @@ int LB216_init(lcd_logical_driver *driver, char *args)
char device[256] = "/dev/lcd";
int speed=B9600;
int backlight_brightness = 255;
LB216 = driver;
//debug("LB216_init: Args(all): %s\n", args);
@@ -153,6 +162,7 @@ int LB216_init(lcd_logical_driver *driver, char *args)
}
// Set up io port correctly, and open it...
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
@@ -184,12 +194,11 @@ int LB216_init(lcd_logical_driver *driver, char *args)
// Do it...
tcsetattr(fd, TCSANOW, &portset);
// Make sure the frame buffer is there...
if (!LB216->framebuf)
LB216->framebuf = (unsigned char *)
malloc (LB216->wid * LB216->hgt);
memset (LB216->framebuf, ' ', LB216->wid * LB216->hgt);
if (framebuf)
framebuf = (unsigned char *)
malloc (width * height);
memset (framebuf, ' ', width * height);
// Set display-specific stuff..
if(reboot)
@@ -200,36 +209,34 @@ int LB216_init(lcd_logical_driver *driver, char *args)
}
sleep(1);
LB216_hidecursor();
LB216_backlight(backlight_brightness);
LB216_backlight(drvthis, backlight_brightness);
// Set the functions the driver supports...
// Set variables for server
drvthis->api_version = api_version;
drvthis->stay_in_foreground = &stay_in_foreground;
drvthis->supports_multiple = &supports_multiple;
driver->clear = LB216_clear;
driver->string = LB216_string;
driver->chr = LB216_chr;
driver->vbar = LB216_vbar;
driver->init_vbar = LB216_init_vbar;
driver->hbar = LB216_hbar;
driver->init_hbar = LB216_init_hbar;
//driver->num = NULL;
//driver->init_num = NULL;
// Set the functions the driver supports
drvthis->clear = LB216_clear;
drvthis->string = LB216_string;
drvthis->chr = LB216_chr;
drvthis->old_vbar = LB216_vbar;
drvthis->init_vbar = LB216_init_vbar;
drvthis->old_hbar = LB216_hbar;
drvthis->init_hbar = LB216_init_hbar;
//drvthis->num = NULL;
//drvthis->init_num = NULL;
driver->init = LB216_init;
driver->close = LB216_close;
driver->flush = LB216_flush;
//driver->flush_box = NULL;
//driver->contrast = NULL;
driver->backlight = LB216_backlight;
driver->set_char = LB216_set_char;
driver->icon = LB216_icon;
driver->draw_frame = LB216_draw_frame;
drvthis->init = LB216_init;
drvthis->close = LB216_close;
drvthis->width = LB216_width;
drvthis->height = LB216_height;
drvthis->flush = LB216_flush;
drvthis->backlight = LB216_backlight;
drvthis->set_char = LB216_set_char;
drvthis->old_icon = LB216_icon;
LB216->cellwid = 5;
LB216->cellhgt = 8;
debug("LB216: foo!\n");
return fd;
return 0;
}
@@ -237,28 +244,66 @@ int LB216_init(lcd_logical_driver *driver, char *args)
/////////////////////////////////////////////////////////////////
// Clean-up
//
void LB216_close()
MODULE_EXPORT void
LB216_close(Driver * drvthis)
{
close (fd);
if(LB216->framebuf) free(LB216->framebuf);
if(framebuf) free(framebuf);
framebuf = NULL;
}
LB216->framebuf = NULL;
/////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
LB216_width (Driver *drvthis)
{
return width;
}
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
LB216_height (Driver *drvthis)
{
return height;
}
/////////////////////////////////////////////////////////////////
// Clears the LCD screen
//
void
LB216_clear ()
MODULE_EXPORT void
LB216_clear (Driver * drvthis)
{
memset (LB216->framebuf, ' ', LB216->wid * LB216->hgt);
memset (framebuf, ' ', width * height);
}
void LB216_flush()
/////////////////////////////////////////////////////////////////
// Flushes the framebuffer to the LCD
//
MODULE_EXPORT void
LB216_flush(Driver * drvthis)
{
LB216_draw_frame(LB216->framebuf);
char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i,j;
snprintf (out, sizeof(out), "%c%c", 254,80);
write(fd, out, 2);
for(j=0; j<height; j++) {
if (j>=2) {
snprintf (out, sizeof(out),"%c%c",254,148+(64*(j-2)));
} else {
snprintf (out, sizeof(out),"%c%c",254,128+(64*(j)));
}
write(fd, out, 2);
for(i=0; i<width; i++) {
write(fd, framebuf + i+(j*width), 1);
}
}
}
@@ -267,13 +312,14 @@ void LB216_flush()
// Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (16,2).
//
void LB216_chr(int x, int y, char c)
MODULE_EXPORT void
LB216_chr(Driver * drvthis, int x, int y, char c)
{
//y--;
// x--;
//if(c < 32 && c >= 0) c += 128;
// LB216->framebuf[(y*LB216->wid) + x] = c;
// framebuf[(y*width) + x] = c;
// char chr[1];
// snprintf (chr, sizeof(chr), "%c", c);
@@ -282,7 +328,7 @@ void LB216_chr(int x, int y, char c)
char chr[2];
chr[0] = c;
chr[1] = 0;
LB216_string (x, y, chr);
LB216_string (drvthis, x, y, chr);
}
@@ -290,7 +336,8 @@ void LB216_chr(int x, int y, char c)
// Sets the backlight on or off -- can be done quickly for
// an intermediate brightness...
//
void LB216_backlight(int on)
MODULE_EXPORT void
LB216_backlight(Driver * drvthis, int on)
{
char out[4];
if(on)
@@ -326,36 +373,8 @@ static void LB216_reboot()
}
/////////////////////////////////////////////////////////////
// Blasts a single frame onscreen, to the lcd...
//
// Input is a character array, sized LB216->wid*LB216->hgt
//
void LB216_draw_frame(char *dat)
{
char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i,j;
if(!dat) return;
snprintf (out, sizeof(out), "%c%c", 254,80);
write(fd, out, 2);
for(j=0; j<LB216->hgt; j++) {
if (j>=2) {
snprintf (out, sizeof(out),"%c%c",254,148+(64*(j-2)));
} else {
snprintf (out, sizeof(out),"%c%c",254,128+(64*(j)));
}
write(fd, out, 2);
for(i=0; i<LB216->wid; i++) {
snprintf (out, sizeof(out),"%c",dat[i+(j*LB216->wid)]);
write(fd, out, 1);
}
}
}
void LB216_string (int x, int y, char string[])
MODULE_EXPORT void
LB216_string (Driver * drvthis, int x, int y, char string[])
{
int i;
char c;
@@ -369,7 +388,7 @@ void LB216_string (int x, int y, char string[])
{
case '\254': c = '#'; break;
}
LB216->framebuf[(y*LB216->wid) + x+i] = c;
framebuf[(y*width) + x+i] = c;
}
}
@@ -377,7 +396,8 @@ void LB216_string (int x, int y, char string[])
/////////////////////////////////////////////////////////////////
// Sets up for vertical bars. Call before LB216->vbar()
//
void LB216_init_vbar()
MODULE_EXPORT void
LB216_init_vbar(Driver * drvthis)
{
char a[] = {
0,0,0,0,0,
@@ -451,13 +471,13 @@ void LB216_init_vbar()
};
if(custom!=vbar) {
LB216_set_char(1,a);
LB216_set_char(2,b);
LB216_set_char(3,c);
LB216_set_char(4,d);
LB216_set_char(5,e);
LB216_set_char(6,f);
LB216_set_char(7,g);
LB216_set_char(drvthis, 1,a);
LB216_set_char(drvthis, 2,b);
LB216_set_char(drvthis, 3,c);
LB216_set_char(drvthis, 4,d);
LB216_set_char(drvthis, 5,e);
LB216_set_char(drvthis, 6,f);
LB216_set_char(drvthis, 7,g);
custom=vbar;
}
}
@@ -465,7 +485,8 @@ void LB216_init_vbar()
/////////////////////////////////////////////////////////////////
// Inits horizontal bars...
//
void LB216_init_hbar()
MODULE_EXPORT void
LB216_init_hbar(Driver * drvthis)
{
char a[] = {
@@ -520,11 +541,11 @@ void LB216_init_hbar()
};
if(custom!=hbar) {
LB216_set_char(1,a);
LB216_set_char(2,b);
LB216_set_char(3,c);
LB216_set_char(4,d);
LB216_set_char(5,e);
LB216_set_char(drvthis, 1,a);
LB216_set_char(drvthis, 2,b);
LB216_set_char(drvthis, 3,c);
LB216_set_char(drvthis, 4,d);
LB216_set_char(drvthis, 5,e);
custom=hbar;
}
}
@@ -532,18 +553,19 @@ void LB216_init_hbar()
/////////////////////////////////////////////////////////////////
// Draws a vertical bar...
//
void LB216_vbar(int x, int len)
MODULE_EXPORT void
LB216_vbar(Driver * drvthis, int x, int len)
{
char map[9] = {32, 1, 2, 3, 4, 5, 6, 7, 255 };
int y;
for(y=LB216->hgt; y > 0 && len>0; y--)
for(y=height; y > 0 && len>0; y--)
{
if(len >= LB216->cellhgt) LB216_chr(x, y, 255);
else LB216_chr(x, y, map[len]);
if(len >= cellheight) LB216_chr(drvthis, x, y, 255);
else LB216_chr(drvthis, x, y, map[len]);
len -= LB216->cellhgt;
len -= cellheight;
}
}
@@ -551,17 +573,18 @@ void LB216_vbar(int x, int len)
/////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right.
//
void LB216_hbar(int x, int y, int len)
MODULE_EXPORT void
LB216_hbar(Driver * drvthis, int x, int y, int len)
{
char map[7] = { 32, 1, 2, 3, 4, 5 };
for(; x<=LB216->wid && len>0; x++)
for(; x<=width && len>0; x++)
{
if(len >= LB216->cellwid) LB216_chr(x,y,map[5]);
else LB216_chr(x, y, map[len]);
if(len >= cellwidth) LB216_chr(drvthis, x,y,map[5]);
else LB216_chr(drvthis, x, y, map[len]);
//printf ("%d,",len);
len -= LB216->cellwid;
len -= cellwidth;
}
// printf ("\n");
@@ -576,7 +599,8 @@ void LB216_hbar(int x, int y, int len)
//
// The input is just an array of characters...
//
void LB216_set_char(int n, char *dat)
MODULE_EXPORT void
LB216_set_char(Driver * drvthis, int n, char *dat)
{
char out[4];
int row, col;
@@ -589,20 +613,21 @@ void LB216_set_char(int n, char *dat)
snprintf (out, sizeof(out), "%c%c", 254, n);
write(fd, out, 2);
for(row=0; row<LB216->cellhgt; row++)
for(row=0; row<cellheight; row++)
{
letter = 1;
for(col=0; col<LB216->cellwid; col++)
for(col=0; col<cellwidth; col++)
{
letter <<= 1;
letter |= (dat[(row*LB216->cellwid) + col] > 0);
letter |= (dat[(row*cellwidth) + col] > 0);
}
snprintf (out, sizeof(out),"%c",letter);
write(fd, out, 1);
}
}
void LB216_icon(int which, char dest)
MODULE_EXPORT void
LB216_icon(Driver * drvthis, int which, char dest)
{
char icons[3][8*8] = {
{
@@ -641,5 +666,5 @@ void LB216_icon(int which, char dest)
};
if(custom==bign) custom=beat;
LB216_set_char(dest, &icons[which][0]);
LB216_set_char(drvthis, dest, &icons[which][0]);
}