diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2019-12-29 14:47:00 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2019-12-29 14:47:00 +0100 |
commit | 3ee478b558307b690b4839c82bb6612cc3c3f3ac (patch) | |
tree | 5d06a580dc004a16e387cb995c9772ac1b19abb2 /src/jo_lowbat.cpp | |
parent | oop rework in progress (diff) | |
download | lowbat-gnu-3ee478b558307b690b4839c82bb6612cc3c3f3ac.tar.gz lowbat-gnu-3ee478b558307b690b4839c82bb6612cc3c3f3ac.tar.bz2 lowbat-gnu-3ee478b558307b690b4839c82bb6612cc3c3f3ac.tar.xz lowbat-gnu-3ee478b558307b690b4839c82bb6612cc3c3f3ac.tar.zst lowbat-gnu-3ee478b558307b690b4839c82bb6612cc3c3f3ac.zip |
work in progress
Diffstat (limited to 'src/jo_lowbat.cpp')
-rw-r--r-- | src/jo_lowbat.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/jo_lowbat.cpp b/src/jo_lowbat.cpp index 56fe655..ab74eaf 100644 --- a/src/jo_lowbat.cpp +++ b/src/jo_lowbat.cpp @@ -1,5 +1,8 @@ #include <jo_lowbat.hpp> #include <iostream> +#include <array> +#include <memory> +#include <algorithm> using namespace std; @@ -11,3 +14,30 @@ Lowbat::jo_testAcpi(void) { } return 0; } + +string +jo_exec(const char* cmd) { + array<char, 128> buffer; + string result; + unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose); + if (!pipe) { + throw runtime_error("popen() failed!"); + } + while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { + result += buffer.data(); + } + return result; +} + +string +Lowbat::jo_fetchBatlvl(void) { + string batlvl; + uint8_t batlvlint; + + cout << "Fetching batlvl: "; + batlvl = this->jo_exec("acpi | awk '{print $4}' | rev | cut -c 3- | rev"); + batlvl.erase(remove(batlvl.begin(), batlvl.end(), '\n'), batlvl.end()); + batlvlint = stoi(batlvl); + cout << batlvlint << "%" << endl; + return (batlvl); +} |