Re: battstat applet



Hi,

After searching i finaly make it.
Here is a patch, that add info about battery voltage, current and power
in Watts to the applet tooltip.

It is posible to add this patch to the next release of this applet?

This is my first patch. Sorry if it is bad :-( I will be very happy if
you can send me some sugestions to improve it :).

I don't no if i must change the Changelog file or it is done by you.

Thank you for you reply.
Have a nice day
Bc. Miroslav Duschek
diff -aur battstat/acpi-linux.c gnome-applets-2.20.0-rd/battstat/acpi-linux.c
--- battstat/acpi-linux.c	2007-07-28 04:02:48.000000000 +0200
+++ battstat/acpi-linux.c	2008-02-09 12:10:25.000000000 +0100
@@ -358,6 +358,7 @@
 {
   guint32 remain;
   guint32 rate;
+  guint32 voltage;
   gboolean charging;
   GHashTable *hash;
   char batt_state[60];
@@ -379,6 +380,7 @@
   charging = FALSE;
   remain = 0;
   rate = 0;
+  voltage = 0;
 
   procdir=opendir("/proc/acpi/battery/");
   if (!procdir)
@@ -406,6 +408,7 @@
          }
         remain += read_long (hash, "remaining capacity");
 	rate += read_long (hash, "present rate");
+	voltage += read_long (hash, "present voltage");
         g_hash_table_destroy (hash);
        }
      }
@@ -414,6 +417,8 @@
 
   apminfo->ac_line_status = acpiinfo->ac_online ? 1 : 0;
   apminfo->battery_status = remain < acpiinfo->low_capacity ? 1 : remain < acpiinfo->critical_capacity ? 2 : 0;
+  apminfo->voltage = voltage;
+  apminfo->rate = rate;
   if (!acpiinfo->max_capacity)
     apminfo->battery_percentage = -1;
   else
diff -aur battstat/apmlib/apm.h gnome-applets-2.20.0-rd/battstat/apmlib/apm.h
--- battstat/apmlib/apm.h	2007-07-28 04:02:48.000000000 +0200
+++ battstat/apmlib/apm.h	2008-02-09 12:19:33.000000000 +0100
@@ -45,6 +45,8 @@
     int battery_percentage;
     int battery_time;
     int using_minutes;
+    int voltage;
+    int rate;
 }
 apm_info;
 
diff -aur battstat/battstat.h gnome-applets-2.20.0-rd/battstat/battstat.h
--- battstat/battstat.h	2007-07-28 04:02:48.000000000 +0200
+++ battstat/battstat.h	2008-02-09 12:19:31.000000000 +0100
@@ -61,6 +61,8 @@
   gboolean present;
   gint minutes;
   gint percent;
+  gint voltage;
+  gint rate;
 } BatteryStatus;
 
 typedef enum
diff -aur battstat/battstat_applet.c gnome-applets-2.20.0-rd/battstat/battstat_applet.c
--- battstat/battstat_applet.c	2007-07-28 04:02:48.000000000 +0200
+++ battstat/battstat_applet.c	2008-02-09 12:34:42.000000000 +0100
@@ -372,6 +372,7 @@
 
 	hours = info->minutes / 60;
 	mins = info->minutes % 60;
+	
 
 	if (info->on_ac_power && !info->charging)
 		return g_strdup_printf (_("Battery charged (%d%%)"), info->percent);
@@ -419,6 +420,7 @@
 						info->percent);
 }
 
+
 static gboolean
 battery_full_notify (GtkWidget *applet)
 {
@@ -688,6 +690,7 @@
   gchar *powerstring;
   gchar *remaining;
   gchar *tiptext;
+  double power;
 
   if (info->present)
   {
@@ -697,8 +700,8 @@
       powerstring = DC_POWER_STRING;
 
     remaining = get_remaining (info);
-
-    tiptext = g_strdup_printf ("%s\n%s", powerstring, remaining);
+    power=(double)(((double)(info->voltage))*((double)(info->rate))/1000000.0);
+    tiptext = g_strdup_printf ("%s\n%s\nVoltage: %d mV\nCurrent: %d mA\nPower: %f W", powerstring, remaining, info->voltage, info->rate,power);
     g_free (remaining);
   }
   else
diff -aur battstat/power-management.c gnome-applets-2.20.0-rd/battstat/power-management.c
--- battstat/power-management.c	2007-07-28 04:02:48.000000000 +0200
+++ battstat/power-management.c	2008-02-09 12:10:43.000000000 +0100
@@ -340,6 +340,8 @@
   status->percent = (guint) apminfo.battery_percentage;
   status->charging = (apminfo.battery_flags & 0x8) ? TRUE : FALSE;
   status->minutes = apminfo.battery_time;
+  status->voltage = apminfo.voltage;
+  status->rate = apminfo.rate;
 
   return NULL;
 }


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