From c604c7368d4c9f56dc7207c9b9105e19259d6fbe Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 28 Jan 2007 16:08:12 +0000 Subject: [PATCH] No more limits to the number of I2C temperatures allowed. SVN revision: 28147 --- src/modules/temperature/e_mod_config.c | 37 ++++++------ src/modules/temperature/e_mod_main.c | 78 +++++++++++++++++++++----- src/modules/temperature/e_mod_main.h | 1 + 3 files changed, 83 insertions(+), 33 deletions(-) diff --git a/src/modules/temperature/e_mod_config.c b/src/modules/temperature/e_mod_config.c index ddbb3889a..13d977635 100644 --- a/src/modules/temperature/e_mod_config.c +++ b/src/modules/temperature/e_mod_config.c @@ -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; + { + char *name; - while ((therm_name = ecore_list_next(therms))) - { - int i; + while ((name = ecore_list_next(therms))) + { + if (ecore_file_exists(name)) + { + int len; - /* 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); - } + 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))) diff --git a/src/modules/temperature/e_mod_main.c b/src/modules/temperature/e_mod_main.c index d9979ce51..bb4943bb9 100644 --- a/src/modules/temperature/e_mod_main.c +++ b/src/modules/temperature/e_mod_main.c @@ -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 */ diff --git a/src/modules/temperature/e_mod_main.h b/src/modules/temperature/e_mod_main.h index 36afefa10..6d28742b8 100644 --- a/src/modules/temperature/e_mod_main.h +++ b/src/modules/temperature/e_mod_main.h @@ -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