next: Fan RPM.

This commit is contained in:
Alastair Poole 2021-05-17 12:21:07 +01:00
parent 16fe06e9fa
commit 099e9a5724
3 changed files with 70 additions and 31 deletions

View File

@ -10,29 +10,36 @@ static Eina_List *network_interfaces = NULL;
int
main(int argc, char **argv)
{
Eina_List *l;
Cpu_Core **cores;
Battery *bat;
Sensor *sensor;
Network_Interface *iface;
ecore_init();
puts("CORES:");
Cpu_Core **cores;
int ncpu = 0;
cores = system_cpu_usage_delayed_get(&ncpu, 1000000);
for (int i = 0; i < ncpu; i++)
printf("core %i = %1.2f%%\n", cores[i]->id, cores[i]->percent);
{
printf("core %i = %1.2f%%\n", cores[i]->id, cores[i]->percent);
free(cores[i]);
}
free(cores);
puts("BATTERIES:");
Battery *bat;
batteries = batteries_find();
EINA_LIST_FOREACH(batteries, l, bat)
EINA_LIST_FREE(batteries, bat)
{
battery_check(bat);
printf("battery %s (%s) => %1.2f\n", bat->name, bat->vendor, bat->percent);
battery_free(bat);
}
EINA_LIST_FREE(batteries, bat)
battery_free(bat);
printf("POWER %i\n", power_ac_check());
printf("POWER: %i\n", power_ac_check());
puts("SENSORS:");
Sensor *sensor;
sensors = sensors_find();
EINA_LIST_FREE(sensors, sensor)
@ -51,6 +58,10 @@ main(int argc, char **argv)
sensor_free(sensor);
}
puts("NETWORK:");
Network_Interface *iface;
network_interfaces = network_interfaces_find();
EINA_LIST_FREE(network_interfaces, iface)
{

View File

@ -2,6 +2,8 @@
#define MACHINE_H
#include <Eina.h>
#include <Ecore.h>
#include <Ecore_File.h>
#include <stdint.h>
#include <stdbool.h>
@ -34,7 +36,7 @@ typedef struct
uint64_t zfs_arc_used;
uint64_t video_count;
Meminfo_Video video[MEM_VIDEO_CARD_MAX];
Meminfo_Video video[MEM_VIDEO_CARD_MAX];
} Meminfo;
typedef enum

View File

@ -20,8 +20,10 @@ sensor_check(Sensor *sensor)
if (d)
{
double val = atof(d);
if (val)
if (sensor->type == THERMAL)
sensor->value = val /= 1000;
else if (sensor->type == FANRPM)
sensor->value = val;
free(d);
return 1;
}
@ -171,7 +173,7 @@ sensors_find(void)
for (int i = 0; i < n; i++)
{
if (!strncmp(names[i]->d_name, "temp", 4))
if ((!strncmp(names[i]->d_name, "temp", 4)) || (!strncmp(names[i]->d_name, "fan", 3)))
{
int id = atoi(names[i]->d_name + 4);
if ((!id) || (id > sizeof(seen)))
@ -190,26 +192,50 @@ sensors_find(void)
free(names[i]);
continue;
}
sensor = calloc(1, sizeof(Sensor));
if (sensor)
snprintf(buf, sizeof(buf), "%s/fan%i_input", link, id);
if (ecore_file_exists(buf))
{
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);
sensor->path = strdup(buf);
char *d = file_contents(buf);
if (d)
sensor = calloc(1, sizeof(Sensor));
if (sensor)
{
sensor->value = atoi(d);
if (sensor->value) sensor->value /= 1000;
free(d);
sensor->type = FANRPM;
sensor->path = strdup(buf);
snprintf(buf, sizeof(buf), "%s/name", link);
sensor->name = file_contents(buf);
snprintf(buf, sizeof(buf), "%s/fan%i_label", link, id);
if (ecore_file_exists(buf))
sensor->child_name = file_contents(buf);
else
{
snprintf(buf, sizeof(buf), "fan%i", id);
sensor->child_name = strdup(buf);
}
sensors = eina_list_append(sensors, sensor);
}
sensors = eina_list_append(sensors, sensor);
}
snprintf(buf, sizeof(buf), "%s/temp%i_input", link, id);
if (ecore_file_exists(buf))
{
sensor = calloc(1, sizeof(Sensor));
if (sensor)
{
sensor->type = THERMAL;
sensor->path = strdup(buf);
snprintf(buf, sizeof(buf), "%s/name", link);
sensor->name = file_contents(buf);
snprintf(buf, sizeof(buf), "%s/temp%i_label", link, id);
if (ecore_file_exists(buf))
sensor->child_name = file_contents(buf);
else
{
snprintf(buf, sizeof(buf), "%i", id);
sensor->child_name = strdup(buf);
}
sensors = eina_list_append(sensors, sensor);
}
}
seen[idx++] = id;
}