This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository enlightenment.

View the commit online.

commit c46ec7794fac83cce068a5a2686501327175947e
Author: Carsten Haitzler <ras...@rasterman.com>
AuthorDate: Sun Nov 10 21:14:59 2024 +0000

    battery - addd lots of extra popup info including graphs
---
 src/modules/battery/batget.c       |  30 ++---
 src/modules/battery/e_mod_main.c   | 243 ++++++++++++++++++++++++++++++++++---
 src/modules/battery/e_mod_main.h   |  18 +++
 src/modules/battery/e_mod_sysctl.c |   6 +-
 src/modules/battery/e_mod_udev.c   |  54 ++++++++-
 src/modules/battery/e_mod_upower.c |   8 +-
 6 files changed, 314 insertions(+), 45 deletions(-)

diff --git a/src/modules/battery/batget.c b/src/modules/battery/batget.c
index f94fb3788..f36ae7fce 100644
--- a/src/modules/battery/batget.c
+++ b/src/modules/battery/batget.c
@@ -209,7 +209,7 @@ darwin_check(void)
    values = CFDictionaryGetValue(device_dict, CFSTR(kIOPSMaxCapacityKey));
    CFNumberGetValue(values, kCFNumberSInt32Type, &maxval);
    /* Calculate the percentage charged. */
-   battery_full = (currentval * 100) / maxval;
+   battery_full = (currentval * 10000) / maxval;
 
    /* Retrieve the remaining battery power or time until charged in minutes. */
    if (!have_power)
@@ -638,7 +638,7 @@ linux_sys_class_power_supply_check(void)
                   else
                     {
                        if (pwr_now < 0)
-                         pwr_now = (((long long)capacity * ((long long)pwr_full - (long long)pwr_empty)) / 100) + pwr_empty;
+                         pwr_now = (((long long)capacity * ((long long)pwr_full - (long long)pwr_empty)) / 10000) + pwr_empty;
                     }
 
                   if (sysev->present) have_battery = 1;
@@ -686,13 +686,13 @@ linux_sys_class_power_supply_check(void)
                {
                   if (sysev->present) have_battery = 1;
                   if (charging) have_power = 1;
-                  total_pwr_max = 100;
+                  total_pwr_max = 10000;
                   total_pwr_now = capacity;
-                  if (total_pwr_now < 100) nofull = 1;
+                  if (total_pwr_now < 10000) nofull = 1;
                }
           }
         if (total_pwr_max > 0)
-          battery_full = ((long long)total_pwr_now * 100) / total_pwr_max;
+          battery_full = ((long long)total_pwr_now * 10000) / total_pwr_max;
         if (nofull == 0)
           time_left = -1;
      }
@@ -972,9 +972,9 @@ fclose_and_continue:
           }
 
         if (acpi_max_full > 0)
-          battery_full = 100 * (long long)capacity / acpi_max_full;
+          battery_full = 10000 * (long long)capacity / acpi_max_full;
         else if (acpi_max_design > 0)
-          battery_full = 100 * (long long)capacity / acpi_max_design;
+          battery_full = 10000 * (long long)capacity / acpi_max_design;
         else
           battery_full = -1;
         if (rate <= 0) time_left = -1;
@@ -1037,7 +1037,7 @@ linux_apm_check(void)
      {
         have_battery = 0;
         have_power = 0;
-        battery_full = 100;
+        battery_full = 10000;
         time_left = 0;
         return;
      }
@@ -1046,8 +1046,8 @@ linux_apm_check(void)
      {
         have_battery = 1;
         have_power = ac_stat;
-        battery_full = bat_val;
-        if (battery_full > 100) battery_full = 100;
+        battery_full = bat_val * 100;
+        if (battery_full > 10000) battery_full = 10000;
         if (ac_stat == 1) time_left = -1;
         else time_left = time_val;
      }
@@ -1058,28 +1058,28 @@ linux_apm_check(void)
            case 0: /* high */
              have_battery = 1;
              have_power = ac_stat;
-             battery_full = 100;
+             battery_full = 10000;
              time_left = -1;
              break;
 
            case 1: /* medium */
              have_battery = 1;
              have_power = ac_stat;
-             battery_full = 50;
+             battery_full = 5000;
              time_left = -1;
              break;
 
            case 2: /* low */
              have_battery = 1;
              have_power = ac_stat;
