-rw-r--r-- | library/power.cpp | 61 |
1 files changed, 2 insertions, 59 deletions
diff --git a/library/power.cpp b/library/power.cpp index ec5b309..21c8960 100644 --- a/library/power.cpp +++ b/library/power.cpp | |||
@@ -99,130 +99,73 @@ bool PowerStatusManager::getProcApmStatus( int &ac, int &bs, int &bf, int &pc, i | |||
99 | ps->bs = PowerStatus::Critical; | 99 | ps->bs = PowerStatus::Critical; |
100 | break; | 100 | break; |
101 | case 0x03: | 101 | case 0x03: |
102 | ps->bs = PowerStatus::Charging; | 102 | ps->bs = PowerStatus::Charging; |
103 | break; | 103 | break; |
104 | case 0x04: | 104 | case 0x04: |
105 | case 0xff: // 0xff is Unknown but we map to NotPresent | 105 | case 0xff: // 0xff is Unknown but we map to NotPresent |
106 | default: | 106 | default: |
107 | ps->bs = PowerStatus::NotPresent; | 107 | ps->bs = PowerStatus::NotPresent; |
108 | break; | 108 | break; |
109 | } | 109 | } |
110 | 110 | ||
111 | switch ( ac ) { | 111 | switch ( ac ) { |
112 | case 0x00: | 112 | case 0x00: |
113 | ps->ac = PowerStatus::Offline; | 113 | ps->ac = PowerStatus::Offline; |
114 | break; | 114 | break; |
115 | case 0x01: | 115 | case 0x01: |
116 | ps->ac = PowerStatus::Online; | 116 | ps->ac = PowerStatus::Online; |
117 | break; | 117 | break; |
118 | case 0x02: | 118 | case 0x02: |
119 | ps->ac = PowerStatus::Backup; | 119 | ps->ac = PowerStatus::Backup; |
120 | break; | 120 | break; |
121 | } | 121 | } |
122 | 122 | ||
123 | if ( pc > 100 ) | 123 | if ( pc > 100 ) pc = 100; |
124 | pc = -1; | 124 | if ( pc < 0 ) pc = 0; |
125 | 125 | ||
126 | ps->percentRemain = pc; | 126 | ps->percentRemain = pc; |
127 | ps->secsRemain = sec; | 127 | ps->secsRemain = sec; |
128 | 128 | ||
129 | ok = true; | 129 | ok = true; |
130 | } | 130 | } |
131 | 131 | ||
132 | return ok; | 132 | return ok; |
133 | } | 133 | } |
134 | 134 | ||
135 | #ifdef QT_QWS_SHARP | ||
136 | |||
137 | void PowerStatusManager::getStatus() | ||
138 | { | ||
139 | int ac, bs, bf, pc, sec; | ||
140 | ps->percentAccurate = TRUE; // not for long... | ||
141 | |||
142 | if ( haveProcApm && getProcApmStatus( ac, bs, bf, pc, sec ) ) { | ||
143 | // special case | ||
144 | if ( bs == 0x7f ) | ||
145 | ps->bs = PowerStatus::VeryLow; | ||
146 | pc = -1; // fake percentage | ||
147 | if ( pc < 0 ) { | ||
148 | switch ( bs ) { | ||
149 | case 0x00: ps->percentRemain = 100; break; // High | ||
150 | case 0x01: ps->percentRemain = 30; break; // Low | ||
151 | case 0x7f: ps->percentRemain = 10; break; // Very Low | ||
152 | case 0x02: ps->percentRemain = 5; break; // Critical | ||
153 | case 0x03: ps->percentRemain = -1; break; // Charging | ||
154 | } | ||
155 | ps->percentAccurate = FALSE; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | char *device = "/dev/apm_bios"; | ||
160 | int fd = ::open (device, O_WRONLY); | ||
161 | if ( fd >= 0 ) { | ||
162 | int bbat_status = ioctl( fd, APM_IOC_BATTERY_BACK_CHK, 0 ); | ||
163 | switch ( bbat_status ) { | ||
164 | case 0x00: | ||
165 | ps->bbs = PowerStatus::High; | ||
166 | break; | ||
167 | case 0x01: | ||
168 | ps->bbs = PowerStatus::Low; | ||
169 | break; | ||
170 | case 0x7f: | ||
171 | ps->bbs = PowerStatus::VeryLow; | ||
172 | break; | ||
173 | case 0x02: | ||
174 | ps->bbs = PowerStatus::Critical; | ||
175 | break; | ||
176 | case 0x03: | ||
177 | ps->bbs = PowerStatus::Charging; | ||
178 | break; | ||
179 | case 0x04: | ||
180 | ps->bbs = PowerStatus::NotPresent; | ||
181 | break; | ||
182 | } | ||
183 | ::close(fd); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | #else | ||
188 | |||
189 | void PowerStatusManager::getStatus() | 135 | void PowerStatusManager::getStatus() |
190 | { | 136 | { |
191 | bool usedApm = FALSE; | 137 | bool usedApm = FALSE; |
192 | 138 | ||
193 | ps->percentAccurate = TRUE; | 139 | ps->percentAccurate = TRUE; |
194 | 140 | ||
195 | // Some iPAQ kernel builds don't have APM. If this is not the case we | 141 | // Some iPAQ kernel builds don't have APM. If this is not the case we |
196 | // save ourselves an ioctl by testing if /proc/apm exists in the | 142 | // save ourselves an ioctl by testing if /proc/apm exists in the |
197 | // constructor and we use /proc/apm instead | 143 | // constructor and we use /proc/apm instead |
198 | int ac, bs, bf, pc, sec; | 144 | int ac, bs, bf, pc, sec; |
199 | if ( haveProcApm ) | 145 | if ( haveProcApm ) |
200 | usedApm = getProcApmStatus( ac, bs, bf, pc, sec ); | 146 | usedApm = getProcApmStatus( ac, bs, bf, pc, sec ); |
201 | 147 | ||
202 | if ( !usedApm ) { | 148 | if ( !usedApm ) { |
203 | #ifdef QT_QWS_IPAQ_NO_APM | 149 | #ifdef QT_QWS_IPAQ_NO_APM |
204 | int fd; | 150 | int fd; |
205 | int err; | 151 | int err; |
206 | struct bat_dev batt_info; | 152 | struct bat_dev batt_info; |
207 | 153 | ||
208 | memset(&batt_info, 0, sizeof(batt_info)); | 154 | memset(&batt_info, 0, sizeof(batt_info)); |
209 | 155 | ||
210 | fd = ::open("/dev/ts",O_RDONLY); | 156 | fd = ::open("/dev/ts",O_RDONLY); |
211 | if( fd < 0 ) | 157 | if( fd < 0 ) |
212 | return; | 158 | return; |
213 | 159 | ||
214 | ioctl(fd, GET_BATTERY_STATUS, &batt_info); | 160 | ioctl(fd, GET_BATTERY_STATUS, &batt_info); |
215 | ac_status = batt_info.ac_status; | 161 | ac_status = batt_info.ac_status; |
216 | ps->percentRemain = ( 425 * batt_info.batt1_voltage ) / 1000 - 298; // from h3600_ts.c | 162 | ps->percentRemain = ( 425 * batt_info.batt1_voltage ) / 1000 - 298; // from h3600_ts.c |
217 | ps->secsRemain = -1; // seconds is bogus on iPAQ | 163 | ps->secsRemain = -1; // seconds is bogus on iPAQ |
218 | ::close (fd); | 164 | ::close (fd); |
219 | #else | 165 | #else |
220 | ps->percentRemain = 100; | 166 | ps->percentRemain = 100; |
221 | ps->secsRemain = -1; | 167 | ps->secsRemain = -1; |
222 | ps->percentAccurate = FALSE; | 168 | ps->percentAccurate = FALSE; |
223 | #endif | 169 | #endif |
224 | } | 170 | } |
225 | } | 171 | } |
226 | |||
227 | #endif | ||
228 | |||