Thursday, September 9, 2010

Increasing battery life on the Blackberry 9700

I've been using my Blackberry 9700 for about 10 months now and am loving the phone - but a lot of collegues are complaining about battery drain in 16 hours, and general poor battery performance. As with any smartphone, the choice of features dictates power consumption, and here I've given a short breakdown of what to change/disable:

3G Mode - With most BIS implementations, you're only getting data at a maximum of 300kbps for UNCACHED local data, nowhere close to 3G speeds currently available, rather throttle back to EDGE (238kbps) and save on the transciever wasting power jumping between 3G and 2G mode (Manage Connections/Mobile Network Options/Network Mode=2G). Granted there will be a speed difference, but if you're using the Blackberry primarily for mail and not as a web browser, you should not notice any difference.

Bluetooth - If you're not going to pair with a headpiece or a carkit on a daily basis, rather just turn this off - even without pairing the battery use from constant device polling reduces efficiency (Manage Connections/Tick "Bluetooth" Off)

Wifi - Another bugbear - WiFi is great for high speed downloads but inside the office, unless you're using a dock to re-charge its not really worth it. Also even if you are not signed into a WLAN, the Wifi transceiver is also still searching for SSID's periodically, using valuable power. (Manage Connections/Tick "Wifi" Off)

GPS - Unless you're using the GPS daily - switch it off, even location based assistance will constantly be in data contact with Cell towers, using battery indescriminately (Options/Avanced Options/GPS/GPS Services "Location Off"; Location Data "Disabled"; Location Aiding "Disabled")

Standby - Switch the phone into standby with the little "Lock" button at the top left of the phone, this will shut off the screen after a few seconds and idle quite nicely. BIS E-mails will still be delivered and the phone will still ring when a call comes in. A simpler way is to use the leather wallet that came with the phone - there is a small magnet in the bottom that signals the phone to go into this mode, and disables standby when its removed from that pouch.

With all these options enabled and a good 10-20 calls per day, the minimum my battery lasts before the phone dies is 6 days - I've had up to 10 days with reduced call volume. This set of disablements does not affect me at all, and the increased battery life is worth having them off.

Friday, September 3, 2010

XBMC Remote Control: Part Deux - The Conclusion

After publishing my previous experience with XBMC, LIRC and the Iguanaworks IR adapter - I felt that after a bit of long term use the solution was a bit lacking for me. I still had to point the Control at the Tv/PC and holding a key to browse through a large list of movies had shuddering.

I did some more research on the matter, and settled on moving to bluetooth for directionless remote control ability. I had a belkin USB bluetooth adapter lying around, and I purchases a PS3 BD Remote Control unit for R400 from a local supplier.

There have been a few forum posts and articles about this for Ubuntu, but since I'm using Fedora Core 12 64-bit, I thought I'd share my experience:

bluetoothd (The Bluetooth Daemon) is installed by default. to provide a layer access between HCI devices and the kernel, you need to install a package called Bluez. Bluez does not natively support the PS3 remote implementation, so we will need to patch the bluez source with a diff from Kitlaan. To keep package management correct, I install the requisite version of bluez from yum, then compile the same version from source with the diff applied.

First to get the packages - Fedora 12 only has Bluez up to 4.58, and we want 4.64 - I just created a custom repo that pointed to the Fedora 13 repo (/etc/yum.repos.d/f13.repo) - file contents are:

name=Fedora $releasever - $basearch

Then execute the yum install of Bluez 4.64:
yum install bluez bluez-libs bluez-libs-devel

Then download the bluez 4.64 source and unzip it
cd ~; wget; tar zxvf bluez-4.64.tar.gz

And download the Kitlaan PS3 bluez patch:

cd ~; wget

Patch the source:
cd ~\bluez-4.64; patch -p1 < ../bluez_ps3remote_4.64.diff 

Then configure, make and install the modified bluez:
cd ~\bluez-4.64; ./configure; make && make install 

Next step is to setup the bluetooth remote as an input device on bluetooth, for this you need "Blueman" management tools, so install them: yum install blueman Now login as root, start X and open "blueman-applet" - clieck on "Search" and then press and hold the playstation remotes Enter and Start Buttons together (this puts the remote in discovery mode) - the device will now pop up in the menu of selectable bluetooth devices. click on setup device, and choost NOT to pair, and choose the input service for the device. Once that is done, trust the device and you are done.

Since I auto-login with the "xbmc" user and auto-run XBMC, blueman-applet tries to run in the background as user "xbmc", but with the reduced privileges it usally crashes out with messages in /var/log/messages like:

Aug 31 15:51:19 localhost python: abrt: detected unhandled Python exception in /usr/bin/blueman-applet 

The simplest solution is just to set sticky bit on blueman-applet so it will hold its original owner permissions after executing:

chown 7755 /usr/bin/blueman-applet 

This got rid of the error messages for me, and it starts up 100% in Gnome. Now that your device is setup with bluetooth, we need to find its Mac address and create a custom mapped input.conf for bluetooth to map the buttons. To find the paired device Mac address (Also check that its connected in /proc):

[root@xbmc ~]# hcitool con 
Connections: > ACL 00:23:06:E7:16:F9 handle 1 state 1 lm MASTER

[root@xbmc ~]# cat /proc/bus/input/devices
I: Bus=0005 Vendor=054c Product=0306 Version=0000
N: Name="PS3 Remote Controller"
P: Phys=
S: Sysfs=/devices/virtual/input/input6
U: Uniq=
H: Handlers=kbd event6
B: EV=3
B: KEY=8000000000000000 30000000000000 0 2100000000000000 0 0 bfc00080001c f01c0000d29a1ffe

