diff options
-rw-r--r-- | src/main.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp index 048726b..88471e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,26 +1,20 @@ #include <jo_lowbat.hpp> +#include <algorithm> int main(int argc, const char *argv[]) { string msg; string acstat; string batlvl; - int batlvlint = 0; - int val1; - int val2; + int batlvlint; - 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]; - } - } + if (argc > 1 && !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"); + acstat.erase(remove(acstat.begin(), acstat.end(), '\n'), acstat.end()); + batlvl.erase(remove(batlvl.begin(), batlvl.end(), '\n'), batlvl.end()); batlvlint = stoi(batlvl); if (batlvlint < 90) { while (!memcmp(acstat.c_str(), "Discharging", strlen(acstat.c_str()))) { @@ -30,6 +24,8 @@ int main(int argc, const char *argv[]) { 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"); + acstat.erase(remove(acstat.begin(), acstat.end(), '\n'), acstat.end()); + batlvl.erase(remove(batlvl.begin(), batlvl.end(), '\n'), batlvl.end()); if (!memcmp(acstat.c_str(), "Charging", strlen(acstat.c_str()))) break ; } |