Files
lcdproc/server/drivers/text.c
T

219 lines
5.3 KiB
C
Raw Normal View History

/*
* TextMode driver
*
* Displays LCD screens, one after another; suitable for hard-copy
* terminals.
*
2004-03-21 15:21:25 +00:00
* Copyright (C) 1998-2004 The LCDproc Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/
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"
2004-03-21 15:21:25 +00:00
#include "report.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
2006-04-07 15:58:43 +00:00
static int width;
static int height;
static char * framebuf;
2001-12-30 00:15:25 +00:00
// 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
text_init (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2004-03-21 15:21:25 +00:00
char buf[256];
2001-12-30 00:15:25 +00:00
// Set display sizes
2006-04-07 15:58:43 +00:00
if ((drvthis->request_display_width() > 0)
&& (drvthis->request_display_height() > 0)) {
2001-12-30 00:15:25 +00:00
// Use size from primary driver
width = drvthis->request_display_width();
height = drvthis->request_display_height();
}
else {
2004-03-21 15:21:25 +00:00
/* Use our own size from config file */
2006-04-07 15:58:43 +00:00
strncpy(buf, drvthis->config_get_string(drvthis->name, "Size", 0, TEXTDRV_DEFAULT_SIZE), sizeof(buf));
buf[sizeof(buf)-1] = '\0';
if ((sscanf(buf , "%dx%d", &width, &height) != 2)
|| (width <= 0) || (width > LCD_MAX_WIDTH)
|| (height <= 0) || (height > LCD_MAX_HEIGHT)) {
report(RPT_WARNING, "%s: cannot read Size: %s; using default %s",
drvthis->name, buf, TEXTDRV_DEFAULT_SIZE);
sscanf(TEXTDRV_DEFAULT_SIZE, "%dx%d", &width, &height);
2004-03-21 15:21:25 +00:00
}
2001-12-30 00:15:25 +00:00
}
2001-12-30 00:15:25 +00:00
// Allocate the framebuffer
2006-04-07 15:58:43 +00:00
framebuf = malloc(width * height);
if (framebuf == NULL) {
report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
return -1;
}
memset(framebuf, ' ', width * height);
2001-11-23 15:15:05 +00:00
2006-04-07 15:58:43 +00:00
report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 1;
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)
2006-04-07 15:58:43 +00:00
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
{
2006-04-07 15:58:43 +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;
2006-04-07 15:58:43 +00:00
printf("+%s+\n", out);
2001-12-30 00:15:25 +00:00
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
out[j] = framebuf[j + (i * width)];
}
out[width] = 0;
2006-04-07 15:58:43 +00:00
printf("|%s|\n", out);
2001-12-30 00:15:25 +00:00
}
for (i = 0; i < width; i++) {
out[i] = '-';
}
out[width] = 0;
2006-04-07 15:58:43 +00:00
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...
if ((y < 0) || (y >= height))
2006-04-07 15:58:43 +00:00
return;
for (i = 0; (string[i] != '\0') && (x < width); i++, x++) {
if (x >= 0) // no write left of left border
framebuf[(y * width) + x] = 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--;
if ((x >= 0) && (y >= 0) && (x < width) && (y < height))
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
{
2006-04-07 15:58:43 +00:00
debug(RPT_DEBUG, "Contrast: %d", 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;
2006-04-07 15:58:43 +00:00
debug(RPT_DEBUG, "Backlight %s", (on) ? "ON" : "OFF");
1999-12-09 23:15:14 +00:00
}