File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change 42
42
43
43
#define POWER_SUPPLY_SUBSYSTEM " power_supply"
44
44
#define POWER_SUPPLY_SYSFS_PATH " /sys/class/" POWER_SUPPLY_SUBSYSTEM
45
+ #define SYSFS_BATTERY_CURRENT " /sys/class/power_supply/battery/current_now"
46
+ #define SYSFS_BATTERY_VOLTAGE " /sys/class/power_supply/battery/voltage_now"
45
47
#define FAKE_BATTERY_CAPACITY 42
46
48
#define FAKE_BATTERY_TEMPERATURE 424
47
49
#define MILLION 1.0e6
@@ -300,19 +302,13 @@ bool BatteryMonitor::update(void) {
300
302
KLOG_WARNING (LOG_TAG, " %s: Unknown power supply type\n " ,
301
303
mChargerNames [i].string ());
302
304
}
303
- path.clear ();
304
- path.appendFormat (" %s/%s/current_max" , POWER_SUPPLY_SYSFS_PATH,
305
- mChargerNames [i].string ());
306
- int ChargingCurrent =
307
- (access (path.string (), R_OK) == 0 ) ? getIntField (path) : 0 ;
308
305
309
- path.clear ();
310
- path.appendFormat (" %s/%s/voltage_max" , POWER_SUPPLY_SYSFS_PATH,
311
- mChargerNames [i].string ());
306
+ int ChargingCurrent =
307
+ (access (SYSFS_BATTERY_CURRENT, R_OK) == 0 ) ? abs (getIntField (String8 (SYSFS_BATTERY_CURRENT))) : 0 ;
312
308
313
309
int ChargingVoltage =
314
- (access (path. string () , R_OK) == 0 ) ? getIntField (path ) :
315
- DEFAULT_VBUS_VOLTAGE;
310
+ (access (SYSFS_BATTERY_VOLTAGE , R_OK) == 0 ) ? getIntField (String8 (SYSFS_BATTERY_VOLTAGE) ) :
311
+ DEFAULT_VBUS_VOLTAGE;
316
312
317
313
double power = ((double )ChargingCurrent / MILLION) *
318
314
((double )ChargingVoltage / MILLION);
You can’t perform that action at this time.
0 commit comments