Files
lcdproc/server/drivers/debug.c
T

518 lines
13 KiB
C
Raw Normal View History

2008-12-19 19:59:01 +00:00
/** \file server/drivers/debug.c
* \c debug driver for LCDd.
* This driver does does nothing more than writing a debug message when
* any one of the driver's functions is called.
*/
/* Copyright (C) ?????? ?????????
2008, Peter Marschall
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 */
1999-12-09 23:15:14 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <sys/errno.h>
2001-12-30 00:15:25 +00:00
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "lcd.h"
1999-12-09 23:15:14 +00:00
#include "debug.h"
2001-12-30 00:15:25 +00:00
#include "report.h"
2008-12-19 19:59:01 +00:00
#define DEFAULT_WIDTH LCD_DEFAULT_WIDTH
#define DEFAULT_HEIGHT LCD_DEFAULT_HEIGHT
#define DEFAULT_CELLWIDTH LCD_DEFAULT_CELLWIDTH
#define DEFAULT_CELLHEIGHT LCD_DEFAULT_CELLHEIGHT
#define DEFAULT_CONTRAST 500
#define DEFAULT_BRIGHTNESS 750
#define DEFAULT_OFFBRIGHTNESS 250
2008-12-21 17:13:26 +00:00
/** private data for the \c debug driver */
2008-12-19 19:59:01 +00:00
typedef struct debug_private_data {
2008-12-21 17:13:26 +00:00
char *framebuf; /**< frame buffer */
int width; /**< display width in characters */
int height; /**< display height in characters */
int cellwidth; /**< character cell width */
int cellheight; /**< character cell height */
int contrast; /**< current contrast */
int brightness; /**< current brightness (for backlight on) */
int offbrightness; /**< current brightness (for backlight off) */
2008-12-19 19:59:01 +00:00
} PrivateData;
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 = 1;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "debug_";
1999-12-09 23:15:14 +00:00
2008-12-19 19:59:01 +00:00
/**
* Initialize the driver.
* \param drvthis Pointer to driver structure.
2008-12-21 17:13:26 +00:00
* \retval 0 Success.
* \retval <0 Error.
2008-12-19 19:59:01 +00:00
*/
2002-02-21 22:50:12 +00:00
MODULE_EXPORT int
debug_init (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
PrivateData *p;
report(RPT_INFO, "%s()", __FUNCTION__);
1999-12-09 23:15:14 +00:00
2008-12-19 19:59:01 +00:00
/* Allocate and store private data */
p = (PrivateData *) calloc(1, sizeof(PrivateData));
if (p == NULL)
return -1;
if (drvthis->store_private_ptr(drvthis, p))
return -1;
p->width = DEFAULT_WIDTH;
p->height = DEFAULT_HEIGHT;
p->cellwidth = DEFAULT_CELLWIDTH;
p->cellheight = DEFAULT_CELLHEIGHT;
p->contrast = DEFAULT_CONTRAST;
p->brightness = DEFAULT_BRIGHTNESS;
p->offbrightness = DEFAULT_OFFBRIGHTNESS;
p->framebuf = malloc(p->width * p->height);
if (p->framebuf == NULL) {
report(RPT_INFO, "%s: unable to allocate framebuffer", drvthis->name);
return -1;
}
1999-12-09 23:15:14 +00:00
debug_clear(drvthis);
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Close the driver (do necessary clean-up).
* \param drvthis Pointer to driver structure.
*/
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
debug_close (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s()", __FUNCTION__);
1999-12-09 23:15:14 +00:00
2008-12-19 19:59:01 +00:00
if (p != NULL) {
if (p->framebuf != NULL)
free(p->framebuf);
p->framebuf = NULL;
free(p);
}
drvthis->store_private_ptr(drvthis, NULL);
2001-12-30 00:15:25 +00:00
}
1999-12-09 23:15:14 +00:00
2008-12-19 19:59:01 +00:00
/**
* Return the display width in characters.
* \param drvthis Pointer to driver structure.
2008-12-21 17:13:26 +00:00
* \return Number of characters the display is wide.
2008-12-19 19:59:01 +00:00
*/
2001-12-30 00:15:25 +00:00
MODULE_EXPORT int
debug_width (Driver *drvthis)
{
2008-12-19 19:59:01 +00:00
PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s()", __FUNCTION__);
2008-12-19 19:59:01 +00:00
return p->width;
2001-12-30 00:15:25 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Return the display height in characters.
* \param drvthis Pointer to driver structure.
2008-12-21 17:13:26 +00:00
* \return Number of characters the display is high.
2008-12-19 19:59:01 +00:00
*/
2001-12-30 00:15:25 +00:00
MODULE_EXPORT int
debug_height (Driver *drvthis)
{
2008-12-19 19:59:01 +00:00
PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s()", __FUNCTION__);
2008-12-19 19:59:01 +00:00
return p->height;
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Return the width of a character in pixels.
* \param drvthis Pointer to driver structure.
2008-12-21 17:13:26 +00:00
* \return Number of pixel columns a character cell is wide.
2008-12-19 19:59:01 +00:00
*/
MODULE_EXPORT int
debug_cellwidth (Driver *drvthis)
{
PrivateData *p = drvthis->private_data;
return p->cellwidth;
}
/**
* Return the height of a character in pixels.
* \param drvthis Pointer to driver structure.
2008-12-21 17:13:26 +00:00
* \return Number of pixel lines a character cell is high.
2008-12-19 19:59:01 +00:00
*/
MODULE_EXPORT int
debug_cellheight (Driver *drvthis)
{
PrivateData *p = drvthis->private_data;
return p->cellheight;
}
/**
* Clear the screen.
* \param drvthis Pointer to driver structure.
*/
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
debug_clear (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s()", __FUNCTION__);
2008-12-19 19:59:01 +00:00
memset (p->framebuf, ' ', p->width * p->height);
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Flush data on screen to the display.
* \param drvthis Pointer to driver structure.
*/
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
debug_flush (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
PrivateData *p = drvthis->private_data;
2001-12-30 00:15:25 +00:00
int i, j;
char out[LCD_MAX_WIDTH];
report(RPT_INFO, "%s()", __FUNCTION__);
2008-12-19 19:59:01 +00:00
for (i = 0; i < p->width; i++) {
2001-12-30 00:15:25 +00:00
out[i] = '-';
}
2008-12-19 19:59:01 +00:00
out[p->width] = 0;
//report(RPT_DEBUG, "+%s+", out);
2001-12-30 00:15:25 +00:00
2008-12-19 19:59:01 +00:00
for (i = 0; i < p->height; i++) {
for (j = 0; j < p->width; j++) {
out[j] = p->framebuf[j + (i * p->width)];
2001-12-30 00:15:25 +00:00
}
2008-12-19 19:59:01 +00:00
out[p->width] = 0;
//report(RPT_DEBUG, "|%s|", out);
2001-12-30 00:15:25 +00:00
}
2008-12-19 19:59:01 +00:00
for (i = 0; i < p->width; i++) {
2001-12-30 00:15:25 +00:00
out[i] = '-';
}
2008-12-19 19:59:01 +00:00
out[p->width] = 0;
//report(RPT_DEBUG, "+%s+", out);
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Print a string on the screen at position (x,y).
* The upper-left corner is (1,1), the lower-right corner is (p->width, p->height).
* \param drvthis Pointer to driver structure.
* \param x Horizontal character position (column).
* \param y Vertical character position (row).
* \param string String that gets written.
*/
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2007-04-02 21:29:53 +00:00
debug_string (Driver *drvthis, int x, int y, const char string[])
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
PrivateData *p = drvthis->private_data;
2000-04-03 22:13:57 +00:00
int i;
1999-12-09 23:15:14 +00:00
report(RPT_INFO, "%s(%i,%i,%.40s)", __FUNCTION__, x, y, string);
1999-12-09 23:15:14 +00:00
2001-09-25 07:19:08 +00:00
y --; x --; // Convert 1-based coords to 0-based...
2008-12-19 19:59:01 +00:00
if ((y < 0) || (y >= p->height))
return;
2008-12-19 19:59:01 +00:00
for (i = 0; (string[i] != '\0') && (x < p->width); i++, x++) {
if (x >= 0) // no write left of left border
2008-12-19 19:59:01 +00:00
p->framebuf[(y * p->width) + x] = string[i];
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Print a character on the screen at position (x,y).
* The upper-left corner is (1,1), the lower-right corner is (p->width, p->height).
* \param drvthis Pointer to driver structure.
* \param x Horizontal character position (column).
* \param y Vertical character position (row).
* \param c Character that gets written.
*/
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
debug_chr (Driver *drvthis, int x, int y, char c)
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
PrivateData *p = drvthis->private_data;
report(RPT_DEBUG, "%s(%i,%i,%c)", __FUNCTION__, x, y, c);
2001-09-25 07:19:08 +00:00
x--; y--;
2008-12-19 19:59:01 +00:00
if ((x >= 0) && (y >= 0) && (x < p->width) && (y < p->height))
p->framebuf[(y * p->width) + x] = c;
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Draw a vertical bar bottom-up.
* \param drvthis Pointer to driver structure.
* \param x Horizontal character position (column) of the starting point.
* \param y Vertical character position (row) of the starting point.
* \param len Number of characters that the bar is high at 100%
* \param promille Current height level of the bar in promille.
* \param options Options (currently unused).
*/
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2002-02-08 00:15:50 +00:00
debug_vbar (Driver *drvthis, int x, int y, int len, int promille, int options)
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
//PrivateData *p = drvthis->private_data;
2002-02-08 00:15:50 +00:00
int pos;
1999-12-09 23:15:14 +00:00
report(RPT_INFO, "%s(%i,%i,%i,%i,%i)", __FUNCTION__, x, y, len, promille, options);
1999-12-09 23:15:14 +00:00
for (pos = 0; pos < len; pos++) {
if (2 * pos < ((long) promille * len / 500 + 1)) {
debug_chr(drvthis, x, y-pos, '|');
2002-02-08 00:15:50 +00:00
} else {
; /* print nothing */
}
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Draw a horizontal bar to the right.
* \param drvthis Pointer to driver structure.
* \param x Horizontal character position (column) of the starting point.
* \param y Vertical character position (row) of the starting point.
* \param len Number of characters that the bar is long at 100%
* \param promille Current length level of the bar in promille.
* \param options Options (currently unused).
*/
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
2002-02-08 00:15:50 +00:00
debug_hbar (Driver *drvthis, int x, int y, int len, int promille, int options)
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
//PrivateData *p = drvthis->private_data;
2002-02-08 00:15:50 +00:00
int pos;
report(RPT_INFO, "%s(%i,%i,%i,%i,%i)", __FUNCTION__, x, y, len, promille, options);
for (pos = 0; pos < len; pos++) {
if (2 * pos < ((long) promille * len / 500 + 1)) {
2002-02-08 00:15:50 +00:00
debug_chr (drvthis, x+pos, y, '-');
} else {
; /* print nothing */
}
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Write a big number to the screen.
* \param drvthis Pointer to driver structure.
* \param x Horizontal character position (column).
* \param num Character to write (0 - 10 with 10 representing ':')
*/
MODULE_EXPORT void
debug_num (Driver *drvthis, int x, int num)
{
//PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s(%i,%i)", __FUNCTION__, x, num);
}
/**
* Place an icon on the screen.
* \param drvthis Pointer to driver structure.
* \param x Horizontal character position (column).
* \param y Vertical character position (row).
* \param icon synbolic value representing the icon.
2008-12-21 14:07:20 +00:00
* \retval 0 Icon has been successfully defined/written.
* \retval <0 Server core shall define/write the icon.
2008-12-19 19:59:01 +00:00
*/
2002-05-23 18:03:36 +00:00
MODULE_EXPORT int
2002-02-08 00:15:50 +00:00
debug_icon (Driver *drvthis, int x, int y, int icon)
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
//PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s(%i,%i,%i)", __FUNCTION__, x, y, icon);
return -1; /* let the core do all the icon stuff */
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Define a custom character and write it to the LCD.
* \param drvthis Pointer to driver structure.
* \param n Custom character to define [0 - (NUM_CCs-1)].
* \param dat Array of 8 (=cellheight) bytes, each representing a pixel row
* starting from the top to bottom.
* The bits in each byte represent the pixels where the LSB
* (least significant bit) is the rightmost pixel in each pixel row.
*/
MODULE_EXPORT void
debug_set_char (Driver *drvthis, int n, char *dat)
{
//PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s(%i,data)", __FUNCTION__, n);
}
/**
* Get current LCD contrast.
* This is only the locally stored contrast, the contrast value
* cannot be retrieved from the LCD.
* \param drvthis Pointer to driver structure.
2008-12-21 17:13:26 +00:00
* \return Stored contrast in promille.
2008-12-19 19:59:01 +00:00
*/
MODULE_EXPORT int
debug_get_contrast (Driver *drvthis)
{
PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s()", __FUNCTION__);
return p->contrast;
}
/**
* Change LCD contrast.
* \param drvthis Pointer to driver structure.
* \param promille New contrast value in promille.
*/
MODULE_EXPORT void
debug_set_contrast (Driver *drvthis, int promille)
{
PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s(%i)", __FUNCTION__, promille);
p->contrast = promille;
}
/**
* Retrieve brightness.
* \param drvthis Pointer to driver structure.
* \param state Brightness state (on/off) for which we want the value.
2008-12-21 17:13:26 +00:00
* \return Stored brightness in promille.
2008-12-19 19:59:01 +00:00
*/
MODULE_EXPORT int
debug_get_brightness(Driver *drvthis, int state)
{
PrivateData *p = drvthis->private_data;
return (state == BACKLIGHT_ON) ? p->brightness : p->offbrightness;
}
/**
* Set on/off brightness.
2008-12-21 17:13:26 +00:00
* \param drvthis Pointer to driver structure.
* \param state Brightness state (on/off) for which we want to store the value.
* \param promille New brightness in promille.
2008-12-19 19:59:01 +00:00
*/
MODULE_EXPORT void
debug_set_brightness(Driver *drvthis, int state, int promille)
{
PrivateData *p = drvthis->private_data;
/* Check it */
if (promille < 0 || promille > 1000)
return;
/* store the software value since there is not get */
if (state == BACKLIGHT_ON) {
p->brightness = promille;
}
else {
p->offbrightness = promille;
}
debug_backlight(drvthis, state);
}
/**
* Turn the backlight on or off.
* \param drvthis Pointer to driver structure.
* \param on New backlight status.
*/
MODULE_EXPORT void
debug_backlight (Driver *drvthis, int on)
{
//PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s(%i)", __FUNCTION__, on);
}
/**
* Handle input from keyboard.
* \param drvthis Pointer to driver structure.
2008-12-21 17:13:26 +00:00
* \return String representation of the key;
* \c NULL if nothing available / unmapped key
2008-12-19 19:59:01 +00:00
*/
MODULE_EXPORT const char *
2002-02-08 00:15:50 +00:00
debug_get_key (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2008-12-19 19:59:01 +00:00
//PrivateData *p = drvthis->private_data;
report(RPT_INFO, "%s()", __FUNCTION__);
2008-12-19 19:59:01 +00:00
2002-02-08 00:15:50 +00:00
return NULL;
1999-12-09 23:15:14 +00:00
}
2008-12-19 19:59:01 +00:00
/**
* Provide some information about this driver.
* \param drvthis Pointer to driver structure.
2008-12-21 17:13:26 +00:00
* \return Constant string with information.
2008-12-19 19:59:01 +00:00
*/
MODULE_EXPORT const char *
debug_get_info(Driver *drvthis)
{
//PrivateData *p = drvthis->private_data;
static char *info_string = "debug driver";
report(RPT_INFO, "%s()", __FUNCTION__);
return info_string;
}