• This repository has been archived on 12/Sep/2021
  • Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    C
  • Created almost 12 years ago
  • Updated almost 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Drawing iPhone Battery Charge / Discharge

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.

More Repositories

1

iOS-Runtime-Headers

iOS Objective-C headers as derived from runtime introspection
Objective-C
7,919
star
2

RuntimeBrowser

Objective-C Runtime Browser, for Mac OS X and iOS
Objective-C
3,507
star
3

objc_dep

Graph the import dependancies in an Objective-C project
Python
1,343
star
4

STTwitter

A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1
Objective-C
1,000
star
5

STHTTPRequest

Obj-C / Cocoa HTTP requests for humans
Objective-C
827
star
6

JSONTestSuite

A comprehensive test suite for RFC 8259 compliant JSON parsers
C++
826
star
7

objc_cover

Quick Python script over otool to help spotting potentially unused methods in Objective-C Mach-O executable files
Python
448
star
8

SpyPhone

This project shows the kind of data a rogue iPhone application can collect.
Objective-C
310
star
9

objc_strings

Helps in localizing Cocoa applications by showing unused/missing keys in Localizable.strings.
Python
191
star
10

BitmapCanvas

Bitmap offscreen drawing in Swift for OS X
Swift
121
star
11

gmap_tiles

Download and merge Google Maps tiles
Python
96
star
12

UniBinary

Encodes data into printable Unicode characters.
JavaScript
90
star
13

nsarray-functional

Objective-C category to add Python-like map, filter and reduce methods to Cocoa NSArray.
Objective-C
83
star
14

ScreenTime

create movies from periodic screenshots
Swift
74
star
15

MobileSignal

Map and chart the signal type and strength on your iOS device
Objective-C
69
star
16

STJSON

A JSON Parser in Swift 3 compliant with RFC 7159
Swift
68
star
17

BinUtils

Swift functions to ease working with binary formats
Swift
68
star
18

SQRiskCursor

Custom UIControl using CoreAnimation
Objective-C
59
star
19

CocoaSlideShow

Simple Image Browser for Mac OS X
Objective-C
52
star
20

SEVerticalTabBar

A vertical tab bar implementation for iPad
41
star
21

UTIsExplorer

Find OS X UTIs, build up the inheritance tree, save it as a Graphviz graph.
Objective-C
40
star
22

bfps

A Brainfuck interpreter written in PostScript
PostScript
35
star
23

ShapefileReader

A shapefile reader in Swift
Swift
34
star
24

FSWalker

A File System Browser for iOS
Objective-C
30
star
25

iCalReport

iCalReport reads iCal events and reports the time you spend on projects.
Python
25
star
26

UnicodePoster

Unicode Poster
Objective-C
25
star
27

CrashReports

Symbolicate iOS crash reports
Perl
23
star
28

filters

Apply filters on iOS Camera.app JPG files imported with Image Capture.
Python
21
star
29

osx_frameworks

Generate a .dot file of OS X frameworks dependencies
Python
21
star
30

Quickies

Simple PHP/MySQL application to share notes organized by category.
PHP
19
star
31

TwitHunter

Cocoa Twitter client with scoring
Objective-C
18
star
32

Brainfuck

A flexible Brainfuck / Brainloller / Braincopter interpreter in Swift 3.1.
Swift
15
star
33

Wireworld

A simple Wireworld cellular automaton explorer in Swift
Swift
13
star
34

draw_bytes

draw any file as a picture
Python
13
star
35

PulsarRuns

Pulsar-plot of Strava runs in Swift 3
Swift
12
star
36

DevTeamActivity

Generates a picture summarising the activity of a dev team on one or several repositories
Swift
11
star
37

Home-Made-Maps

Home Made Maps
11
star
38

SwissSMS

Mac OS X SMS sender
Objective-C
11
star
39

ECAExplorer

A simple and interactive tool to explore Elementary Cellular Automata, in Swift
Swift
10
star
40

Intertwined

Draw intertwined threads, knots and knitting figures with PyCairo
Python
9
star
41

EasterEggs

A social game that consists in catching QR-codes
Python
9
star
42

efx-backtest

Simple tool to backtest eForex strategies
Python
9
star
43

SwiftDrawing

Drawing in Swift
Swift
9
star
44

STMovingImages

Create .MOV and .GIF from NSImages in Swift 3
Swift
8
star
45

Twitter-Saver

Save your Twitter statuses in CSV format.
Python
7
star
46

deprecated-fb_albums

Download photos from Facebook photo albums.
Python
6
star
47

Isometric

Isometric screensaver for macOS, written in Swift
Swift
6
star
48

PyCairoVisualDoc

Turns PyCairo snippets into HTML
Python
6
star
49

AntennasAssignment

A combinatorial optimisation problem
Objective-C
5
star
50

HTTPRequests

NSURLRequest extensions in Swift
Swift
4
star
51

pmlogs_to_ical

Create a calendar of wake-sleep sessions based on power management logs.
4
star
52

JavaDoc

Legacy OS X Dashboard widget to access Java documentation
Objective-C
3
star
53

IsoRenderer

A 2D isometric renderer in Python 3 based on PyCairo
Python
3
star
54

Boggle

Python
2
star
55

WangTilesTuringMachines

Simulating Wang Tiles with Turing Machines
Python
2
star
56

matplotlib_experiments

Matplotlib experiments
2
star
57

MNIST

Measuring the accuracy of a trivial approach to the MNIST digits classification problem
Python
2
star
58

newsmemory

Django web application to crawl, store and browse pieces of news
Python
2
star
59

AVS

encrypt / decrypt Swiss AVS IDs
Python
1
star
60

HEIG-VD

A few projects from my time at Engineering School HEIG-VD
C
1
star
61

phpMyFlatSite

Minimal framework to run a classic, single user, dynamic web site.
PHP
1
star
62

Mowgli

Generate a static website from Markdown files with <150 lines of Python
CSS
1
star
63

PyGame

Experiments with PyGame
Python
1
star
64

STStrava

Experimental visualisation of runs using Swift and Strava API
Swift
1
star