curses: configfile support; CFontz: configfile parsing bugfix
This commit is contained in:
@@ -34,6 +34,7 @@ Harald Klein - Lirc driver, Metar Client
|
|||||||
|
|
||||||
Rene Wagner <reenoo@gmx.de> - LCDM001 driver, ASCII emulation
|
Rene Wagner <reenoo@gmx.de> - LCDM001 driver, ASCII emulation
|
||||||
of BigNum, CFontz driver update (configfile, reporting)
|
of BigNum, CFontz driver update (configfile, reporting)
|
||||||
|
curses driver update (configfile and reporting support)
|
||||||
|
|
||||||
|
|
||||||
Please let us know if your name is missing, or your credit
|
Please let us know if your name is missing, or your credit
|
||||||
|
|||||||
@@ -115,13 +115,21 @@ Reboot=no
|
|||||||
[curses]
|
[curses]
|
||||||
# Curses driver
|
# Curses driver
|
||||||
|
|
||||||
Arguments="-f blue -b cyan -B red -t 20x4"
|
# color settings
|
||||||
|
# foreground color [blue]
|
||||||
|
foreground=blue
|
||||||
|
# background color [cyan]
|
||||||
|
background=cyan
|
||||||
|
# backlight color [red]
|
||||||
|
backlight=red
|
||||||
|
|
||||||
# -f <color> Foreground color
|
# display size [20x4]
|
||||||
# -b <color> Background color
|
size=20x4
|
||||||
# -B Big numbers size?
|
|
||||||
# -t Display size
|
|
||||||
|
|
||||||
|
# What position (X,Y) to start the left top corner at...
|
||||||
|
# Default: (7,7)
|
||||||
|
topleftx=7
|
||||||
|
toplefty=7
|
||||||
|
|
||||||
|
|
||||||
[GLK]
|
[GLK]
|
||||||
|
|||||||
@@ -100,10 +100,10 @@ CFontz_init (lcd_logical_driver * driver, char *args)
|
|||||||
|| (w <= 0) || (w > LCD_MAX_WIDTH)
|
|| (w <= 0) || (w > LCD_MAX_WIDTH)
|
||||||
|| (h <= 0) || (h > LCD_MAX_HEIGHT)) {
|
|| (h <= 0) || (h > LCD_MAX_HEIGHT)) {
|
||||||
report (RPT_WARNING, "CFontz_init: Cannot read size: %s. Using default value.\n", size);
|
report (RPT_WARNING, "CFontz_init: Cannot read size: %s. Using default value.\n", size);
|
||||||
} else {
|
sscanf( DEFAULT_SIZE , "%dx%d", &w, &h );
|
||||||
driver->wid = w;
|
|
||||||
driver->hgt = h;
|
|
||||||
}
|
}
|
||||||
|
driver->wid = w;
|
||||||
|
driver->hgt = h;
|
||||||
|
|
||||||
/*Which contrast*/
|
/*Which contrast*/
|
||||||
if (0<=config_get_int ( DriverName , "Contrast" , 0 , DEFAULT_CONTRAST) && config_get_int ( DriverName , "Contrast" , 0 , DEFAULT_CONTRAST) <= 255) {
|
if (0<=config_get_int ( DriverName , "Contrast" , 0 , DEFAULT_CONTRAST) && config_get_int ( DriverName , "Contrast" , 0 , DEFAULT_CONTRAST) <= 255) {
|
||||||
|
|||||||
+72
-84
@@ -1,10 +1,24 @@
|
|||||||
/*
|
/* This is the LCDproc driver for ncurses.
|
||||||
* ncurses driver
|
It displays an emulated LCD display at top left of terminal screen
|
||||||
*
|
using ncurses.
|
||||||
* Display LCD display at top left of terminal screen
|
|
||||||
* using ncurses.
|
Copyright (C) ?????? ?????????
|
||||||
*
|
|
||||||
*/
|
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 */
|
||||||
|
|
||||||
|
/*Configfile support added by Rene Wagner (C) 2001*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Different implementations of (n)curses available on:
|
Different implementations of (n)curses available on:
|
||||||
@@ -52,7 +66,8 @@ SunOS (5.5.1):
|
|||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
#include "curses_drv.h"
|
#include "curses_drv.h"
|
||||||
//#include "drv_base.h"
|
#include "shared/report.h"
|
||||||
|
#include "configfile.h"
|
||||||
|
|
||||||
// ACS_S9 and ACS_S1 are defined as part of XSI Curses standard, Issue 4.
|
// ACS_S9 and ACS_S1 are defined as part of XSI Curses standard, Issue 4.
|
||||||
// However, ACS_S3 and ACS_S7 are not; these definitions were created to support
|
// However, ACS_S3 and ACS_S7 are not; these definitions were created to support
|
||||||
@@ -212,10 +227,7 @@ int current_color_pair, current_border_pair, curses_backlight_state = 0;
|
|||||||
int
|
int
|
||||||
curses_drv_init (struct lcd_logical_driver *driver, char *args)
|
curses_drv_init (struct lcd_logical_driver *driver, char *args)
|
||||||
{
|
{
|
||||||
char *argv[64];
|
char buf[256];
|
||||||
int argc;
|
|
||||||
int i;
|
|
||||||
char buf[64], *p;
|
|
||||||
|
|
||||||
// Colors....
|
// Colors....
|
||||||
chtype back_color = DEFAULT_BACKGROUND_COLOR,
|
chtype back_color = DEFAULT_BACKGROUND_COLOR,
|
||||||
@@ -223,86 +235,62 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
|
|||||||
backlight_color = DEFAULT_BACKGROUND_COLOR;
|
backlight_color = DEFAULT_BACKGROUND_COLOR;
|
||||||
|
|
||||||
// Screen position (top left)
|
// Screen position (top left)
|
||||||
int screen_begx = TOP_LEFT_X,
|
int screen_begx = CONF_DEF_TOP_LEFT_X,
|
||||||
screen_begy = TOP_LEFT_Y;
|
screen_begy = CONF_DEF_TOP_LEFT_Y;
|
||||||
|
|
||||||
curses_drv = driver;
|
curses_drv = driver;
|
||||||
|
|
||||||
memset(&argv, '\0', sizeof(argv));
|
// TODO: replace DriverName with driver->name when that field exists.
|
||||||
argc = get_args (argv, args, 64);
|
#define DriverName "curses"
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
/*Get settings from config file*/
|
||||||
p = argv[i];
|
|
||||||
if (*p == '-') {
|
|
||||||
p++;
|
|
||||||
switch (*p) {
|
|
||||||
case 'f':
|
|
||||||
if (i + 1 >= argc) {
|
|
||||||
fprintf (stderr, "curses_init: %s requires an argument\n", argv[i]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
strncpy(buf, argv[++i], sizeof(buf));
|
|
||||||
fore_color = set_foreground_color(buf);
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
if (i + 1 >= argc) {
|
|
||||||
fprintf (stderr, "curses_init: %s requires an argument\n", argv[i]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
strncpy(buf, argv[++i], sizeof(buf));
|
|
||||||
back_color = set_background_color(buf);
|
|
||||||
break;
|
|
||||||
case 'B':
|
|
||||||
if (i + 1 >= argc) {
|
|
||||||
fprintf (stderr, "curses_init: %s requires an argument\n", argv[i]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
strncpy(buf, argv[++i], sizeof(buf));
|
|
||||||
backlight_color = set_background_color(buf);
|
|
||||||
break;
|
|
||||||
case 'h':
|
|
||||||
printf ("LCDproc [n]curses driver\n"
|
|
||||||
"\t-f\tChange the foreground color\n"
|
|
||||||
"\t-b\tChange the background color\n"
|
|
||||||
"\t-t\tChange the type of screen (20x2, etc.)\n"
|
|
||||||
// "\t-b\t--backcolor\tChange the backlight's \"off\" color\n"
|
|
||||||
// "\t-B\t--backlight\tChange the backlight's \"on\" color\n"
|
|
||||||
"\t-h\t--help\t\tShow this help information\n");
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
if (i + 1 > argc) {
|
|
||||||
fprintf (stderr, "curses_init: %s requires an argument\n", argv[i]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
p = argv[i];
|
|
||||||
|
|
||||||
if (isdigit((unsigned int) *p) && isdigit((unsigned int) *(p+1))) {
|
/*Get color settings*/
|
||||||
int wid, hgt;
|
/*foreground color*/
|
||||||
|
strncpy(buf, config_get_string ( DriverName , "foreground" , 0 , CONF_DEF_FOREGR),200);
|
||||||
|
if (strlen(buf)>199) strncat(buf, "\0", 1);
|
||||||
|
fore_color = set_foreground_color(buf);
|
||||||
|
debug( RPT_DEBUG, "CURSES: using foreground color: %s", buf);
|
||||||
|
/*background color*/
|
||||||
|
strncpy(buf, config_get_string ( DriverName , "background" , 0 , CONF_DEF_BACKGR),200);
|
||||||
|
if (strlen(buf)>199) strncat(buf, "\0", 1);
|
||||||
|
back_color = set_background_color(buf);
|
||||||
|
debug( RPT_DEBUG, "CURSES: using background color: %s", buf);
|
||||||
|
/*backlight color*/
|
||||||
|
strncpy(buf, config_get_string ( DriverName , "backlight" , 0 , CONF_DEF_BACKLIGHT),200);
|
||||||
|
if (strlen(buf)>199) strncat(buf, "\0", 1);
|
||||||
|
backlight_color = set_background_color(buf);
|
||||||
|
debug( RPT_DEBUG, "CURSES: using backlight color: %s", buf);
|
||||||
|
|
||||||
wid = ((*p - '0') * 10) + (*(p+1) - '0');
|
//TODO: Make it possible to configure the backlight's "off" color and its "on" color
|
||||||
p += 2;
|
// Or maybe don't do so? - Rene Wagner
|
||||||
|
|
||||||
if (*p != 'x')
|
/*Get size settings*/
|
||||||
break;
|
strncpy(buf, config_get_string ( DriverName , "size" , 0 , CONF_DEF_SIZE),200);
|
||||||
|
if (strlen(buf)>199) strncat(buf, "\0", 1);
|
||||||
p++;
|
int wid, hgt;
|
||||||
if (!isdigit((unsigned int) *p))
|
if( sscanf(buf , "%dx%d", &wid, &hgt ) != 2
|
||||||
break;
|
|| (wid <= 0)
|
||||||
|
|| (hgt <= 0)) {
|
||||||
hgt = (*p - '0');
|
report (RPT_WARNING, "CURSES: Cannot read size: %s. Using default value.\n", buf);
|
||||||
|
sscanf( CONF_DEF_SIZE , "%dx%d", &wid, &hgt );
|
||||||
curses_drv->wid = wid;
|
|
||||||
curses_drv->hgt = hgt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
driver->wid = wid;
|
||||||
|
driver->hgt = hgt;
|
||||||
|
|
||||||
|
/*Get position settings*/
|
||||||
|
if (0<=config_get_int ( DriverName , "topleftx" , 0 , CONF_DEF_TOP_LEFT_X) && config_get_int ( DriverName , "topleftx" , 0 , CONF_DEF_TOP_LEFT_X) <= 255) {
|
||||||
|
screen_begx = config_get_int ( DriverName , "topleftx" , 0 , CONF_DEF_TOP_LEFT_X);
|
||||||
|
} else {
|
||||||
|
report (RPT_WARNING, "CURSES: topleftx must between 0 and 255. Using default value %d.\n",CONF_DEF_TOP_LEFT_X);
|
||||||
|
}
|
||||||
|
if (0<=config_get_int ( DriverName , "toplefty" , 0 , CONF_DEF_TOP_LEFT_Y) && config_get_int ( DriverName , "toplefty" , 0 , CONF_DEF_TOP_LEFT_Y) <= 255) {
|
||||||
|
screen_begy = config_get_int ( DriverName , "toplefty" , 0 , CONF_DEF_TOP_LEFT_Y);
|
||||||
|
} else {
|
||||||
|
report (RPT_WARNING, "CURSES: toplefty must between 0 and 255. Using default value %d.\n",CONF_DEF_TOP_LEFT_Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug: sleep(1);
|
||||||
|
|
||||||
// Init curses...
|
// Init curses...
|
||||||
initscr ();
|
initscr ();
|
||||||
|
|||||||
@@ -21,4 +21,12 @@ void curses_drv_init_num ();
|
|||||||
void curses_drv_num (int x, int num);
|
void curses_drv_num (int x, int num);
|
||||||
void curses_drv_heartbeat (int type);
|
void curses_drv_heartbeat (int type);
|
||||||
|
|
||||||
|
/*Default settings for config file parsing*/
|
||||||
|
#define CONF_DEF_FOREGR "blue"
|
||||||
|
#define CONF_DEF_BACKGR "cyan"
|
||||||
|
#define CONF_DEF_BACKLIGHT "red"
|
||||||
|
#define CONF_DEF_SIZE "20x4"
|
||||||
|
#define CONF_DEF_TOP_LEFT_X 7
|
||||||
|
#define CONF_DEF_TOP_LEFT_Y 7
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user