- From: Poussa, Sakari <sakari.poussa@intel.com>
- Date: Tue, 8 Nov 2011 06:31:16 +0000
- To: "public-device-status@w3.org" <public-device-status@w3.org>
Hey, Here comes the proposal for the threshold attribute for the battery API as discussed DAP F2F meeting last week and captured on [1]. Background: During the F2F it was raised as a concern that the Battery API does not have the dedicated low and critical events anymore. Instead, the level and other events comes in on unspecified (implementation dependent) rate. Finally, there was no way for WebApp to be a good power management citizen by limiting the number (wakeup) events it was consuming. On battery powered devices (e.g. phones), every wake-up counts. The less wake-ups you have the better you battery life is. Proposal: the discussed solution was to define a 'threshold' parameter. When set, the API doesn't level events if the battery level is above the threshold. This way the WebApp can specify when it starts to receive battery events. When not set, the events will behave like now (without the threshold parameter). [NoInterfaceObject] interface BatteryManager : EventTarget { readonly attribute boolean charging; readonly attribute double chargingTime; readonly attribute float level; attribute float levelThreshold; /* NEW */ readonly attribute double dischargingTime; attribute Function? onchargingchange; attribute Function? onchargingtimechange; attribute Function? onlevelchange; attribute Function? ondischargingtimechange; }; attribute levelThreshold : When set (scale 0 - 1.0), indicates the level threshold when the the system should start sending the 'onlevelchange' events. When not set (equals to zero), the rate of the events is left to implementation. Below is an example which uses the new attribute to avoid any messages before the battery level drops below 20%. <script> // Power friendly app which only start receiving // any events when the battery level drops below 20% var battery = navigator.battery; // Start tracking the level only when it drops below 20% battery.levelThreshold = 0.2; battery.onlevelchange = function () { // Now we have only 20% left, start tracking the remaining time as well battery.ondischargingtimechange = function () { console.log("Battery level: " + battery.level + ", Remaining time (sec): " + battery.dischargingTime); }; }; </script> Any comments? -sakari [1] http://www.w3.org/2009/dap/track/actions/459
Received on Tuesday, 8 November 2011 06:38:33 UTC