v0.5 kick-off
This commit is contained in:
+146
-136
@@ -6,6 +6,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -17,24 +21,7 @@
|
||||
|
||||
#include "lcd.h"
|
||||
#include "text.h"
|
||||
#include "drv_base.h"
|
||||
|
||||
static void text_close ();
|
||||
static void text_clear ();
|
||||
static void text_flush ();
|
||||
static void text_string (int x, int y, char string[]);
|
||||
static void text_chr (int x, int y, char c);
|
||||
static int text_contrast (int contrast);
|
||||
static void text_backlight (int on);
|
||||
//static void text_init_vbar ();
|
||||
//static void text_init_hbar ();
|
||||
//static void text_init_num ();
|
||||
static void text_vbar (int x, int len);
|
||||
static void text_hbar (int x, int y, int len);
|
||||
static void text_num (int x, int num);
|
||||
//static void text_set_char (int n, char *dat);
|
||||
//static void text_flush_box (int lft, int top, int rgt, int bot);
|
||||
static void text_draw_frame (char *dat);
|
||||
//#include "drv_base.h"
|
||||
|
||||
/* Ugly code extracted by David GLAUDE from lcdm001.c ;)*/
|
||||
static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
|
||||
@@ -79,106 +66,160 @@ static char num_icon [10][4][3] = {{{' ','_',' '}, /*0*/
|
||||
{' ',' ',' '}}};
|
||||
/* End of ugly code ;) by Rene Wagner */
|
||||
|
||||
lcd_logical_driver *text;
|
||||
// Variables
|
||||
int width;
|
||||
int height;
|
||||
char * framebuf;
|
||||
|
||||
// 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 = "text_";
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// For Text-Mode Output //////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define LCD_DEFAULT_WIDTH 20
|
||||
#define LCD_DEFAULT_HEIGHT 4
|
||||
// The two value below are fake, we don't support custom char.
|
||||
#define LCD_DEFAULT_CELL_WIDTH 5
|
||||
#define LCD_DEFAULT_CELL_HEIGHT 8
|
||||
|
||||
// TODO: When using the text driver, ^C fails to interrupt!
|
||||
// Why? Fix it...
|
||||
// DONE??? Are you sure, not in my Konsole. David GLAUDE
|
||||
|
||||
int
|
||||
text_init (lcd_logical_driver * driver, char *args)
|
||||
text_init (Driver *drvthis, char *args)
|
||||
{
|
||||
text = driver;
|
||||
// Set display sizes
|
||||
if( drvthis->request_display_width() > 0
|
||||
&& drvthis->request_display_height() > 0 ) {
|
||||
// Use size from primary driver
|
||||
width = drvthis->request_display_width();
|
||||
height = drvthis->request_display_height();
|
||||
}
|
||||
else {
|
||||
// Use default size
|
||||
width = LCD_DEFAULT_WIDTH;
|
||||
height = LCD_DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
// Make sure the frame buffer is there...
|
||||
if (!text->framebuf)
|
||||
text->framebuf = (unsigned char *)
|
||||
malloc (text->wid * text->hgt);
|
||||
memset (text->framebuf, ' ', text->wid * text->hgt);
|
||||
// Allocate the framebuffer
|
||||
framebuf = (unsigned char *) malloc (width * height);
|
||||
memset (framebuf, ' ', width * height);
|
||||
|
||||
// Set variables for server
|
||||
drvthis->api_version = api_version;
|
||||
drvthis->stay_in_foreground = &stay_in_foreground;
|
||||
drvthis->supports_multiple = &supports_multiple;
|
||||
|
||||
// Set the functions the driver supports
|
||||
drvthis->init = text_init;
|
||||
drvthis->close = text_close;
|
||||
drvthis->width = text_width;
|
||||
drvthis->height = text_height;
|
||||
|
||||
text->wid = LCD_DEFAULT_WIDTH;
|
||||
text->hgt = LCD_DEFAULT_HEIGHT;
|
||||
text->cellwid = LCD_DEFAULT_CELL_WIDTH;
|
||||
text->cellhgt = LCD_DEFAULT_CELL_HEIGHT;
|
||||
drvthis->clear = text_clear;
|
||||
drvthis->flush = text_flush;
|
||||
drvthis->string = text_string;
|
||||
drvthis->chr = text_chr;
|
||||
|
||||
text->clear = text_clear;
|
||||
text->string = text_string;
|
||||
text->chr = text_chr;
|
||||
text->vbar = text_vbar;
|
||||
//text->init_vbar = NULL;
|
||||
text->hbar = text_hbar;
|
||||
//text->init_hbar = NULL;
|
||||
text->num = text_num;
|
||||
//text->init_num = NULL;
|
||||
drvthis->old_vbar = text_vbar;
|
||||
//drvthis->init_vbar = NULL;
|
||||
drvthis->old_hbar = text_hbar;
|
||||
//drvthis->init_hbar = NULL;
|
||||
drvthis->num = text_num;
|
||||
//drvthis->init_num = NULL;
|
||||
|
||||
text->init = text_init;
|
||||
text->close = text_close;
|
||||
text->flush = text_flush;
|
||||
//text->flush_box = NULL;
|
||||
//text->contrast = NULL;
|
||||
//text->backlight = NULL;
|
||||
//text->set_char = NULL;
|
||||
//text->icon = NULL;
|
||||
text->draw_frame = text_draw_frame;
|
||||
drvthis->set_contrast = text_set_contrast;
|
||||
drvthis->backlight = text_backlight;
|
||||
|
||||
//text->getkey = NULL;
|
||||
//drvthis->set_char = NULL;
|
||||
//drvthis->icon = NULL;
|
||||
|
||||
return 200; // 200 is arbitrary. (must be 1 or more)
|
||||
//drvthis->getkey = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
text_close ()
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Closes the device
|
||||
//
|
||||
MODULE_EXPORT void
|
||||
text_close (Driver *drvthis)
|
||||
{
|
||||
if (text->framebuf != NULL)
|
||||
free (text->framebuf);
|
||||
if (framebuf != NULL)
|
||||
free (framebuf);
|
||||
|
||||
text->framebuf = NULL;
|
||||
framebuf = NULL;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Returns the display width
|
||||
//
|
||||
MODULE_EXPORT int
|
||||
text_width (Driver *drvthis)
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Returns the display height
|
||||
//
|
||||
MODULE_EXPORT int
|
||||
text_height (Driver *drvthis)
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Clears the LCD screen
|
||||
//
|
||||
static void
|
||||
text_clear ()
|
||||
MODULE_EXPORT void
|
||||
text_clear (Driver *drvthis)
|
||||
{
|
||||
memset (text->framebuf, ' ', text->wid * text->hgt);
|
||||
memset (framebuf, ' ', width * height);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Flushes all output to the lcd...
|
||||
//
|
||||
static void
|
||||
text_flush ()
|
||||
MODULE_EXPORT void
|
||||
text_flush (Driver *drvthis)
|
||||
{
|
||||
text_draw_frame (text->framebuf);
|
||||
int i, j;
|
||||
|
||||
char out[LCD_MAX_WIDTH];
|
||||
|
||||
for (i = 0; i < width; i++) {
|
||||
out[i] = '-';
|
||||
}
|
||||
out[width] = 0;
|
||||
printf ("+%s+\n", out);
|
||||
|
||||
for (i = 0; i < height; i++) {
|
||||
for (j = 0; j < width; j++) {
|
||||
out[j] = framebuf[j + (i * width)];
|
||||
}
|
||||
out[width] = 0;
|
||||
printf ("|%s|\n", out);
|
||||
|
||||
}
|
||||
|
||||
for (i = 0; i < width; i++) {
|
||||
out[i] = '-';
|
||||
}
|
||||
out[width] = 0;
|
||||
printf ("+%s+\n", out);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// 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).
|
||||
//
|
||||
static void
|
||||
text_string (int x, int y, char string[])
|
||||
MODULE_EXPORT void
|
||||
text_string (Driver *drvthis, int x, int y, char string[])
|
||||
{
|
||||
int i;
|
||||
|
||||
x--; y--; // Convert 1-based coords to 0-based...
|
||||
|
||||
for (i = 0; string[i]; i++) {
|
||||
text->framebuf[(y * text->wid) + x + i] = string[i];
|
||||
framebuf[(y * width) + x + i] = string[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,24 +227,33 @@ text_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).
|
||||
//
|
||||
static void
|
||||
text_chr (int x, int y, char c)
|
||||
MODULE_EXPORT void
|
||||
text_chr (Driver *drvthis, int x, int y, char c)
|
||||
{
|
||||
y--; x--;
|
||||
|
||||
text->framebuf[(y * text->wid) + x] = c;
|
||||
framebuf[(y * width) + x] = c;
|
||||
}
|
||||
|
||||
static int
|
||||
text_contrast (int contrast)
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Sets the contrast
|
||||
//
|
||||
MODULE_EXPORT void
|
||||
text_set_contrast (Driver *drvthis, int promille)
|
||||
{
|
||||
// printf("Contrast: %i\n", contrast);
|
||||
return 0;
|
||||
/*
|
||||
printf("Contrast: %d\n", promille);
|
||||
*/
|
||||
}
|
||||
|
||||
static void
|
||||
text_backlight (int on)
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Sets the backlight brightness
|
||||
//
|
||||
MODULE_EXPORT void
|
||||
text_backlight (Driver *drvthis, int on)
|
||||
{
|
||||
//PrivateData * p = (PrivateData*) drvthis->private_data;
|
||||
|
||||
/*
|
||||
if(on)
|
||||
{
|
||||
@@ -237,14 +287,16 @@ text_backlight (int on)
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Writes a big number. (by Rene Wagner from lcdm001.c)
|
||||
//
|
||||
static void text_num (int x, int num)
|
||||
MODULE_EXPORT void text_num (Driver *drvthis, int x, int num)
|
||||
{
|
||||
//PrivateData * p = (PrivateData*) drvthis->private_data;
|
||||
|
||||
int y, dx;
|
||||
|
||||
// printf("BigNum(%i, %i)\n", x, num);
|
||||
for (y = 1; y < 5; y++)
|
||||
for (dx = 0; dx < 3; dx++)
|
||||
text_chr (x + dx, y, num_icon[num][y-1][dx]);
|
||||
text_chr (drvthis, x + dx, y, num_icon[num][y-1][dx]);
|
||||
}
|
||||
|
||||
//void
|
||||
@@ -256,14 +308,14 @@ static void text_num (int x, int num)
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Draws a vertical bar; erases entire column onscreen.
|
||||
//
|
||||
static void
|
||||
text_vbar (int x, int len)
|
||||
MODULE_EXPORT void
|
||||
text_vbar (Driver *drvthis, int x, int len)
|
||||
{
|
||||
int y;
|
||||
for (y = text->hgt; y > 0 && len > 0; y--) {
|
||||
text_chr (x, y, '|');
|
||||
for (y = height; y > 0 && len > 0; y--) {
|
||||
text_chr (drvthis, x, y, '|');
|
||||
|
||||
len -= text->cellhgt;
|
||||
len -= LCD_DEFAULT_CELLHEIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -271,56 +323,14 @@ text_vbar (int x, int len)
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Draws a horizontal bar to the right.
|
||||
//
|
||||
static void
|
||||
text_hbar (int x, int y, int len)
|
||||
MODULE_EXPORT void
|
||||
text_hbar (Driver *drvthis, int x, int y, int len)
|
||||
{
|
||||
for (; x <= text->wid && len > 0; x++) {
|
||||
text_chr (x, y, '-');
|
||||
for (; x <= width && len > 0; x++) {
|
||||
text_chr (drvthis, x, y, '-');
|
||||
|
||||
len -= text->cellwid;
|
||||
len -= LCD_DEFAULT_CELLWIDTH;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
text_flush_box (int lft, int top, int rgt, int bot)
|
||||
{
|
||||
text_flush ();
|
||||
}
|
||||
|
||||
static void
|
||||
text_draw_frame (char *dat)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
char out[LCD_MAX_WIDTH];
|
||||
|
||||
if (!dat)
|
||||
return;
|
||||
|
||||
// printf("Frame (%ix%i): \n%s\n", lcd.wid, lcd.hgt, dat);
|
||||
|
||||
for (i = 0; i < text->wid; i++) {
|
||||
out[i] = '-';
|
||||
}
|
||||
out[text->wid] = 0;
|
||||
printf ("+%s+\n", out);
|
||||
|
||||
for (i = 0; i < text->hgt; i++) {
|
||||
for (j = 0; j < text->wid; j++) {
|
||||
out[j] = dat[j + (i * text->wid)];
|
||||
}
|
||||
out[text->wid] = 0;
|
||||
printf ("|%s|\n", out);
|
||||
|
||||
}
|
||||
|
||||
for (i = 0; i < text->wid; i++) {
|
||||
out[i] = '-';
|
||||
}
|
||||
out[text->wid] = 0;
|
||||
printf ("+%s+\n", out);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user