9
9
using namespace std ::chrono;
10
10
11
11
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 () );
14
14
int percent = (int )power->BatteryLifePercent ;
15
- delete power;
16
15
if (ret == 0 ) // 表示获取失败
17
16
return 0 ;
18
17
return percent;
@@ -27,6 +26,12 @@ int main(int argc, char* argv[])
27
26
auto pEc = path+L" \\ ectool.exe" ;
28
27
int blimit = 80 ; // 默认到80停止充电
29
28
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
+
30
35
if (argc>1 )
31
36
blimit = atoi (argv[1 ]);
32
37
@@ -39,7 +44,7 @@ int main(int argc, char* argv[])
39
44
40
45
// 执行任务
41
46
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);
43
48
else
44
49
ShellExecute (NULL , L" open" , pEc.c_str (), L" chargecontrol normal" , NULL , SW_HIDE);
45
50
std::wcout<<pEc.c_str ();
0 commit comments