aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2019-12-04 00:23:45 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2019-12-04 00:23:45 +0100
commit86f4eeac510753024dd94b69988bed700446ef37 (patch)
treee2fddd65127ad0eeef58f5eb4e5c5c57cd23ae39 /src
parent.gitignore C++ update, doing some debug (diff)
downloadlowbat-gnu-86f4eeac510753024dd94b69988bed700446ef37.tar.gz
lowbat-gnu-86f4eeac510753024dd94b69988bed700446ef37.tar.bz2
lowbat-gnu-86f4eeac510753024dd94b69988bed700446ef37.tar.xz
lowbat-gnu-86f4eeac510753024dd94b69988bed700446ef37.tar.zst
lowbat-gnu-86f4eeac510753024dd94b69988bed700446ef37.zip
Better now
Diffstat (limited to 'src')
-rw-r--r--src/jo_notify.cpp12
-rw-r--r--src/main.cpp23
2 files changed, 18 insertions, 17 deletions
diff --git a/src/jo_notify.cpp b/src/jo_notify.cpp
index bd14db0..154b0b7 100644
--- a/src/jo_notify.cpp
+++ b/src/jo_notify.cpp
@@ -2,25 +2,21 @@
int
jo_notify(const string batlvl) {
- string str = nullptr;
- const char *cmd = nullptr;
+ string str;
str = "notify-send \"";
str += batlvl;
str += "%\" \"Please plug in computer\" -u critical -t 15000";
- cmd = str.c_str();
- return system(cmd);
+ return system(str.c_str());
}
int
jo_speak(const string msg) {
- string str = nullptr;
- const char *cmd = nullptr;
+ string str;
str = "echo \"";
str += msg;
str += "\" | espeak";
- cmd = str.c_str();
- return system(cmd);
+ return system(str.c_str());
}
diff --git a/src/main.cpp b/src/main.cpp
index ed05f71..048726b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,31 +1,36 @@
#include <jo_lowbat.hpp>
int main(int argc, const char *argv[]) {
- string msg = nullptr;
- string acstat = nullptr;
- string batlvl = nullptr;
+ 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 = "beep beep - low battery";
- else
+ 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 < 15) {
- while (!memcmp(acstat, "Discharging", strlen(acstat))) {
+ 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, "Charging", strlen(acstat)))
+ if (!memcmp(acstat.c_str(), "Charging", strlen(acstat.c_str())))
break ;
}
}