X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fpsensor.c;h=badd6d632a80f9266a64968a86f9f7ec2137b696;hb=ba0ded662ced0e4334ac0652d8f7991f485f0899;hp=e11d75d22b5114f3792970e9108f2fa98bd46935;hpb=ec65d9b7efd82760ea3c57b84afd0c5842899003;p=psensor.git diff --git a/src/lib/psensor.c b/src/lib/psensor.c index e11d75d..badd6d6 100644 --- a/src/lib/psensor.c +++ b/src/lib/psensor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2013 jeanfi@gmail.com + * Copyright (C) 2010-2014 jeanfi@gmail.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -23,12 +23,14 @@ #include #define _(str) gettext(str) -#include "hdd.h" -#include "psensor.h" -#include "lmsensor.h" +#include +#include +#include +#include #ifdef HAVE_GTOP -#include "cpu.h" +#include +#include #endif struct psensor *psensor_create(char *id, @@ -37,8 +39,9 @@ struct psensor *psensor_create(char *id, unsigned int type, int values_max_length) { - struct psensor *psensor - = (struct psensor *)malloc(sizeof(struct psensor)); + struct psensor *psensor; + + psensor = (struct psensor *)malloc(sizeof(struct psensor)); psensor->id = id; psensor->name = name; @@ -170,7 +173,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 *)); @@ -184,6 +189,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; @@ -208,18 +229,8 @@ int is_fan_type(unsigned int type) return type & SENSOR_TYPE_FAN; } -double celcius_to_fahrenheit(double c) -{ - return c * (9.0/5.0) + 32; -} - -double fahrenheit_to_celcius(double f) -{ - return (f - 32) * (5.0/9.0); -} - char * -psensor_value_to_str(unsigned int type, double value, int use_celcius) +psensor_value_to_str(unsigned int type, double value, int use_celsius) { char *str; const char *unit; @@ -230,10 +241,10 @@ psensor_value_to_str(unsigned int type, double value, int use_celcius) */ str = malloc(20); - unit = psensor_type_to_unit_str(type, use_celcius); + unit = psensor_type_to_unit_str(type, use_celsius); - if (is_temp_type(type) && !use_celcius) - value = celcius_to_fahrenheit(value); + if (is_temp_type(type) && !use_celsius) + value = celsius_to_fahrenheit(value); sprintf(str, "%.0f%s", value, unit); @@ -243,9 +254,9 @@ psensor_value_to_str(unsigned int type, double value, int use_celcius) char * psensor_measure_to_str(const struct measure *m, unsigned int type, - unsigned int use_celcius) + unsigned int use_celsius) { - return psensor_value_to_str(type, m->value, use_celcius); + return psensor_value_to_str(type, m->value, use_celsius); } void psensor_set_current_value(struct psensor *sensor, double value) @@ -426,6 +437,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; @@ -436,8 +451,20 @@ struct psensor **get_all_sensors(int use_libatasmart, int values_max_length) const char *psensor_type_to_str(unsigned int type) { - if (type & SENSOR_TYPE_NVCTRL) - return "NVidia GPU"; + if (type & SENSOR_TYPE_NVCTRL) { + if (type & SENSOR_TYPE_TEMP) + 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"; + else + return "NVIDIA GPU"; + } if (type & SENSOR_TYPE_ATIADL) { if (type & SENSOR_TYPE_TEMP) @@ -457,7 +484,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) @@ -466,14 +493,17 @@ 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"; } -const char *psensor_type_to_unit_str(unsigned int type, int use_celcius) +const char *psensor_type_to_unit_str(unsigned int type, int use_celsius) { if (is_temp_type(type)) { - if (use_celcius) + if (use_celsius) return "\302\260C"; else return "\302\260F"; @@ -492,6 +522,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)) @@ -540,11 +571,11 @@ struct psensor **psensor_list_copy(struct psensor **sensors) } char * -psensor_current_value_to_str(const struct psensor *s, unsigned int celcius) +psensor_current_value_to_str(const struct psensor *s, unsigned int use_celsius) { return psensor_value_to_str(s->type, psensor_get_current_value(s), - celcius); + use_celsius); } struct psensor **psensor_list_filter_graph_enabled(struct psensor **sensors)