forked from enlightenment/evisum
parent
42b9ecadc6
commit
9fc5b94d6a
|
@ -84,6 +84,8 @@ system_info_all_free(Sys_Info *info)
|
|||
snsr = info->sensors[i];
|
||||
if (snsr->name)
|
||||
free(snsr->name);
|
||||
if (snsr->child_name)
|
||||
free(snsr->child_name);
|
||||
free(snsr);
|
||||
}
|
||||
if (info->sensors)
|
||||
|
|
|
@ -33,6 +33,7 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
char *child_name;
|
||||
double value;
|
||||
bool invalid;
|
||||
} sensor_t;
|
||||
|
|
|
@ -70,44 +70,78 @@ system_sensors_thermal_get(int *sensor_count)
|
|||
}
|
||||
#elif defined(__linux__)
|
||||
sensor_t *sensor;
|
||||
char *type, *value;
|
||||
struct dirent **names;
|
||||
int i, n;
|
||||
DIR *dir;
|
||||
struct dirent *dh;
|
||||
struct dirent **names = NULL;
|
||||
char *link;
|
||||
char buf[4096];
|
||||
int seen[128];
|
||||
int n, idx;
|
||||
|
||||
n = scandir("/sys/class/thermal", &names, 0, alphasort);
|
||||
if (n < 0) return NULL;
|
||||
dir = opendir("/sys/class/hwmon");
|
||||
if (!dir) return NULL;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (strncmp(names[i]->d_name, "thermal_zone", 12))
|
||||
while ((dh = readdir(dir)) != NULL)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "/sys/class/hwmon/%s", dh->d_name);
|
||||
link = realpath(buf, NULL);
|
||||
if (!link) continue;
|
||||
|
||||
idx = 0;
|
||||
memset(&seen, 0, sizeof(seen));
|
||||
n = scandir(link, &names, 0, alphasort);
|
||||
if (n < 0) continue;
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
free(names[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
type = file_contents(strsli_printf("/sys/class/thermal/%s/type", names[i]->d_name));
|
||||
if (type)
|
||||
{
|
||||
sensors =
|
||||
realloc(sensors, (1 + (*sensor_count)) * sizeof(sensor_t *));
|
||||
sensors[(*sensor_count)++] =
|
||||
sensor = calloc(1, sizeof(sensor_t));
|
||||
|
||||
sensor->name = type;
|
||||
|
||||
value = file_contents(strsli_printf("/sys/class/thermal/%s/temp", names[i]->d_name));
|
||||
if (!value)
|
||||
sensor->invalid = true;
|
||||
else
|
||||
if (!strncmp(names[i]->d_name, "temp", 4))
|
||||
{
|
||||
sensor->value = (float)atoi(value) / 1000.0;
|
||||
free(value);
|
||||
int id = atoi(names[i]->d_name + 4);
|
||||
if ((!id) || (id > sizeof(seen)))
|
||||
{
|
||||
free(names[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
int found = 0;
|
||||
|
||||
for (int j = 0; seen[j] != 0 && j < sizeof(seen); j++)
|
||||
if (seen[j] == id) found = 1;
|
||||
|
||||
if (found)
|
||||
{
|
||||
free(names[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
sensors = realloc(sensors, (1 + (*sensor_count)) * sizeof(sensor_t *));
|
||||
sensors[(*sensor_count)++] = sensor = calloc(1,sizeof(sensor_t));
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/name", link);
|
||||
sensor->name = file_contents(buf);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/temp%d_label", link, id);
|
||||
sensor->child_name = file_contents(buf);
|
||||
snprintf(buf, sizeof(buf), "%s/temp%d_input", link, id);
|
||||
|
||||
char *d = file_contents(buf);
|
||||
if (d)
|
||||
{
|
||||
sensor->value = atoi(d);
|
||||
if (sensor->value) sensor->value /= 1000;
|
||||
free(d);
|
||||
}
|
||||
seen[idx++] = id;
|
||||
}
|
||||
free(names[i]);
|
||||
}
|
||||
|
||||
free(names[i]);
|
||||
free(names);
|
||||
free(link);
|
||||
}
|
||||
|
||||
free(names);
|
||||
closedir(dir);
|
||||
|
||||
#elif defined(__MacOS__)
|
||||
#endif
|
||||
return sensors;
|
||||
|
|
|
@ -71,6 +71,7 @@ static Eina_Bool
|
|||
_sensor_usage_add(Evas_Object *box, sensor_t **sensors, int count)
|
||||
{
|
||||
Evas_Object *frame, *vbox, *hbox, *pb, *ic, *label;
|
||||
Eina_Strbuf *name;
|
||||
sensor_t *snsr;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
|
@ -94,8 +95,14 @@ _sensor_usage_add(Evas_Object *box, sensor_t **sensors, int count)
|
|||
evas_object_show(label);
|
||||
elm_box_pack_end(vbox, label);
|
||||
|
||||
name = eina_strbuf_new();
|
||||
eina_strbuf_append(name, snsr->name);
|
||||
if (snsr->child_name)
|
||||
eina_strbuf_append_printf(name, " (%s)", snsr->child_name);
|
||||
|
||||
elm_object_text_set(label, eina_slstr_printf("%s",
|
||||
snsr->name));
|
||||
eina_strbuf_string_get(name)));
|
||||
eina_strbuf_free(name);
|
||||
|
||||
hbox = elm_box_add(box);
|
||||
evas_object_size_hint_align_set(hbox, FILL, FILL);
|
||||
|
@ -170,6 +177,8 @@ _misc_free(power_t *power, sensor_t **sensors, int sensor_count)
|
|||
sensor_t *snsr = sensors[i];
|
||||
if (snsr->name)
|
||||
free(snsr->name);
|
||||
if (snsr->child_name)
|
||||
free(snsr->child_name);
|
||||
free(snsr);
|
||||
}
|
||||
if (sensors)
|
||||
|
|
Loading…
Reference in New Issue