style
[psensor.git] / src / lib / psensor.c
index 348885a..b589c03 100644 (file)
 #include <libintl.h>
 #define _(str) gettext(str)
 
-#include "hdd.h"
-#include "psensor.h"
-#include "lmsensor.h"
+#include <hdd.h>
+#include <psensor.h>
+#include <lmsensor.h>
+#include <temperature.h>
 
 #ifdef HAVE_GTOP
-#include "cpu.h"
+#include <cpu.h>
+#include <pmem.h>
 #endif
 
 struct psensor *psensor_create(char *id,
@@ -81,6 +83,7 @@ void psensor_values_resize(struct psensor *s, int new_size)
 
        if (cur_ms) {
                int i;
+
                for (i = 0; i < new_size - 1 && i < cur_size - 1; i++)
                        measure_copy(&cur_ms[cur_size - i - 1],
                                     &new_ms[new_size - i - 1]);
@@ -171,7 +174,9 @@ int psensor_list_contains_type(struct psensor **sensors, unsigned int type)
 struct psensor **psensor_list_add(struct psensor **sensors,
                                  struct psensor *sensor)
 {
-       int size = psensor_list_size(sensors);
+       int size;
+
+       size = psensor_list_size(sensors);
 
        struct psensor **result
            = malloc((size + 1 + 1) * sizeof(struct psensor *));
@@ -185,6 +190,22 @@ struct psensor **psensor_list_add(struct psensor **sensors,
        return result;
 }
 
+void psensor_list_append(struct psensor ***sensors, struct psensor *sensor)
+{
+       struct psensor **tmp;
+
+       if (!sensor)
+               return;
+
+       tmp = psensor_list_add(*sensors, sensor);
+
+       if (tmp != *sensors) {
+               free(*sensors);
+               *sensors = tmp;
+       }
+}
+
+
 struct psensor *psensor_list_get_by_id(struct psensor **sensors, const char *id)
 {
        struct psensor **sensors_cur = sensors;
@@ -204,21 +225,6 @@ int is_temp_type(unsigned int type)
        return type & SENSOR_TYPE_TEMP;
 }
 
-int is_fan_type(unsigned int type)
-{
-       return type & SENSOR_TYPE_FAN;
-}
-
-double celsius_to_fahrenheit(double c)
-{
-       return c * (9.0/5.0) + 32;
-}
-
-double fahrenheit_to_celsius(double f)
-{
-       return (f - 32) * (5.0/9.0);
-}
-
 char *
 psensor_value_to_str(unsigned int type, double value, int use_celsius)
 {
@@ -343,6 +349,7 @@ double get_max_value(struct psensor **sensors, int type)
                if (sensor->type & type) {
                        int i;
                        double t;
+
                        for (i = 0; i < sensor->values_max_length; i++) {
                                t = sensor->measures[i].value;
 
@@ -427,6 +434,10 @@ struct psensor **get_all_sensors(int use_libatasmart, int values_max_length)
                }
 #endif
 
+#ifdef HAVE_GTOP
+       mem_psensor_list_add(&psensors, values_max_length);
+#endif
+
        if (!psensors) {        /* there is no detected sensors */
                psensors = malloc(sizeof(struct psensor *));
                *psensors = NULL;
@@ -439,9 +450,17 @@ const char *psensor_type_to_str(unsigned int type)
 {
        if (type & SENSOR_TYPE_NVCTRL) {
                if (type & SENSOR_TYPE_TEMP)
-                       return "NVIDIA GPU Temperature";
-               else
-                       return "NVIDIA GPU";
+                       return "Temperature";
+               else if (type & SENSOR_TYPE_GRAPHICS)
+                       return "Graphics usage";
+               else if (type & SENSOR_TYPE_VIDEO)
+                       return "Video usage";
+               else if (type & SENSOR_TYPE_MEMORY)
+                       return "Memory usage";
+               else if (type & SENSOR_TYPE_PCIE)
+                       return "PCIe usage";
+
+               return "NVIDIA GPU";
        }
 
        if (type & SENSOR_TYPE_ATIADL) {
@@ -449,8 +468,8 @@ const char *psensor_type_to_str(unsigned int type)
                        return "AMD GPU Temperature";
                else if (type & SENSOR_TYPE_RPM)
                        return "AMD GPU Fan Speed";
-               else /* type & SENSOR_TYPE_USAGE */
-                       return "AMD GPU Usage";
+               /*else type & SENSOR_TYPE_USAGE */
+               return "AMD GPU Usage";
        }
 
        if ((type & SENSOR_TYPE_HDD_TEMP) == SENSOR_TYPE_HDD_TEMP)
@@ -462,7 +481,7 @@ const char *psensor_type_to_str(unsigned int type)
        if (type & SENSOR_TYPE_TEMP)
                return "Temperature";
 
-       if (type & SENSOR_TYPE_FAN)
+       if (type & SENSOR_TYPE_RPM)
                return "Fan";
 
        if (type & SENSOR_TYPE_CPU)
@@ -471,6 +490,9 @@ const char *psensor_type_to_str(unsigned int type)
        if (type & SENSOR_TYPE_REMOTE)
                return "Remote";
 
+       if (type & SENSOR_TYPE_MEMORY)
+               return "Memory";
+
        return "N/A";
 }
 
@@ -480,15 +502,13 @@ const char *psensor_type_to_unit_str(unsigned int type, int use_celsius)
        if (is_temp_type(type)) {
                if (use_celsius)
                        return "\302\260C";
-               else
-                       return "\302\260F";
-       } else if (is_fan_type(type)) {
+               return "\302\260F";
+       } else if (type & SENSOR_TYPE_RPM) {
                return _("RPM");
-       } else if (type & SENSOR_TYPE_CPU_USAGE) {
+       } else if (type & SENSOR_TYPE_PERCENT) {
                return _("%");
-       } else {
-               return _("N/A");
        }
+       return _("N/A");
 }
 
 void psensor_list_update_measures(struct psensor **sensors)
@@ -497,6 +517,7 @@ void psensor_list_update_measures(struct psensor **sensors)
 
 #ifdef HAVE_GTOP
        cpu_psensor_list_update(sensors);
+       mem_psensor_list_update(sensors);
 #endif
 
        if (psensor_list_contains_type(sensors, SENSOR_TYPE_HDDTEMP))