temp - move entirely to hwmon based temp sensors on linux

This commit is contained in:
Carsten Haitzler 2020-09-11 00:00:38 +01:00
parent d039b53484
commit 1d87379d47
4 changed files with 839 additions and 660 deletions

View File

@ -6,16 +6,14 @@
struct _E_Config_Dialog_Data
{
struct
{
int interval;
} poll;
struct {
int interval;
} poll;
int unit_method;
struct
{
int low, high;
} temp;
struct {
int low, high;
} temp;
int sensor;
Eina_List *sensors;
@ -28,56 +26,11 @@ struct _E_Config_Dialog_Data
/* local function prototypes */
static void *_create_data(E_Config_Dialog *cfd);
static void _fill_data_tempget(E_Config_Dialog_Data *cfdata);
static void _fill_sensors(E_Config_Dialog_Data *cfdata, const char *name);
static void _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static void _cb_display_changed(void *data, Evas_Object *obj EINA_UNUSED);
static Eina_List *
temperature_get_bus_files(const char *bus)
{
Eina_List *result;
Eina_List *therms;
char path[PATH_MAX + PATH_MAX + 3];
char busdir[PATH_MAX];
char *name;
result = NULL;
snprintf(busdir, sizeof(busdir), "/sys/bus/%s/devices", bus);
/* Look through all the devices for the given bus. */
therms = ecore_file_ls(busdir);
EINA_LIST_FREE(therms, name)
{
Eina_List *files;
char *file;
/* Search each device for temp*_input, these should be
* temperature devices. */
snprintf(path, sizeof(path), "%s/%s", busdir, name);
files = ecore_file_ls(path);
EINA_LIST_FREE(files, file)
{
if ((!strncmp("temp", file, 4)) &&
(!strcmp("_input", &file[strlen(file) - 6])))
{
char *f;
snprintf(path, sizeof(path),
"%s/%s/%s", busdir, name, file);
f = strdup(path);
if (f) result = eina_list_append(result, f);
}
free(file);
}
free(name);
}
return result;
}
void
config_temperature_module(Config_Face *inst)
{
@ -118,119 +71,38 @@ _fill_data_tempget(E_Config_Dialog_Data *cfdata)
cfdata->temp.low = cfdata->inst->low;
cfdata->temp.high = cfdata->inst->high;
cfdata->sensor = 0;
switch (cfdata->inst->sensor_type)
#if defined (__FreeBSD__) || defined(__DragonFly__)
#elif defined(__OpenBSD__)
#else
Eina_List *sensors;
Sensor *sen;
int n;
sensors = temperature_tempget_sensor_list();
n = 0;
EINA_LIST_FREE(sensors, sen)
{
case SENSOR_TYPE_NONE:
case SENSOR_TYPE_FREEBSD:
case SENSOR_TYPE_OMNIBOOK:
case SENSOR_TYPE_LINUX_MACMINI:
case SENSOR_TYPE_LINUX_PBOOK:
case SENSOR_TYPE_LINUX_INTELCORETEMP:
break;
case SENSOR_TYPE_LINUX_I2C:
_fill_sensors(cfdata, "i2c");
break;
case SENSOR_TYPE_LINUX_PCI:
_fill_sensors(cfdata, "pci");
break;
case SENSOR_TYPE_LINUX_ACPI:
{
Eina_List *l;
if ((l = ecore_file_ls("/proc/acpi/thermal_zone")))
{
char *name;
int n = 0;
EINA_LIST_FREE(l, name)
{
cfdata->sensors =
eina_list_append(cfdata->sensors, name);
if (cfdata->inst->sensor_name)
{
if (!strcmp(cfdata->inst->sensor_name, name))
cfdata->sensor = n;
}
n++;
}
}
break;
}
case SENSOR_TYPE_LINUX_SYS:
{
Eina_List *l;
if ((l = ecore_file_ls("/sys/class/thermal")))
{
char *name;
int n = 0;
EINA_LIST_FREE(l, name)
{
if (!strncmp(name, "thermal", 7))
{
cfdata->sensors =
eina_list_append(cfdata->sensors, name);
if (cfdata->inst->sensor_name)
{
if (!strcmp(cfdata->inst->sensor_name, name))
cfdata->sensor = n;
}
n++;
}
}
}
break;
}
default:
break;
}
}
static void
_fill_sensors(E_Config_Dialog_Data *cfdata, const char *name)
{
Eina_List *therms, *l;
char *n;
if (!name) return;
if ((therms = temperature_get_bus_files(name)))
{
char path[PATH_MAX];
EINA_LIST_FREE(therms, n)
{
if (ecore_file_exists(n))
{
int len;
sprintf(path, "%s", ecore_file_file_get(n));
len = strlen(path);
if (len > 6) path[len - 6] = '\0';
cfdata->sensors =
eina_list_append(cfdata->sensors, strdup(path));
}
free(n);
}
}
EINA_LIST_FOREACH(cfdata->sensors, l, n)
{
if (cfdata->inst->sensor_name)
{
if (!strcmp(cfdata->inst->sensor_name, n)) break;
}
cfdata->sensor++;
if ((cfdata->inst->sensor_name) &&
(!strcmp(sen->name, cfdata->inst->sensor_name)))
cfdata->sensor = n;
cfdata->sensors = eina_list_append(cfdata->sensors, sen);
n++;
}
#endif
}
static void
_free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
char *sensor;
Sensor *sen;
cfdata->inst->config_dialog = NULL;
EINA_LIST_FREE(cfdata->sensors, sensor)
free(sensor);
EINA_LIST_FREE(cfdata->sensors, sen)
{
eina_stringshare_replace(&(sen->name), NULL);
eina_stringshare_replace(&(sen->label), NULL);
free(sen);
}
E_FREE(cfdata);
}
@ -246,15 +118,15 @@ _basic_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data
if (cfdata->sensors)
{
Sensor *sen;
Eina_List *l;
char *name;
int n = 0;
ol = e_widget_list_add(evas, 0, 0);
rg = e_widget_radio_group_new(&(cfdata->sensor));
EINA_LIST_FOREACH(cfdata->sensors, l, name)
EINA_LIST_FOREACH(cfdata->sensors, l, sen)
{
ow = e_widget_radio_add(evas, _(name), n, rg);
ow = e_widget_radio_add(evas, sen->label, n, rg);
e_widget_list_object_append(ol, ow, 1, 0, 0.5);
n++;
}
@ -314,13 +186,16 @@ _basic_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data
static int
_basic_apply(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
Sensor *sen;
cfdata->inst->poll_interval = cfdata->poll.interval;
cfdata->inst->units = cfdata->unit_method;
cfdata->inst->low = cfdata->temp.low;
cfdata->inst->high = cfdata->temp.high;
eina_stringshare_replace(&cfdata->inst->sensor_name,
eina_list_nth(cfdata->sensors, cfdata->sensor));
sen = eina_list_nth(cfdata->sensors, cfdata->sensor);
if (sen)
eina_stringshare_replace(&(cfdata->inst->sensor_name), sen->name);
e_config_save_queue();
temperature_face_update_config(cfdata->inst);

View File

@ -51,7 +51,6 @@ static void
_temperature_thread_free(Tempthread *tth)
{
eina_stringshare_del(tth->sensor_name);
eina_stringshare_del(tth->sensor_path);
e_powersave_sleeper_free(tth->sleeper);
free(tth->extn);
free(tth);
@ -123,7 +122,6 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
inst->poll_interval = 128;
inst->low = 30;
inst->high = 80;
inst->sensor_type = SENSOR_TYPE_LINUX_SYS;
inst->sensor_name = NULL;
inst->temp = -900;
inst->units = CELSIUS;
@ -207,7 +205,6 @@ _gc_id_new(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
inst->poll_interval = 128;
inst->low = 30;
inst->high = 80;
inst->sensor_type = SENSOR_TYPE_LINUX_SYS;
inst->sensor_name = NULL;
inst->units = CELSIUS;
if (!temperature_config->faces)
@ -282,11 +279,6 @@ _temperature_face_id_max(const Eina_Hash *hash EINA_UNUSED, const void *key, voi
p = strrchr(key, '.');
if (p) num = atoi(p + 1);
if (num > *max) *max = num;
#if defined (__FreeBSD__) || defined(__DragonFly__) || defined (__OpenBSD__)
cf->sensor_type = SENSOR_TYPE_FREEBSD;
#else
cf->sensor_type = SENSOR_TYPE_LINUX_SYS;
#endif
return EINA_TRUE;
}
@ -302,8 +294,8 @@ _temperature_check_main(void *data, Ecore_Thread *th)
temp = temperature_tempget_get(tth);
if (ptemp != temp) ecore_thread_feedback(th, (void *)((long)temp));
ptemp = temp;
e_powersave_sleeper_sleep(tth->sleeper, tth->poll_interval);
if (ecore_thread_check(th)) break;
e_powersave_sleeper_sleep(tth->sleeper, tth->poll_interval);
}
}
@ -333,7 +325,6 @@ temperature_face_update_config(Config_Face *inst)
tth = calloc(1, sizeof(Tempthread));
tth->poll_interval = inst->poll_interval;
tth->sensor_type = inst->sensor_type;
tth->inst = inst;
tth->sleeper = e_powersave_sleeper_new();
if (inst->sensor_name)
@ -365,7 +356,6 @@ e_modapi_init(E_Module *m)
E_CONFIG_VAL(D, T, poll_interval, INT);
E_CONFIG_VAL(D, T, low, INT);
E_CONFIG_VAL(D, T, high, INT);
E_CONFIG_VAL(D, T, sensor_type, INT);
E_CONFIG_VAL(D, T, sensor_name, STR);
E_CONFIG_VAL(D, T, units, INT);
@ -383,6 +373,7 @@ e_modapi_init(E_Module *m)
eina_hash_foreach(temperature_config->faces, _temperature_face_id_max, &uuid);
temperature_config->module = m;
temperature_tempget_setup();
e_gadcon_provider_register(&_gadcon_class);
return m;
}
@ -394,6 +385,7 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED)
if (temperature_config->faces)
eina_hash_foreach(temperature_config->faces, _temperature_face_shutdown, NULL);
eina_hash_free(temperature_config->faces);
temperature_tempget_clear();
free(temperature_config);
temperature_config = NULL;
E_CONFIG_DD_FREE(conf_face_edd);

