Advertisement
Guest User

lxpanel battery patch for teres 1

a guest
Nov 9th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.00 KB | None | 0 0
  1. diff -ur lxpanel-0.9.3/plugins/batt/batt_sys.c lxpanel-0.9.3-r1/plugins/batt/batt_sys.c
  2. --- lxpanel-0.9.3/plugins/batt/batt_sys.c   2017-01-20 21:34:34.000000000 +0000
  3. +++ lxpanel-0.9.3-r1/plugins/batt/batt_sys.c    2017-11-09 11:10:21.820000980 +0000
  4. @@ -45,7 +45,10 @@
  5.      //b->capacity_unit = "mAh";
  6.      b->energy_full = -1;
  7.      b->charge_full = -1;
  8. +    b->capacity = -1;
  9.      b->voltage_now = -1;
  10. +    b->voltage_min_design = -1;
  11. +    b->voltage_max_design = -1;
  12.      b->energy_full_design = -1;
  13.      b->charge_full_design = -1;
  14.      b->energy_now = -1;
  15. @@ -94,6 +97,22 @@
  16.      return value;
  17.  }
  18.  
  19. +/* get_gint_1000_from_infofile():
  20. + *         If the sys_file exists, then its value is converted to an int,
  21. + *         NOT divided by 1000, and returned.
  22. + *         Failure is indicated by returning -1. */
  23. +static gint get_gint_1000_from_infofile(battery *b, gchar *sys_file)
  24. +{
  25. +    gchar *file_content = parse_info_file(b, sys_file);
  26. +    gint value = -1;
  27. +
  28. +    if (file_content != NULL)
  29. +        value = atoi(file_content);
  30. +    g_free(file_content);
  31. +
  32. +    return value;
  33. +}
  34. +
  35.  static gchar* get_gchar_from_infofile(battery *b, gchar *sys_file)
  36.  {
  37.      return parse_info_file(b, sys_file);
  38. @@ -196,6 +215,10 @@
  39.      b->energy_full_design = get_gint_from_infofile(b, "energy_full_design");
  40.  
  41.      b->voltage_now = get_gint_from_infofile(b, "voltage_now");
  42. +    b->voltage_min_design = get_gint_from_infofile(b, "voltage_min_design");
  43. +    b->voltage_max_design = get_gint_from_infofile(b, "voltage_max_design");
  44. +    
  45. +    b->capacity = get_gint_1000_from_infofile(b, "capacity");
  46.  
  47.      gctmp = get_gchar_from_infofile(b, "type");
  48.      b->type_battery = gctmp ? (strcasecmp(gctmp, "battery") == 0) : TRUE;
  49. @@ -259,6 +282,14 @@
  50.      else if (b->energy_full != -1 && b->energy_now != -1)
  51.          /* no charge data, let try energy instead */
  52.          promille = (b->energy_now * 1000) / b->energy_full;
  53. +    else if (b->capacity != -1)
  54. +        /* teres 1: use "capacity" */
  55. +        promille = b->capacity * 10;
  56. +    else if (b->voltage_now != -1 && b->voltage_min_design != -1 && b->voltage_max_design != -1)
  57. +        /* fallback, try voltage */
  58. +        /* on teres 1, the min voltage is 1000 times less than it should be */
  59. +        promille = ((b->voltage_now - 1000 * b->voltage_min_design) * 1000) /
  60. +            (b->voltage_max_design - 1000 * b->voltage_min_design);
  61.      else
  62.          promille = 0;
  63.  
  64. diff -ur lxpanel-0.9.3/plugins/batt/batt_sys.h lxpanel-0.9.3-r1/plugins/batt/batt_sys.h
  65. --- lxpanel-0.9.3/plugins/batt/batt_sys.h   2016-11-19 18:28:43.000000000 +0000
  66. +++ lxpanel-0.9.3-r1/plugins/batt/batt_sys.h    2017-11-09 09:00:42.320021695 +0000
  67. @@ -44,10 +44,13 @@
  68.      int current_now;
  69.      int power_now;
  70.      int voltage_now;
  71. +    int voltage_min_design;
  72. +    int voltage_max_design;
  73.      int charge_full_design;
  74.      int energy_full_design;
  75.      int charge_full;
  76.      int energy_full;
  77. +    int capacity;
  78.      /* extra info */
  79.      int seconds;
  80.      int percentage;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement