Revision | c01605a8ad6d3be83e75c70665110fd176cde952 (tree) |
---|---|
Time | 2010-01-15 06:08:58 |
Author | satofumi |
Commiter | satofumi |
BatteryState の実装を調整
@@ -1,3 +1,10 @@ | ||
1 | +2010/01/07 | |
2 | +---------------------------------------------------------------------- | |
3 | +download.html | |
4 | +qlm_batmon-0.0.4 を公開 | |
5 | +Linux で /proc/acpi/battery/BAT1 だけでなく /proc/acpi/battery/BAT0 も探索するように修正しました。 | |
6 | + | |
7 | + | |
1 | 8 | 2010/01/07 |
2 | 9 | ---------------------------------------------------------------------- |
3 | 10 | download.html |
@@ -71,7 +71,8 @@ | ||
71 | 71 | { |
72 | 72 | bool is_available_; |
73 | 73 | size_t full_capacity_; |
74 | - string battery_string_; | |
74 | + string state_file_; | |
75 | + string info_file_; | |
75 | 76 | |
76 | 77 | |
77 | 78 | pImpl(void) : is_available_(false), full_capacity_(1) |
@@ -80,7 +81,10 @@ | ||
80 | 81 | for (size_t id = 0; id < 2; ++id) { |
81 | 82 | char buffer[] = "BAT0"; |
82 | 83 | snprintf(buffer, sizeof(buffer), "BAT%d", id); |
83 | - battery_string_ = buffer; | |
84 | + | |
85 | + state_file_ = "/proc/acpi/battery/" + string(buffer) + "/state"; | |
86 | + info_file_ = "/proc/acpi/battery/" + string(buffer) + "/info"; | |
87 | + | |
84 | 88 | if (loadFullCapacity()) { |
85 | 89 | break; |
86 | 90 | } |
@@ -130,8 +134,7 @@ | ||
130 | 134 | bool loadFullCapacity(void) |
131 | 135 | { |
132 | 136 | // /proc/acpi/battery/BATx/info ファイルの "last full capacity" を読み出す |
133 | - string file = "/proc/acpi/battery/" + battery_string_ + "/info"; | |
134 | - if ((matchData(full_capacity_, file.c_str(), "last full capacity")) && | |
137 | + if ((matchData(full_capacity_, info_file_.c_str(), "last full capacity")) && | |
135 | 138 | (full_capacity_ > 0)) { |
136 | 139 | is_available_ = true; |
137 | 140 | return true; |
@@ -154,11 +157,9 @@ | ||
154 | 157 | } |
155 | 158 | |
156 | 159 | // 電源が接続されていないときに false を返す |
157 | - // !!! 充電中のときにどのような文字列が返されるか確認して追加すべき | |
158 | - // /proc/acpi/battery/BAT1/state ファイルの "charging state" を読み出す | |
160 | + // /proc/acpi/battery/BATx/state ファイルの "charging state" を読み出す | |
159 | 161 | string state; |
160 | - string file = "/proc/acpi/battery/" + battery_string_ + "/state"; | |
161 | - if (matchData(state, file.c_str(), "charging state") && | |
162 | + if (matchData(state, state_file_.c_str(), "charging state") && | |
162 | 163 | ((! state.compare("charged")) || (! state.compare("charging")))) { |
163 | 164 | return true; |
164 | 165 | } |
@@ -173,11 +174,11 @@ | ||
173 | 174 | return 0; |
174 | 175 | } |
175 | 176 | |
176 | - // "/proc/acpi/battery/BAT1/state" ファイルの | |
177 | + // "/proc/acpi/battery/BATx/state" ファイルの | |
177 | 178 | // "remaining capacity" を読み出し full_capacity_ から残量を計算する |
178 | 179 | size_t remaining_capacity = 0; |
179 | - string file = "/proc/acpi/battery/" + battery_string_ + "/state"; | |
180 | - if (! matchData(remaining_capacity, file.c_str(), "remaining capacity")) { | |
180 | + if (! matchData(remaining_capacity, | |
181 | + state_file_.c_str(), "remaining capacity")) { | |
181 | 182 | return 0; |
182 | 183 | } |
183 | 184 |
@@ -198,17 +199,17 @@ | ||
198 | 199 | return 0; |
199 | 200 | } |
200 | 201 | |
201 | - // "/proc/acpi/battery/BAT1/state" ファイルの | |
202 | + // "/proc/acpi/battery/BATx/state" ファイルの | |
202 | 203 | // "present rate" [mW] と "remaining capacity" [mWh] を読み出し、 |
203 | 204 | // バッテリーが使える時間を計算する |
204 | 205 | size_t present_rate = 0; |
205 | - string file = "/proc/acpi/battery/" + battery_string_ + "/state"; | |
206 | - if (! matchData(present_rate, file.c_str(), "present rate")) { | |
206 | + if (! matchData(present_rate, state_file_.c_str(), "present rate")) { | |
207 | 207 | return 0; |
208 | 208 | } |
209 | 209 | |
210 | 210 | size_t remaining_capacity = 0; |
211 | - if (! matchData(remaining_capacity, file.c_str(), "remaining capacity")) { | |
211 | + if (! matchData(remaining_capacity, | |
212 | + state_file_.c_str(), "remaining capacity")) { | |
212 | 213 | return 0; |
213 | 214 | } |
214 | 215 |
@@ -7,7 +7,7 @@ | ||
7 | 7 | |
8 | 8 | TEMPLATE = app |
9 | 9 | TARGET = |
10 | -VERSION = -0.0.3 | |
10 | +VERSION = -0.0.4 | |
11 | 11 | DEPENDPATH += . |
12 | 12 | INCLUDEPATH += . |
13 | 13 |