aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile.am1
-rw-r--r--Makefile.in9
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure12
-rw-r--r--lcd4linux.conf.sample17
-rw-r--r--plugin.c14
-rw-r--r--plugin_uptime.c237
-rw-r--r--plugins.m48
8 files changed, 292 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am
index 84710b7..badf184 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -88,6 +88,7 @@ plugin_ppp.c \
plugin_proc_stat.c \
plugin_seti.c \
plugin_uname.c \
+plugin_uptime.c \
plugin_wireless.c \
plugin_xmms.c
diff --git a/Makefile.in b/Makefile.in
index f95b582..2a7bbfb 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -101,7 +101,7 @@ lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h deb
#liblcd4linux_la_SOURCES =
-EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h BeckmannEgle.c drv_Crystalfontz.c drv_Cwlinux.c drv_HD44780.c drv_M50530.c drv_T6963.c drv_USBLCD.c drv_MatrixOrbital.c MilfordInstruments.c PalmPilot.c Raster.c drv_X11.c Text.c font_6x8.h plugin_apm.c plugin_cpuinfo.c plugin_dvb.c plugin_exec.c plugin_i2c_sensors.c plugin_imon.c plugin_isdn.c plugin_loadavg.c plugin_meminfo.c plugin_mysql.c plugin_netdev.c plugin_pop3.c plugin_ppp.c plugin_proc_stat.c plugin_seti.c plugin_uname.c plugin_wireless.c plugin_xmms.c
+EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h BeckmannEgle.c drv_Crystalfontz.c drv_Cwlinux.c drv_HD44780.c drv_M50530.c drv_T6963.c drv_USBLCD.c drv_MatrixOrbital.c MilfordInstruments.c PalmPilot.c Raster.c drv_X11.c Text.c font_6x8.h plugin_apm.c plugin_cpuinfo.c plugin_dvb.c plugin_exec.c plugin_i2c_sensors.c plugin_imon.c plugin_isdn.c plugin_loadavg.c plugin_meminfo.c plugin_mysql.c plugin_netdev.c plugin_pop3.c plugin_ppp.c plugin_proc_stat.c plugin_seti.c plugin_uname.c plugin_uptime.c plugin_wireless.c plugin_xmms.c
EXTRA_DIST = lcd4linux.conf.sample lcd4kde.conf lcd4linux.kdelnk lcd4linux.xpm lcd4linux.lsm curses.m4 AUTHORS CREDITS FAQ NEWS TODO README README.Rows README.Tokens README.Drivers README.Plugins README.KDE plugin_sample.c
@@ -154,9 +154,10 @@ DEP_FILES = .deps/BeckmannEgle.P .deps/MilfordInstruments.P \
.deps/plugin_mysql.P .deps/plugin_netdev.P .deps/plugin_pop3.P \
.deps/plugin_ppp.P .deps/plugin_proc_stat.P .deps/plugin_seti.P \
.deps/plugin_string.P .deps/plugin_time.P .deps/plugin_uname.P \
-.deps/plugin_wireless.P .deps/plugin_xmms.P .deps/qprintf.P \
-.deps/thread.P .deps/timer.P .deps/udelay.P .deps/widget.P \
-.deps/widget_bar.P .deps/widget_icon.P .deps/widget_text.P
+.deps/plugin_uptime.P .deps/plugin_wireless.P .deps/plugin_xmms.P \
+.deps/qprintf.P .deps/thread.P .deps/timer.P .deps/udelay.P \
+.deps/widget.P .deps/widget_bar.P .deps/widget_icon.P \
+.deps/widget_text.P
SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES)
OBJECTS = $(lcd4linux_OBJECTS)
diff --git a/config.h.in b/config.h.in
index ab5b2b7..b1e163f 100644
--- a/config.h.in
+++ b/config.h.in
@@ -278,6 +278,9 @@
/* uname plugin */
#undef PLUGIN_UNAME
+/* uptime plugin */
+#undef PLUGIN_UPTIME
+
/* wireless plugin */
#undef PLUGIN_WIRELESS
diff --git a/configure b/configure
index 68d071c..ebf9082 100755
--- a/configure
+++ b/configure
@@ -5748,6 +5748,7 @@ echo "$as_me: error: run ./configure --with-plugins=..." >&2;}
PLUGIN_PROC_STAT="yes"
PLUGIN_SETI="yes"
PLUGIN_UNAME="yes"
+ PLUGIN_UPTIME="yes"
PLUGIN_WIRELESS="yes"
PLUGIN_XMMS="yes"
;;
@@ -5799,6 +5800,9 @@ echo "$as_me: error: run ./configure --with-plugins=..." >&2;}
uname)
PLUGIN_UNAME=$val
;;
+ uptime)
+ PLUGIN_UPTIME=$val
+ ;;
wireless)
PLUGIN_WIRELESS=$val
;;
@@ -6641,6 +6645,14 @@ cat >>confdefs.h <<\_ACEOF
_ACEOF
fi
+if test "$PLUGIN_UPTIME" = "yes"; then
+ PLUGINS="$PLUGINS plugin_uptime.o"
+
+cat >>confdefs.h <<\_ACEOF
+#define PLUGIN_UPTIME 1
+_ACEOF
+
+fi
if test "$PLUGIN_WIRELESS" = "yes"; then
PLUGINS="$PLUGINS plugin_wireless.o"
diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample
index 9367805..9f57059 100644
--- a/lcd4linux.conf.sample
+++ b/lcd4linux.conf.sample
@@ -247,6 +247,15 @@ Widget MySQLtest2 {
update minute
}
+Widget Uptime {
+ class 'Text'
+ expression uptime('%d days %H:%M:%S')
+ width 20
+ align 'R'
+ prefix 'Up '
+ update 1000
+}
+
Widget Heartbeat {
class 'Icon'
speed 800
@@ -457,17 +466,17 @@ Layout testMySQL {
#Display 'LK204'
-Display 'HD44780-20x4'
+#Display 'HD44780-20x4'
#Display 'M50530-24x8'
#Display 'CF631'
#Display 'CF632'
#Display 'CF633'
-#Display 'USBLCD'
+Display 'USBLCD'
#Display 'T6963-240x64'
#Display 'XWindow'
-#Layout 'Default'
-Layout 'L16x2'
+Layout 'Default'
+#ayout 'L16x2'
#Layout 'Test'
diff --git a/plugin.c b/plugin.c
index 5e2a58e..69a6212 100644
--- a/plugin.c
+++ b/plugin.c
@@ -1,4 +1,4 @@
-/* $Id: plugin.c,v 1.29 2004/05/20 07:47:51 reinelt Exp $
+/* $Id: plugin.c,v 1.30 2004/05/22 18:30:02 reinelt Exp $
*
* plugin handler for the Evaluator
*
@@ -22,6 +22,10 @@
*
*
* $Log: plugin.c,v $
+ * Revision 1.30 2004/05/22 18:30:02 reinelt
+ *
+ * added plugin 'uptime'
+ *
* Revision 1.29 2004/05/20 07:47:51 reinelt
* added plugin_time
*
@@ -209,6 +213,8 @@ int plugin_init_seti(void);
void plugin_exit_seti(void);
int plugin_init_uname (void);
void plugin_exit_uname (void);
+int plugin_init_uptime (void);
+void plugin_exit_uptime (void);
int plugin_init_wireless(void);
void plugin_exit_wireless(void);
int plugin_init_xmms (void);
@@ -270,6 +276,9 @@ int plugin_init (void)
#ifdef PLUGIN_UNAME
plugin_init_uname();
#endif
+#ifdef PLUGIN_UPTIME
+ plugin_init_uptime();
+#endif
#ifdef PLUGIN_WIRELESS
plugin_init_wireless();
#endif
@@ -330,6 +339,9 @@ void plugin_exit(void) {
#ifdef PLUGIN_UNAME
plugin_exit_uname();
#endif
+#ifdef PLUGIN_UPTIME
+ plugin_exit_uptime();
+#endif
#ifdef PLUGIN_WIRELESS
plugin_exit_wireless();
#endif
diff --git a/plugin_uptime.c b/plugin_uptime.c
new file mode 100644
index 0000000..1519ad1
--- /dev/null
+++ b/plugin_uptime.c
@@ -0,0 +1,237 @@
+/* $Id: plugin_uptime.c,v 1.1 2004/05/22 18:30:02 reinelt Exp $
+ *
+ * plugin for uptime
+ *
+ * Copyright 2003 Michael Reinelt <reinelt@eunet.at>
+ * Copyright 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
+ *
+ * This file is part of LCD4Linux.
+ *
+ * LCD4Linux 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, or (at your option)
+ * any later version.
+ *
+ * LCD4Linux 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: plugin_uptime.c,v $
+ * Revision 1.1 2004/05/22 18:30:02 reinelt
+ *
+ * added plugin 'uptime'
+ *
+ */
+
+/*
+ * exported functions:
+ *
+ * int plugin_init_uptime (void)
+ * adds functions for uptime
+ *
+ */
+
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <fcntl.h>
+
+#include "debug.h"
+#include "plugin.h"
+
+static int fd = -2;
+
+
+static char *itoa(char* buffer, size_t size, unsigned int value)
+{
+ char *p;
+
+ // sanity checks
+ if (buffer==NULL || size<2) return (NULL);
+
+ // p points to last char
+ p = buffer+size-1;
+
+ // set terminating zero
+ *p='\0';
+
+ do {
+ *--p = value%10 + '0';
+ value = value/10;
+ } while (value!=0 && p>buffer);
+
+ return p;
+}
+
+
+char *struptime (unsigned int uptime, char *format)
+{
+ static char string[256];
+ const char *src;
+ char *dst;
+ int len, size;
+
+ src = format;
+ dst = string;
+ len = 0;
+
+ // leave room for terminating zero
+ size = sizeof(string) - 1;
+
+ while (len < size) {
+
+ if (*src == '%') {
+ src++;
+
+ if (strchr ("sSmMhHd", *src) != NULL) {
+ char buffer[12], *s;
+ unsigned int value = 0;
+ int leading_zero = 0;
+ switch (*src++) {
+ case 's':
+ value = uptime;
+ break;
+ case 'S':
+ value = uptime % 60;
+ leading_zero = 1;
+ break;
+ case 'm':
+ value = uptime / 60;
+ break;
+ case 'M':
+ value = (uptime / 60) % 60;
+ leading_zero = 1;
+ break;
+ case 'h':
+ value = uptime / 60 / 60;
+ break;
+ case 'H':
+ value = (uptime / 60 / 60) % 24;
+ leading_zero = 1;
+ break;
+ case 'd':
+ value = uptime / 60 / 60 / 24;
+ break;
+ }
+
+ if (leading_zero && value < 10) {
+ len++;
+ *dst++ = '0';
+ }
+
+ s = itoa (buffer, sizeof(buffer), value);
+ while (len < size && *s != '\0') {
+ len++;
+ *dst++ = *s++;
+ }
+
+ } else if (*src == '%') {
+ len++;
+ *dst++ = '%';
+
+ } else {
+ len += 2;
+ *dst++ = '%';
+ *dst++ = *src++;
+ }
+
+ } else {
+ len++;
+ *dst++ = *src;
+ if (*src++ == '\0') break;
+ }
+ }
+
+ // enforce terminating zero
+ if (len >= size && *(dst-1) != '\0') {
+ len++;
+ *dst = '\0';
+ }
+
+ return string;
+}
+
+
+double getuptime (void)
+{
+ char buffer[36];
+ int i;
+
+ if (fd == -2) fd = open ("/proc/uptime", O_RDONLY);
+ if (fd < 0) return -1;
+
+ lseek(fd, 0, SEEK_SET);
+
+ i = read (fd, buffer, sizeof(buffer) - 1);
+ if (i < 0) return -1;
+
+ buffer[i-1] = '\0';
+
+ // ignore the 2nd value from /proc/uptime
+ return strtod(buffer, NULL);
+}
+
+
+static void my_uptime (RESULT *result, int argc, RESULT *argv[])
+{
+ int age;
+ static double uptime = 0.0;
+ static struct timeval last_value;
+ struct timeval now;
+
+ if (argc>1) {
+ error ("uptime(): wrong number of parameters");
+ SetResult(&result, R_STRING, "");
+ return;
+ }
+
+ gettimeofday(&now,NULL);
+
+ age = (now.tv_sec - last_value.tv_sec)*1000 + (now.tv_usec - last_value.tv_usec)/1000;
+ // reread every 100 msec only
+ if (fd == -2 || age == 0 || age > 100) {
+ uptime = getuptime();
+ if (uptime < 0.0) {
+ error ("parse(/proc/uptime) failed!");
+ SetResult(&result, R_STRING, "");
+ return;
+ }
+
+ last_value = now;
+ }
+
+ if (argc == 0) {
+ SetResult (&result, R_NUMBER, &uptime);
+ } else {
+ SetResult (&result, R_STRING, struptime(uptime, R2S(argv[0])));
+ }
+
+ return;
+
+}
+
+int plugin_init_uptime (void)
+{
+ AddFunction ("uptime", -1, my_uptime);
+ return 0;
+}
+
+void plugin_exit_uptime(void)
+{
+ if (fd > 0) close(fd);
+ fd = -2;
+}
diff --git a/plugins.m4 b/plugins.m4
index 4e97005..547fc57 100644
--- a/plugins.m4
+++ b/plugins.m4
@@ -46,6 +46,7 @@ for plugin in $plugins; do
PLUGIN_PROC_STAT="yes"
PLUGIN_SETI="yes"
PLUGIN_UNAME="yes"
+ PLUGIN_UPTIME="yes"
PLUGIN_WIRELESS="yes"
PLUGIN_XMMS="yes"
;;
@@ -97,6 +98,9 @@ for plugin in $plugins; do
uname)
PLUGIN_UNAME=$val
;;
+ uptime)
+ PLUGIN_UPTIME=$val
+ ;;
wireless)
PLUGIN_WIRELESS=$val
;;
@@ -199,6 +203,10 @@ if test "$PLUGIN_UNAME" = "yes"; then
PLUGINS="$PLUGINS plugin_uname.o"
AC_DEFINE(PLUGIN_UNAME,1,[uname plugin])
fi
+if test "$PLUGIN_UPTIME" = "yes"; then
+ PLUGINS="$PLUGINS plugin_uptime.o"
+ AC_DEFINE(PLUGIN_UPTIME,1,[uptime plugin])
+fi
if test "$PLUGIN_WIRELESS" = "yes"; then
PLUGINS="$PLUGINS plugin_wireless.o"
AC_DEFINE(PLUGIN_WIRELESS,1,[wireless plugin])