v0.5 kick-off
This commit is contained in:
+133
-162
@@ -1,7 +1,7 @@
|
||||
/* wirz-sli.c -- Source file for LCDproc Wirz SLI driver
|
||||
Copyright (C) 1999 Horizon Technologies-http://horizon.pair.com/
|
||||
Written by Bryan Rittmeyer <bryanr@pair.com> - Released under GPL
|
||||
|
||||
|
||||
LCD info: http://www.wirz.com/ */
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#include "lcd.h"
|
||||
#include "wirz-sli.h"
|
||||
#include "drv_base.h"
|
||||
//#include "drv_base.h"
|
||||
|
||||
#include "shared/debug.h"
|
||||
#include "shared/str.h"
|
||||
@@ -32,15 +32,22 @@ typedef enum {
|
||||
} custom_type;
|
||||
|
||||
static int fd;
|
||||
static char lastframe[32];
|
||||
static char *framebuf = NULL;
|
||||
static int width = 0;
|
||||
static int height = 0;
|
||||
|
||||
// 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 = "sli_";
|
||||
|
||||
lcd_logical_driver *sli;
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Opens com port and sets baud correctly...
|
||||
//
|
||||
int
|
||||
sli_init (lcd_logical_driver * driver, char *args)
|
||||
sli_init (Driver *drvthis, char *args)
|
||||
{
|
||||
char *argv[64];
|
||||
int argc;
|
||||
@@ -52,8 +59,6 @@ sli_init (lcd_logical_driver * driver, char *args)
|
||||
char device[256] = "/dev/lcd";
|
||||
int speed = B19200;
|
||||
|
||||
sli = driver;
|
||||
|
||||
//debug("sli_init: Args(all): %s\n", args);
|
||||
|
||||
argc = get_args (argv, args, 64);
|
||||
@@ -135,7 +140,7 @@ sli_init (lcd_logical_driver * driver, char *args)
|
||||
// Do it...
|
||||
tcsetattr (fd, TCSANOW, &portset);
|
||||
|
||||
/* Initialize SLI using autobaud detection, and then turn off cursor
|
||||
/* Initialize SLI using autobaud detection, and then turn off cursor
|
||||
and clear screen */
|
||||
usleep (150000); /* 150ms delay to allow SLI to power on */
|
||||
out[0] = 13; /* CR for SLI autobaud */
|
||||
@@ -151,92 +156,109 @@ sli_init (lcd_logical_driver * driver, char *args)
|
||||
// Set LCD parameters (I use a 16x2 LCD) -- small but still useful
|
||||
// Its also much cheaper than the higher quality Matrix Orbital modules
|
||||
// Currently, $30 for interface kit and 16x2 non-backlit LCD...
|
||||
driver->wid = 15;
|
||||
driver->hgt = 2;
|
||||
width = 15;
|
||||
height = 2;
|
||||
|
||||
// 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 = sli_clear;
|
||||
driver->string = sli_string;
|
||||
driver->chr = sli_chr;
|
||||
driver->vbar = sli_vbar;
|
||||
driver->init_vbar = sli_init_vbar;
|
||||
driver->hbar = sli_hbar;
|
||||
driver->init_hbar = sli_init_hbar;
|
||||
//driver->num = NULL;
|
||||
//driver->init_num = NULL;
|
||||
// Set the functions the driver supports
|
||||
drvthis->clear = sli_clear;
|
||||
drvthis->string = sli_string;
|
||||
drvthis->chr = sli_chr;
|
||||
drvthis->old_vbar = sli_vbar;
|
||||
drvthis->init_vbar = sli_init_vbar;
|
||||
drvthis->old_hbar = sli_hbar;
|
||||
drvthis->init_hbar = sli_init_hbar;
|
||||
//drvthis->num = NULL;
|
||||
//drvthis->init_num = NULL;
|
||||
|
||||
driver->init = sli_init;
|
||||
driver->close = sli_close;
|
||||
driver->flush = sli_flush;
|
||||
driver->flush_box = sli_flush_box;
|
||||
//driver->contrast = NULL;
|
||||
//driver->backlight = NULL;
|
||||
driver->set_char = sli_set_char;
|
||||
driver->icon = sli_icon;
|
||||
driver->draw_frame = sli_draw_frame;
|
||||
drvthis->init = sli_init;
|
||||
drvthis->close = sli_close;
|
||||
drvthis->flush = sli_flush;
|
||||
//drvthis->contrast = NULL;
|
||||
//drvthis->backlight = NULL;
|
||||
drvthis->set_char = sli_set_char;
|
||||
drvthis->old_icon = sli_icon;
|
||||
|
||||
//driver->getkey = NULL;
|
||||
//drvthis->getkey = NULL;
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* Clean-up */
|
||||
void
|
||||
sli_close ()
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Clean up
|
||||
//
|
||||
MODULE_EXPORT void
|
||||
sli_close (Driver *drvthis)
|
||||
{
|
||||
close (fd);
|
||||
|
||||
if (sli->framebuf)
|
||||
free (sli->framebuf);
|
||||
if (framebuf)
|
||||
free (framebuf);
|
||||
|
||||
sli->framebuf = NULL;
|
||||
framebuf = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
sli_flush ()
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Returns the display width
|
||||
//
|
||||
MODULE_EXPORT int
|
||||
sli_width (Driver *drvthis)
|
||||
{
|
||||
sli_draw_frame (sli->framebuf);
|
||||
return width;
|
||||
}
|
||||
|
||||
/* no bounds checking is done in MtxOrb.c (which I shamelessly ripped)
|
||||
this is bad imho, so I added it.. may remove later
|
||||
speed is not a huge issue though, this isnt a
|
||||
device driver or anything ;) */
|
||||
void
|
||||
sli_flush_box (int lft, int top, int rgt, int bot)
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Returns the display height
|
||||
//
|
||||
MODULE_EXPORT int
|
||||
sli_height (Driver *drvthis)
|
||||
{
|
||||
int y;
|
||||
char out[2]; /* Why does the matrix driver allocate so much here? */
|
||||
return height;
|
||||
}
|
||||
|
||||
/* simple bounds checking */
|
||||
if ((top > sli->hgt) | (bot > sli->hgt))
|
||||
return;
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Flush framebuffer to LCD
|
||||
//
|
||||
MODULE_EXPORT void
|
||||
sli_flush (Driver *drvthis)
|
||||
{
|
||||
char out[2]; /* Again, why does the Matrix driver allocate so much here? */
|
||||
|
||||
if ((lft > sli->wid) | (rgt > sli->wid))
|
||||
return;
|
||||
/*
|
||||
out[0]=0x0FE;
|
||||
out[1]=0x001;
|
||||
write(fd, out, 2);
|
||||
*/
|
||||
|
||||
// printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot);
|
||||
/* Don't update if we have no new data
|
||||
this keeps me from getting a migraine
|
||||
(just like those copyleft penguin mints... mmmmmm) */
|
||||
|
||||
/* I like having hex, everywhere and all the time */
|
||||
for (y = top; y <= bot; y++) {
|
||||
if (y == 1)
|
||||
snprintf (out, sizeof(out), "%c%c", 0x0FE, 0x080 + lft);
|
||||
if (y == 2)
|
||||
snprintf (out, sizeof(out), "%c%c", 0x0FE, 0x0C0 + lft);
|
||||
write (fd, out, 0x002);
|
||||
write (fd, sli->framebuf + (y * sli->wid) + lft, rgt - lft + 1);
|
||||
}
|
||||
// if (!strncmp(dat,lastframe,32)) /* Nothing has changed */
|
||||
// return;
|
||||
|
||||
/* Do the actual refresh */
|
||||
out[0] = 0x0FE;
|
||||
out[1] = 0x080;
|
||||
write (fd, out, 2);
|
||||
write (fd, &framebuf[0], 16);
|
||||
usleep (10);
|
||||
write (fd, &framebuf[16], 15);
|
||||
|
||||
// strncpy(lastframe,dat,32); // Update lastframe...
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Clears the LCD screen
|
||||
//
|
||||
void
|
||||
sli_clear ()
|
||||
MODULE_EXPORT void
|
||||
sli_clear (Driver *drvthis)
|
||||
{
|
||||
memset (sli->framebuf, ' ', sli->wid * sli->hgt);
|
||||
memset (framebuf, ' ', width * height);
|
||||
|
||||
}
|
||||
|
||||
@@ -244,8 +266,8 @@ sli_clear ()
|
||||
// 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
|
||||
sli_string (int x, int y, char string[])
|
||||
MODULE_EXPORT void
|
||||
sli_string (Driver *drvthis, int x, int y, char string[])
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -254,9 +276,9 @@ sli_string (int x, int y, char string[])
|
||||
|
||||
for (i = 0; string[i]; i++) {
|
||||
// Check for buffer overflows...
|
||||
if ((y * sli->wid) + x + i > (sli->wid * sli->hgt))
|
||||
if ((y * width) + x + i > (width * height))
|
||||
break;
|
||||
sli->framebuf[(y * sli->wid) + x + i] = string[i];
|
||||
framebuf[(y * width) + x + i] = string[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,26 +286,13 @@ sli_string (int x, int y, char string[])
|
||||
// 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
|
||||
sli_chr (int x, int y, char c)
|
||||
MODULE_EXPORT void
|
||||
sli_chr (Driver *drvthis, int x, int y, char c)
|
||||
{
|
||||
y--;
|
||||
x--;
|
||||
|
||||
sli->framebuf[(y * sli->wid) + x] = c;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
sli_chr (int x, int y, char c)
|
||||
{
|
||||
y--;
|
||||
x--;
|
||||
|
||||
sli->framebuf[(y * sli->wid) + x] = c;
|
||||
framebuf[(y * width) + x] = c;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
@@ -293,14 +302,14 @@ sli_chr (int x, int y, char c)
|
||||
/* Because of the way we do this (custom characters in CGRAM)
|
||||
we can't have both horizontal and vertical bars at once...
|
||||
this also appears to be a limitation of the Matrix Orbital
|
||||
modules so I will assume that all client coders know about it
|
||||
modules so I will assume that all client coders know about it
|
||||
|
||||
I think it would be cool to use triangular stuff for the non-full
|
||||
characters, so that you can do both bar types at once.. maybe I
|
||||
characters, so that you can do both bar types at once.. maybe I
|
||||
will release a new version of the SLI driver that attempts this */
|
||||
|
||||
void
|
||||
sli_init_vbar ()
|
||||
MODULE_EXPORT void
|
||||
sli_init_vbar (Driver *drvthis)
|
||||
{
|
||||
char a[] = {
|
||||
0, 0, 0, 0, 0,
|
||||
@@ -374,13 +383,13 @@ sli_init_vbar ()
|
||||
};
|
||||
|
||||
if (custom != vbar) {
|
||||
sli_set_char (1, a);
|
||||
sli_set_char (2, b);
|
||||
sli_set_char (3, c);
|
||||
sli_set_char (4, d);
|
||||
sli_set_char (5, e);
|
||||
sli_set_char (6, f);
|
||||
sli_set_char (7, g);
|
||||
sli_set_char (drvthis, 1, a);
|
||||
sli_set_char (drvthis, 2, b);
|
||||
sli_set_char (drvthis, 3, c);
|
||||
sli_set_char (drvthis, 4, d);
|
||||
sli_set_char (drvthis, 5, e);
|
||||
sli_set_char (drvthis, 6, f);
|
||||
sli_set_char (drvthis, 7, g);
|
||||
custom = vbar;
|
||||
}
|
||||
}
|
||||
@@ -388,8 +397,8 @@ sli_init_vbar ()
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Inits horizontal bars...
|
||||
//
|
||||
void
|
||||
sli_init_hbar ()
|
||||
MODULE_EXPORT void
|
||||
sli_init_hbar (Driver *drvthis)
|
||||
{
|
||||
|
||||
char a[] = {
|
||||
@@ -434,10 +443,10 @@ sli_init_hbar ()
|
||||
};
|
||||
|
||||
if (custom != hbar) {
|
||||
sli_set_char (1, a);
|
||||
sli_set_char (2, b);
|
||||
sli_set_char (3, c);
|
||||
sli_set_char (4, d);
|
||||
sli_set_char (drvthis, 1, a);
|
||||
sli_set_char (drvthis, 2, b);
|
||||
sli_set_char (drvthis, 3, c);
|
||||
sli_set_char (drvthis, 4, d);
|
||||
custom = hbar;
|
||||
}
|
||||
}
|
||||
@@ -451,19 +460,19 @@ sli_init_hbar ()
|
||||
since we only have 2 lines anyway this is rather pointless
|
||||
for me to add */
|
||||
|
||||
void
|
||||
sli_vbar (int x, int len)
|
||||
MODULE_EXPORT void
|
||||
sli_vbar (Driver *drvthis, int x, int len)
|
||||
{
|
||||
char map[9] = { 32, 1, 2, 3, 4, 5, 6, 7, 255 };
|
||||
|
||||
int y;
|
||||
for (y = sli->hgt; y > 0 && len > 0; y--) {
|
||||
if (len >= sli->cellhgt)
|
||||
sli_chr (x, y, 255);
|
||||
for (y = height; y > 0 && len > 0; y--) {
|
||||
if (len >= LCD_DEFAULT_CELLHEIGHT)
|
||||
sli_chr (drvthis, x, y, 255);
|
||||
else
|
||||
sli_chr (x, y, map[len]);
|
||||
sli_chr (drvthis, x, y, map[len]);
|
||||
|
||||
len -= sli->cellhgt;
|
||||
len -= LCD_DEFAULT_CELLHEIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -471,18 +480,18 @@ sli_vbar (int x, int len)
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Draws a horizontal bar to the right.
|
||||
//
|
||||
void
|
||||
sli_hbar (int x, int y, int len)
|
||||
MODULE_EXPORT void
|
||||
sli_hbar (Driver *drvthis, int x, int y, int len)
|
||||
{
|
||||
char map[6] = { 32, 1, 2, 3, 4, 255 };
|
||||
|
||||
for (; x <= sli->wid && len > 0; x++) {
|
||||
if (len >= sli->cellwid)
|
||||
sli_chr (x, y, 255);
|
||||
for (; x <= width && len > 0; x++) {
|
||||
if (len >= LCD_DEFAULT_CELLWIDTH)
|
||||
sli_chr (drvthis, x, y, 255);
|
||||
else
|
||||
sli_chr (x, y, map[len]);
|
||||
sli_chr (drvthis, x, y, map[len]);
|
||||
|
||||
len -= sli->cellwid;
|
||||
len -= LCD_DEFAULT_CELLWIDTH;
|
||||
|
||||
}
|
||||
|
||||
@@ -495,8 +504,8 @@ sli_hbar (int x, int y, int len)
|
||||
//
|
||||
// The input is just an array of characters...
|
||||
//
|
||||
void
|
||||
sli_set_char (int n, char *dat)
|
||||
MODULE_EXPORT void
|
||||
sli_set_char (Driver *drvthis, int n, char *dat)
|
||||
{
|
||||
char out[2];
|
||||
int row, col;
|
||||
@@ -513,11 +522,11 @@ sli_set_char (int n, char *dat)
|
||||
out[1] = 0x040 + 8 * n;
|
||||
write (fd, out, 2);
|
||||
|
||||
for (row = 0; row < sli->cellhgt; row++) {
|
||||
for (row = 0; row < LCD_DEFAULT_CELLHEIGHT; row++) {
|
||||
letter = 0;
|
||||
for (col = 0; col < sli->cellwid; col++) {
|
||||
for (col = 0; col < LCD_DEFAULT_CELLWIDTH; col++) {
|
||||
letter <<= 1;
|
||||
letter |= (dat[(row * sli->cellwid) + col] > 0);
|
||||
letter |= (dat[(row * LCD_DEFAULT_CELLWIDTH) + col] > 0);
|
||||
}
|
||||
letter |= 0x020; /* SLI can't accept CR, LF, etc in this character! */
|
||||
write (fd, &letter, 1);
|
||||
@@ -529,8 +538,8 @@ sli_set_char (int n, char *dat)
|
||||
write (fd, out, 2);
|
||||
}
|
||||
|
||||
void
|
||||
sli_icon (int which, char dest)
|
||||
MODULE_EXPORT void
|
||||
sli_icon (Driver *drvthis, int which, char dest)
|
||||
{
|
||||
char icons[3][5 * 8] = {
|
||||
{
|
||||
@@ -570,44 +579,6 @@ sli_icon (int which, char dest)
|
||||
|
||||
if (custom == bign)
|
||||
custom = beat;
|
||||
sli_set_char (dest, &icons[which][0]);
|
||||
sli_set_char (drvthis, dest, &icons[which][0]);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Blasts a single frame onscreen, to the lcd...
|
||||
//
|
||||
// Input is a character array, sized sli->wid*sli->hgt
|
||||
//
|
||||
void
|
||||
sli_draw_frame (char *dat)
|
||||
{
|
||||
char out[2]; /* Again, why does the Matrix driver allocate so much here? */
|
||||
int y;
|
||||
|
||||
if (!dat)
|
||||
return;
|
||||
|
||||
/*
|
||||
out[0]=0x0FE;
|
||||
out[1]=0x001;
|
||||
write(fd, out, 2);
|
||||
*/
|
||||
|
||||
/* Don't update if we have no new data
|
||||
this keeps me from getting a migraine
|
||||
(just like those copyleft penguin mints... mmmmmm) */
|
||||
|
||||
// if (!strncmp(dat,lastframe,32)) /* Nothing has changed */
|
||||
// return;
|
||||
|
||||
/* Do the actual refresh */
|
||||
out[0] = 0x0FE;
|
||||
out[1] = 0x080;
|
||||
write (fd, out, 2);
|
||||
write (fd, &dat[0], 16);
|
||||
usleep (10);
|
||||
write (fd, &dat[16], 15);
|
||||
|
||||
// strncpy(lastframe,dat,32); // Update lastframe...
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user