add full udev support for temp module:

if e is compiled with eeze as the preferred backend, a new config page will appear in the settings for the temperature module where internal and udev are selectable options.
udev mode should support ALL possible hardware, so if you've been having issues with the current temp module, try udev mode!
also note that udev mode provides an extra amount of precision for hahas; it also still obeys the configurable polling intervals.
please test and report all bugs!


SVN revision: 49062
This commit is contained in:
Mike Blumenkrantz 2010-05-20 10:12:41 +00:00
parent 8b6b36637d
commit 95c4186748
5 changed files with 218 additions and 188 deletions

View File

@ -1,6 +1,12 @@
MAINTAINERCLEANFILES = Makefile.in MAINTAINERCLEANFILES = Makefile.in
MODULE = temperature MODULE = temperature
if HAVE_EEZE_UDEV
DEVICE_FILE = e_mod_udev.c
else
DEVICE_FILE =
endif
# data files for the module # data files for the module
filesdir = $(libdir)/enlightenment/modules/$(MODULE) filesdir = $(libdir)/enlightenment/modules/$(MODULE)
files_DATA = \ files_DATA = \
@ -21,6 +27,8 @@ pkg_LTLIBRARIES = module.la
module_la_SOURCES = e_mod_main.c \ module_la_SOURCES = e_mod_main.c \
e_mod_main.h \ e_mod_main.h \
e_mod_config.c \ e_mod_config.c \
e_mod_tempget.c \
$(DEVICE_FILE) \
e_mod_main_private.h e_mod_main_private.h
module_la_LIBADD = @e_libs@ @dlopen_libs@ module_la_LIBADD = @e_libs@ @dlopen_libs@
module_la_LDFLAGS = -module -avoid-version module_la_LDFLAGS = -module -avoid-version

View File

@ -12,7 +12,9 @@ struct _E_Config_Dialog_Data
} poll; } poll;
int unit_method; int unit_method;
#ifdef HAVE_EEZE_UDEV
int backend;
#endif
struct struct
{ {
int low, high; int low, high;
@ -28,7 +30,7 @@ struct _E_Config_Dialog_Data
/* local function prototypes */ /* local function prototypes */
static void *_create_data(E_Config_Dialog *cfd); static void *_create_data(E_Config_Dialog *cfd);
static void _fill_data(E_Config_Dialog_Data *cfdata); static void _fill_data_tempget(E_Config_Dialog_Data *cfdata);
static void _fill_sensors(E_Config_Dialog_Data *cfdata, const char *name); static void _fill_sensors(E_Config_Dialog_Data *cfdata, const char *name);
static void _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata); static void _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
@ -63,18 +65,23 @@ _create_data(E_Config_Dialog *cfd)
cfdata = E_NEW(E_Config_Dialog_Data, 1); cfdata = E_NEW(E_Config_Dialog_Data, 1);
cfdata->inst = cfd->data; cfdata->inst = cfd->data;
_fill_data(cfdata); _fill_data_tempget(cfdata);
return cfdata; return cfdata;
} }
static void static void
_fill_data(E_Config_Dialog_Data *cfdata) _fill_data_tempget(E_Config_Dialog_Data *cfdata)
{ {
cfdata->unit_method = cfdata->inst->units; cfdata->unit_method = cfdata->inst->units;
cfdata->poll.interval = cfdata->inst->poll_interval; cfdata->poll.interval = cfdata->inst->poll_interval;
cfdata->temp.low = cfdata->inst->low; cfdata->temp.low = cfdata->inst->low;
cfdata->temp.high = cfdata->inst->high; cfdata->temp.high = cfdata->inst->high;
cfdata->sensor = 0; cfdata->sensor = 0;
#ifdef HAVE_EEZE_UDEV
cfdata->backend = cfdata->inst->backend;
if (cfdata->backend == TEMPGET)
{
#endif
switch (cfdata->inst->sensor_type) switch (cfdata->inst->sensor_type)
{ {
case SENSOR_TYPE_NONE: case SENSOR_TYPE_NONE:
@ -113,6 +120,9 @@ _fill_data(E_Config_Dialog_Data *cfdata)
default: default:
break; break;
} }
#ifdef HAVE_EEZE_UDEV
}
#endif
} }
static void static void
@ -230,7 +240,16 @@ _basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
e_widget_toolbook_page_append(otb, NULL, _("Temperatures"), ol, e_widget_toolbook_page_append(otb, NULL, _("Temperatures"), ol,
1, 0, 1, 0, 0.5, 0.0); 1, 0, 1, 0, 0.5, 0.0);
#ifdef HAVE_EEZE_UDEV
ol = e_widget_list_add(evas, 0, 0);
rg = e_widget_radio_group_new(&(cfdata->backend));
ow = e_widget_radio_add(evas, _("Internal"), TEMPGET, rg);
e_widget_list_object_append(ol, ow, 1, 1, 0.5);
ow = e_widget_radio_add(evas, _("udev"), UDEV, rg);
e_widget_list_object_append(ol, ow, 1, 1, 0.5);
e_widget_toolbook_page_append(otb, NULL, _("Hardware"), ol,
0, 0, 0, 0, 0.5, 0.0);
#endif
e_widget_toolbook_page_show(otb, 0); e_widget_toolbook_page_show(otb, 0);
return otb; return otb;
} }
@ -242,6 +261,9 @@ _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
cfdata->inst->units = cfdata->unit_method; cfdata->inst->units = cfdata->unit_method;
cfdata->inst->low = cfdata->temp.low; cfdata->inst->low = cfdata->temp.low;
cfdata->inst->high = cfdata->temp.high; cfdata->inst->high = cfdata->temp.high;
#ifdef HAVE_EEZE_UDEV
cfdata->inst->backend = cfdata->backend;
#endif
eina_stringshare_replace(&cfdata->inst->sensor_name, eina_stringshare_replace(&cfdata->inst->sensor_name,
eina_list_nth(cfdata->sensors, cfdata->sensor)); eina_list_nth(cfdata->sensors, cfdata->sensor));

