2016-05-30 23:58:58 -04:00
|
|
|
#pragma once
|
2016-05-19 10:41:06 -04:00
|
|
|
|
2016-06-14 23:32:35 -04:00
|
|
|
#include "config.hpp"
|
2016-05-19 10:41:06 -04:00
|
|
|
#include "drawtypes/animation.hpp"
|
|
|
|
#include "drawtypes/label.hpp"
|
2016-06-14 23:32:35 -04:00
|
|
|
#include "drawtypes/progressbar.hpp"
|
2016-05-19 10:41:06 -04:00
|
|
|
#include "drawtypes/ramp.hpp"
|
2016-06-14 23:32:35 -04:00
|
|
|
#include "modules/meta.hpp"
|
|
|
|
#include "utils/file.hpp"
|
|
|
|
#include "utils/inotify.hpp"
|
|
|
|
#include "utils/string.hpp"
|
|
|
|
|
|
|
|
LEMONBUDDY_NS
|
|
|
|
|
|
|
|
namespace modules {
|
2016-10-30 09:41:06 -04:00
|
|
|
enum class battery_state { NONE = 0, UNKNOWN, CHARGING, DISCHARGING, FULL };
|
2016-06-14 23:32:35 -04:00
|
|
|
class battery_module : public inotify_module<battery_module> {
|
|
|
|
public:
|
|
|
|
using inotify_module::inotify_module;
|
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void setup();
|
|
|
|
void start();
|
|
|
|
void teardown();
|
2016-11-03 07:56:33 -04:00
|
|
|
void idle();
|
2016-11-02 15:22:45 -04:00
|
|
|
bool on_event(inotify_event* event);
|
|
|
|
string get_format() const;
|
|
|
|
bool build(builder* builder, string tag) const;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
protected:
|
2016-11-02 15:22:45 -04:00
|
|
|
int current_percentage();
|
|
|
|
battery_state current_state();
|
|
|
|
void subthread();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr auto FORMAT_CHARGING = "format-charging";
|
|
|
|
static constexpr auto FORMAT_DISCHARGING = "format-discharging";
|
|
|
|
static constexpr auto FORMAT_FULL = "format-full";
|
|
|
|
|
|
|
|
static constexpr auto TAG_ANIMATION_CHARGING = "<animation-charging>";
|
|
|
|
static constexpr auto TAG_BAR_CAPACITY = "<bar-capacity>";
|
|
|
|
static constexpr auto TAG_RAMP_CAPACITY = "<ramp-capacity>";
|
|
|
|
static constexpr auto TAG_LABEL_CHARGING = "<label-charging>";
|
|
|
|
static constexpr auto TAG_LABEL_DISCHARGING = "<label-discharging>";
|
|
|
|
static constexpr auto TAG_LABEL_FULL = "<label-full>";
|
|
|
|
|
|
|
|
animation_t m_animation_charging;
|
|
|
|
ramp_t m_ramp_capacity;
|
|
|
|
progressbar_t m_bar_capacity;
|
|
|
|
label_t m_label_charging;
|
|
|
|
label_t m_label_discharging;
|
|
|
|
label_t m_label_full;
|
|
|
|
|
|
|
|
string m_battery;
|
|
|
|
string m_adapter;
|
|
|
|
string m_path_capacity;
|
|
|
|
string m_path_adapter;
|
|
|
|
|
2016-10-30 09:41:06 -04:00
|
|
|
battery_state m_state = battery_state::UNKNOWN;
|
|
|
|
std::atomic_int m_percentage{0};
|
|
|
|
|
2016-11-03 07:56:33 -04:00
|
|
|
interval_t m_interval;
|
|
|
|
chrono::system_clock::time_point m_lastpoll;
|
|
|
|
|
2016-10-30 09:41:06 -04:00
|
|
|
int m_fullat = 100;
|
2016-05-19 10:41:06 -04:00
|
|
|
};
|
|
|
|
}
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
LEMONBUDDY_NS_END
|