Commit MetaInfo

Revisionc01605a8ad6d3be83e75c70665110fd176cde952 (tree)
Time2010-01-15 06:08:58
Authorsatofumi
Commitersatofumi

Log Message

BatteryState の実装を調整

Change Summary

Incremental Difference

diff -r 18ed5d8321ba -r c01605a8ad6d history_log.txt
--- a/history_log.txt Thu Jan 14 09:37:15 2010 +0000
+++ b/history_log.txt Thu Jan 14 21:08:58 2010 +0000
@@ -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+
18 2010/01/07
29 ----------------------------------------------------------------------
310 download.html
diff -r 18ed5d8321ba -r c01605a8ad6d qlm_batmon/BatteryState.cpp
--- a/qlm_batmon/BatteryState.cpp Thu Jan 14 09:37:15 2010 +0000
+++ b/qlm_batmon/BatteryState.cpp Thu Jan 14 21:08:58 2010 +0000
@@ -71,7 +71,8 @@
7171 {
7272 bool is_available_;
7373 size_t full_capacity_;
74- string battery_string_;
74+ string state_file_;
75+ string info_file_;
7576
7677
7778 pImpl(void) : is_available_(false), full_capacity_(1)
@@ -80,7 +81,10 @@
8081 for (size_t id = 0; id < 2; ++id) {
8182 char buffer[] = "BAT0";
8283 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+
8488 if (loadFullCapacity()) {
8589 break;
8690 }
@@ -130,8 +134,7 @@
130134 bool loadFullCapacity(void)
131135 {
132136 // /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")) &&
135138 (full_capacity_ > 0)) {
136139 is_available_ = true;
137140 return true;
@@ -154,11 +157,9 @@
154157 }
155158
156159 // 電源が接続されていないときに false を返す
157- // !!! 充電中のときにどのような文字列が返されるか確認して追加すべき
158- // /proc/acpi/battery/BAT1/state ファイルの "charging state" を読み出す
160+ // /proc/acpi/battery/BATx/state ファイルの "charging state" を読み出す
159161 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") &&
162163 ((! state.compare("charged")) || (! state.compare("charging")))) {
163164 return true;
164165 }
@@ -173,11 +174,11 @@
173174 return 0;
174175 }
175176
176- // "/proc/acpi/battery/BAT1/state" ファイルの
177+ // "/proc/acpi/battery/BATx/state" ファイルの
177178 // "remaining capacity" を読み出し full_capacity_ から残量を計算する
178179 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")) {
181182 return 0;
182183 }
183184
@@ -198,17 +199,17 @@
198199 return 0;
199200 }
200201
201- // "/proc/acpi/battery/BAT1/state" ファイルの
202+ // "/proc/acpi/battery/BATx/state" ファイルの
202203 // "present rate" [mW] と "remaining capacity" [mWh] を読み出し、
203204 // バッテリーが使える時間を計算する
204205 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")) {
207207 return 0;
208208 }
209209
210210 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")) {
212213 return 0;
213214 }
214215
diff -r 18ed5d8321ba -r c01605a8ad6d qlm_batmon/qlm_batmon.pro
--- a/qlm_batmon/qlm_batmon.pro Thu Jan 14 09:37:15 2010 +0000
+++ b/qlm_batmon/qlm_batmon.pro Thu Jan 14 21:08:58 2010 +0000
@@ -7,7 +7,7 @@
77
88 TEMPLATE = app
99 TARGET =
10-VERSION = -0.0.3
10+VERSION = -0.0.4
1111 DEPENDPATH += .
1212 INCLUDEPATH += .
1313
Show on old repository browser