No more limits to the number of I2C temperatures allowed.
authorDavid Walter Seikel <onefang@gmail.com>
Sun, 28 Jan 2007 16:08:12 +0000 (16:08 +0000)
committerDavid Walter Seikel <onefang@gmail.com>
Sun, 28 Jan 2007 16:08:12 +0000 (16:08 +0000)
SVN revision: 28147

src/modules/temperature/e_mod_config.c
src/modules/temperature/e_mod_main.c
src/modules/temperature/e_mod_main.h

index ddbb388..13d9776 100644 (file)
@@ -125,28 +125,27 @@ _fill_data(E_Config_Dialog_Data *cfdata)
       case SENSOR_TYPE_LINUX_MACMINI:
         break;
       case SENSOR_TYPE_LINUX_I2C:
-        therms = ecore_file_ls("/sys/bus/i2c/devices");
+        therms = temperature_get_i2c_files();
         if (therms)
-           {
-              char *therm_name;
-
-              while ((therm_name = ecore_list_next(therms)))
-                {
-                   int i;
-
-                    /* If there are ever more than 9 temperatures, then just increase this number. */
-                   for (i = 0; i < 9; i++)
-                     {
-                        sprintf(path, "/sys/bus/i2c/devices/%s/temp%d_input", therm_name, i);
-                        if (ecore_file_exists(path))
-                          {
-                             sprintf(path, "temp%d", i);
-                             ecore_list_append(cfdata->sensors, strdup(path));
-                          }
-                     }
-                }
-              ecore_list_destroy(therms);
-           }
+          {
+              char *name;
+
+             while ((name = ecore_list_next(therms)))
+               {
+                  if (ecore_file_exists(name))
+                    {
+                       int len;
+
+                       sprintf(path, "%s", ecore_file_get_file(name));
+                       len = strlen(path);
+                       if (len > 6)
+                          path[len - 6] = '\0';
+                       ecore_list_append(cfdata->sensors, strdup(path));
+                       /* TODO: Track down the user friendly names and display them instead. */
+                    }
+               }
+             ecore_list_destroy(therms);
+          }
 
         ecore_list_goto_first(cfdata->sensors);
         while ((name = ecore_list_next(cfdata->sensors)))
index d9979ce..bb4943b 100644 (file)
@@ -238,28 +238,25 @@ _temperature_sensor_init(Config_Face *inst)
               }
             else
               {
-                 therms = ecore_file_ls("/sys/bus/i2c/devices");
+                  therms = temperature_get_i2c_files();
                  if (therms)
                    {
                       char *name;
 
-                      while ((name = ecore_list_next(therms)))
-                        {
-                           int i;
-
-                            /* If there are ever more than 9 temperatures, then just increase this number. */
-                           for (i = 0; i < 9; i++)
-                             {
-                                sprintf(path, "/sys/bus/i2c/devices/%s/temp%d_input", name, i);
-                                if (ecore_file_exists(path))
+                      if ((name = ecore_list_next(therms)))
+                        {
+                                if (ecore_file_exists(name))
                                   {
-                                     sprintf(path, "temp%d", i);
+                                     int len;
+
+                                     sprintf(path, "%s", ecore_file_get_file(name));
+                                     len = strlen(path);
+                                     if (len > 6)
+                                        path[len - 6] = '\0';
                                      inst->sensor_type = SENSOR_TYPE_LINUX_I2C;
+                                     inst->sensor_path = evas_stringshare_add(name);
                                      inst->sensor_name = evas_stringshare_add(path);
-                                     break;
                                   }
-                             }
-                           if (inst->sensor_type) break;
                         }
                       ecore_list_destroy(therms);
                    }
@@ -304,6 +301,7 @@ _temperature_sensor_init(Config_Face *inst)
                        if (ecore_file_exists(path))
                          {
                             inst->sensor_path = evas_stringshare_add(path);
+                            /* We really only care about the first one for the default. */
                             break;
                          }
                     }
@@ -527,6 +525,58 @@ temperature_face_update_config(Config_Face *inst)
      ecore_timer_add(inst->poll_time, _temperature_cb_check, inst);
 }
 
+Ecore_List *
+temperature_get_i2c_files()
+{
+   Ecore_List *result;
+   Ecore_List *therms;
+   char        path[PATH_MAX];
+
+   result = ecore_list_new();
+   if (result)
+     {
+        ecore_list_set_free_cb(result, free);
+
+        /* Look through all the i2c devices. */
+        therms = ecore_file_ls("/sys/bus/i2c/devices");
+        if (therms)
+          {
+             char *name;
+
+            while ((name = ecore_list_next(therms)))
+              {
+                  Ecore_List *files;
+
+                  /* Search each device for temp*_input, these should be i2c temperature devices. */
+                 sprintf(path, "/sys/bus/i2c/devices/%s", name);
+                 files = ecore_file_ls(path);
+                 if (files)
+                   {
+                       char *file;
+
+                      while ((file = ecore_list_next(files)))
+                        {
+                           if ((strncmp("temp", file, 4) == 0) && (strcmp("_input", &file[strlen(file) - 6]) == 0))
+                             {
+                                char *f;
+
+                                sprintf(path, "/sys/bus/i2c/devices/%s/%s", name, file);
+                                f = strdup(path);
+                                if (f)
+                                   ecore_list_append(result, f);
+                             }
+                        }
+                      ecore_list_destroy(files);
+                   }
+              }
+            ecore_list_destroy(therms);
+          }
+        ecore_list_goto_first(result);
+     }
+
+   return result;
+}
+
 /***************************************************************************/
 /**/
 /* module setup */
index 36afefa..6d28742 100644 (file)
@@ -64,6 +64,7 @@ EAPI int   e_modapi_about    (E_Module *m);
 
 void config_temperature_module(Config_Face *inst);
 void temperature_face_update_config(Config_Face *inst);
+Ecore_List *temperature_get_i2c_files(void);
 
 
 #endif