0

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.

  • Batteries are never around room temperature. They produce heat when they provide electricity- lots of it. Ever felt your phone getting hot after use? That's the battery. 42C is a very reasonable battery temperature. – Gabe Sechan Aug 09 '17 at 20:58
  • I don't know where the 424 value came from. When I put my hand on the battery and run the `cat` cammand again, the value goes from 24.7 to 24.9. What I want is to get that reading from the driver. – Siu Lung Leung Aug 09 '17 at 21:01
  • Are you sure that your Manager takes this value from correct driver and not stubbed ? – once2go Aug 09 '17 at 21:15

1 Answers1

0

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