aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-01-15 07:47:03 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-01-15 07:47:03 +0000
commit8bd25913d494772e695311c5745bbcc8a5a57e77 (patch)
treef68e6fa36a66eb421d67154ef105b28971e483c3
parent89e4f42deb9e5c5bdc712613d85629d4398e19b7 (diff)
downloadlcd4linux-8bd25913d494772e695311c5745bbcc8a5a57e77.tar.gz
[lcd4linux @ 2004-01-15 07:47:02 by reinelt]
debian/ postinst and watch added (did CVS forget about them?) evaluator: conditional expressions (a?b:c) added text widget nearly finished git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@313 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--debian/postinst5
-rw-r--r--debian/watch2
-rw-r--r--drv_MatrixOrbital.c18
-rw-r--r--evaluator.c112
-rw-r--r--lcd4linux.conf.sample43
-rw-r--r--widget_text.c117
-rw-r--r--widget_text.h13
7 files changed, 210 insertions, 100 deletions
diff --git a/debian/postinst b/debian/postinst
new file mode 100644
index 0000000..284d07d
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,5 @@
+#!/bin/sh -e
+
+. /usr/share/debconf/confmodule
+
+#DEBHELPER#
diff --git a/debian/watch b/debian/watch
new file mode 100644
index 0000000..932ab07
--- /dev/null
+++ b/debian/watch
@@ -0,0 +1,2 @@
+version=2
+http://prdownloads.sourceforge.net/lcd4linux/lcd4linux-(.*[0-9])\.tgz debian uupdate
diff --git a/drv_MatrixOrbital.c b/drv_MatrixOrbital.c
index 2fdf1ef..43b7dd7 100644
--- a/drv_MatrixOrbital.c
+++ b/drv_MatrixOrbital.c
@@ -1,4 +1,4 @@
-/* $Id: drv_MatrixOrbital.c,v 1.7 2004/01/14 11:33:00 reinelt Exp $
+/* $Id: drv_MatrixOrbital.c,v 1.8 2004/01/15 07:47:02 reinelt Exp $
*
* new style driver for Matrix Orbital serial display modules
*
@@ -23,6 +23,11 @@
*
*
* $Log: drv_MatrixOrbital.c,v $
+ * Revision 1.8 2004/01/15 07:47:02 reinelt
+ * debian/ postinst and watch added (did CVS forget about them?)
+ * evaluator: conditional expressions (a?b:c) added
+ * text widget nearly finished
+ *
* Revision 1.7 2004/01/14 11:33:00 reinelt
* new plugin 'uname' which does what it's called
* text widget nearly finished
@@ -443,12 +448,15 @@ static int drv_MO_start (char *section)
bar_add_segment( 0, 0,255, 32); // ASCII 32 = blank
bar_add_segment(255,255,255,255); // ASCII 255 = block
-
- // Fixme: get rid of this function
- // drv_MO_clear(1);
+
// Fixme: where to init contrast?
- drv_MO_contrast(160);
+ drv_MO_contrast(128);
+ if (PROTOCOL==2)
+ drv_MO_write ("\376\130", 2); // Clear Screen
+ else
+ drv_MO_write ("\014", 1); // Clear Screen
+
drv_MO_write ("\376B", 3); // backlight on
drv_MO_write ("\376K", 2); // cursor off
drv_MO_write ("\376T", 2); // blink off
diff --git a/evaluator.c b/evaluator.c
index ce0623d..ebede11 100644
--- a/evaluator.c
+++ b/evaluator.c
@@ -1,4 +1,4 @@
-/* $Id: evaluator.c,v 1.8 2004/01/12 03:51:01 reinelt Exp $
+/* $Id: evaluator.c,v 1.9 2004/01/15 07:47:02 reinelt Exp $
*
* expression evaluation
*
@@ -10,6 +10,11 @@
* FIXME: GPL or not GPL????
*
* $Log: evaluator.c,v $
+ * Revision 1.9 2004/01/15 07:47:02 reinelt
+ * debian/ postinst and watch added (did CVS forget about them?)
+ * evaluator: conditional expressions (a?b:c) added
+ * text widget nearly finished
+ *
* Revision 1.8 2004/01/12 03:51:01 reinelt
* evaluating the 'Variables' section in the config file
*
@@ -133,7 +138,7 @@
#define is_blank(c) (c==' ' || c=='\t')
#define is_number(c) (isdigit(c) || c=='.')
#define is_name(c) (isalnum(c) || c=='_')
-#define is_delim(c) (strchr("+-*/%^().,;=<>!&|", c)!=NULL)
+#define is_delim(c) (strchr("+-*/%^().,;:=<>?!&|", c)!=NULL)
typedef struct {
@@ -469,6 +474,7 @@ static void Level08 (RESULT *result);
static void Level09 (RESULT *result);
static void Level10 (RESULT *result);
static void Level11 (RESULT *result);
+static void Level12 (RESULT *result);
@@ -534,9 +540,9 @@ static void Parse (void)
static void Level01 (RESULT *result)
{
do {
- while (*Token==';') Parse();
+ while (Type==T_DELIMITER && *Token==';') Parse();
Level02(result);
- } while (*Token==';');
+ } while (Type==T_DELIMITER && *Token==';');
}
@@ -550,7 +556,7 @@ static void Level02 (RESULT *result)
name=strdup(Token);
Parse();
Parse();
- if (*Token && *Token!=';') {
+ if (*Token && (Type!=T_DELIMITER || *Token!=';')) {
Level03(result);
SetVariable(name, result);
} else {
@@ -564,17 +570,47 @@ static void Level02 (RESULT *result)
}
-// logical 'or'
+// conditional expression a?b:c
static void Level03 (RESULT *result)
{
- RESULT operand;
- double value;
+ RESULT r_then = {0, 0.0, NULL};
+ RESULT r_else = {0, 0.0, NULL};
Level04(result);
- while(*Token=='|') {
+ while(Type==T_DELIMITER && *Token=='?') {
Parse();
- Level04 (&operand);
+ Level01 (&r_then);
+ if (Type==T_DELIMITER && *Token==':') {
+ Parse();
+ Level01 (&r_else);
+ } else {
+ ERROR(E_SYNTAX);
+ }
+ if (R2N(result)!=0.0) {
+ DelResult(result);
+ DelResult(&r_else);
+ *result=r_then;
+ } else {
+ DelResult(result);
+ DelResult(&r_then);
+ *result=r_else;
+ }
+ }
+}
+
+
+// logical 'or'
+static void Level04 (RESULT *result)
+{
+ RESULT operand = {0, 0.0, NULL};
+ double value;
+
+ Level05(result);
+
+ while(Type==T_DELIMITER && *Token=='|') {
+ Parse();
+ Level05 (&operand);
value = (R2N(result)!=0.0) || (R2N(&operand)!=0.0);
SetResult(&result, R_NUMBER, &value);
}
@@ -582,16 +618,16 @@ static void Level03 (RESULT *result)
// logical 'and'
-static void Level04 (RESULT *result)
+static void Level05 (RESULT *result)
{
RESULT operand;
double value;
- Level05(result);
+ Level06(result);
- while(*Token=='&') {
+ while(Type==T_DELIMITER && *Token=='&') {
Parse();
- Level05 (&operand);
+ Level06 (&operand);
value = (R2N(result)!=0.0) && (R2N(&operand)!=0.0);
SetResult(&result, R_NUMBER, &value);
}
@@ -599,17 +635,17 @@ static void Level04 (RESULT *result)
// equal, not equal
-static void Level05 (RESULT *result)
+static void Level06 (RESULT *result)
{
char operator;
RESULT operand = {0, 0.0, NULL};
double value;
- Level06 (result);
+ Level07 (result);
- if (((operator=Token[0])=='=' || operator=='!') && Token[1]=='=') {
+ if (Type==T_DELIMITER && ((operator=Token[0])=='=' || operator=='!') && Token[1]=='=') {
Parse();
- Level06 (&operand);
+ Level07 (&operand);
if (operator=='=')
value = (R2N(result) == R2N(&operand));
else
@@ -620,19 +656,19 @@ static void Level05 (RESULT *result)
// relational operators
-static void Level06 (RESULT *result)
+static void Level07 (RESULT *result)
{
char operator[2];
RESULT operand = {0, 0.0, NULL};
double value;
- Level07 (result);
+ Level08 (result);
- if (*Token=='<' || *Token=='>') {
+ if (Type==T_DELIMITER && (*Token=='<' || *Token=='>')) {
operator[0]=Token[0];
operator[1]=Token[1];
Parse();
- Level07 (&operand);
+ Level08 (&operand);
if (operator[0]=='<')
if (operator[1]=='=')
value = (R2N(result) <= R2N(&operand));
@@ -649,17 +685,17 @@ static void Level06 (RESULT *result)
// addition, subtraction, concatenation
-static void Level07 (RESULT *result)
+static void Level08 (RESULT *result)
{
char operator;
RESULT operand = {0, 0.0, NULL};
double value;
- Level08(result);
+ Level09(result);
- while((operator=*Token)=='+' || operator=='-' || operator=='.') {
+ while(Type==T_DELIMITER && ((operator=*Token)=='+' || operator=='-' || operator=='.')) {
Parse();
- Level08 (&operand);
+ Level09 (&operand);
if (operator=='+') {
value = (R2N(result) + R2N(&operand));
SetResult(&result, R_NUMBER, &value);
@@ -680,17 +716,17 @@ static void Level07 (RESULT *result)
// multiplication, division, modulo
-static void Level08 (RESULT *result)
+static void Level09 (RESULT *result)
{
char operator;
RESULT operand = {0, 0.0, NULL};
double value;
- Level09 (result);
+ Level10 (result);
- while((operator=*Token)=='*' || operator=='/' || operator=='%') {
+ while(Type==T_DELIMITER && ((operator=*Token)=='*' || operator=='/' || operator=='%')) {
Parse();
- Level09(&operand);
+ Level10(&operand);
if (operator == '*') {
value = (R2N(result) * R2N(&operand));
} else if (operator == '/') {
@@ -706,16 +742,16 @@ static void Level08 (RESULT *result)
// x^y
-static void Level09 (RESULT *result)
+static void Level10 (RESULT *result)
{
RESULT exponent = {0, 0.0, NULL};
double value;
- Level10 (result);
+ Level11 (result);
- if (*Token == '^') {
+ if (Type==T_DELIMITER && *Token == '^') {
Parse();
- Level10 (&exponent);
+ Level11 (&exponent);
value = pow(R2N(result), R2N(&exponent));
SetResult(&result, R_NUMBER, &value);
}
@@ -723,17 +759,17 @@ static void Level09 (RESULT *result)
// unary + or - signs or logical 'not'
-static void Level10 (RESULT *result)
+static void Level11 (RESULT *result)
{
char sign=0;
double value;
- if (*Token=='+' || *Token=='-' || *Token=='!') {
+ if (Type==T_DELIMITER && (*Token=='+' || *Token=='-' || *Token=='!')) {
sign=*Token;
Parse();
}
- Level11 (result);
+ Level12 (result);
if (sign == '-') {
value = -R2N(result);
@@ -747,7 +783,7 @@ static void Level10 (RESULT *result)
// literal numbers, variables, functions
-static void Level11 (RESULT *result)
+static void Level12 (RESULT *result)
{
RESULT *param[10];
diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample
index 780876e..fdd34d3 100644
--- a/lcd4linux.conf.sample
+++ b/lcd4linux.conf.sample
@@ -2,7 +2,7 @@ Display LK204 {
Driver 'MatrixOrbital'
Model 'LK204-24-USB'
Port '/dev/usb/tts/0'
- Port '/dev/tts/0'
+# Port '/dev/tts/0'
Speed 19200
Contrast 256/2
}
@@ -18,8 +18,8 @@ Widget OS {
Widget CPU {
class 'Text'
expression uname('machine')
- postfix ' CPU'
- width 10
+ prefix 'CPU '
+ width 9
align 'L'
update tick
}
@@ -29,30 +29,21 @@ Widget RAM {
class 'Text'
expression meminfo('MemTotal')/1024
postfix ' MB RAM'
- width 5
+ width 11
precision 0
align 'R'
update tick
}
-Widget Disk {
- class 'text'
- expression Pi
- width 10
- precision 2
- align 'R'
- update tick
-}
-
-
-Widget LAN {
- class 'text'
- expression "12.12345678"
+Widget Load {
+ class 'Text'
+ expression loadavg(1)
+ prefix 'Load'
+ postfix loadavg(1)>1.0?'!':' '
width 10
precision 2
- align 'M'
- update tick
- speed tack
+ align 'R'
+ update tack
}
@@ -60,15 +51,25 @@ Layout Default {
Row1 {
Col1 'OS'
}
- Row02 {
+ Row2 {
Col1 'CPU'
Col10 'RAM'
}
+ Row3 {
+ }
+ Row4 {
+ Col1 'Load'
+ }
}
+
Display 'LK204'
Layout 'Default'
+#Row1 "*** %o %v ***"
+#Row2 "%p CPU %r MB RAM"
+#Row3 "Busy %cb%% $r10cs+cb"
+#Row4 "Load%l1%L$r10l1"
Variables {
tick 500
diff --git a/widget_text.c b/widget_text.c
index 5f91c5d..9d99b2c 100644
--- a/widget_text.c
+++ b/widget_text.c
@@ -1,4 +1,4 @@
-/* $Id: widget_text.c,v 1.5 2004/01/15 04:29:45 reinelt Exp $
+/* $Id: widget_text.c,v 1.6 2004/01/15 07:47:02 reinelt Exp $
*
* simple text widget handling
*
@@ -21,6 +21,11 @@
*
*
* $Log: widget_text.c,v $
+ * Revision 1.6 2004/01/15 07:47:02 reinelt
+ * debian/ postinst and watch added (did CVS forget about them?)
+ * evaluator: conditional expressions (a?b:c) added
+ * text widget nearly finished
+ *
* Revision 1.5 2004/01/15 04:29:45 reinelt
* moved lcd4linux.conf.sample to *.old
* lcd4linux.conf.sample with new layout
@@ -75,43 +80,55 @@ void widget_text_scroll (void *Self)
WIDGET *W = (WIDGET*)Self;
WIDGET_TEXT *T = W->data;
- int num, len, pad;
+ int num, len, width, pad;
char *src, *dst;
- src=T->value;
- dst=T->buffer;
- num=0;
- len=strlen(T->value);
-
+ num = 0;
+ len = strlen(T->value);
+ width = T->width-strlen(T->preval)-strlen(T->postval);
+ if (width<0) width=0;
+
switch (T->align) {
case ALIGN_LEFT:
pad=0;
break;
case ALIGN_CENTER:
- pad=(T->width - len)/2;
+ pad=(width - len)/2;
if (pad<0) pad=0;
break;
case ALIGN_RIGHT:
- pad=T->width - len;
+ pad=width - len;
if (pad<0) pad=0;
break;
case ALIGN_MARQUEE:
- pad=T->width - T->scroll;
+ pad=width - T->scroll;
T->scroll++;
- if (T->scroll >= T->width+len) T->scroll=0;
+ if (T->scroll >= width+len) T->scroll=0;
break;
default: // not reached
pad=0;
}
+ dst=T->buffer;
+
+ // process prefix
+ src=T->preval;
+ while (num < T->width) {
+ if (*src=='\0') break;
+ *(dst++)=*(src++);
+ num++;
+ }
+
+ src=T->value;
+
// pad blanks on the beginning
- while (pad>0) {
+ while (pad > 0 && num < T->width) {
*(dst++)=' ';
num++;
pad--;
}
- // overread src (marquee)
+ // skip src chars (marquee)
while (pad<0) {
src++;
pad++;
@@ -125,42 +142,52 @@ void widget_text_scroll (void *Self)
}
// pad blanks on the end
- while (num < T->width) {
+ src=T->postval;
+ len=strlen(src);
+ while (num < T->width-len) {
*(dst++)=' ';
num++;
}
+
+ // process postfix
+ while (num < T->width) {
+ if (*src=='\0') break;
+ *(dst++)=*(src++);
+ num++;
+ }
+
*dst='\0';
// finally, draw it!
if (W->class->draw)
W->class->draw(W);
}
-
+
void widget_text_update (void *Self)
{
WIDGET *W = (WIDGET*)Self;
WIDGET_TEXT *T = W->data;
RESULT result = {0, 0.0, NULL};
- char *prefix, *postfix, *value;
+ char *preval, *postval, *value;
+ int update;
// evaluate prefix
if (T->prefix!=NULL && strlen(T->prefix)>0) {
Eval(T->prefix, &result);
- prefix=strdup(R2S(&result));
+ preval=strdup(R2S(&result));
DelResult (&result);
} else {
- prefix=strdup("");
+ preval=strdup("");
}
// evaluate postfix
if (T->postfix!=NULL && *(T->postfix)!='\0') {
- debug ("Eval_postfix(%s)", T->postfix);
Eval(T->postfix, &result);
- postfix=strdup(R2S(&result));
+ postval=strdup(R2S(&result));
DelResult (&result);
} else {
- postfix=strdup("");
+ postval=strdup("");
}
// evaluate expression
@@ -171,7 +198,8 @@ void widget_text_update (void *Self)
value=strdup(R2S(&result));
} else {
double number=R2N(&result);
- int width=T->width;
+ int width=T->width-strlen(preval)-strlen(postval);
+ if (width<0) width=0;
int precision=T->precision;
// print zero bytes so we can specify NULL as target
// and get the length of the resulting string
@@ -187,7 +215,6 @@ void widget_text_update (void *Self)
}
// number still doesn't fit: display '*****'
if (size>width) {
- debug ("overflow");
value=malloc(width+1);
memset (value, '*', width);
*(value+width)='\0';
@@ -196,25 +223,49 @@ void widget_text_update (void *Self)
snprintf (value, size+1, "%.*f", precision, number);
}
}
-
+
DelResult (&result);
- // has value changed?
+ update=0;
+
+ // prefix changed?
+ if (T->preval == NULL || strcmp(T->preval, preval)!=0) {
+ update=1;
+ if (T->preval) free (T->preval);
+ T->preval=preval;
+ T->scroll=0; // reset marquee counter
+ } else {
+ free (preval);
+ }
+
+ // postfix changed?
+ if (T->postval == NULL || strcmp(T->postval, postval)!=0) {
+ update=1;
+ if (T->postval) free (T->postval);
+ T->postval=postval;
+ T->scroll=0; // reset marquee counter
+ } else {
+ free (postval);
+ }
+
+ // value changed?
if (T->value == NULL || strcmp(T->value, value)!=0) {
- // free old value
+ update=1;
if (T->value) free (T->value);
T->value=value;
- // reset marquee counter
- T->scroll=0;
+ T->scroll=0; // reset marquee counter
+ } else {
+ free (value);
+ }
+
+ // something has changed and should be updated
+ if (update) {
// if there's a marquee scroller active, it has its own
// update callback timer, so we do nothing here; otherwise
// we simply call this scroll callback directly
if (T->align!=ALIGN_MARQUEE) {
widget_text_scroll (Self);
}
- } else {
- // value is the same, so free our buffer
- free (value);
}
}
@@ -235,8 +286,8 @@ int widget_text_init (WIDGET *Self)
memset (T, 0, sizeof(WIDGET_TEXT));
// get raw pre- and postfix (we evaluate it ourselves)
- T->prefix = cfg_get_raw (section, "prefix", NULL);
- T->postfix = cfg_get_raw (section, "prefix", NULL);
+ T->prefix = cfg_get_raw (section, "prefix", NULL);
+ T->postfix = cfg_get_raw (section, "postfix", NULL);
// get raw expression (we evaluate it ourselves)
T->expression = cfg_get_raw (section, "expression", "''");
diff --git a/widget_text.h b/widget_text.h
index 7d678e8..d3e20c5 100644
--- a/widget_text.h
+++ b/widget_text.h
@@ -1,4 +1,4 @@
-/* $Id: widget_text.h,v 1.1 2004/01/15 04:29:45 reinelt Exp $
+/* $Id: widget_text.h,v 1.2 2004/01/15 07:47:03 reinelt Exp $
*
* simple text widget handling
*
@@ -23,6 +23,11 @@
*
*
* $Log: widget_text.h,v $
+ * Revision 1.2 2004/01/15 07:47:03 reinelt
+ * debian/ postinst and watch added (did CVS forget about them?)
+ * evaluator: conditional expressions (a?b:c) added
+ * text widget nearly finished
+ *
* Revision 1.1 2004/01/15 04:29:45 reinelt
* moved lcd4linux.conf.sample to *.old
* lcd4linux.conf.sample with new layout
@@ -38,8 +43,10 @@
typedef enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_MARQUEE } ALIGN;
typedef struct WIDGET_TEXT {
- char *prefix; // label on the left side
- char *postfix; // label on the right side
+ char *prefix; // expression for label on the left side
+ char *preval; // value for label on the left side
+ char *postfix; // expression for label on the right side
+ char *postval; // value for label on the right side
char *expression; // expression that delivers the value
char *value; // evaluated value from expression
char *buffer; // string with 'width+1' bytes allocated