netstar pushed a commit to branch master.

http://git.enlightenment.org/apps/evisum.git/commit/?id=099e9a5724c4599affa23c8de9273484cfd4576e

commit 099e9a5724c4599affa23c8de9273484cfd4576e
Author: Alastair Poole <nets...@gmail.com>
Date:   Mon May 17 12:21:07 2021 +0100

    next: Fan RPM.
---
 src/bin/evisum_watcher.c       | 33 ++++++++++++++--------
 src/bin/next/machine.h         |  4 ++-
 src/bin/next/machine/sensors.x | 64 +++++++++++++++++++++++++++++-------------
 3 files changed, 70 insertions(+), 31 deletions(-)

diff --git a/src/bin/evisum_watcher.c b/src/bin/evisum_watcher.c
index fbe261d..6932760 100644
--- a/src/bin/evisum_watcher.c
+++ b/src/bin/evisum_watcher.c
@@ -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)
      {
diff --git a/src/bin/next/machine.h b/src/bin/next/machine.h
index 3386cd1..6d6b0db 100644
--- a/src/bin/next/machine.h
+++ b/src/bin/next/machine.h
@@ -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
diff --git a/src/bin/next/machine/sensors.x b/src/bin/next/machine/sensors.x
index 96b0302..d9cf0c0 100644
--- a/src/bin/next/machine/sensors.x
+++ b/src/bin/next/machine/sensors.x
@@ -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;
                }

-- 


Reply via email to