netstar pushed a commit to branch master.

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

commit dcf23687a338e79441ecc0faf024e8af499d1b72
Author: Alastair Poole <[email protected]>
Date:   Tue Jun 16 14:29:06 2020 +0100

    openbsd et al. Support as many sensors we can find.
    
    This isn't finished, build broken for Linux and others.
---
 src/bin/system/machine.c | 70 ++++++++++++++++++++++--------------------------
 src/bin/system/machine.h | 13 ++++++---
 src/bin/ui/ui.h          |  1 -
 src/bin/ui/ui_cpu.c      | 11 --------
 src/bin/ui/ui_misc.c     | 18 +++++++++++++
 5 files changed, 60 insertions(+), 53 deletions(-)

diff --git a/src/bin/system/machine.c b/src/bin/system/machine.c
index 5007bbb..7fbe112 100644
--- a/src/bin/system/machine.c
+++ b/src/bin/system/machine.c
@@ -638,51 +638,54 @@ swap_out:
 }
 
 static void
-_thermal_zone_temp_get(float *temperature)
+_sensors_thermal_get(Sys_Info *sysinfo)
 {
+   sensor_t **sensors = sysinfo->sensors;
 #if defined(__OpenBSD__) || defined(__NetBSD__)
    int mibs[5] = { CTL_HW, HW_SENSORS, 0, 0, 0 };
-   int devn, numt;
+   int devn, n;
    struct sensor snsr;
    size_t slen = sizeof(struct sensor);
    struct sensordev snsrdev;
    size_t sdlen = sizeof(struct sensordev);
+   sensor_t *sensor;
 
-   for (devn = 0;; devn++) {
+   for (devn = 0;; devn++)
+     {
         mibs[2] = devn;
 
         if (sysctl(mibs, 3, &snsrdev, &sdlen, NULL, 0) == -1)
           {
-             if (errno == ENOENT)
-               break;
-             else
-               continue;
+             if (errno == ENOENT) break;
+             continue;
           }
-        if (!strcmp("cpu0", snsrdev.xname))
-          break;
-        else if (!strcmp("km0", snsrdev.xname))
-          break;
-        else if (!strncmp("bcmt", snsrdev.xname, 4))
-          break;
-     }
 
-   for (numt = 0; numt < snsrdev.maxnumt[SENSOR_TEMP]; numt++) {
-        mibs[4] = numt;
+        if ((strcmp("cpu0", snsrdev.xname)) && (strcmp("kmo", snsrdev.xname)) 
&&
+            (strcmp("acpitz0", snsrdev.xname)) && (strncmp("bcmt", 
snsrdev.xname, 4)))
+          {
+             continue;
+          }
 
-        if (sysctl(mibs, 5, &snsr, &slen, NULL, 0) == -1)
-          continue;
+        sensors = realloc(sensors, 1 + sysinfo->snsr_count * sizeof(sensor_t 
*));
+        sensors[sysinfo->snsr_count++] = sensor = calloc(1, sizeof(sensor_t));
+        sensor->name = strdup(snsrdev.xname);
 
-        if (slen > 0 && (snsr.flags & SENSOR_FINVALID) == 0)
-          break;
-     }
+        for (n = 0; n < snsrdev.maxnumt[SENSOR_TEMP]; n++)
+          {
+             mibs[4] = n;
 
-   if (sysctl(mibs, 5, &snsr, &slen, NULL, 0)
-       != -1)
-     {
-        *temperature = (snsr.value - 273150000) / 1000000.0;
+             if (sysctl(mibs, 5, &snsr, &slen, NULL, 0) == -1)
+               continue;
+
+             if (slen > 0 && (snsr.flags & SENSOR_FINVALID) == 0)
+               break;
+          }
+
+        if (sysctl(mibs, 5, &snsr, &slen, NULL, 0) != -1)
+          sensor->value = (snsr.value - 273150000) / 1000000.0;
+        else
+          sensor->invalid = true;
      }
-   else
-     *temperature = INVALID_TEMP;
 #elif defined(__FreeBSD__) || defined(__DragonFly__)
    unsigned int value;
    size_t len = sizeof(value);
@@ -735,6 +738,7 @@ _thermal_zone_temp_get(float *temperature)
 #elif defined(__MacOS__)
    *temperature = INVALID_TEMP;
 #endif
+   sysinfo->sensors = sensors;
 }
 
 static int
@@ -1176,16 +1180,6 @@ _results_cpu(cpu_core_t **cores, int cpu_count)
    return total;
 }
 