View File

@ -28,11 +28,10 @@ static const E_Gadcon_Client_Class _gadcon_class =
}; };
/* actual module specifics */ /* actual module specifics */
static int _temperature_cb_exe_data(void *data, int type, void *event);
static int _temperature_cb_exe_del(void *data, int type, void *event);
static void _temperature_face_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _temperature_face_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _temperature_face_cb_post_menu(void *data, E_Menu *m); static void _temperature_face_cb_post_menu(void *data, E_Menu *m);
static void _temperature_face_level_set(Config_Face *inst, double level);
static void _temperature_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi); static void _temperature_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item *mi);
static Eina_Bool _temperature_face_shutdown(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *hdata, void *fdata __UNUSED__); static Eina_Bool _temperature_face_shutdown(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *hdata, void *fdata __UNUSED__);
@ -63,6 +62,9 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
inst->sensor_type = SENSOR_TYPE_NONE; inst->sensor_type = SENSOR_TYPE_NONE;
inst->sensor_name = NULL; inst->sensor_name = NULL;
inst->units = CELCIUS; inst->units = CELCIUS;
#ifdef HAVE_EEZE_UDEV
inst->backend = TEMPGET;
#endif
if (!temperature_config->faces) if (!temperature_config->faces)
temperature_config->faces = eina_hash_string_superfast_new(NULL); temperature_config->faces = eina_hash_string_superfast_new(NULL);
eina_hash_direct_add(temperature_config->faces, inst->id, inst); eina_hash_direct_add(temperature_config->faces, inst->id, inst);
@ -72,6 +74,9 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
E_CONFIG_LIMIT(inst->low, 0, 100); E_CONFIG_LIMIT(inst->low, 0, 100);
E_CONFIG_LIMIT(inst->high, 0, 220); E_CONFIG_LIMIT(inst->high, 0, 220);
E_CONFIG_LIMIT(inst->units, CELCIUS, FAHRENHEIT); E_CONFIG_LIMIT(inst->units, CELCIUS, FAHRENHEIT);
#ifdef HAVE_EEZE_UDEV
E_CONFIG_LIMIT(inst->backend, TEMPGET, UDEV);
#endif
o = edje_object_add(gc->evas); o = edje_object_add(gc->evas);
e_theme_edje_object_set(o, "base/theme/modules/temperature", e_theme_edje_object_set(o, "base/theme/modules/temperature",
@ -84,14 +89,24 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
inst->o_temp = o; inst->o_temp = o;
inst->module = temperature_config->module; inst->module = temperature_config->module;
inst->have_temp = -1; inst->have_temp = -1;
#ifdef HAVE_EEZE_UDEV
if (inst->backend == TEMPGET)
{
#endif
inst->tempget_data_handler = inst->tempget_data_handler =
ecore_event_handler_add(ECORE_EXE_EVENT_DATA, ecore_event_handler_add(ECORE_EXE_EVENT_DATA,
_temperature_cb_exe_data, inst); _temperature_cb_exe_data, inst);
inst->tempget_del_handler = inst->tempget_del_handler =
ecore_event_handler_add(ECORE_EXE_EVENT_DEL, ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
_temperature_cb_exe_del, inst); _temperature_cb_exe_del, inst);
#ifdef HAVE_EEZE_UDEV
}
else
{
inst->temp_poller = ecore_poller_add(ECORE_POLLER_CORE, inst->poll_interval, temperature_udev_update_poll, inst);
temperature_udev_update(inst);
}
#endif
temperature_face_update_config(inst); temperature_face_update_config(inst);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
@ -105,6 +120,7 @@ _gc_shutdown(E_Gadcon_Client *gcc)
Config_Face *inst; Config_Face *inst;
inst = gcc->data; inst = gcc->data;
if (inst->tempget_exe) if (inst->tempget_exe)
{ {
ecore_exe_terminate(inst->tempget_exe); ecore_exe_terminate(inst->tempget_exe);
@ -121,6 +137,10 @@ _gc_shutdown(E_Gadcon_Client *gcc)
ecore_event_handler_del(inst->tempget_del_handler); ecore_event_handler_del(inst->tempget_del_handler);
inst->tempget_del_handler = NULL; inst->tempget_del_handler = NULL;
} }
#ifdef HAVE_EEEZ_UDEV
if (inst->temp_poller)
ecore_poller_del(inst->temp_poller);
#endif
if (inst->o_temp) evas_object_del(inst->o_temp); if (inst->o_temp) evas_object_del(inst->o_temp);
inst->o_temp = NULL; inst->o_temp = NULL;
if (inst->config_dialog) e_object_del(E_OBJECT(inst->config_dialog)); if (inst->config_dialog) e_object_del(E_OBJECT(inst->config_dialog));
@ -171,84 +191,16 @@ _gc_id_new(E_Gadcon_Client_Class *client_class)
inst->sensor_type = SENSOR_TYPE_NONE; inst->sensor_type = SENSOR_TYPE_NONE;
inst->sensor_name = NULL; inst->sensor_name = NULL;
inst->units = CELCIUS; inst->units = CELCIUS;
#ifdef HAVE_EEZE_UDEV
inst->backend = TEMPGET;
#endif
if (!temperature_config->faces) if (!temperature_config->faces)
temperature_config->faces = eina_hash_string_superfast_new(NULL); temperature_config->faces = eina_hash_string_superfast_new(NULL);
eina_hash_direct_add(temperature_config->faces, inst->id, inst); eina_hash_direct_add(temperature_config->faces, inst->id, inst);
return inst->id; return inst->id;
} }
static int
_temperature_cb_exe_data(void *data, int type, void *event)
{
Ecore_Exe_Event_Data *ev;
Config_Face *inst;
int temp;
ev = event;
inst = data;
if (ev->exe != inst->tempget_exe) return 1;
temp = -999;
if ((ev->lines) && (ev->lines[0].line))
{
int i;
for (i = 0; ev->lines[i].line; i++)
{
if (!strcmp(ev->lines[i].line, "ERROR"))
temp = -999;
else
temp = atoi(ev->lines[i].line);
}
}
if (temp != -999)
{
char buf[256];
if (inst->units == FAHRENHEIT)
temp = (temp * 9.0 / 5.0) + 32;
if (inst->have_temp != 1)
{
/* enable therm object */
edje_object_signal_emit(inst->o_temp, "e,state,known", "");
inst->have_temp = 1;
}
if (inst->units == FAHRENHEIT)
snprintf(buf, sizeof(buf), "%i°F", temp);
else
snprintf(buf, sizeof(buf), "%i°C", temp);
_temperature_face_level_set(inst,
(double)(temp - inst->low) /
(double)(inst->high - inst->low));
edje_object_part_text_set(inst->o_temp, "e.text.reading", buf);
}
else
{
if (inst->have_temp != 0)
{
/* disable therm object */
edje_object_signal_emit(inst->o_temp, "e,state,unknown", "");
edje_object_part_text_set(inst->o_temp, "e.text.reading", "N/A");
_temperature_face_level_set(inst, 0.5);
inst->have_temp = 0;
}
}
return 0;
}
static int
_temperature_cb_exe_del(void *data, int type, void *event)
{
Ecore_Exe_Event_Del *ev;
Config_Face *inst;
ev = event;
inst = data;
if (ev->exe != inst->tempget_exe) return 1;
inst->tempget_exe = NULL;
return 0;
}
static void static void
_temperature_face_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) _temperature_face_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
@ -295,7 +247,7 @@ _temperature_face_cb_post_menu(void *data, E_Menu *m)
inst->menu = NULL; inst->menu = NULL;
} }
static void void
_temperature_face_level_set(Config_Face *inst, double level) _temperature_face_level_set(Config_Face *inst, double level)
{ {
Edje_Message_Float msg; Edje_Message_Float msg;
@ -324,6 +276,14 @@ _temperature_face_shutdown(const Eina_Hash *hash __UNUSED__, const void *key __U
inst = hdata; inst = hdata;
if (inst->sensor_name) eina_stringshare_del(inst->sensor_name); if (inst->sensor_name) eina_stringshare_del(inst->sensor_name);
if (inst->id) eina_stringshare_del(inst->id); if (inst->id) eina_stringshare_del(inst->id);
#ifdef HAVE_EEZE_UDEV
if (inst->tempdevs)
{
const char *s;
EINA_LIST_FREE(inst->tempdevs, s)
eina_stringshare_del(s);
}
#endif
free(inst); free(inst);
return EINA_TRUE; return EINA_TRUE;
} }
@ -353,6 +313,16 @@ temperature_face_update_config(Config_Face *inst)
ecore_exe_free(inst->tempget_exe); ecore_exe_free(inst->tempget_exe);
inst->tempget_exe = NULL; inst->tempget_exe = NULL;
} }
#ifdef HAVE_EEZE_UDEV
if (inst->backend == TEMPGET)
{
if (inst->temp_poller)
{
ecore_poller_del(inst->temp_poller);
inst->temp_poller = NULL;
}
#endif
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
"%s/%s/tempget %i \"%s\" %i", "%s/%s/tempget %i \"%s\" %i",
e_module_dir_get(temperature_config->module), MODULE_ARCH, e_module_dir_get(temperature_config->module), MODULE_ARCH,
@ -364,6 +334,16 @@ temperature_face_update_config(Config_Face *inst)
ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ_LINE_BUFFERED |
ECORE_EXE_NOT_LEADER, ECORE_EXE_NOT_LEADER,
inst); inst);
#ifdef HAVE_EEZE_UDEV
}
else
{/*avoid creating a new poller if possible*/
if (inst->temp_poller)
ecore_poller_poller_interval_set(inst->temp_poller, inst->poll_interval);
else
inst->temp_poller = ecore_poller_add(ECORE_POLLER_CORE, inst->poll_interval, temperature_udev_update_poll, inst);
}
#endif
} }
Eina_List * Eina_List *
@ -434,6 +414,9 @@ e_modapi_init(E_Module *m)
E_CONFIG_VAL(D, T, low, INT); E_CONFIG_VAL(D, T, low, INT);
E_CONFIG_VAL(D, T, high, INT); E_CONFIG_VAL(D, T, high, INT);
E_CONFIG_VAL(D, T, sensor_type, INT); E_CONFIG_VAL(D, T, sensor_type, INT);
#ifdef HAVE_EEZE_UDEV
E_CONFIG_VAL(D, T, backend, INT);
#endif
E_CONFIG_VAL(D, T, sensor_name, STR); E_CONFIG_VAL(D, T, sensor_name, STR);
E_CONFIG_VAL(D, T, units, INT); E_CONFIG_VAL(D, T, units, INT);

