]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2004-02-16 08:19:44 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 16 Feb 2004 08:19:44 +0000 (08:19 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 16 Feb 2004 08:19:44 +0000 (08:19 +0000)
i2c_sensors patch from Xavier

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

plugin_i2c_sensors.c

index 662f6c2e282058e8dc110e80e12c1b0b9114312d..812f6760f1a49aa0922e7c81bf33acb110abc92e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_i2c_sensors.c,v 1.11 2004/02/15 21:43:43 reinelt Exp $
+/* $Id: plugin_i2c_sensors.c,v 1.12 2004/02/16 08:19:44 reinelt Exp $
  *
  * I2C sensors plugin
  *
@@ -23,6 +23,9 @@
  *
  *
  * $Log: plugin_i2c_sensors.c,v $
+ * Revision 1.12  2004/02/16 08:19:44  reinelt
+ * i2c_sensors patch from Xavier
+ *
  * Revision 1.11  2004/02/15 21:43:43  reinelt
  * T6963 driver nearly finished
  * framework for graphic displays done
 #endif
 
 static char *path=NULL;
-static int use_sysfs=0;
 static HASH I2Csensors = { 0, };
 
 static const char *procfs_tokens[4][3] = {
@@ -131,6 +133,8 @@ static const char *procfs_tokens[4][3] = {
   {"fan_min", "fan_input", ""}                 // for fan#
 };
 
+static int (*parse_i2c_sensors)(char *key);
+
        /***********************************************\
        * Parsing for new 2.6 kernels 'sysfs' interface *
        \***********************************************/
@@ -265,11 +269,7 @@ void my_i2c_sensors(RESULT *result, RESULT *arg)
   
   age=hash_age(&I2Csensors, key, &val);
   if (age<0 || age>250) {
-    if (use_sysfs) {
-      parse_i2c_sensors_sysfs(key);
-    } else {
-      parse_i2c_sensors_procfs(key);    
-    }
+    parse_i2c_sensors(key);
     val=hash_get(&I2Csensors, key);
   }
   if (val) {
@@ -279,6 +279,7 @@ void my_i2c_sensors(RESULT *result, RESULT *arg)
   }
 }
 
+
 void my_i2c_sensors_path(char *method)
 {
   struct dirent *dir;
@@ -310,7 +311,7 @@ void my_i2c_sensors_path(char *method)
   
   while((dir = readdir(fd1)))   {
     // Skip non-directories and '.' and '..'
-    if (dir->d_type!=DT_DIR ||
+    if ((dir->d_type!=DT_DIR && dir->d_type!=DT_LNK) ||
        strcmp(dir->d_name, "." )==0 ||
        strcmp(dir->d_name, "..")==0) {
       continue;
@@ -337,6 +338,7 @@ void my_i2c_sensors_path(char *method)
   closedir(fd1);
 }
 
+
 int plugin_init_i2c_sensors (void)
 {
   char *path_cfg=cfg_get(NULL, "i2c_sensors-path", "");
@@ -370,14 +372,17 @@ int plugin_init_i2c_sensors (void)
   }
 
   // we activate the function only if there's a possibly path found
-  if (!path) {
-    free(path);
-  } else {
+  if (path!=NULL) {
     if (strncmp(path, "/sys", 4)==0) {
-      use_sysfs=1;
+      parse_i2c_sensors=parse_i2c_sensors_sysfs;
+      AddFunction ("i2c_sensors", 1, my_i2c_sensors);
+    } else if (strncmp(path, "/proc", 5)==0) {
+      parse_i2c_sensors=parse_i2c_sensors_procfs;      
+      AddFunction ("i2c_sensors", 1, my_i2c_sensors);
+    } else {
+      error("[i2c_sensors] unknown path %s, should start with /sys or /proc");
     }
-    AddFunction ("i2c_sensors", 1, my_i2c_sensors);
   }
+  
   return 0;
 }