-             battery_full = 25;
+             battery_full = 2500;
              time_left = -1;
              break;
 
            case 3: /* charging */
              have_battery = 1;
              have_power = ac_stat;
-             battery_full = 100;
+             battery_full = 10000;
              time_left = -1;
              break;
           }
@@ -1195,7 +1195,7 @@ fclose_and_continue:
 
              free(name);
           }
-        if (max_charge > 0) battery_full = ((long long)charge * 100) / max_charge;
+        if (max_charge > 0) battery_full = ((long long)charge * 10000) / max_charge;
         else battery_full = 0;
         time_left = seconds;
      }
diff --git a/src/modules/battery/e_mod_main.c b/src/modules/battery/e_mod_main.c
index b00dacc6c..d3834bb05 100644
--- a/src/modules/battery/e_mod_main.c
+++ b/src/modules/battery/e_mod_main.c
@@ -36,6 +36,14 @@ typedef struct __Popup_Widgets
    Evas_Object *remaining;
    Evas_Object *health;
    Evas_Object *technology;
+
+   Evas_Object *drain;
+   Evas_Object *full;
+   Evas_Object *power;
+
+   Evas_Object *gr_bat;
+   Evas_Object *gr_pow;
+//   Evas_Object *gr_crg;
 } _Popup_Widgets;
 
 typedef struct __Popup_Data
@@ -186,6 +194,60 @@ _gc_id_new(const E_Gadcon_Client_Class *client_class)
    return buf;
 }
 
