forked from mixxxdj/mixxx
/
battery.h
47 lines (37 loc) · 1.19 KB
/
battery.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include "util/timer.h"
class Battery : public QObject {
Q_OBJECT
public:
static constexpr int TIME_UNKNOWN = -1;
enum ChargingState {
UNKNOWN,
DISCHARGING,
CHARGING,
CHARGED,
};
static Battery* getBattery(QObject* parent=nullptr);
~Battery() override = default;
// The number of minutes the battery has remaining to depletion (when
// m_chargingState is DISCHARGING) or to being fully charged (when
// m_chargingState is CHARGING).
int getMinutesLeft() { return m_iMinutesLeft; }
// The current battery percentage charged (from 0 to 100).
double getPercentage() { return m_dPercentage; }
// The charging state of the battery.
ChargingState getChargingState() { return m_chargingState; }
public slots:
// calls read(), checks if state changed, invokes stateChanged
virtual void update();
signals:
// signal is emitted if the percentage or the charging state changed
void stateChanged();
protected:
Battery(QObject* parent=nullptr);
virtual void read() = 0;
ChargingState m_chargingState;
double m_dPercentage;
int m_iMinutesLeft;
private:
QTimer m_timer;
};