Skip to content

Commit c408cd6

Browse files
Update chromebook_batterymanage.cpp
1 parent 6244db9 commit c408cd6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

chromebook_batterymanage.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
using namespace std::chrono;
1010

1111
int battery_monitor() {
12-
LPSYSTEM_POWER_STATUS power = new _SYSTEM_POWER_STATUS();
13-
int ret = GetSystemPowerStatus(power);
12+
std::unique_ptr<_SYSTEM_POWER_STATUS> power(new _SYSTEM_POWER_STATUS());
13+
int ret = GetSystemPowerStatus(power.get());
1414
int percent = (int)power->BatteryLifePercent;
15-
delete power;
1615
if (ret == 0) //表示获取失败
1716
return 0;
1817
return percent;
@@ -27,6 +26,12 @@ int main(int argc, char* argv[])
2726
auto pEc = path+L"\\ectool.exe";
2827
int blimit = 80; //默认到80停止充电
2928

29+
// 执行不成功
30+
if (ShellExecute(NULL, L"open", pEc.c_str(), L"hello", NULL, SW_HIDE) != 0) {
31+
MessageBox(0, L"与BIOS通信失败,即将退出\n似乎您不是coreboot(chromebook)", L"出现错误", MB_OK | MB_ICONHAND);
32+
exit(1);
33+
}
34+
3035
if (argc>1)
3136
blimit = atoi(argv[1]);
3237

@@ -39,7 +44,7 @@ int main(int argc, char* argv[])
3944

4045
// 执行任务
4146
if (battery_monitor() >= blimit)
42-
ShellExecute(NULL, L"open", pEc.c_str(), L"chargecontrol discharge", NULL, SW_HIDE);
47+
ShellExecute(NULL, L"open", pEc.c_str(), L"chargecontrol idle", NULL, SW_HIDE);
4348
else
4449
ShellExecute(NULL, L"open", pEc.c_str(), L"chargecontrol normal", NULL, SW_HIDE);
4550
std::wcout<<pEc.c_str();

0 commit comments

Comments
 (0)