View File

@ -21,6 +21,11 @@ struct _Config_Face
/* saved * loaded config values */ /* saved * loaded config values */
int poll_interval; int poll_interval;
int low, high; int low, high;
#ifdef HAVE_EEZE_UDEV
Eina_List *tempdevs;
int backend;
Ecore_Poller *temp_poller;
#endif
int sensor_type; int sensor_type;
const char *sensor_name; const char *sensor_name;
Unit units; Unit units;
@ -36,8 +41,7 @@ struct _Config_Face
Ecore_Event_Handler *tempget_data_handler; Ecore_Event_Handler *tempget_data_handler;
Ecore_Event_Handler *tempget_del_handler; Ecore_Event_Handler *tempget_del_handler;
// Ecore_Poller *temperature_check_poller; Eina_Bool have_temp:1;
unsigned char have_temp;
#ifdef __FreeBSD__ #ifdef __FreeBSD__
int mib[5]; int mib[5];
#endif #endif
@ -51,12 +55,25 @@ struct _Config
E_Module *module; E_Module *module;
}; };
#ifdef HAVE_EEZE_UDEV
typedef enum _Backend
{
TEMPGET,
UDEV
} Backend;
int temperature_udev_update_poll(void *data);
void temperature_udev_update(void *data);
#endif
EAPI extern E_Module_Api e_modapi; EAPI extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *m); EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m); EAPI int e_modapi_shutdown (E_Module *m);
EAPI int e_modapi_save (E_Module *m); EAPI int e_modapi_save (E_Module *m);
int _temperature_cb_exe_data(void *data, int type, void *event);
int _temperature_cb_exe_del(void *data, int type, void *event);
void _temperature_face_level_set(Config_Face *inst, double level);
void config_temperature_module(Config_Face *inst); void config_temperature_module(Config_Face *inst);
void temperature_face_update_config(Config_Face *inst); void temperature_face_update_config(Config_Face *inst);
Eina_List *temperature_get_bus_files(const char* bus); Eina_List *temperature_get_bus_files(const char* bus);