diff options
Diffstat (limited to 'src/jo_lowbat.cpp')
-rw-r--r-- | src/jo_lowbat.cpp | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/src/jo_lowbat.cpp b/src/jo_lowbat.cpp index f4c3b2e..b6cc0d6 100644 --- a/src/jo_lowbat.cpp +++ b/src/jo_lowbat.cpp @@ -8,10 +8,31 @@ using namespace std; uint8_t Lowbat::jo_testAcpi(void) { - if (system("acpi > /dev/null 2>&1")) { - cout << "acpi is not installed. Please install it in order to run lowbat." << endl; + if (system("which acpi > /dev/null 2>&1")) { + cout << "acpi is not installed. Please install it in order to run lowbat" << endl; return 1; } + cout << "acpi is installed" << endl; + return 0; +} + +uint8_t +Lowbat::jo_testNotifySend(void) { + if (system("which notify-send > /dev/null 2>&1")) { + cout << "notify-send is not installed. Please install it in order to run lowbat" << endl; + return 1; + } + cout << "notify-send is installed" + return 0; +} + +void +Lowbat::jo_testEspeak(void) { + if (system("which espeak > /dev/null 2>&1")) { + cout << "espeak is not installed. Please install it in order to run --say option" << endl; + return 1; + } + cout << "espeak is installed" << endl; return 0; } @@ -21,7 +42,17 @@ Lowbat::jo_fetchBatlvl(void) { 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)); + return stoi(m_batlvl); +} + +int +Lowbat::jo_fetchAcstat(void) { + const int ret = system("acpi | grep -q Discharging"); + if (ret != 0) + cout << ret << "acstat: Charging" << endl; + else + cout << "acstat: Discharging" << endl; + return ret; } string @@ -48,3 +79,19 @@ Lowbat::jo_notify(void) { cout << "Notifying" << endl; return system(str.c_str()); } + +int +Lowbat::jo_speak(void) { + string str; + + str = "echo \""; + str += m_msg; + str += "\" | espeak"; + cout << "Speaking: " << m_msg << endl; + return system(str.c_str()); +} + +void +Lowbat::jo_setMsg(const char *msg) { + m_msg = msg; +} |