Mercurial > sdl-ios-xcode
comparison src/power/beos/SDL_syspower.c @ 3186:51750b7a966f
indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 10 Jun 2009 13:34:20 +0000 |
parents | 510e3f36c04a |
children | f7b03b6838cb |
comparison
equal
deleted
inserted
replaced
3185:44d5474c2c8a | 3186:51750b7a966f |
---|---|
39 #define APM_BIOS_CALL (B_DEVICE_OP_CODES_END + 3) | 39 #define APM_BIOS_CALL (B_DEVICE_OP_CODES_END + 3) |
40 | 40 |
41 #include "SDL_power.h" | 41 #include "SDL_power.h" |
42 | 42 |
43 SDL_bool | 43 SDL_bool |
44 SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent) | 44 SDL_GetPowerInfo_BeOS(SDL_PowerState * state, int *seconds, int *percent) |
45 { | 45 { |
46 const int fd = open("/dev/misc/apm", O_RDONLY); | 46 const int fd = open("/dev/misc/apm", O_RDONLY); |
47 SDL_bool need_details = SDL_FALSE; | 47 SDL_bool need_details = SDL_FALSE; |
48 uint16 regs[6]; | 48 uint16 regs[6]; |
49 uint8 ac_status; | 49 uint8 ac_status; |
51 uint8 battery_flags; | 51 uint8 battery_flags; |
52 uint8 battery_life; | 52 uint8 battery_life; |
53 uint32 battery_time; | 53 uint32 battery_time; |
54 | 54 |
55 if (fd == -1) { | 55 if (fd == -1) { |
56 return SDL_FALSE; /* maybe some other method will work? */ | 56 return SDL_FALSE; /* maybe some other method will work? */ |
57 } | 57 } |
58 | 58 |
59 memset(regs, '\0', sizeof (regs)); | 59 memset(regs, '\0', sizeof(regs)); |
60 regs[0] = APM_FUNC_OFFSET + APM_FUNC_GET_POWER_STATUS; | 60 regs[0] = APM_FUNC_OFFSET + APM_FUNC_GET_POWER_STATUS; |
61 regs[1] = APM_DEVICE_ALL; | 61 regs[1] = APM_DEVICE_ALL; |
62 rc = ioctl(fd, APM_BIOS_CALL, regs); | 62 rc = ioctl(fd, APM_BIOS_CALL, regs); |
63 close(fd); | 63 close(fd); |
64 | 64 |
71 battery_flags = regs[2] >> 8; | 71 battery_flags = regs[2] >> 8; |
72 battery_life = regs[2] & 0xFF; | 72 battery_life = regs[2] & 0xFF; |
73 battery_time = (uint32) regs[3]; | 73 battery_time = (uint32) regs[3]; |
74 | 74 |
75 /* in theory, _something_ should be set in battery_flags, right? */ | 75 /* in theory, _something_ should be set in battery_flags, right? */ |
76 if (battery_flags == 0x00) { /* older APM BIOS? Less fields. */ | 76 if (battery_flags == 0x00) { /* older APM BIOS? Less fields. */ |
77 battery_time = 0xFFFF; | 77 battery_time = 0xFFFF; |
78 if (battery_status == 0xFF) { | 78 if (battery_status == 0xFF) { |
79 battery_flags = 0xFF; | 79 battery_flags = 0xFF; |
80 } else { | 80 } else { |
81 battery_flags = (1 << status.battery_status); | 81 battery_flags = (1 << status.battery_status); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 if ( (battery_time != 0xFFFF) && (battery_time & (1 << 15)) ) { | 85 if ((battery_time != 0xFFFF) && (battery_time & (1 << 15))) { |
86 /* time is in minutes, not seconds */ | 86 /* time is in minutes, not seconds */ |
87 battery_time = (battery_time & 0x7FFF) * 60; | 87 battery_time = (battery_time & 0x7FFF) * 60; |
88 } | 88 } |
89 | 89 |
90 if (battery_flags == 0xFF) { /* unknown state */ | 90 if (battery_flags == 0xFF) { /* unknown state */ |
91 *state = SDL_POWERSTATE_UNKNOWN; | 91 *state = SDL_POWERSTATE_UNKNOWN; |
92 } else if (battery_flags & (1 << 7)) { /* no battery */ | 92 } else if (battery_flags & (1 << 7)) { /* no battery */ |
93 *state = SDL_POWERSTATE_NO_BATTERY; | 93 *state = SDL_POWERSTATE_NO_BATTERY; |
94 } else if (battery_flags & (1 << 3)) { /* charging */ | 94 } else if (battery_flags & (1 << 3)) { /* charging */ |
95 *state = SDL_POWERSTATE_CHARGING; | 95 *state = SDL_POWERSTATE_CHARGING; |
96 need_details = SDL_TRUE; | 96 need_details = SDL_TRUE; |
97 } else if (ac_status == 1) { | 97 } else if (ac_status == 1) { |
98 *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */ | 98 *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */ |
99 need_details = SDL_TRUE; | 99 need_details = SDL_TRUE; |
100 } else { | 100 } else { |
101 *state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */ | 101 *state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */ |
102 need_details = SDL_TRUE; | 102 need_details = SDL_TRUE; |
103 } | 103 } |
104 | 104 |
105 *percent = -1; | 105 *percent = -1; |
106 *seconds = -1; | 106 *seconds = -1; |
107 if (need_details) { | 107 if (need_details) { |
108 const int pct = (int) battery_life; | 108 const int pct = (int) battery_life; |
109 const int secs = (int) battery_time; | 109 const int secs = (int) battery_time; |
110 | 110 |
111 if (pct != 255) { /* 255 == unknown */ | 111 if (pct != 255) { /* 255 == unknown */ |
112 *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ | 112 *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ |
113 } | 113 } |
114 if (secs != 0xFFFF) { /* 0xFFFF == unknown */ | 114 if (secs != 0xFFFF) { /* 0xFFFF == unknown */ |
115 *seconds = secs; | 115 *seconds = secs; |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 return SDL_TRUE; /* the definitive answer if APM driver replied. */ | 119 return SDL_TRUE; /* the definitive answer if APM driver replied. */ |
120 } | 120 } |
121 | 121 |
122 #endif /* SDL_POWER_BEOS */ | 122 #endif /* SDL_POWER_BEOS */ |
123 #endif /* SDL_POWER_DISABLED */ | 123 #endif /* SDL_POWER_DISABLED */ |
124 | 124 |
125 /* vi: set ts=4 sw=4 expandtab: */ | 125 /* vi: set ts=4 sw=4 expandtab: */ |
126 |