aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: 048726b95347085fbe7c0c07332b81d7d623716c (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
#include <jo_lowbat.hpp>

int main(int argc, const char *argv[]) {
	string			msg;
	string			acstat;
	string			batlvl;
	int				batlvlint = 0;
	int val1;
	int val2;

	acstat = jo_exec("acpi | awk '{print $3}' | rev | cut -c 2- | rev");
	val1 = strlen(acstat.c_str());
	val2 = strlen("Discharging");
	msg = "beep beep - low battery";
	if (argc > 1) {
		if (!memcmp(argv[1], "--say", strlen(argv[1]))) {
			msg = argv[2];
		}
	}

	while (true) {
		acstat = jo_exec("acpi | awk '{print $3}' | rev | cut -c 2- | rev");
		batlvl = jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev");
		batlvlint = stoi(batlvl);
		if (batlvlint < 90) {
			while (!memcmp(acstat.c_str(), "Discharging", strlen(acstat.c_str()))) {
				jo_notify(batlvl);
				if (memcmp(argv[1], "--silent", strlen(argv[1])))
					jo_speak(msg);
				sleep_for(seconds(20));
				acstat = jo_exec("acpi | awk '{print $3}' | rev | cut -c 2- | rev");
				batlvl = jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev");
				if (!memcmp(acstat.c_str(), "Charging", strlen(acstat.c_str())))
					break ;
			}
		}
		sleep_for(seconds(240));
	}
	return 0;
}