OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
6.4 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../epplets16/epower-acpi.patch
  5. # Copyright (C) 2004 - 2006 The T2 SDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. --- epplets-0.7/epplets/E-Power.c 2001-10-13 20:32:19.000000000 +0200
  17. +++ epplets-0.7-jsaw/epplets/E-Power.c 2005-07-26 00:05:04.000000000 +0200
  18. @@ -1,22 +1,40 @@
  19. #include "epplet.h"
  20. +int use_acpi = 0;
  21. +#define MAX_ACPI_BAT 4
  22. +struct __acpibat {
  23. + /* info */
  24. + int present[MAX_ACPI_BAT];
  25. + int design_capacity[MAX_ACPI_BAT];
  26. +
  27. + int last_full_capacity[MAX_ACPI_BAT];
  28. + int design_capacity_warning[MAX_ACPI_BAT];
  29. + int design_capacity_low[MAX_ACPI_BAT];
  30. +} acpibat;
  31. +
  32. int prev_bat_val = 110;
  33. -int bat_val = 0;
  34. -int time_val = 0;
  35. +int bat_num = 0;
  36. +int bat_val = 0, ac_stat, bat_stat, bat_flags;
  37. +
  38. +int up2, time_val = 0;
  39. int prev_up[16] =
  40. {0, 0, 0, 0, 0, 0, 0, 0,
  41. 0, 0, 0, 0, 0, 0, 0, 0};
  42. int prev_count = 0;
  43. Epplet_gadget b_close, b_suspend, b_sleep, b_help, image, label;
  44. +static void power_setup(void);
  45. +
  46. static void cb_timer(void *data);
  47. static void cb_close(void *data);
  48. static void cb_in(void *data, Window w);
  49. static void cb_out(void *data, Window w);
  50. static void cb_help(void *data);
  51. -static void
  52. -cb_timer(void *data)
  53. +static int cb_apm();
  54. +static int cb_acpi();
  55. +
  56. +static int cb_apm()
  57. {
  58. static FILE *f;
  59. @@ -24,8 +42,8 @@
  60. if (f)
  61. {
  62. char s[256], s1[32], s2[32], s3[32];
  63. - int apm_flags, ac_stat, bat_stat, bat_flags;
  64. - int i, hours, minutes, up, up2;
  65. + int apm_flags;
  66. + int i, up;
  67. char *s_ptr;
  68. fgets(s, 255, f);
  69. @@ -49,13 +67,111 @@
  70. prev_count++;
  71. if (prev_count >= 16)
  72. prev_count = 0;
  73. + }
  74. +}
  75. +
  76. +#define TAG(tag) !strncmp(tag, s, strlen(tag))
  77. +static int cb_acpi()
  78. +{
  79. + FILE *f;
  80. + char s[256], *s_val;
  81. + int rate = 0, remain = 0;
  82. +
  83. + bat_num++;
  84. + while ((bat_num < MAX_ACPI_BAT) && (acpibat.present[bat_num] < 0)) bat_num++;
  85. + if (bat_num >= MAX_ACPI_BAT)
  86. + bat_num = 0;
  87. +
  88. + if (acpibat.present[bat_num] <= 0) {
  89. + bat_flags = 0x80;
  90. + return 0;
  91. + }
  92. +
  93. + bat_flags = 0x00;
  94. +
  95. + /* parse state */
  96. + snprintf(s, 256, "/proc/acpi/battery/BAT%d/state", bat_num);
  97. + f = fopen(s, "r");
  98. + if (!f) {
  99. + bat_flags = 0x80;
  100. + return 0;
  101. + }
  102. +
  103. + while (!feof(f)) {
  104. + if (fgets(s, 256, f))
  105. + {
  106. + s_val = s;
  107. + while(*s_val != ':') s_val++; s_val++;
  108. + while((*s_val == ' ')||(*s_val == '\t')) s_val++;
  109. - s_ptr = s;
  110. + /* FIXME "capacity state:" ??? */
  111. + if (TAG("charging state:"))
  112. + {
  113. + if (!strncmp(s_val, "char", 4)) {
  114. + ac_stat = 1;
  115. + bat_stat = 3; /* CHARGING */
  116. + }
  117. + else {
  118. + ac_stat = 0;
  119. + bat_stat = 0;
  120. + }
  121. + }
  122. + else if (TAG("present rate:")) {
  123. + rate = strtol(s_val, NULL, 10);
  124. + }
  125. + else if (TAG("remaining capacity:")) {
  126. + remain = strtol(s_val, NULL, 10);
  127. + }
  128. + else if (TAG("present rate:")) {
  129. + rate = strtol(s_val, NULL, 10);
  130. + }
  131. + }
  132. + }
  133. + fclose(f);
  134. +
  135. + bat_val = (remain * 100) / acpibat.last_full_capacity[bat_num];
  136. + if (bat_stat != 3) {
  137. + if (remain < acpibat.design_capacity_low[bat_num])
  138. + bat_stat = 2;
  139. + else if (remain < acpibat.design_capacity_warning[bat_num])
  140. + bat_stat = 1;
  141. + else
  142. + bat_stat = 0;
  143. +
  144. + time_val = (remain * 3600)/rate;
  145. + }
  146. + else {
  147. + time_val = ((acpibat.last_full_capacity[bat_num]-remain) * 3600)/rate;
  148. + }
  149. +
  150. + /*
  151. + up2 ????
  152. + */
  153. +
  154. + return 0;
  155. +}
  156. +static void
  157. +cb_timer(void *data)
  158. +{
  159. + int fail;
  160. + char s[256];
  161. + char *s_ptr = s;
  162. + int hours, minutes;
  163. +
  164. + if (use_acpi) fail = cb_acpi();
  165. + else fail = cb_apm();
  166. +
  167. + if (!fail)
  168. + {
  169. + /* convert to display */
  170. if( bat_flags != 0xff
  171. && bat_flags & 0x80 )
  172. {
  173. - s_ptr += sprintf( s_ptr, "no battery" );
  174. + if (use_acpi)
  175. + s_ptr += sprintf( s_ptr, "no bat. [%d]", bat_num );
  176. + else
  177. + s_ptr += sprintf( s_ptr, "no battery" );
  178. }
  179. else
  180. {
  181. @@ -97,9 +213,10 @@
  182. else
  183. s_ptr += sprintf(s_ptr, "%i:%02i", hours, minutes);
  184. }
  185. + s_ptr += sprintf( s_ptr, " [%d]", bat_num );
  186. Epplet_change_label(label, s);
  187. - sprintf(s, EROOT"/epplet_data/E-Power//E-Power-Bat-%i.png",
  188. + sprintf(s, EROOT"/epplet_data/E-Power/E-Power-Bat-%i.png",
  189. ((bat_val + 5) / 10) * 10);
  190. Epplet_change_image(image, 44, 24, s);
  191. Epplet_timer(cb_timer, NULL, 30.0, "TIMER");
  192. @@ -170,6 +287,8 @@
  193. int
  194. main(int argc, char **argv)
  195. {
  196. + power_setup();
  197. +
  198. Epplet_Init("E-Power", "0.1", "Enlightenment Laptop Power Epplet",
  199. 3, 3, argc, argv, 0);
  200. atexit(Epplet_cleanup);
  201. @@ -200,3 +319,69 @@
  202. Epplet_Loop();
  203. return 0;
  204. }
  205. +
  206. +static void power_setup(void)
  207. +{
  208. + FILE *f;
  209. +
  210. + f = fopen("/proc/apm", "r");
  211. + if (f)
  212. + {
  213. + fclose(f);
  214. + }
  215. + else
  216. + { /* try acpi */
  217. + int i;
  218. + char s[256];
  219. + char *s_val;
  220. +
  221. + memset(&acpibat, 0, sizeof(struct __acpibat));
  222. +
  223. + for(i=0; i<MAX_ACPI_BAT; i++) {
  224. + snprintf(s, 256, "/proc/acpi/battery/BAT%d/info", i);
  225. + acpibat.present[i] = -1;
  226. +
  227. + f = fopen(s, "r");
  228. + if (f)
  229. + {
  230. + use_acpi++;
  231. +
  232. + while (!feof(f)) {
  233. + if (fgets(s, 256, f))
  234. + {
  235. + s_val = s;
  236. + while(*s_val != ':') s_val++; s_val++;
  237. + while((*s_val == ' ')||(*s_val == '\t')) s_val++;
  238. +
  239. + if (TAG("present:"))
  240. + {
  241. + if (!strncmp(s_val, "yes", 3))
  242. + acpibat.present[i] = 1;
  243. + else
  244. + acpibat.present[i] = 0;
  245. + }
  246. + else if (TAG("design capacity:"))
  247. + {
  248. + acpibat.design_capacity[i] = strtol(s_val, NULL, 10);
  249. + }
  250. + else if (TAG("last full capacity:"))
  251. + {
  252. + acpibat.last_full_capacity[i] = strtol(s_val, NULL, 10);
  253. + }
  254. + else if (TAG("design capacity warning:"))
  255. + {
  256. + acpibat.design_capacity_warning[i] = strtol(s_val, NULL, 10);
  257. + }
  258. + else if (TAG("design capacity low:"))
  259. + {
  260. + acpibat.design_capacity_low[i] = strtol(s_val, NULL, 10);
  261. + }
  262. + }
  263. +
  264. + }
  265. +
  266. + fclose(f);
  267. + }
  268. + }
  269. + }
  270. +}