worked around deprecated warnings when compiling for either 2.0 or 3.1.2

This commit is contained in:
matthias.ringwald 2009-12-07 23:04:11 +00:00
parent 6772a24cc3
commit b490540f96
3 changed files with 95 additions and 23 deletions

View File

@ -59,11 +59,15 @@ typedef enum {
} BluetoothConnectionState; } BluetoothConnectionState;
@interface BTDevice : NSObject { @interface BTDevice : NSObject {
bd_addr_t address;
bd_addr_t address; // potential key
NSString * name; NSString * name;
uint32_t classOfDevice;
uint8_t pageScanRepetitionMode; uint8_t pageScanRepetitionMode;
uint16_t clockOffset; uint16_t clockOffset;
uint32_t classOfDevice;
BluetoothConnectionState connectionState; BluetoothConnectionState connectionState;
} }

View File

@ -39,6 +39,11 @@
#include <btstack/hci_cmds.h> // for HCI_STATE #include <btstack/hci_cmds.h> // for HCI_STATE
#define PREFS_SHARED_SUITE "ch.ringwald.BTstack"
#define PREFS_DEVICES "Devices"
#define PREFS_NAME "Name"
#define PREFS_LINK_KEY "LinkKey"
@class BTDevice; @class BTDevice;
@protocol BTInquiryDelegate; @protocol BTInquiryDelegate;
@ -61,6 +66,9 @@ typedef enum {
bool allowSelection; bool allowSelection;
bool showIcons; bool showIcons;
// used to store link keys and remote names (soon :)
// NSMutableDictionary *deviceInfo;
// hacks // hacks
bool stopRemoteNameGathering; bool stopRemoteNameGathering;
bool restartInquiry; bool restartInquiry;
@ -68,6 +76,9 @@ typedef enum {
BTDevice *remoteDevice; // device for which connection is pending BTDevice *remoteDevice; // device for which connection is pending
BTDevice *connectedDevice; // device to which we're connected BTDevice *connectedDevice; // device to which we're connected
bool notifyDelegateOnInquiryStopped; bool notifyDelegateOnInquiryStopped;
// 2.0 - 3.0 compatibilty
bool onSDK20;
} }
- (void) startInquiry; - (void) startInquiry;
@ -80,6 +91,7 @@ typedef enum {
@property (nonatomic, assign) bool showIcons; @property (nonatomic, assign) bool showIcons;
@property (nonatomic, retain) NSMutableArray *devices; @property (nonatomic, retain) NSMutableArray *devices;
@property (nonatomic, retain) id<BTInquiryDelegate> delegate; @property (nonatomic, retain) id<BTInquiryDelegate> delegate;
// @property (nonatomic, retain) NSMutableDictionary *deviceInfo;
@end @end
@protocol BTInquiryDelegate @protocol BTInquiryDelegate

View File

@ -39,9 +39,18 @@
#import "BTDevice.h" #import "BTDevice.h"
#include <btstack/btstack.h> #include <btstack/btstack.h>
#include <dlfcn.h>
#define INQUIRY_INTERVAL 3 #define INQUIRY_INTERVAL 3
#ifndef __IPHONE_3_0
#define __IPHONE_3_0 30000
// SDK 30 defines missing in SDK 20
@interface UITableViewCell (NewIn30)
- (id)initWithStyle:(int)style reuseIdentifier:(NSString *)reuseIdentifier;
@end
#endif
static BTInquiryViewController *inqView; static BTInquiryViewController *inqView;
static btstack_packet_handler_t clientHandler; static btstack_packet_handler_t clientHandler;
static uint8_t remoteNameIndex; static uint8_t remoteNameIndex;
@ -62,6 +71,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
@implementation BTInquiryViewController @implementation BTInquiryViewController
@synthesize devices; @synthesize devices;
// @synthesize deviceInfo;
@synthesize delegate; @synthesize delegate;
@synthesize allowSelection; @synthesize allowSelection;
@synthesize showIcons; @synthesize showIcons;
@ -86,6 +96,24 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
devices = [[NSMutableArray alloc] init]; devices = [[NSMutableArray alloc] init];
inqView = self; inqView = self;
// create suite preferences
//CFStringRef testValue = CFSTR("TEST!!!");
//CFPreferencesSetAppValue (CFSTR(PREFS_DEVICES), testValue, CFSTR(PREFS_DEVICES));
//CFPreferencesAppSynchronize (CFSTR(PREFS_SHARED_SUITE));
// preferences
/* NSMutableDictionary *emptyDeviceInfo = [NSMutableDictionary dictionary];
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
[defaultValues setObject:emptyDeviceInfo forKey:@PREFS_DEVICES];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
[[NSUserDefaults standardUserDefaults] addSuiteNamed:@PREFS_SHARED_SUITE];
[self setDeviceInfo:[[NSUserDefaults standardUserDefaults] objectForKey:@PREFS_DEVICES] ];
*/
// check for the one missing method
onSDK20 = [UITableViewCell instancesRespondToSelector:@selector(initWithFrame:reuseIdentifier:)];
return self; return self;
} }
@ -217,6 +245,12 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
[self getNextRemoteName]; [self getNextRemoteName];
break; break;
case HCI_EVENT_LINK_KEY_REQUEST:
// link key request
bt_flip_addr(event_addr, &packet[2]);
bt_send_cmd(&hci_link_key_request_negative_reply, &event_addr);
break;
default: default:
break; break;
@ -423,69 +457,83 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) { if (cell == nil) {
if(onSDK20){
// @TODO 2.0 fix this:
// cell = [[UITableViewCell alloc] initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier;
} else {
cell = [[[UITableViewCell alloc] initWithStyle:/* UITableViewCellStyleDefault = */0 reuseIdentifier:CellIdentifier] autorelease]; cell = [[[UITableViewCell alloc] initWithStyle:/* UITableViewCellStyleDefault = */0 reuseIdentifier:CellIdentifier] autorelease];
// cell.selectionStyle = UITableViewCellSelectionStyleNone; }
} }
// Set up the cell... // Set up the cell...
NSString *label = nil; NSString *theLabel = nil;
UIImage *theImage = nil;
UIFont *theFont = nil;
int idx = [indexPath indexAtPosition:1]; int idx = [indexPath indexAtPosition:1];
if (bluetoothState != HCI_STATE_WORKING || idx >= [devices count]) { if (bluetoothState != HCI_STATE_WORKING || idx >= [devices count]) {
if (bluetoothState == HCI_STATE_INITIALIZING){ if (bluetoothState == HCI_STATE_INITIALIZING){
label = @"Activating BTstack..."; theLabel = @"Activating BTstack...";
cell.accessoryView = bluetoothActivity; cell.accessoryView = bluetoothActivity;
} else if (bluetoothState == HCI_STATE_OFF){ } else if (bluetoothState == HCI_STATE_OFF){
label = @"Bluetooth not accessible!"; theLabel = @"Bluetooth not accessible!";
cell.accessoryView = nil; cell.accessoryView = nil;
} else { } else {
if (connectedDevice) { if (connectedDevice) {
label = @"Disconnect"; theLabel = @"Disconnect";
cell.accessoryView = nil; cell.accessoryView = nil;
} else if (remoteDevice) { } else if (remoteDevice) {
label = @"Connecting..."; theLabel = @"Connecting...";
cell.accessoryView = bluetoothActivity; cell.accessoryView = bluetoothActivity;
} else { } else {
switch (inquiryState){ switch (inquiryState){
case kInquiryInactive: case kInquiryInactive:
if ([devices count] > 0){ if ([devices count] > 0){
label = @"Find more devices..."; theLabel = @"Find more devices...";
} else { } else {
label = @"Find devices..."; theLabel = @"Find devices...";
} }
cell.accessoryView = nil; cell.accessoryView = nil;
break; break;
case kInquiryActive: case kInquiryActive:
label = @"Searching..."; theLabel = @"Searching...";
cell.accessoryView = bluetoothActivity; cell.accessoryView = bluetoothActivity;
break; break;
case kInquiryRemoteName: case kInquiryRemoteName:
label = @"Query device names..."; theLabel = @"Query device names...";
cell.accessoryView = bluetoothActivity; cell.accessoryView = bluetoothActivity;
break; break;
} }
} }
} }
} else { } else {
BTDevice *dev = [devices objectAtIndex:idx]; BTDevice *dev = [devices objectAtIndex:idx];
label = [dev nameOrAddress];
// pick font
theLabel = [dev nameOrAddress];
if ([dev name]){ if ([dev name]){
cell.font = deviceNameFont; theFont = deviceNameFont;
} else { } else {
cell.font = macAddressFont; theFont = macAddressFont;
} }
// pick an icon for the devices // pick an icon for the devices
if (showIcons) { if (showIcons) {
int major = ([dev classOfDevice] & 0x1f00) >> 8; int major = ([dev classOfDevice] & 0x1f00) >> 8;
if (major == 0x01) { if (major == 0x01) {
cell.image = [UIImage imageNamed:@"computer.png"]; theImage = [UIImage imageNamed:@"computer.png"];
} else if (major == 0x02) { } else if (major == 0x02) {
cell.image = [UIImage imageNamed:@"smartphone.png"]; theImage = [UIImage imageNamed:@"smartphone.png"];
} else if ( major == 0x05 && ([dev classOfDevice] & 0xff) == 0x40){ } else if ( major == 0x05 && ([dev classOfDevice] & 0xff) == 0x40){
cell.image = [UIImage imageNamed:@"keyboard.png"]; theImage = [UIImage imageNamed:@"keyboard.png"];
} else { } else {
cell.image = [UIImage imageNamed:@"bluetooth.png"]; theImage = [UIImage imageNamed:@"bluetooth.png"];
} }
} }
// set accessory view
switch ([dev connectionState]) { switch ([dev connectionState]) {
case kBluetoothConnectionNotConnected: case kBluetoothConnectionNotConnected:
case kBluetoothConnectionConnected: case kBluetoothConnectionConnected:
@ -497,7 +545,15 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
break; break;
} }
} }
cell.text = label; #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0
if (theLabel) cell.textLabel.text = theLabel;
if (theFont) cell.textLabel.font = theFont;
if (theImage) cell.imageView.image = theImage;
#else
if (theLabel) cell.text = theLabel;
if (theFont) cell.font = theFont;
if (theImage) cell.image = theImage;
#endif
return cell; return cell;
} }