diff options
-rw-r--r-- | Makefile | 6 | ||||
-rwxr-xr-x | bin/lowbat | 33 | ||||
-rw-r--r-- | obj/jo_exec.o | bin | 5016 -> 0 bytes | |||
-rw-r--r-- | src/jo_notify.cpp | 12 | ||||
-rw-r--r-- | src/main.cpp | 23 |
5 files changed, 22 insertions, 52 deletions
@@ -36,7 +36,8 @@ OPTIMIZE = -O2 CFLAGS = -Wall CFLAGS += -Wextra CFLAGS += -Werror -CFLAGS += ${OPTIMIZE} +#CFLAGS += ${OPTIMIZE} +CFLAGS += ${DEBUG} #------------------------------------------------------------------------------# NAME = lowbat #==============================================================================# @@ -81,9 +82,10 @@ clean: ${RM} ${OBJS_DIR} #------------------------------------------------------------------------------# fclean: clean + ${RM} ${TRGT_DIR} #------------------------------------------------------------------------------# re: fclean all -#------------------------------------------------------------------------------# ${RM} ${TRGT_DIR} +#------------------------------------------------------------------------------# .PHONY: all lowbat clean fclean re install uninstall #==================================== EOF =====================================# diff --git a/bin/lowbat b/bin/lowbat deleted file mode 100755 index 7aaaede..0000000 --- a/bin/lowbat +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -if [ ! "$1" = "--silent" ]; then - if [ ! "$1" = "--say" ]; then - message="beep beep - low battery" - else - message=$2 - fi -fi - -ntf() { - notify-send "Low battery: $batlvl%" "Please plug in computer" -u critical -t 15000 - if [ ! "$message" = "--silent" ]; then - echo "$message" | espeak - fi -} - -while true ; do - acstat=$(acpi | awk '{print $3}' | rev | cut -c 2- | rev) - batlvl=$(acpi | awk '{print $4}' | rev | cut -c 3- | rev) - if [ "$batlvl" -lt 15 ]; then - while [ "$acstat" = "Discharging" ]; do - ntf - sleep 20 - acstat=$(acpi | awk '{print $3}' | rev | cut -c 2- | rev) - batlvl=$(acpi | awk '{print $4}' | rev | cut -c 3- | rev) - if [ "$acstat" = "Charging" ]; then - break - fi - done - fi - sleep 240 -done diff --git a/obj/jo_exec.o b/obj/jo_exec.o Binary files differdeleted file mode 100644 index 8cf7a7d..0000000 --- a/obj/jo_exec.o +++ /dev/null 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 ; } } |