I am trying to integrate a BQ27531 battery gas gauge into a i.MX6 SoM. I loaded the drivers and everything looks good on the sysfs. When I run cat /sys/bus/i2c/devices/2-0055/power_supply/bq27531-0/temp
, I get a correct value of 247 (which means 24.7°C).
Now, I want to get the value in the Android system. I wrote a simple app that basically calls:
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent intent = registerReceiver(null, filter);
int temprature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
This should give me the temperature readings, but it is returning 424 (42.4°C). Why is the temperature value wrong? I am sure that the battery is around room temperature.
So, it turns out that my system did not recognize the battery, and 424 is the default "fake" temperature. It is defined in platform/system/core/healthd
:
#define POWER_SUPPLY_SUBSYSTEM "power_supply"
#define POWER_SUPPLY_SYSFS_PATH "/sys/class/" POWER_SUPPLY_SUBSYSTEM
#define FAKE_BATTERY_CAPACITY 42
#define FAKE_BATTERY_TEMPERATURE 424
#define ALWAYS_PLUGGED_CAPACITY 100
#define MILLION 1.0e6
#define DEFAULT_VBUS_VOLTAGE 5000000