+static inline const Battery_Hist *
+_battery_history_get(const Battery *bat, int age)
+{
+// should not have to check
+//  if (age >= BATTERY_HIST_MAX) return NULL;
+  int pos = (bat->history_pos + age) % BATTERY_HIST_MAX;
+  return &(bat->history[pos]);
+}
+
+static void
+_battery_history_store(Battery *bat, unsigned long long tim, int full, int mwatts, Eina_Bool ac, Eina_Bool charging)
+{
+  // last timepoint
+  unsigned long long tprev = bat->history[bat->history_pos].timepoint;
+
+  // 30 sec resoolution
+  if ((tim - tprev) < 10) return;
+  // bump pos with wrap-around
+  bat->history_pos = (bat->history_pos + BATTERY_HIST_MAX - 1) % BATTERY_HIST_MAX;
+  // store time and values
+  bat->history[bat->history_pos].timepoint = tim;
+  bat->history[bat->history_pos].full = full;
+  mwatts /= 100000;
+  if (mwatts > 16383) mwatts = 16383;
+  bat->history[bat->history_pos].power_now = mwatts;
+  bat->history[bat->history_pos].ac = ac;
+  bat->history[bat->history_pos].charging = charging;
+  if (bat->history[bat->history_pos].power_now > bat->history_power_now_max)
+    bat->history_power_now_max = bat->history[bat->history_pos].power_now;
+}
+
+static double
+_battery_wattage_get(Battery *bat, unsigned long long timeperiod)
+{
+  int i = 0;
+  const Battery_Hist *h0, *h1;
+  int diff;
+
+  h0 = _battery_history_get(bat, i);
+  if ((!h0) || (h0->timepoint == 0)) return -1.0;
+  for (;;)
+    {
+      i++;
+      h1 = _battery_history_get(bat, i);
+      if ((!h1) || (h1->timepoint == 0)) return -1.0;
+      if ((h0->timepoint - h1->timepoint) >= timeperiod) break;
+    }
+  diff = h0->full - h1->full;
+  if (diff < 0) diff = -diff;
+  return
+    (double)(bat->last_full_charge * diff * 3600) /
+    (10000.0 * 1000000.0 * (double)timeperiod);
+}
+
 static void
 _battery_popup_usage_destroy(Instance *inst)
 {
@@ -228,14 +290,14 @@ _battery_popup_usage_content_update_cb(void *data)
      {
         _Popup_Widgets *w = &pd->widgets[i++];
 
-        elm_progressbar_value_set(w->pb_usage, (double) bat->percent / 100.0);
+        elm_progressbar_value_set(w->pb_usage, (double) bat->percent / 10000.0);
 
         t = bat->time_left;
-        if ((battery_config->have_power) && (battery_config->full < 100))
+        if ((battery_config->have_power) && (battery_config->full < 10000))
           {
              elm_object_text_set(w->state, _("Charging"));
           }
-        else if ((!battery_config->have_power) && (battery_config->full < 100))
+        else if ((!battery_config->have_power) && (battery_config->full < 10000))
           {
              elm_object_text_set(w->state, _("Discharging"));
           }
@@ -263,6 +325,87 @@ _battery_popup_usage_content_update_cb(void *data)
           elm_object_text_set(w->technology, bat->technology);
         else
           elm_object_text_set(w->technology, _("Unknown"));
+
+        if (bat->is_micro_watts)
+          {
+            // over the past 5 mins
+            double watts = _battery_wattage_get(bat, 60);
+
+            if (watts >= 0.0)
+              {
+                snprintf(buf, sizeof(buf), "%1.2fW", watts);
+                elm_object_text_set(w->drain, buf);
+              }
+            else
+              elm_object_text_set(w->drain, _("Unknown"));
+          }
+        else
+          elm_object_text_set(w->drain, _("Unknown"));
+
+        if (bat->is_micro_watts)
+          {
+            double wh = (double)bat->last_full_charge / 1000000.0;
+            snprintf(buf, sizeof(buf), "%1.2fWh", wh);
+            elm_object_text_set(w->full, buf);
+          }
+        else
+          elm_object_text_set(w->full, _("Unknown"));
+
+        if (bat->is_micro_watts)
+          {
+            double watt = (double)bat->power_now / 1000000.0;
+            snprintf(buf, sizeof(buf), "%1.2fW", watt);
+            elm_object_text_set(w->power, buf);
+          }
+        else
+          elm_object_text_set(w->power, _("Unknown"));
+
+         {
+           int *v_full, *v_pow, age;
+           unsigned int vals_num;
+           const Battery_Hist *bh;
+           unsigned long long time_now = time(NULL), td, tp;
+           int full_tot, pow_tot, tot;
+
+           e_graph_colorspec_set(w->gr_pow, "cc::selected-alt");
+           e_graph_colorspec_set(w->gr_bat, "cc::selected");
+           vals_num = 50;
+           v_full = calloc(vals_num, sizeof(int));
+           v_pow = calloc(vals_num, sizeof(int));
+           if ((v_full) && (v_pow))
+             {
+               age = 0;
+               tp = 120;
+               for (i = 0; i < vals_num; i++)
+                 {
+                   full_tot = pow_tot = tot = 0;
+                   for (;;)
+                     {
+                       bh = _battery_history_get(bat, age);
+                       if (!bh) break;
+                       td = time_now - bh->timepoint;
+                       if (td < tp)
+                         {
+                           full_tot += bh->full;
+                           pow_tot += bh->power_now;
+                           tot++;
+                           age++;
+                         }
+                       else break;
+                     }
+                   if (tot > 0)
+                     {
+                       v_pow[vals_num - i - 1] = pow_tot / tot;
+                       v_full[vals_num - i - 1] = full_tot / tot;
+                     }
+                   tp += 120; // 1 val == 120 sec
+                 }
+               e_graph_values_set(w->gr_pow, vals_num, v_pow, 0, bat->history_power_now_max);
+               e_graph_values_set(w->gr_bat, vals_num, v_full, 0, 10000);
+             }
+           free(v_full);
+           free(v_pow);
+        }
         if (i == (pd->n_units - 1)) break;
      }
    return ECORE_CALLBACK_RENEW;
@@ -308,7 +451,7 @@ _content_get(void *data, Evas_Object *obj, const char *part)
    o = evas_object_rectangle_add(evas_object_evas_get(obj));
    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
    evas_object_size_hint_weight_set(o, 1.0, 0);
-   evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(220), ELM_SCALE_SIZE(20));
+   evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(280), ELM_SCALE_SIZE(20));
    elm_table_pack(tb, o, 0, 0, 8, 1);
 
    w->pb_usage = o = elm_progressbar_add(obj);
@@ -370,6 +513,63 @@ _content_get(void *data, Evas_Object *obj, const char *part)
    elm_table_pack(tb, o, 7, 1, 1, 1);
    evas_object_show(o);
 
