Files
lcdproc/server/drivers/text.c
T

194 lines
3.8 KiB
C
Raw Normal View History

/*
* TextMode driver
*
* Displays LCD screens, one after another; suitable for hard-copy
* terminals.
*
*/
2001-12-30 00:15:25 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
1999-12-09 23:15:14 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include "lcd.h"
#include "text.h"
2001-12-30 00:15:25 +00:00
//#include "drv_base.h"
2001-11-29 08:42:41 +00:00
2001-12-30 00:15:25 +00:00
// 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_";
1999-12-09 23:15:14 +00:00
//////////////////////////////////////////////////////////////////////////
////////////////////// For Text-Mode Output //////////////////////////////
//////////////////////////////////////////////////////////////////////////
2001-09-25 07:29:38 +00:00
2002-02-21 22:50:12 +00:00
MODULE_EXPORT int
2001-12-30 00:15:25 +00:00
text_init (Driver *drvthis, char *args)
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +00:00
// 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;
}
2001-12-30 00:15:25 +00:00
// Allocate the framebuffer
framebuf = (unsigned char *) malloc (width * height);
memset (framebuf, ' ', width * height);
2001-11-23 15:15:05 +00:00
2001-12-30 00:15:25 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
2001-12-30 00:15:25 +00:00
/////////////////////////////////////////////////////////////////
// Closes the device
//
MODULE_EXPORT void
text_close (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +00:00
if (framebuf != NULL)
free (framebuf);
2001-12-30 00:15:25 +00:00
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;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Clears the LCD screen
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
text_clear (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +00:00
memset (framebuf, ' ', width * height);
1999-12-09 23:15:14 +00:00
}
//////////////////////////////////////////////////////////////////
// Flushes all output to the lcd...
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
text_flush (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +00:00
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);
fflush(stdin);
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).
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
text_string (Driver *drvthis, 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
2001-09-25 07:29:38 +00:00
x--; y--; // Convert 1-based coords to 0-based...
2000-04-03 22:13:57 +00:00
for (i = 0; string[i]; i++) {
2001-12-30 00:15:25 +00:00
framebuf[(y * width) + x + i] = string[i];
2000-04-03 22:13:57 +00:00
}
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).
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
text_chr (Driver *drvthis, int x, int y, char c)
1999-12-09 23:15:14 +00:00
{
2001-09-25 07:29:38 +00:00
y--; x--;
2001-12-30 00:15:25 +00:00
framebuf[(y * width) + x] = c;
1999-12-09 23:15:14 +00:00
}
2001-12-30 00:15:25 +00:00
/////////////////////////////////////////////////////////////////
// Sets the contrast
//
MODULE_EXPORT void
text_set_contrast (Driver *drvthis, int promille)
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +00:00
/*
printf("Contrast: %d\n", promille);
*/
1999-12-09 23:15:14 +00:00
}
2001-12-30 00:15:25 +00:00
/////////////////////////////////////////////////////////////////
// Sets the backlight brightness
//
MODULE_EXPORT void
text_backlight (Driver *drvthis, int on)
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +00:00
//PrivateData * p = (PrivateData*) drvthis->private_data;
1999-12-09 23:15:14 +00:00
/*
if(on)
{
printf("Backlight ON\n");
}
else
{
printf("Backlight OFF\n");
}
*/
}