-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRetroDevicePower.cpp
62 lines (52 loc) · 1.47 KB
/
QRetroDevicePower.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#if QRETRO_HAVE_SYSTEMINFO
#include <QSystemBatteryInfo>
QTM_USE_NAMESPACE
#endif
#include "QRetroDevicePower.h"
bool QRetroDevicePower::get(retro_device_power *power)
{
/* On null pointer, just report support state */
if (!power)
return true;
else if (m_Spoofing)
{
*power = m_SpoofPower;
return true;
}
#if QRETRO_HAVE_SYSTEMINFO
QSystemBatteryInfo battery;
/** Set device power state */
auto state = battery.chargingState();
auto type = battery.chargingType();
if (state == QSystemBatteryInfo::ChargingError)
return false;
else if (state == QSystemBatteryInfo::BatteryFull)
power->state = RETRO_POWERSTATE_CHARGED;
else if (state == QSystemBatteryInfo::NotCharging)
{
if (type == QSystemBatteryInfo::BatteryUnknown)
power->state = RETRO_POWERSTATE_PLUGGED_IN;
else
power->state = RETRO_POWERSTATE_DISCHARGING;
}
else if (state == QSystemBatteryInfo::Charging)
power->state = RETRO_POWERSTATE_CHARGING;
/**
* Set device power seconds.
* Will use default value if not running off battery.
*/
if (power->state != RETRO_POWERSTATE_DISCHARGING)
power->seconds = RETRO_POWERSTATE_NO_ESTIMATE;
else
{
auto remain = battery.remainingCapacity();
auto flow = battery.currentFlow();
power->seconds = static_cast<int>(remain / flow * 3600);
}
/** Set device power percent */
power->percent = static_cast<int8_t>(battery.remainingCapacityPercent());
return true;
#else
return false;
#endif
}