3 /// Talk to the Blackberry just enough to change the Max Power
4 /// to 500mA. Cycles through all devices attached to USB,
5 /// attempting to set all matching Blackberry devices to charge.
7 /// This file is part of the Barry project:
9 /// http://www.netdirect.ca/software/packages/barry/index.php
10 /// http://sourceforge.net/projects/barry
12 /// Compile with the following command (needs libusb):
14 /// g++ -o bcharge bcharge.cc -lusb
18 Copyright (C) 2006-2007, Net Direct Inc. (http://www.netdirect.ca/)
20 This program is free software; you can redistribute it and/or modify
21 it under the terms of the GNU General Public License as published by
22 the Free Software Foundation; either version 2 of the License, or
23 (at your option) any later version.
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29 See the GNU General Public License in the COPYING file at the
30 root directory of this project for more details.
37 #define VENDOR_RIM 0x0fca
38 #define PRODUCT_RIM_BLACKBERRY 0x0001
39 #define PRODUCT_RIM_PEARL 0x0006
41 #define BLACKBERRY_INTERFACE 0
42 #define BLACKBERRY_CONFIGURATION 1
44 void charge(struct usb_device
*dev
)
46 usb_dev_handle
*handle
= usb_open(dev
);
50 // the special sauce... these 3 steps seem to do the trick
51 // for the 7750 series... needs testing on others
53 usb_control_msg(handle
, 0xc0, 0xa5, 0, 1, buffer
, 2, 100);
54 usb_control_msg(handle
, 0x40, 0xa2, 0, 1, buffer
, 0, 100);
55 usb_set_configuration(handle
, BLACKBERRY_CONFIGURATION
);
57 // the Blackberry Pearl doesn't reset itself after the above,
59 if( dev
->descriptor
.idProduct
== PRODUCT_RIM_PEARL
) {
63 // let it reset itself
72 struct usb_bus
*busses
;
77 busses
= usb_get_busses();
79 printf("Scanning for Blackberry devices...\n");
83 for( bus
= busses
; bus
; bus
= bus
->next
) {
84 struct usb_device
*dev
;
86 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
87 // Is this a blackberry?
88 if( dev
->descriptor
.idVendor
== VENDOR_RIM
&&
89 (dev
->descriptor
.idProduct
== PRODUCT_RIM_BLACKBERRY
||
90 dev
->descriptor
.idProduct
== PRODUCT_RIM_PEARL
) ) {
93 dev
->descriptor
.bNumConfigurations
>= 1 &&
94 dev
->config
[0].MaxPower
< 250 ) {
95 printf("attempting to adjust charge setting.\n");
100 printf("already at 500mA\n");
106 printf("%d device%s adjusted.\n", found
, found
> 1 ? "s" : "");