[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[E-devel] [patch] temp module, acpi thermal_zone selection



Hello hello,
There was some brief talk about adding acpi thermal zone selection to the temperature module on irc a few days back. I ground this out which should work for the relatively generic naming convention which lies within /proc/acpi/thermal_zone/. I tested it out on the laptop which has 3 sensors (TZ0 TZ1 TZ2), and another box which has none (uses lm_sensors) without any difficulties. I'm still curious as to what other naming conventions are lurking about in people's thermal_zone's.

--Kent (der_Metzger)
? acpitempselector.patch
Index: e_mod_config.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/modules/temperature/e_mod_config.c,v
retrieving revision 1.23
diff -u -p -r1.23 e_mod_config.c
--- e_mod_config.c	3 Sep 2006 07:40:45 -0000	1.23
+++ e_mod_config.c	18 Oct 2006 18:06:33 -0000
@@ -29,6 +29,7 @@ struct _E_Config_Dialog_Data
    int high_temp;
 
    int sensor;
+   int acpizone;
 };
 
 /* Protos */
@@ -67,6 +68,7 @@ static void
 _fill_data(E_Config_Dialog_Data *cfdata) 
 {
    double p;
+   Ecore_List *therms;
    
    cfdata->units = temperature_config->units;
    if (temperature_config->units == CELCIUS) 
@@ -117,6 +119,20 @@ _fill_data(E_Config_Dialog_Data *cfdata)
 	else if (!strcmp(temperature_config->sensor_name, "temp3")) 
 	  cfdata->sensor = 2;
      }
+   cfdata->acpizone= 0;
+   if (temperature_config->acpi_sel)
+     {
+       therms = ecore_file_ls("/proc/acpi/thermal_zone");
+       char *tzone;
+       int n = 0;
+       while ((tzone = ecore_list_next(therms)))
+         {
+	   if (!strcmp(temperature_config->acpi_sel, tzone))
+	     cfdata->acpizone = n;
+	   else n++;
+	 }
+       ecore_list_destroy(therms);
+     }
 }
 
 static void *
@@ -293,6 +309,25 @@ _advanced_create_widgets(E_Config_Dialog
 	       }
 	  }
      }
+   else
+     {
+	if (!ecore_list_is_empty(therms))
+	  {
+	     of = e_widget_framelist_add(evas, _("ACPI Temperature"), 0);
+	     rg = e_widget_radio_group_new(&(cfdata->acpizone));
+	     char *tzone;
+	     int n = 0;
+	     while ((tzone = ecore_list_next(therms)))
+	       {
+		  ob = e_widget_radio_add(evas, _(tzone), n, rg);
+		  e_widget_framelist_object_append(of, ob);
+		  n++;
+	       }
+	     e_widget_list_object_append(o, of, 1, 1, 0.5);
+	     ecore_list_destroy(therms);
+	     therms = NULL;
+	  }
+     }
    if (therms) ecore_list_destroy(therms);
 #endif
 
@@ -381,6 +416,23 @@ _advanced_apply_data(E_Config_Dialog *cf
 	temperature_config->sensor_name = evas_stringshare_add("temp3");
 	break;
      }
+   if (temperature_config->acpi_sel)
+     evas_stringshare_del(temperature_config->acpi_sel);
+   temperature_config->acpi_sel = NULL;
+   int n = 0;
+   Ecore_List *therms;
+   char *tzone;
+   therms = ecore_file_ls("/proc/acpi/thermal_zone");
+   if ((therms) || !ecore_list_is_empty(therms))
+     {
+       while ((tzone = ecore_list_next(therms)))
+         {
+	   if (n == cfdata->acpizone)
+	     temperature_config->acpi_sel = evas_stringshare_add(tzone);
+	   n++;
+	 }
+     } 
+   ecore_list_destroy(therms);  
    _temperature_face_cb_config_updated();
    e_config_save_queue();
    return 1;
Index: e_mod_main.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/modules/temperature/e_mod_main.c,v
retrieving revision 1.70
diff -u -p -r1.70 e_mod_main.c
--- e_mod_main.c	18 Sep 2006 03:49:45 -0000	1.70
+++ e_mod_main.c	18 Oct 2006 18:06:33 -0000
@@ -276,7 +276,7 @@ _temperature_cb_check(void *data)
 	  {
 	     char *p, *q;
 	     FILE *f;
-
+	     name = temperature_config->acpi_sel;
 	     snprintf(buf, sizeof(buf), "/proc/acpi/thermal_zone/%s/temperature", name);
 	     f = fopen(buf, "rb");
 	     if (f)
@@ -403,6 +403,7 @@ e_modapi_init(E_Module *m)
    E_CONFIG_VAL(D, T, high, INT);
    E_CONFIG_VAL(D, T, sensor_name, STR);
    E_CONFIG_VAL(D, T, units, INT);
+   E_CONFIG_VAL(D, T, acpi_sel, STR);
 
    temperature_config = e_config_domain_load("module.temperature", conf_edd);
    if (!temperature_config)
@@ -413,6 +414,7 @@ e_modapi_init(E_Module *m)
 	temperature_config->high = 80;
 	temperature_config->sensor_name = evas_stringshare_add("temp1");
 	temperature_config->units = CELCIUS;
+	temperature_config->acpi_sel = evas_stringshare_add("TZ1");
      }
    E_CONFIG_LIMIT(temperature_config->poll_time, 0.5, 1000.0);
    E_CONFIG_LIMIT(temperature_config->low, 0, 100);
Index: e_mod_main.h
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/modules/temperature/e_mod_main.h,v
retrieving revision 1.23
diff -u -p -r1.23 e_mod_main.h
--- e_mod_main.h	6 Jun 2006 15:25:13 -0000	1.23
+++ e_mod_main.h	18 Oct 2006 18:06:33 -0000
@@ -18,6 +18,7 @@ struct _Config
    double           poll_time;
    int              low, high;
    const char      *sensor_name;
+   const char	   *acpi_sel;
    Unit             units;
    /* just config state */
    E_Module        *module;