Arduino Leonardo(Atmega32u4) - Detecting if USB is connected to a computer? The closest thing I can find is if(Serial) but that only returns true if there's a serial port open.

The function I want, ideally, should:

Return true if plugged into a computer

Return false if plugged into a USB power bank

Return false if not plugged in at all(Running off of its own lithium cell)
ADDEN of UDADDR is set if the '32U4 has been assigned a USB address by the host and the firmware wants to enable USB connectivity.

UDADDR &amp; _BV(ADDEN)