aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--Makefile.in17
-rw-r--r--plugin.c10
-rw-r--r--plugin_i2c_sensors.c189
4 files changed, 207 insertions, 10 deletions
diff --git a/Makefile.am b/Makefile.am
index b93c710..c7877b5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,6 +22,7 @@ plugin.c plugin.h \
plugin_math.c \
plugin_string.c \
plugin_xmms.c \
+plugin_i2c_sensors.c \
system.c system.h \
isdn.c isdn.h \
wifi.c wifi.h \
diff --git a/Makefile.in b/Makefile.in
index d899b1c..1c9ce36 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -101,7 +101,7 @@ AM_CFLAGS = $(X_CFLAGS) -D_GNU_SOURCE -Wall
lcd4linux_LDFLAGS = $(X_LIBS)
lcd4linux_LDADD = liblcd4linux.la @DRVLIBS@
-lcd4linux_SOURCES = lcd4linux.c pid.c pid.h parser.c parser.h processor.c processor.h evaluator.c evaluator.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_xmms.c system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h widget.c widget.h exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h
+lcd4linux_SOURCES = lcd4linux.c pid.c pid.h parser.c parser.h processor.c processor.h evaluator.c evaluator.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_xmms.c plugin_i2c_sensors.c system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h widget.c widget.h exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h
liblcd4linux_la_DEPENDENCIES = @DRIVERS@
@@ -139,10 +139,10 @@ PROGRAMS = $(bin_PROGRAMS)
lcd4linux_OBJECTS = lcd4linux.$(OBJEXT) pid.$(OBJEXT) parser.$(OBJEXT) \
processor.$(OBJEXT) evaluator.$(OBJEXT) plugin.$(OBJEXT) \
plugin_math.$(OBJEXT) plugin_string.$(OBJEXT) plugin_xmms.$(OBJEXT) \
-system.$(OBJEXT) isdn.$(OBJEXT) wifi.$(OBJEXT) mail.$(OBJEXT) \
-seti.$(OBJEXT) battery.$(OBJEXT) dvb.$(OBJEXT) filter.$(OBJEXT) \
-widget.$(OBJEXT) exec.$(OBJEXT) expr.$(OBJEXT) mail2.$(OBJEXT) \
-socket.$(OBJEXT) imon.$(OBJEXT)
+plugin_i2c_sensors.$(OBJEXT) system.$(OBJEXT) isdn.$(OBJEXT) \
+wifi.$(OBJEXT) mail.$(OBJEXT) seti.$(OBJEXT) battery.$(OBJEXT) \
+dvb.$(OBJEXT) filter.$(OBJEXT) widget.$(OBJEXT) exec.$(OBJEXT) \
+expr.$(OBJEXT) mail2.$(OBJEXT) socket.$(OBJEXT) imon.$(OBJEXT)
lcd4linux_DEPENDENCIES = liblcd4linux.la
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -168,9 +168,10 @@ DEP_FILES = .deps/BeckmannEgle.P .deps/Crystalfontz.P .deps/Cwlinux.P \
.deps/expr.P .deps/filter.P .deps/fontmap.P .deps/icon.P .deps/imon.P \
.deps/isdn.P .deps/lcd4linux.P .deps/lock.P .deps/mail.P .deps/mail2.P \
.deps/parport.P .deps/parser.P .deps/pid.P .deps/pixmap.P \
-.deps/plugin.P .deps/plugin_math.P .deps/plugin_string.P \
-.deps/plugin_xmms.P .deps/processor.P .deps/seti.P .deps/socket.P \
-.deps/system.P .deps/udelay.P .deps/widget.P .deps/wifi.P
+.deps/plugin.P .deps/plugin_i2c_sensors.P .deps/plugin_math.P \
+.deps/plugin_string.P .deps/plugin_xmms.P .deps/processor.P \
+.deps/seti.P .deps/socket.P .deps/system.P .deps/udelay.P \
+.deps/widget.P .deps/wifi.P
SOURCES = $(liblcd4linux_la_SOURCES) $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES)
OBJECTS = $(liblcd4linux_la_OBJECTS) $(lcd4linux_OBJECTS)
diff --git a/plugin.c b/plugin.c
index 3872a5c..0729a02 100644
--- a/plugin.c
+++ b/plugin.c
@@ -1,4 +1,4 @@
-/* $Id: plugin.c,v 1.5 2004/01/06 17:33:45 reinelt Exp $
+/* $Id: plugin.c,v 1.6 2004/01/10 17:36:56 reinelt Exp $
*
* plugin handler for the Evaluator
*
@@ -22,6 +22,10 @@
*
*
* $Log: plugin.c,v $
+ * Revision 1.6 2004/01/10 17:36:56 reinelt
+ *
+ * I2C Sensors plugin from Xavier added
+ *
* Revision 1.5 2004/01/06 17:33:45 reinelt
*
* Evaluator: functions with variable argument lists
@@ -79,6 +83,7 @@
int plugin_init_math (void);
int plugin_init_string (void);
int plugin_init_xmms (void);
+int plugin_init_i2c_sensors (void);
int plugin_init (void)
@@ -86,7 +91,8 @@ int plugin_init (void)
plugin_init_math();
plugin_init_string();
plugin_init_xmms();
-
+ plugin_init_i2c_sensors;
+
return 0;
}
diff --git a/plugin_i2c_sensors.c b/plugin_i2c_sensors.c
new file mode 100644
index 0000000..f6bd574
--- /dev/null
+++ b/plugin_i2c_sensors.c
@@ -0,0 +1,189 @@
+/* $Id: plugin_i2c_sensors.c,v 1.1 2004/01/10 17:36:56 reinelt Exp $
+ *
+ * I2C sensors plugin
+ *
+ * Copyright 2003,2004 Xavier Vello <xavier66@free.fr>
+ *
+ * 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_i2c_sensors.c,v $
+ * Revision 1.1 2004/01/10 17:36:56 reinelt
+ *
+ * I2C Sensors plugin from Xavier added
+ *
+ *
+ */
+
+/*
+ * exported functions:
+ *
+ * int plugin_init_i2c_sensors (void)
+ * adds function i2c_sensors() to retrieve informations from
+ * the i2c sensors via the sysfs interface of 2.6.x kernels
+ *
+ * -- WARNING --
+ * This plugin is only for kernel series 2.5/2.6 and higher !
+ * It uses the new sysfs pseudo-filesystem that you can mount with:
+ * mount -t sysfs none /sys
+ *
+ * -- WARNING #2 --
+ * This plugin should detect where your sensors are at startup.
+ * If you can't get any token to work, ensure you don't get
+ * an error message with "lcd4linux -F".
+ *
+ * If so, try to force the path to your sensors in the conf like this :
+ * i2c_sensors.path /sys/bus/i2c/devices/0-6000/
+ *
+ * - replace 0-6000 with the appropriate dir
+ * - DON'T forget the trailing slash or it won't work !
+ *
+ */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <dirent.h>
+
+#include "debug.h"
+#include "plugin.h"
+#include "cfg.h"
+
+static char *path=NULL;
+
+static void my_i2c_sensors (RESULT *result, RESULT *arg)
+{
+ int fd=-2;
+ double value;
+ char buffer[32];
+ char *key=R2S(arg);
+ char *file;
+
+ // construct absolute path to the file to read
+ // Fixme: MR: free the path again??
+ file = strdup(path);
+ file = realloc(file, strlen(path)+strlen(key)+1);
+ file = strcat(file, key);
+
+ // read of file to buffer
+ fd = open(file, O_RDONLY);
+ read (fd, &buffer, 31);
+ close(fd);
+
+ if (!buffer) {
+ SetResult(&result, R_STRING, "??");
+ return;
+ }
+
+ // now the formating stuff, depending on the file wanted
+ if (!strncmp(key, "temp_", 5) ||
+ !strncmp(key, "curr_", 5) ||
+ !strncmp(key, "in_", 3) ||
+ !strncmp(key, "vid", 3)) {
+ value = strtod(buffer, NULL);
+ value /= 1000.0;
+ if (value) {
+ SetResult(&result, R_NUMBER, &value);
+ return;
+ }
+
+ } else if (!strncmp(key, "fan_", 4) ||
+ !strncmp(key, "pwn_", 4) ||
+ !strncmp(key, "vrm", 5)) {
+ value = strtod(buffer, NULL);
+ if (value) {
+ SetResult(&result, R_NUMBER, &buffer);
+ return;
+ }
+
+ } else {
+ SetResult(&result, R_STRING, &buffer);
+ return;
+ }
+
+ // fallback is there's a problem
+ SetResult(&result, R_STRING, "??");
+}
+
+
+void my_i2c_sensors_path(void)
+{
+ struct dirent *dir;
+ struct dirent *file;
+ char *base="/sys/bus/i2c/devices/";
+ char dname[64];
+ DIR *fd1;
+ DIR *fd2;
+ int done;
+
+ fd1 = opendir(base);
+ while((dir = readdir(fd1))) {
+ // Skip '.' and '..'
+ if (strcmp(dir->d_name, "." )==0 ||
+ strcmp(dir->d_name, "..")==0) {
+ continue;
+ }
+
+ // dname is the absolute path
+ strcpy(dname, base);
+ strcat(dname, dir->d_name);
+ strcat(dname, "/");
+
+ fd2 = opendir(dname);
+ done = 0;
+ while((file = readdir(fd2))) {
+ if (!strcmp(file->d_name, "temp_input1")) { // FIXME : do all sensors have a temp_input1 ?
+ path = realloc(path, strlen(dname));
+ strcpy(path, dname); // we've got it ;)
+ done=1;
+ break;
+ }
+ }
+ closedir(fd2);
+ if (done) break;
+ }
+ closedir(fd1);
+
+ // fallback is path undefined
+ if (*path != '/') {
+ error("[i2c_sensors] No i2c sensors found via the i2c interface !");
+ error("[i2c_sensors] Try to specify the path to the sensors !");
+ }
+}
+
+
+int plugin_init_i2c_sensors (void)
+{
+ // char *path_cfg=cfg_get(NULL, "i", "");
+ // printf("%s\n", path_cfg);
+ // if (strncmp(path_cfg, "/", 1)) {
+ // printf("%s\n", "Calling my_i2c_sensors_path()");
+ my_i2c_sensors_path();
+ // } else {
+ // path = realloc(path, strlen(path_cfg)+1);
+ // strcpy(path, path_cfg);
+ // }
+
+ AddFunction ("i2c_sensors", 1, my_i2c_sensors);
+
+ printf("%s\n", path);
+ return 0;
+}
+