yun Battery powered - detect external supply or USB host on micro usb port.

Hi there arduino-people :)

I filed following feature request:

https://github.com/arduino/Arduino/issues/1875#issuecomment-35428359

I need a way to find out if the yun is connected to a power source like a cellphone charger or a usb host (like a computer) in order to do some useful battery management using the built in atmel µC.

basic ideea:

if 5V is present on USB-Port: - disable battery power for the device and use power from USB - charge the battery from the 5V net.

(and also prevent the battery from powering its own charger - wasting energy...)

if there are other suggestions or ideas how to detect the presence of an external power source on the micro usb port you can make me very happy :)

martin