I ran into an odd problem when working with a boron running on solar power. I wanted the device to automatically sleep without connecting on startup if the battery was under a certain cutoff value, to prevent the device from getting stuck in a loop attempting to connect and failing because of low power, keeping the battery from recharging.
However, when using System.batteryCharge() immediately upon calling setup() to determine whether to sleep, it would always sleep even with a fully charged battery, because the call would return -1 as if the battery were disconnected. Instantiating a FuelGauge object and calling getNormalizedSoC() did not have this issue at all. Also, naively delaying a few seconds before checking the battery resolved the issue, but this is not ideal.
Is there some sort of race condition at play with System.batteryCharge() on startup? The docs say that function internally calls getNormalizedSoC(), so I'm not sure what's going on here.
Also, when creating an instance of FuelGauge, does calling its methods always return the current value of battery charge/voltage/etc., or does a new instance need to be instantiated each time a reading is taken?