+   o = elm_icon_add(obj);
+   elm_icon_standard_set(o, "battery-good-charging");
+   evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(20), ELM_SCALE_SIZE(20));
+   elm_table_pack(tb, o, 0, 2, 1, 1);
+   evas_object_show(o);
+
+   w->drain = o = elm_label_add(obj);
+   evas_object_size_hint_align_set(o, 0.0, 0.5);
+   evas_object_size_hint_weight_set(o, 1.0, 0);
+   elm_table_pack(tb, o, 1, 2, 1, 1);
+   evas_object_show(o);
+
+   o = elm_icon_add(obj);
+   elm_icon_standard_set(o, "battery-full");
+   evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(20), ELM_SCALE_SIZE(20));
+   elm_table_pack(tb, o, 2, 2, 1, 1);
+   evas_object_show(o);
+
+   w->full = o = elm_label_add(obj);
+   evas_object_size_hint_align_set(o, 0.0, 0.5);
+   evas_object_size_hint_weight_set(o, 1.0, 0);
+   elm_table_pack(tb, o, 3, 2, 1, 1);
+   evas_object_show(o);
+
+   o = elm_icon_add(obj);
+   elm_icon_standard_set(o, "battery-empty-charging");
+   evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(20), ELM_SCALE_SIZE(20));
+   elm_table_pack(tb, o, 4, 2, 1, 1);
+   evas_object_show(o);
+
+   w->power = o = elm_label_add(obj);
+   evas_object_size_hint_align_set(o, 0.0, 0.5);
+   evas_object_size_hint_weight_set(o, 1.0, 0);
+   elm_table_pack(tb, o, 5, 2, 1, 1);
+   evas_object_show(o);
+
+   w->gr_bat = o = e_graph_add(obj);
+   evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_size_hint_weight_set(o, 1.0, 0.0);
+   evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(80), ELM_SCALE_SIZE(40));
+   elm_table_pack(tb, o, 0, 3, 8, 1);
+   evas_object_show(o);
+
+   w->gr_pow = o = e_graph_add(obj);
+   evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(80), ELM_SCALE_SIZE(40));
+   elm_table_pack(tb, o, 0, 4, 8, 1);
+   evas_object_show(o);
+
+/*
+   w->gr_crg = o = e_graph_add(obj);
+   evas_object_size_hint_align_set(o, -1.0, -1.0);
+   evas_object_size_hint_weight_set(o, 1.0,  1.0);
+   evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(80), ELM_SCALE_SIZE(80));
+   elm_table_pack(tb, o, 0, 3, 8, 1);
+   evas_object_show(o);
+ */
    return tb;
 }
 
@@ -400,7 +600,7 @@ _battery_popup_usage_new(Instance *inst)
    evas_object_show(tb);
 
    rec = evas_object_rectangle_add(evas_object_evas_get(base));
-   evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(360), ELM_SCALE_SIZE(160));
+   evas_object_size_hint_min_set(rec, ELM_SCALE_SIZE(320), ELM_SCALE_SIZE(220));
    evas_object_size_hint_max_set(rec, ELM_SCALE_SIZE(560), ELM_SCALE_SIZE(400));
    elm_table_pack(tb, rec, 0, 0, 1, 1);
 
@@ -589,9 +789,9 @@ _battery_device_update(void)
    int have_battery = 0;
    int have_power = 0;
    int charging = 0;
-
    int batnum = 0;
    int acnum = 0;
+   unsigned long long tim = time(NULL);
 
    EINA_LIST_FOREACH(device_ac_adapters, l, ac)
      {
@@ -613,9 +813,9 @@ _battery_device_update(void)
         if (bat->percent >= 0)
           full += bat->percent;
         else if (bat->last_full_charge > 0)
-          full += (bat->current_charge * 100) / bat->last_full_charge;
+          full += (bat->current_charge * 10000) / bat->last_full_charge;
         else if (bat->design_charge > 0)
-          full += (bat->current_charge * 100) / bat->design_charge;
+          full += (bat->current_charge * 10000) / bat->design_charge;
         if (bat->time_left > 0)
           {
              if (time_left < 0) time_left = bat->time_left;
@@ -627,13 +827,16 @@ _battery_device_update(void)
              else time_full += bat->time_full;
           }
         charging += bat->charging;
+        _battery_history_store(bat, tim,
+                               full, bat->power_now,
+                               have_power, bat->charging);
      }
 
    if ((device_batteries) && (batnum == 0))
      return;  /* not ready yet, no properties received for any battery */
 
    if (batnum > 0) full /= batnum;