-float
-system_thermal_zone_temp_get(void)
-{
-   float temp;
-
-   _thermal_zone_temp_get(&temp);
-
-   return temp;
-}
-
 void
 system_power_state_get(power_t *power)
 {
@@ -1276,7 +1270,7 @@ sys_info_all_get(void)
    if (_power_battery_count_get(&results->power))
      _power_state_get(&results->power);
 
-   _thermal_zone_temp_get(&results->temperature);
+   _sensors_thermal_get(results);
 
    if (!error)
      {
diff --git a/src/bin/system/machine.h b/src/bin/system/machine.h
index 7f6de85..9e7112f 100644
--- a/src/bin/system/machine.h
+++ b/src/bin/system/machine.h
@@ -24,6 +24,13 @@ typedef struct
    unsigned long long zfs_arc_used;
 } meminfo_t;
 
+typedef struct
+{
+   char   *name;
+   double value;
+   bool   invalid;
+} sensor_t;
+
 #define MAX_BATTERIES 10
 
 typedef struct
@@ -54,14 +61,14 @@ struct Sys_Info
 {
    int           cpu_count;
    cpu_core_t  **cores;
-
    meminfo_t     memory;
-
    power_t       power;
 
+   int            snsr_count;
+   sensor_t     **sensors;
+
    unsigned long incoming;
    unsigned long outgoing;
-   float         temperature;
 };
 
 Sys_Info *
diff --git a/src/bin/ui/ui.h b/src/bin/ui/ui.h
index e7889ab..d24e9ba 100644
--- a/src/bin/ui/ui.h
+++ b/src/bin/ui/ui.h
@@ -100,7 +100,6 @@ typedef struct Ui
 
    Eina_List       *cpu_times;
    Eina_List       *cpu_list;
-   Evas_Object     *temp_label;
 
    int             poll_delay;
 
diff --git a/src/bin/ui/ui_cpu.c b/src/bin/ui/ui_cpu.c
index c4a6070..2bc0eae 100644
--- a/src/bin/ui/ui_cpu.c
+++ b/src/bin/ui/ui_cpu.c
@@ -56,12 +56,6 @@ ui_tab_cpu_add(Ui *ui)
    evas_object_show(label);
    elm_box_pack_end(box, label);
 
-   ui->temp_label = label = elm_label_add(box);
-   evas_object_size_hint_align_set(label, FILL, 0);
-   evas_object_size_hint_weight_set(label, EXPAND, EXPAND);
-   evas_object_show(label);
-   elm_box_pack_end(box, label);
-
    cpu_count = system_cpu_online_count_get();
    for (int i = 0; i < cpu_count; i++)
      {
@@ -98,11 +92,6 @@ ui_tab_cpu_update(Ui *ui, Sys_Info *sysinfo)
    if (!ui->cpu_visible)
      return;
 
-   if (sysinfo->temperature != INVALID_TEMP)
-     elm_object_text_set(ui->temp_label,
-                    eina_slstr_printf(_("Thermal Zone: %1.1f°C"),
-                    sysinfo->temperature));
-
    EINA_LIST_FOREACH(ui->cpu_list, l, pb)
      {
         elm_progressbar_value_set(pb, sysinfo->cores[i]->percent / 100);
diff --git a/src/bin/ui/ui_misc.c b/src/bin/ui/ui_misc.c
index 35e218d..b30617f 100644
--- a/src/bin/ui/ui_misc.c
+++ b/src/bin/ui/ui_misc.c
@@ -77,6 +77,23 @@ _battery_usage_add(Evas_Object *box, power_t *power)
      free(power->batteries);
 }
 
+static void
+_sensor_usage_add(Evas_Object *box, Sys_Info *sysinfo)
+{
+   sensor_t *snsr;
+
+   for (int i = 0; i < sysinfo->snsr_count; i++)
+     {
+        snsr = sysinfo->sensors[i];
+        printf("%s => %1.2f\n", snsr->name, snsr->value);
+        if (snsr->name)
+          free(snsr->name);
+        free(snsr);
+     }
+   if (sysinfo->sensors)
+     free(sysinfo->sensors);
+}
+
 static char *
 _network_transfer_format(double rate)
 {
@@ -219,6 +236,7 @@ ui_tab_misc_update(Ui *ui, Sys_Info *sysinfo)
    evas_object_show(box);
 
    _battery_usage_add(box, &sysinfo->power);
+   _sensor_usage_add(box, sysinfo);
    _network_usage_add(ui, box, sysinfo->incoming, EINA_TRUE);
    _network_usage_add(ui, box, sysinfo->outgoing, EINA_FALSE);
 

-- 


Reply via email to