Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b45f1f5b authored by Todd Poynor's avatar Todd Poynor
Browse files

healthd: add optional current_now and charge_counter to tracked state

uA and uAh units are converted to mA and mAh.

If current_now is present, add it to the heartbeat log (c=nnn).

Change-Id: I2b5fe7b4505c98ca2d11c3f94564c1c38493c8b9
parent d893e39d
Loading
Loading
Loading
Loading
+36 −6
Original line number Original line Diff line number Diff line
@@ -176,6 +176,8 @@ bool BatteryMonitor::update(void) {
    props.chargerWirelessOnline = false;
    props.chargerWirelessOnline = false;
    props.batteryStatus = BATTERY_STATUS_UNKNOWN;
    props.batteryStatus = BATTERY_STATUS_UNKNOWN;
    props.batteryHealth = BATTERY_HEALTH_UNKNOWN;
    props.batteryHealth = BATTERY_HEALTH_UNKNOWN;
    props.batteryCurrentNow = INT_MIN;
    props.batteryChargeCounter = INT_MIN;


    if (!mBatteryPresentPath.isEmpty())
    if (!mBatteryPresentPath.isEmpty())
        props.batteryPresent = getBooleanField(mBatteryPresentPath);
        props.batteryPresent = getBooleanField(mBatteryPresentPath);
@@ -184,6 +186,13 @@ bool BatteryMonitor::update(void) {


    props.batteryLevel = getIntField(mBatteryCapacityPath);
    props.batteryLevel = getIntField(mBatteryCapacityPath);
    props.batteryVoltage = getIntField(mBatteryVoltagePath) / 1000;
    props.batteryVoltage = getIntField(mBatteryVoltagePath) / 1000;

    if (!mBatteryCurrentNowPath.isEmpty())
        props.batteryCurrentNow = getIntField(mBatteryCurrentNowPath) / 1000;

    if (!mBatteryChargeCounterPath.isEmpty())
        props.batteryChargeCounter = getIntField(mBatteryChargeCounterPath) / 1000;

    props.batteryTemperature = getIntField(mBatteryTemperaturePath);
    props.batteryTemperature = getIntField(mBatteryTemperaturePath);


    const int SIZE = 128;
    const int SIZE = 128;
@@ -229,12 +238,23 @@ bool BatteryMonitor::update(void) {
        }
        }
    }
    }


    KLOG_INFO(LOG_TAG, "battery l=%d v=%d t=%s%d.%d h=%d st=%d chg=%s%s%s\n",
    char dmesgline[256];
    snprintf(dmesgline, sizeof(dmesgline),
             "battery l=%d v=%d t=%s%d.%d h=%d st=%d",
             props.batteryLevel, props.batteryVoltage,
             props.batteryLevel, props.batteryVoltage,
             props.batteryTemperature < 0 ? "-" : "",
             props.batteryTemperature < 0 ? "-" : "",
             abs(props.batteryTemperature / 10),
             abs(props.batteryTemperature / 10),
             abs(props.batteryTemperature % 10), props.batteryHealth,
             abs(props.batteryTemperature % 10), props.batteryHealth,
              props.batteryStatus,
             props.batteryStatus);

    if (!mBatteryCurrentNowPath.isEmpty()) {
        char b[20];

        snprintf(b, sizeof(b), " c=%d", props.batteryCurrentNow);
        strlcat(dmesgline, b, sizeof(dmesgline));
    }

    KLOG_INFO(LOG_TAG, "%s chg=%s%s%s\n", dmesgline,
              props.chargerAcOnline ? "a" : "",
              props.chargerAcOnline ? "a" : "",
              props.chargerUsbOnline ? "u" : "",
              props.chargerUsbOnline ? "u" : "",
              props.chargerWirelessOnline ? "w" : "");
              props.chargerWirelessOnline ? "w" : "");
@@ -304,6 +324,16 @@ void BatteryMonitor::init(bool nosvcmgr) {
                            mBatteryVoltagePath = path;
                            mBatteryVoltagePath = path;
                }
                }


                path.clear();
                path.appendFormat("%s/%s/current_now", POWER_SUPPLY_SYSFS_PATH, name);
                if (access(path, R_OK) == 0)
                    mBatteryCurrentNowPath = path;

                path.clear();
                path.appendFormat("%s/%s/charge_counter", POWER_SUPPLY_SYSFS_PATH, name);
                if (access(path, R_OK) == 0)
                    mBatteryChargeCounterPath = path;

                path.clear();
                path.clear();
                path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH, name);
                path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH, name);
                if (access(path, R_OK) == 0) {
                if (access(path, R_OK) == 0) {
+2 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,8 @@ class BatteryMonitor {
    String8 mBatteryVoltagePath;
    String8 mBatteryVoltagePath;
    String8 mBatteryTemperaturePath;
    String8 mBatteryTemperaturePath;
    String8 mBatteryTechnologyPath;
    String8 mBatteryTechnologyPath;
    String8 mBatteryCurrentNowPath;
    String8 mBatteryChargeCounterPath;


    Vector<String8> mChargerNames;
    Vector<String8> mChargerNames;