]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2004-05-22 18:30:01 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 22 May 2004 18:30:02 +0000 (18:30 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 22 May 2004 18:30:02 +0000 (18:30 +0000)
added plugin 'uptime'

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@427 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

Makefile.am
Makefile.in
config.h.in
configure
lcd4linux.conf.sample
plugin.c
plugin_uptime.c [new file with mode: 0644]
plugins.m4

index 84710b7fa990f4838624b696df448760f66b697e..badf1842f2ed6aa8e42902759295e18cb65b5d24 100644 (file)
@@ -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
 
index f95b5824b978c14ec184c1e77c9ab05db6e67727..2a7bbfba3a5967008aa297b8c4a6ae679e5dff26 100644 (file)
@@ -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)
 
index ab5b2b7d7f9107f1ac608d72060938f9057e3d5a..b1e163f74ea69c189b6f958cca6c84e58145ec11 100644 (file)
 /* uname plugin */
 #undef PLUGIN_UNAME
 
+/* uptime plugin */
+#undef PLUGIN_UPTIME
+
 /* wireless plugin */
 #undef PLUGIN_WIRELESS
 
index 68d071c91c39bf63742b498279a33eed69fb5fc6..ebf90826ac7a19cd20511f050d917b3a2460b019 100755 (executable)
--- 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
          ;;
@@ -6640,6 +6644,14 @@ cat >>confdefs.h <<\_ACEOF
 #define PLUGIN_UNAME 1
 _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"
index 936780582396ae54c868cc192ca687461a263509..9f570592f2f45231c2066334677caf52b274d103 100644 (file)
@@ -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'
 
 
index 5e2a58e3992eb3367cd148ea592749ce7d17ceec..69a6212b3070c3adda19f526fe27d7de6c9df761 100644 (file)
--- 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
  *
  *
  *
  * $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 (file)
index 0000000..1519ad1
--- /dev/null
@@ -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;
+}
index 4e970051128d2b750d7ed69c3f137b7dd89524fa..547fc5703afc6bd18021c0f1d1e6db0ac8b8b04c 100644 (file)
@@ -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])