blob: 62c20b80656669ec314c1eb8b5cc8910276f96b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#include <jo_lowbat.hpp>
#include <iostream>
#include <cstring>
#include <thread>
#include <chrono>
#include <algorithm>
using namespace this_thread;
using namespace chrono;
int main(int argc, const char *argv[]) {
string* msg;
string acstat;
string batlvl;
int batlvlint;
Lowbat lowbat;
if (lowbat.jo_testAcpi())
return (1);
while (true) {
cout << "Fetching batlvl: ";
batlvl = jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev");
batlvl.erase(remove(batlvl.begin(), batlvl.end(), '\n'), batlvl.end());
batlvlint = stoi(batlvl);
cout << batlvlint << "%" << endl;
while (batlvlint < 15 && !system("acpi | grep -q Discharging")) {
jo_notify(batlvl);
if (argc == 1) {
msg = new string("beep beep - low battery");
jo_speak(*msg);
delete msg;
}
else if (argc > 1 && strcmp(argv[1], "--silent")) {
if (argc > 2 && !strcmp(argv[1], "--say")) {
msg = new string(argv[2]);
}
else {
msg = new string("beep beep - low battery");
}
jo_speak(*msg);
delete msg;
}
cout << "Sleep for 20s" << endl;
sleep_for(seconds(20));
batlvl.clear();
batlvl = jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev");
batlvl.erase(remove(batlvl.begin(), batlvl.end(), '\n'), batlvl.end());
batlvlint = stoi(batlvl);
}
cout << "Sleep for 4m" << endl;
sleep_for(seconds(240));
}
return 0;
}
|