-   if ((full == 100) && have_power)
+   if ((full == 10000) && have_power)
      {
         time_left = -1;
         time_full = -1;
@@ -845,7 +1048,7 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
                edje_object_signal_emit(inst->o_battery, "e,state,ac,on", "e");
              else
                edje_object_signal_emit(inst->o_battery, "e,state,ac,off", "e");
-             if (have_power && (full < 100))
+             if (have_power && (full < 10000))
                {
                   edje_object_signal_emit(inst->o_battery, "e,state,charging", "e");
                   if (inst->popup_battery)
@@ -864,8 +1067,8 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
                {
                   double val;
 
-                  if (full >= 100) val = 1.0;
-                  else val = (double)full / 100.0;
+                  if (full >= 10000) val = 1.0;
+                  else val = (double)full / 10000.0;
                   _battery_face_level_set(inst->o_battery, val);
                   if (inst->popup_battery)
                     _battery_face_level_set(inst->popup_battery, val);
@@ -898,7 +1101,7 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
           }
         if (have_battery &&
             (!have_power) &&
-            (full < 100) &&
+            (full < 10000) &&
             (
               (
                 (time_left > 0) &&
@@ -917,7 +1120,7 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
              printf("-------------------------------------- bat warn .. why below\n");
              printf("have_battery = %i\n", (int)have_battery);
              printf("have_power = %i\n", (int)have_power);
-             printf("full = %i\n", (int)full);
+             printf("full = %i\n", (int)full / 100);
              printf("time_left = %i\n", (int)time_left);
              printf("battery_config->alert = %i\n", (int)battery_config->alert);
              printf("battery_config->alert_p = %i\n", (int)battery_config->alert_p);
@@ -926,17 +1129,17 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
                {
                   printf("t-debounce = %3.3f\n", (t - debounce_time));
                   debounce_time = t;
-                  if (((t - init_time) > 5.0) && (full < 15))
-                    _battery_warning_popup(inst, time_left, (double)full / 100.0);
+                  if (((t - init_time) > 5.0) && (full < 1500))
+                    _battery_warning_popup(inst, time_left, (double)full / 10000.0);
                }
           }
         else if (have_power || ((time_left / 60) > battery_config->alert))
           _battery_warning_popup_destroy(inst);
         if ((have_battery) && (!have_power) && (full >= 0) &&
             (battery_config->suspend_below > 0) &&
-            (full < battery_config->suspend_below))
+            (full < battery_config->suspend_below / 100))
           {
-             printf("battery %i suspend below %i\n", full, battery_config->suspend_below);
+             printf("battery %i suspend below %i\n", full / 100, battery_config->suspend_below);
              if (battery_config->suspend_method == SUSPEND)
                e_sys_action_do(E_SYS_SUSPEND_MODE, NULL);
              else if (battery_config->suspend_method == HIBERNATE)
@@ -951,9 +1154,9 @@ _battery_update(int full, int time_left, int time_full, Eina_Bool have_battery,
      {
         if (have_power)
           e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
-        else if (full > 95)
+        else if (full > 9500)
           e_powersave_mode_set(E_POWERSAVE_MODE_MEDIUM);
-        else if (full > 30)
+        else if (full > 3000)
           e_powersave_mode_set(E_POWERSAVE_MODE_HIGH);
         else
           e_powersave_mode_set(E_POWERSAVE_MODE_EXTREME);
diff --git a/src/modules/battery/e_mod_main.h b/src/modules/battery/e_mod_main.h
index 0549b2f1a..582b008d2 100644
--- a/src/modules/battery/e_mod_main.h
+++ b/src/modules/battery/e_mod_main.h
@@ -61,6 +61,18 @@ struct _Config
 
 typedef struct _Battery Battery;
 typedef struct _Ac_Adapter Ac_Adapter;
+typedef struct _Battery_Hist Battery_Hist;
+typedef struct _Battery_Hist_Other Battery_Hist_Other;
+
+#define BATTERY_HIST_MAX 1000
+struct _Battery_Hist
+{
+  unsigned long long timepoint  : 34; // time_t - but only 34 bits -> 1970 + 544 = ~2500
+  unsigned long long full       : 14; // 0-10000 = 0->100%
+  unsigned long long power_now  : 14; // 0-16383 = 1unit = 0.1w 
+  unsigned long long ac         : 1;
+  unsigned long long charging   : 1;
+};
 
 struct _Battery
 {
@@ -69,11 +81,14 @@ struct _Battery
    Ecore_Poller *poll;
    Eina_Bool     present E_BITFIELD;
    Eina_Bool     charging E_BITFIELD;
+   Eina_Bool     is_micro_watts E_BITFIELD;
    double        last_update;
    double        percent;
+   double        power_now;
    double        current_charge;
    double        design_charge;
    double        last_full_charge;
+   double        design_voltage;
    double        charge_rate;
    double        time_full;
    double        time_left;
@@ -91,6 +106,9 @@ struct _Battery
    const char   *technology;
    const char   *model;
    const char   *vendor;
+   Battery_Hist  history[BATTERY_HIST_MAX];
+   int           history_pos;
+   int           history_power_now_max;
    Eina_Bool     got_prop E_BITFIELD;
    Eldbus_Proxy *proxy;
 #if defined __FreeBSD__ || defined __DragonFly__
diff --git a/src/modules/battery/e_mod_sysctl.c b/src/modules/battery/e_mod_sysctl.c
index 738b6ef3c..ba0ec65ed 100644
--- a/src/modules/battery/e_mod_sysctl.c
+++ b/src/modules/battery/e_mod_sysctl.c
@@ -237,9 +237,9 @@ _battery_sysctl_battery_update(Battery *bat)
          bat->charge_rate = ((charge - bat->current_charge) / (_time - bat->last_update));
        bat->last_update = _time;
        bat->current_charge = charge;
-       bat->percent = 100 * (bat->current_charge / bat->last_full_charge);
+       bat->percent = (10000 * bat->current_charge) / bat->last_full_charge;
        if (bat->current_charge >= bat->last_full_charge)
-         bat->percent = 100;
+         bat->percent = 10000;
 
        if (bat->got_prop)
          {
@@ -289,7 +289,7 @@ _battery_sysctl_battery_update(Battery *bat)
          }
        bat->got_prop = 1;
 
-       bat->percent = battio.battinfo.cap;
+       bat->percent = battio.battinfo.cap * 100;
        _time = ecore_time_get();
        bat->last_update = _time;
 
diff --git a/src/modules/battery/e_mod_udev.c b/src/modules/battery/e_mod_udev.c
index e43b20521..aa58d7bef 100644
--- a/src/modules/battery/e_mod_udev.c
+++ b/src/modules/battery/e_mod_udev.c
@@ -98,6 +98,7 @@ _battery_udev_battery_add(const char *syspath)
    Battery *bat;
    const char *type, *test;
    double full_design = 0.0;
+   double voltage_min_design = 0.0;
    double full = 0.0;
 
    if ((bat = _battery_battery_find(syspath)))
@@ -134,7 +135,12 @@ _battery_udev_battery_add(const char *syspath)
 
    test = eeze_udev_syspath_get_property(syspath, "POWER_SUPPLY_ENERGY_FULL");
    if (!test)
-     test = eeze_udev_syspath_get_property(syspath, "POWER_SUPPLY_CHARGE_FULL");
+    {
+      test = eeze_udev_syspath_get_property(syspath, "POWER_SUPPLY_VOLTAGE_MIN_DESIGN");
+      if (test)
+        voltage_min_design = strtod(test, NULL);
+      test = eeze_udev_syspath_get_property(syspath, "POWER_SUPPLY_CHARGE_FULL");
+    }
    if (test)
     {
       full = strtod(test, NULL);
@@ -152,6 +158,7 @@ _battery_udev_battery_add(const char *syspath)
         eina_stringshare_del(syspath);
         return;
      }
+   bat->design_voltage = voltage_min_design;
    bat->last_update = ecore_time_get();
    bat->udi = eina_stringshare_add(syspath);
    bat->poll = ecore_poller_add(ECORE_POLLER_CORE,
@@ -268,11 +275,44 @@ _battery_udev_battery_update(const char *syspath, Battery *bat)
         GET_STR(bat, vendor, POWER_SUPPLY_MANUFACTURER);
         GET_NUM(bat, design_charge, POWER_SUPPLY_ENERGY_FULL_DESIGN);
         if (eina_dbl_exact(bat->design_charge, 0))
-          GET_NUM(bat, design_charge, POWER_SUPPLY_CHARGE_FULL_DESIGN);
+         {
+           GET_NUM(bat, design_charge, POWER_SUPPLY_CHARGE_FULL_DESIGN);
+           if (bat->design_voltage > 0.0)
+             {
+               bat->design_charge = bat->design_charge * bat->design_voltage / 1000000.0;
+               bat->is_micro_watts = EINA_TRUE;
+             }
+         }
+     }
+   bat->power_now = 0;
+   GET_NUM(bat, power_now, POWER_SUPPLY_POWER_NOW);
+   if (eina_dbl_exact(bat->power_now, 0))
+     {
+       test = eeze_udev_syspath_get_property(bat->udi, "POWER_SUPPLY_CURRENT_NOW");
+       if (test)
+         {
+           double current_now = strtod(test, NULL);
+
+           test = eeze_udev_syspath_get_property(bat->udi, "POWER_SUPPLY_VOLTAGE_NOW");
+           if (test)
+             {
+               double voltage_now = strtod(test, NULL);
+               bat->power_now = current_now * voltage_now / 1000000.0;
+             }
+         }
      }
    GET_NUM(bat, last_full_charge, POWER_SUPPLY_ENERGY_FULL);
    if (eina_dbl_exact(bat->last_full_charge, 0))
-     GET_NUM(bat, last_full_charge, POWER_SUPPLY_CHARGE_FULL);
+     {
+       GET_NUM(bat, last_full_charge, POWER_SUPPLY_CHARGE_FULL);
+       if (bat->design_voltage > 0.0)
+         {
+           bat->last_full_charge = bat->last_full_charge * bat->design_voltage / 1000000.0;
+           bat->is_micro_watts = EINA_TRUE;
+         }
+     }
+   else
+     bat->is_micro_watts = EINA_TRUE;
    test = eeze_udev_syspath_get_property(bat->udi, "POWER_SUPPLY_ENERGY_NOW");
    if (!test)
      test = eeze_udev_syspath_get_property(bat->udi, "POWER_SUPPLY_CHARGE_NOW");
@@ -280,8 +320,8 @@ _battery_udev_battery_update(const char *syspath, Battery *bat)
      {
         if (eina_dbl_exact(bat->last_full_charge, 0))
           {
-             bat->last_full_charge = 100;
-             bat->design_charge = 100;
+             bat->last_full_charge = 10000;
+             bat->design_charge = 10000;
           }
         test = eeze_udev_syspath_get_property(bat->udi, "POWER_SUPPLY_CAPACITY");
      }
@@ -290,6 +330,8 @@ _battery_udev_battery_update(const char *syspath, Battery *bat)
         double charge_rate = 0;
 
         charge = strtod(test, NULL);
+        if (bat->design_voltage > 0.0)
+           charge = charge * bat->design_voltage / 1000000.0;
         eina_stringshare_del(test);
         t = ecore_time_get();
         if ((bat->got_prop) &&
@@ -305,7 +347,7 @@ _battery_udev_battery_update(const char *syspath, Battery *bat)
              bat->current_charge = charge;
              bat->charge_rate = charge_rate;
           }
-        bat->percent = (100 * bat->current_charge) / bat->last_full_charge;
+        bat->percent = (10000 * bat->current_charge) / bat->last_full_charge;
         if (bat->got_prop)
           {
              if (bat->charge_rate > 0)
diff --git a/src/modules/battery/e_mod_upower.c b/src/modules/battery/e_mod_upower.c
index ad0b933e1..805bb8297 100644
--- a/src/modules/battery/e_mod_upower.c
+++ b/src/modules/battery/e_mod_upower.c
@@ -149,12 +149,13 @@ _bat_get_all_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending E
         else if (!strcmp(key, "Percentage"))
           {
              eldbus_message_iter_arguments_get(variant, "d", &val.d);
-             bat->percent = (int) val.d;
+             bat->percent = (int) (val.d * 100.0); // 0->10000
           }
         else if (!strcmp(key, "Energy"))
           {
              eldbus_message_iter_arguments_get(variant, "d", &val.d);
              bat->current_charge = (int) val.d;
+             bat->is_micro_watts = EINA_TRUE;
           }
         else if (!strcmp(key, "EnergyFullDesign"))
           {
@@ -166,6 +167,11 @@ _bat_get_all_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending E
              eldbus_message_iter_arguments_get(variant, "d", &val.d);
              bat->last_full_charge = (int) val.d;
           }
+        else if (!strcmp(key, "EnergyRate"))
+          {
+             eldbus_message_iter_arguments_get(variant, "d", &val.d);
+             bat->power_now = (int) val.d;
+          }
         else if (!strcmp(key, "TimeToFull"))
           {
              eldbus_message_iter_arguments_get(variant, "x", &val.i64);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to