Charging flag is not working if device charged with PC

Hi,

I wrote a battery widget but realized for myself (as well as some customer complaint) that the widget does not recoginize if the watch is charged with PC. I got a message from a user with a vivoactive 3 and I own a 945. This means it's not device specific. 

Now I have to write a workaround in the background service which drains more power as if the flag would work as expected. Is ths a known bug?

  • It's increasing when plugged into a PC.  During that time, the only thing in the log I posted is line 6 - my note that it's plugged into a PC, where the battery level on line 5 is 83% and then 100% on line 7..  Line 7 is after I unplugged. Lines 7-13, the watch isn't plugged in to anything, and there you see the battery decrease.

    Line 14 is my note that I plugged into wall power, and you see it goes from 98% back to 100%.in the next couple lines.

    The difference between line 6 and what happens in lines 15-20, is the background is running in lines 15-20, while in both cases, it's charging..

    The log starts with the watch not plugged into anything for about 30 mins, then plugged into a pc for about 30 mins (background doesn't run during that time), then not plugged into anything for about 30 mins, then plugged into a USB power supply for about 30 mins.

    By design - when you're plugged into a pc and in MTP/Mass store mode, most of the functions on the watch stop - no widgets/watch faces, etc run.  All it's really doing is charging and showing the full screen charging screen.

    Run the widget I posted yourself and see what's going on in the log, and you can see the background doesn't run while you're plugged into a pc, or when you are running a CIQ device app.

  • Thanks for clearing things up, Jim.

    Due to your information I reworte the background process. To summarize: The background process doesn't run during charging at the PC. This means, I have to check in the background process that battery level is increasing, but have to iron out some faulty readings (e. g. battery level rises due to temperature). I did this by two means/assumptions:

    1. the battery level has to be increased at least 4 % to the last time, the background process ran

    2. the watch has to be at least 400 seconds at the PC, to make this more robust

    The background process looks like this now:

    	function onTemporalEvent() {
           	var data = Background.getBackgroundData();
    		if (data == null) { data = {}; }
            var stats  = Sys.getSystemStats();
            var watchConnectedToPc = false;
           
            if (data["lastBat"] != null) {
           		if (stats.battery > data["lastBat"]) { // seems redundant but shall save power
           			// typically a watch chages 1 % per minute. Assuming that the watch is at least 10 minutes 
           			// at the PC, battery level should increase around 10 percent. To be on the safeside , check for 4%:
           			if (stats.battery - 4 > data["lastBat"]) { // iron out glitches if battery level increases accidentially e. g. through temp
           				// Robustness: last but not least check if the time between two background processes is at least 400 (>5 min)
           				// to minimize the risk of a faulty charge recognition due to a glitch in battery reading between two regular 
           				// checks
           				if (Date.now().value() - data["timeLastBatCheck"] > 400) {
           					watchConnectedToPc = true;
           				}
           			
           			}
           		} 
           	}
     
     
           	if (stats.charging or watchConnectedToPc) {
           		data.put("batAtUnplug", stats.battery);
           		data.put("timeAtUnplug", Date.now().value());
      			data.put("isCharging", true);
           	}
           	
           	data.put("lastBat", stats.battery);
           	data.put("timeLastBatCheck", Date.now().value());
    		
            Background.exit(data);
        }
    

    What do you think?

    Furthermore, as I understood you right, the use can't start the widget during charging, which means that I never need to implement some checks in the foreground process, assuming that the background process runs instantly after charging the PC. Right?

  • I've not looked at the code, but a clarification.  If you charging with a wall USB power supply, you can look at the widget, as the watch is running normally.  It would be the same where you use something like a battery based charger to top off your battery while "on the go".

    But the thing to really keep in mind is that the background might not run for long periods of time - when charging from a pc or running a CIQ device app.

  • One thing to consider is how/when/what is useful in something linke this.  Consider the following temporal event:

        function onTemporalEvent() {
        	var old=Background.getBackgroundData();
            var newData=[Time.now().value(),Sys.getSystemStats().battery];
            if(old!=null) {
            	newData=old.add(newData);
            	var sz=newData.size();
            	if(sz>maxSize) {newData=newData.slice(1, sz);}
            } else {
            	newData=[newData];
            }      
            Background.exit(newData);
        }

    Really simply and light.  There's an array, and the newest one is just added to what's not been seen by the widget yet, with  a "max" for how many samples.  I'm using a maxSize of 144 right now, with is one reading every 10 minutes for 24 hours.  In onBackgroundData, what it knows is combined with the new data, and is again limited to "maxSize" vales.

    So, the widget ends up with up to maxSize samples, with time stamps.  And the widget, which only runs a few times a day, can do the "heavy lifting" and display the data.  With this scheme, the widget can easily see the change in the last hour (with the timestamp), see when the last changing happened (the level increased x% from the older reading), and can see when the background didn't run because the watch was off, plugged into a PC, running a CIQ device app, etc. The time stamp again).

    So what you can show is something like:

    This is from the sim so a bit boring, but purple is the low value, green the high,the space on the graph with the pink underneath, the times the background didn't run, change over the last hour, how long ago it was charged and the change since then, etc.