aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorJoe <bousset.rudy@gmail.com>2019-12-03 20:21:09 +0100
committerJoe <bousset.rudy@gmail.com>2019-12-03 20:21:09 +0100
commit89737ad005f4c066234a5282a1a46eb68b2c1ace (patch)
tree7b521091227050c84dca220715e20bf1347c39d3 /src/main.cpp
parentREADME update (diff)
downloadlowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.tar.gz
lowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.tar.bz2
lowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.tar.xz
lowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.tar.zst
lowbat-gnu-89737ad005f4c066234a5282a1a46eb68b2c1ace.zip
cpp mode
Diffstat (limited to '')
-rw-r--r--src/main.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..2fe6063
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,35 @@
+#include <jo_lowbat.hpp>
+
+int main(int argc, const char *argv[]) {
+ string msg = nullptr;
+ string acstat = nullptr;
+ string batlvl = nullptr;
+ stringstream battoint = nullptr;
+ int batlvlint = 0;
+
+ if (memcmp(argv[1], "--say", strlen(argv[1])))
+ msg = "beep beep - low battery";
+ else
+ 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");
+ battoint = batlvl;
+ battoint >> batlvlint;
+ if (batlvlint < 15) {
+ while (!memcmp(acstat, "Discharging", strlen(acstat))) {
+ 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, "Charging", strlen(acstat)))
+ break ;
+ }
+ }
+ sleep_for(seconds(240));
+ }
+ return 0;
+}