GithubHelp home page GithubHelp logo

batterychart's Introduction

Drawing iPhone Battery Charge / Discharge

Goals

  • play with iOS battery related APIs
  • find out the best way to measure the battery's charge
  • tell if the charge level is linear in time

Methodology

I wrote the BatteryChart iPhone application. This applications listens to battery data changes notifications and logs the following data into a CSV file:

[0] date
[1] UIStatusBarServerThread StatusBarData -> batteryCapacity
[2] -[OSDBattery _getBatteryLevel]
[3] -[UIDevice batteryLevel]
[4] -[OSDBattery _getBatteryCurrentCapacity]
[5] -[OSDBattery _getBatteryMaxCapacity]
[6] -[OSDBattery _getRawBatteryVoltage]
[7] IOKit IOPSGetPowerSourceDescription CurrentCapacity / MaxCapacity

Note that only [3] is a public API.

The log file is appended and saved after each measure, so that even if the device shuts down the measures remain saved. You can retrieve the latest file by sending it to your email address. You can also retrieve all the files through Xcode Organizer.

Battery chart draws the current charge according to the time. More precisely it draws -[OSDBattery getBatteryCurrentCapacity] divided by -[OSDBattery getBatteryMaxCapacity].

Results

Here is a sample chart:

Data showing a full charge / discharge cycle are available in the /data/ directory.

Observations

Charge
  • discharge is linerar
  • charge is linear until 80%
  • after 80% happens "trickle charging":

Most lithium-ion polymer batteries use a fast charge to charge your device to 80% battery capacity, then switch to trickle charging. That’s about two hours of charge time to power an iPod to 80% capacity, then another two hours to fully charge it, if you are not using the iPod while charging. http://www.apple.com/batteries/

Measures
  • the public API -[UIDevice batteryLevel] is the less accurate, returning the status bar value rounded to 0.5
  • all other ways of measuring the battery level return different results, especially when the battery reaches full charge (see charts below)
  • -[OSDBattery _getBatteryCurrentCapacity] sporadically returns 0
  • -[OSDBattery _getBatteryLevel] returns the same result as _getBatteryCurrentCapacity / _getBatteryMaxCapacity
  • -[OSDBattery _getBatteryLevel] is very close to IOKit measure
Other noticeable APIs
  • [OSDBattery _getBatterySerialNumber]
  • [OSDBattery _getBatteryCycleCount]

Charts

Here are two charts showing the full discharge / recharge.

The charts are plotted with the matplotlib Python library. The code is available in the data directory.

batterychart's People

Contributors

nst avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.