aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2019-12-29 17:59:11 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2019-12-29 17:59:11 +0100
commit58ee60be9de472ee9d7558e64f23fb53e4d8cb4e (patch)
treea288ae2387e9ad447ce90ab18c8716287cedf8c0 /src
parentin progress (diff)
downloadlowbat-gnu-58ee60be9de472ee9d7558e64f23fb53e4d8cb4e.tar.gz
lowbat-gnu-58ee60be9de472ee9d7558e64f23fb53e4d8cb4e.tar.bz2
lowbat-gnu-58ee60be9de472ee9d7558e64f23fb53e4d8cb4e.tar.xz
lowbat-gnu-58ee60be9de472ee9d7558e64f23fb53e4d8cb4e.tar.zst
lowbat-gnu-58ee60be9de472ee9d7558e64f23fb53e4d8cb4e.zip
Starting to look good
Diffstat (limited to 'src')
-rw-r--r--src/jo_lowbat.cpp29
-rw-r--r--src/main.cpp40
2 files changed, 33 insertions, 36 deletions
diff --git a/src/jo_lowbat.cpp b/src/jo_lowbat.cpp
index 96686e5..f4c3b2e 100644
--- a/src/jo_lowbat.cpp
+++ b/src/jo_lowbat.cpp
@@ -15,8 +15,17 @@ Lowbat::jo_testAcpi(void) {
return 0;
}
+int
+Lowbat::jo_fetchBatlvl(void) {
+ cout << "Fetching batlvl: ";
+ m_batlvl = Lowbat::jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev");
+ m_batlvl.erase(remove(m_batlvl.begin(), m_batlvl.end(), '\n'), m_batlvl.end());
+ cout << m_batlvl << "%" << endl;
+ return(stoi(m_batlvl));
+}
+
string
-jo_exec(const char* cmd) {
+Lowbat::jo_exec(const char* cmd) {
array<char, 128> buffer;
string result;
unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
@@ -29,15 +38,13 @@ jo_exec(const char* cmd) {
return result;
}
-string
-Lowbat::jo_fetchBatlvl(void) {
- string batlvl;
- uint8_t batlvlint;
+int
+Lowbat::jo_notify(void) {
+ string str;
- cout << "Fetching batlvl: ";
- batlvl = Lowbat::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;
- return (batlvl);
+ str = "notify-send \"Low battery: ";
+ str += m_batlvl;
+ str += "%\" \"Please plug in computer\" -u critical -t 15000";
+ cout << "Notifying" << endl;
+ return system(str.c_str());
}
diff --git a/src/main.cpp b/src/main.cpp
index c614cca..a6c291d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -23,31 +23,21 @@ int main(int argc, const char *argv[]) {
if (lowbat.jo_testAcpi())
return (1);
while (true) {
- lowbat.jo_fetchBatlvl();
- // 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);
- // }
+ while (lowbat.jo_fetchBatlvl() < 115 && !system("acpi | grep -q Discharging")) {
+ lowbat.jo_notify();
+ 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));
+ }
cout << "Sleep for 4m" << endl;
sleep_for(seconds(240));
}