Copy that ACL Mac address, you'll need to for /etc/bluetooth/input.conf (Listed is my custom configuration, which works for me, but you can change as required):

# Set idle timeout (in seconds) before the connection will
# be disconnect (defaults to 0 for no timeout)
# This section contains options that are specific to a device
# change this MAC address to that of your paired device
# use "hcitool con" to list active bluetooth connections
[00:23:06:E7:16:F9] <-- Replace this with YOUR Mac Address
# This section is the PS3 Remote keymap. It is loaded when bluez starts.
# Use 'uinput.h' from bluez sources or '/usr/include/linux/input.h' for
# a list of possible KEY_* values.
[PS3 Remote Map]
# When the 'OverlayBuiltin' option is TRUE (the default), the keymap uses
# the built-in keymap as a starting point. When FALSE, an empty keymap is
# the starting point.
#OverlayBuiltin = TRUE
#buttoncode = keypress # Button label = action with default key mappings
0x16 = KEY_EJECTCD        # EJECT = Eject CD/DVD Drive
0x64 = KEY_Y              # AUDIO = Mute Audio 
0x65 = KEY_Z              # ANGLE = cycle aspect ratio
0x63 = KEY_T              # SUBTITLE = toggle subtitles
0x0f = KEY_TAB            # CLEAR = Clear menu items on screen
0x28 = KEY_B              # TIMER = toggle through sleep
0x00 = KEY_1              # NUM-1
0x01 = KEY_2              # NUM-2
0x02 = KEY_3              # NUM-3
0x03 = KEY_4              # NUM-4
0x04 = KEY_5              # NUM-5
0x05 = KEY_6              # NUM-6
0x06 = KEY_7              # NUM-7
0x07 = KEY_8              # NUM-8
0x08 = KEY_9              # NUM-9
0x09 = KEY_0              # NUM-0
0x81 = KEY_F2             # RED = red
0x82 = KEY_F3             # GREEN = green
0x80 = KEY_F4             # BLUE = blue
0x83 = KEY_F5             # YELLOW = yellow
0x70 = KEY_I              # DISPLAY = show information
0x1a = KEY_S              # TOP MENU = show guide
0x40 = KEY_M              # POP UP/MENU = menu
0x0e = KEY_ESC            # RETURN = back/escape/cancel
0x5c = KEY_END            # TRIANGLE/OPTIONS = cycle through recording options
0x5d = KEY_BACKSPACE      # CIRCLE/BACK = back/escape/cancel
0x5f = KEY_MUTE           # SQUARE/VIEW = Adjust Playback timestretch
0x5e = KEY_O              # CROSS = select
0x54 = KEY_UP             # UP = Up/Skip forward 10 minutes
0x56 = KEY_DOWN           # DOWN = Down/Skip back 10 minutes
0x57 = KEY_LEFT           # LEFT = Left/Skip back 5 seconds
0x55 = KEY_RIGHT          # RIGHT = Right/Skip forward 30 seconds
0x0b = KEY_ENTER          # ENTER = select
0x5a = KEY_MINUS          # L1 = volume down
0x58 = KEY_Q              # L2 = Queue Media
0x51 = KEY_W              # L3 = Mark as Watched
0x5b = KEY_EQUAL            # R1 = volume up
0x59 = KEY_PAGEUP         # R2 = move up one page in watch recordings/EPG
0x52 = KEY_PAGEDOWN       # R3 = move down one page in watch recordings/EPG
0x43 = KEY_F9             # PS button = mute
0x50 = KEY_M              # SELECT = menu (as per PS convention)
0x53 = KEY_ENTER          # START = select / Enter (matches terminology in mythwelcome)
0x33 = KEY_R              # SCAN BACK =  decrease scan forward speed / play backwards; playback speed; 3x, 5, 10, 20, 30, 60, 120, 180
0x32 = KEY_P              # PLAY = play/pause
0x34 = KEY_F              # SCAN FORWARD = decrease scan backard speed / increase playback speed; 3x, 5, 10, 20, 30, 60, 120, 180
0x30 = KEY_DOWN           # PREVIOUS = skip back 10 mins
0x38 = KEY_X              # STOP = back/escape/cancel
0x31 = KEY_UP             # NEXT = skip forward 10 mins
# 0x60 = KEY_COMMA          # SLOW/STEP BACK = jump back (default 10 minutes)
0x39 = KEY_SPACE          # PAUSE = play/pause
# 0x61 = KEY_DOT            # SLOW/STEP FORWARD = jump forward (default 10 minutes)
0xff = KEY_MAX

I added the following keys to /usr/local/share/xbmc/system/keymaps/keyboard.xml for the two extra buttons I mapped above (B and Y):


And thats it, you dont need LIRC or any special key mapping XML's for XBMC, the remote is now just a keyboard, with its buttons mapped to specific keyboard keys. This works extremely well, as holding a button will repeat it, allowing you to run through long lists of movies, etc.. The remote also does not need to be pointed at the TV or PC to work, will work up to about 10 metres (33 feet) away and behind at least one wall. Compared to the Infra-Red setup I did with the Xbox360 remote, this is MUCH better and works 100% without any intervention. Battery life is good, I've been going about 4 weeks without changing batteries so far, with no signs of degraded signal.

Here is the PS3 remote layout on my system: