Mercurial > sdl-ios-xcode
annotate src/power/linux/SDL_syspower.c @ 3174:c8b9c6d27476
Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Sam, you might want to check to see that the spellings I picked are the spellings you wanted.
author | Bob Pendleton <bob@pendleton.com> |
---|---|
date | Mon, 08 Jun 2009 19:24:38 +0000 |
parents | b7a48f533966 |
children | 51750b7a966f |
rev | line source |
---|---|
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 /* |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2009 Sam Lantinga |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 Sam Lantinga |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 #ifndef SDL_POWER_DISABLED |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 #ifdef SDL_POWER_LINUX |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 #include <stdio.h> |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 #include <unistd.h> |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
3174
c8b9c6d27476
Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Bob Pendleton <bob@pendleton.com>
parents:
3170
diff
changeset
|
30 #include <sys/types.h> |
c8b9c6d27476
Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Bob Pendleton <bob@pendleton.com>
parents:
3170
diff
changeset
|
31 #include <sys/stat.h> |
c8b9c6d27476
Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Bob Pendleton <bob@pendleton.com>
parents:
3170
diff
changeset
|
32 #include <fcntl.h> |
c8b9c6d27476
Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Bob Pendleton <bob@pendleton.com>
parents:
3170
diff
changeset
|
33 |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 #include "SDL_power.h" |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 SDL_bool |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 SDL_GetPowerInfo_Linux_sys_power(SDL_PowerState *state, |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 int *seconds, int *percent) |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 return SDL_FALSE; /* !!! FIXME: write me. */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 #if 0 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 const int fd = open("/sys/power", O_RDONLY); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 if (fd == -1) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 return SDL_FALSE; /* can't use this interface. */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 return SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 #endif |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 SDL_bool |
3174
c8b9c6d27476
Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Bob Pendleton <bob@pendleton.com>
parents:
3170
diff
changeset
|
51 SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *state, |
c8b9c6d27476
Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Bob Pendleton <bob@pendleton.com>
parents:
3170
diff
changeset
|
52 int *seconds, int *percent) |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 return SDL_FALSE; /* !!! FIXME: write me. */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 #if 0 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 const int fd = open("/proc/acpi", O_RDONLY); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 if (fd == -1) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 return SDL_FALSE; /* can't use this interface. */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 return SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 #endif |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 static SDL_bool |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 next_string(char **_ptr, char **_str) |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 char *ptr = *_ptr; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 char *str = *_str; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 while (*ptr == ' ') { /* skip any spaces... */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 ptr++; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 if (*ptr == '\0') { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 str = ptr; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 while ((*ptr != ' ') && (*ptr != '\0')) |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 ptr++; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 if (*ptr != '\0') |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 *(ptr++) = '\0'; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 *_str = str; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 *_ptr = ptr; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 return SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 static SDL_bool |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 int_string(char *str, int *val) |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 char *endptr = NULL; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 *val = (int) strtol(str+2, &endptr, 16); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 return ((*str != '\0') && (*endptr == '\0')); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 /* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 SDL_bool |
3174
c8b9c6d27476
Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Bob Pendleton <bob@pendleton.com>
parents:
3170
diff
changeset
|
100 SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state, |
c8b9c6d27476
Fixed some typos and added a couple of includes. All were need to get SDL_power to compile on Linux.
Bob Pendleton <bob@pendleton.com>
parents:
3170
diff
changeset
|
101 int *seconds, int *percent) |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 SDL_bool need_details = SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 int ac_status = 0; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 int battery_status = 0; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 int battery_flag = 0; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 int battery_percent = 0; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 int battery_time = 0; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 const int fd = open("/proc/apm", O_RDONLY); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 char buf[128]; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 char *ptr = &buf[0]; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 char *str = NULL; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 ssize_t br; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 if (fd == -1) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 return SDL_FALSE; /* can't use this interface. */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 br = read(fd, buf, sizeof (buf) - 1); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 close(fd); |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 if (br < 0) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 buf[br] = '\0'; // null-terminate the string. |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 if (!next_string(&ptr, &str)) { /* driver version */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 if (!next_string(&ptr, &str)) { /* BIOS version */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 if (!next_string(&ptr, &str)) { /* APM flags */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 if (!next_string(&ptr, &str)) { /* AC line status */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 } else if (!int_string(str, &ac_status)) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 if (!next_string(&ptr, &str)) { /* battery status */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 } else if (!int_string(str, &battery_status)) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 if (!next_string(&ptr, &str)) { /* battery flag */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 } else if (!int_string(str, &battery_flag)) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 if (!next_string(&ptr, &str)) { /* remaining battery life percent */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 if (str[strlen(str) - 1] == '%') { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 str[strlen(str) - 1] = '\0'; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 if (!int_string(str, &battery_percent)) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 if (!next_string(&ptr, &str)) { /* remaining battery life time */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 } else if (!int_string(str, &battery_time)) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 if (!next_string(&ptr, &str)) { /* remaining battery life time units */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 return SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 } else if (strcmp(str, "min") == 0) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 battery_time *= 60; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 if (battery_flag == 0xFF) { /* unknown state */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 *state = SDL_POWERSTATE_UNKNOWN; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 } else if (battery_flag & (1 << 7)) { /* no battery */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 *state = SDL_POWERSTATE_NO_BATTERY; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 } else if (battery_flag & (1 << 3)) { /* charging */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 *state = SDL_POWERSTATE_CHARGING; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 need_details = SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 } else if (ac_status == 1) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 need_details = SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 } else { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 *state = SDL_POWERSTATE_ON_BATTERY; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 need_details = SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 *percent = -1; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 *seconds = -1; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 if (need_details) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 const int pct = battery_percent; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 const int secs = battery_time; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 if (pct >= 0) { /* -1 == unknown */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 if (secs >= 0) { /* -1 == unknown */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 *seconds = secs; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 return SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 #endif /* SDL_POWER_LINUX */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 #endif /* SDL_POWER_DISABLED */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 /* vi: set ts=4 sw=4 expandtab: */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 |