Alright, after charging I need to find a way to empty the battery so that I can recharge it again :P . After all this a smart power pack, not just a smart battery charger. Lo and behold -
The bottom circuit consists of a 1$ eBay-bought buck converter - this uses a synchronous buck converter over the bigger LM2576 ones so they are much smaller. This is connected to the SYS voltage rail - the output of the adapter MOSFET. The bq24725a automatically switches on the other MOSFET to connect the battery to the SYS rail when the adapter is not present. When an adapter is connected, the adapter supplies power to the charger and the battery charges.
The 10uF electrolytic cap hides a TPS2513A which is responsible for applying appropriate voltages on D- and D+ pins so that the device being charged can draw maximum possible current from the supply (the converter should be able to able to provide 2A+ current.
There's an INA219A current monitor which uses a 0.1ohm shunt to monitor current flowing through the device. This can be used for efficiency calculations as well as you know V & I coming from the smart battery and V & I going out to the device - I see values around 86% efficiency which seems reasonable.
I also wrote a simple Python script (code here) using the curses library to provide an interactive display of the battery and INA219 values on the screen - here's a screenshot:
Zero current being drawn from the battery means that the buck converter is being powered from the mains rather than the battery! As soon as I disconnect adapter the battery will show a negative current flow indicating discharge. When charging, value of current is positive.
The final Smarter Power pack version will have 3 independent 5V outputs, and will be supervised by a microcontroller rather than my BeagleBone Black which I am using for prototyping right now.
Such a script would be great to have if the power pack is used to power the BeagleBone itself as a UPS - so the BeagleBone Black can take upon the role of a supervisor in that case. This script can run on the Pi as well and it can also be adapted to applications like automatically shutting down the system when battery is low, so on and so forth.
This is going to be really interesting now.