View File

@ -3,22 +3,6 @@
#include "e.h"
typedef enum _Sensor_Type
{
SENSOR_TYPE_NONE,
SENSOR_TYPE_FREEBSD,
SENSOR_TYPE_OPENBSD,
SENSOR_TYPE_OMNIBOOK,
SENSOR_TYPE_LINUX_MACMINI,
SENSOR_TYPE_LINUX_I2C,
SENSOR_TYPE_LINUX_ACPI,
SENSOR_TYPE_LINUX_PCI,
SENSOR_TYPE_LINUX_PBOOK,
SENSOR_TYPE_LINUX_INTELCORETEMP,
SENSOR_TYPE_LINUX_THINKPAD,
SENSOR_TYPE_LINUX_SYS
} Sensor_Type;
typedef struct _Config Config;
typedef struct _Config_Face Config_Face;
typedef struct _Tempthread Tempthread;
@ -33,9 +17,7 @@ struct _Tempthread
{
Config_Face *inst;
int poll_interval;
Sensor_Type sensor_type;
const char *sensor_name;
const char *sensor_path;
void *extn;
E_Powersave_Sleeper *sleeper;
Eina_Bool initted E_BITFIELD;
@ -80,7 +62,16 @@ E_API int e_modapi_save(E_Module *m);
void config_temperature_module(Config_Face *inst);
void temperature_face_update_config(Config_Face *inst);
int temperature_tempget_get(Tempthread *tth);
typedef struct
{
const char *name;
const char *label;
} Sensor;
int temperature_tempget_get(Tempthread *tth);
Eina_List *temperature_tempget_sensor_list(void);
void temperature_tempget_setup(void);
void temperature_tempget_clear(void);
/**
* @addtogroup Optional_Gadgets

File diff suppressed because it is too large Load Diff