mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-18 19:21:54 +00:00
allow for BTInquiryDelegate that gets notified on device selection
This commit is contained in:
parent
287f9f01fb
commit
09f92ef2fe
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
#include <btstack/hci_cmds.h> // for HCI_STATE
|
#include <btstack/hci_cmds.h> // for HCI_STATE
|
||||||
|
|
||||||
|
@class BTDevice;
|
||||||
|
@protocol BTInquiryDelegate;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
kInquiryInactive,
|
kInquiryInactive,
|
||||||
kInquiryActive,
|
kInquiryActive,
|
||||||
@ -22,10 +25,16 @@ typedef enum {
|
|||||||
UIActivityIndicatorView *bluetoothActivity;
|
UIActivityIndicatorView *bluetoothActivity;
|
||||||
UIFont * deviceNameFont;
|
UIFont * deviceNameFont;
|
||||||
UIFont * macAddressFont;
|
UIFont * macAddressFont;
|
||||||
|
id<BTInquiryDelegate> delegate;
|
||||||
}
|
}
|
||||||
- (void) setBluetoothState:(HCI_STATE)state;
|
- (void) setBluetoothState:(HCI_STATE)state;
|
||||||
- (void) setInquiryState:(InquiryState)state;
|
- (void) setInquiryState:(InquiryState)state;
|
||||||
- (InquiryState) inquiryState;
|
- (InquiryState) inquiryState;
|
||||||
- (HCI_STATE) bluetoothState;
|
- (HCI_STATE) bluetoothState;
|
||||||
@property (nonatomic, retain) NSMutableArray *devices;
|
@property (nonatomic, retain) NSMutableArray *devices;
|
||||||
|
@property (nonatomic, retain) id<BTInquiryDelegate> delegate;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@protocol BTInquiryDelegate
|
||||||
|
-(void) deviceChoosen:(BTInquiryViewController *) inqView device:(BTDevice*) device;
|
||||||
@end
|
@end
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
@implementation BTInquiryViewController
|
@implementation BTInquiryViewController
|
||||||
|
|
||||||
@synthesize devices;
|
@synthesize devices;
|
||||||
|
@synthesize delegate;
|
||||||
// #define MOCKUP
|
|
||||||
|
|
||||||
int mock_state = 0;
|
int mock_state = 0;
|
||||||
|
|
||||||
@ -170,63 +169,17 @@ int mock_state = 0;
|
|||||||
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
|
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
|
||||||
// [self.navigationController pushViewController:anotherViewController];
|
// [self.navigationController pushViewController:anotherViewController];
|
||||||
// [anotherViewController release];
|
// [anotherViewController release];
|
||||||
|
|
||||||
#ifdef MOCKUP
|
// valid selection?
|
||||||
switch (mock_state) {
|
int idx = [indexPath indexAtPosition:1];
|
||||||
|
if (bluetoothState == HCI_STATE_WORKING && inquiryState == kInquiryInactive && idx < [devices count]){
|
||||||
case 0:
|
if (delegate && [delegate respondsToSelector:@selector(deviceChoosen:device:)]){
|
||||||
bluetoothState = HCI_STATE_WORKING;
|
NSLog(@"delegate would respond");
|
||||||
[tableView reloadData];
|
[delegate deviceChoosen:self device:[devices objectAtIndex:idx]];
|
||||||
mock_state++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
inquiryState = kInquiryActive;
|
|
||||||
[tableView reloadData];
|
|
||||||
mock_state++;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
case 3: {
|
|
||||||
BTDevice * dev = [[BTDevice alloc] init];
|
|
||||||
bd_addr_t addr = { mock_state, mock_state, mock_state, mock_state, mock_state, mock_state};
|
|
||||||
[dev setAddress:&addr];
|
|
||||||
[devices addObject:dev];
|
|
||||||
[tableView reloadData];
|
|
||||||
mock_state++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 4: {
|
|
||||||
inquiryState = kInquiryRemoteName;
|
|
||||||
BTDevice * dev;
|
|
||||||
dev = [devices objectAtIndex:0];
|
|
||||||
// [dev setConnectionState:kBluetoothConnectionRemoteName];
|
|
||||||
dev = [devices objectAtIndex:1];
|
|
||||||
// [dev setConnectionState:kBluetoothConnectionRemoteName];
|
|
||||||
[tableView reloadData];
|
|
||||||
mock_state++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 5: {
|
|
||||||
BTDevice * dev;
|
|
||||||
dev = [devices objectAtIndex:0];
|
|
||||||
[dev setName:@"Fake Device 1"];
|
|
||||||
[dev setConnectionState:kBluetoothConnectionNotConnected];
|
|
||||||
[tableView reloadData];
|
|
||||||
mock_state++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 6: {
|
|
||||||
inquiryState = kInquiryInactive;
|
|
||||||
BTDevice * dev;
|
|
||||||
dev = [devices objectAtIndex:1];
|
|
||||||
[dev setConnectionState:kBluetoothConnectionNotConnected];
|
|
||||||
[dev setName:@"Fake Device 2"];
|
|
||||||
[tableView reloadData];
|
|
||||||
mock_state = 1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
[tableView deselectRowAtIndexPath:indexPath animated:TRUE];
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#import "BTInquiryViewController.h"
|
#import "BTInquiryViewController.h"
|
||||||
|
|
||||||
@interface BTstackCocoaAppDelegate : NSObject <UIApplicationDelegate> {
|
@interface BTstackCocoaAppDelegate : NSObject <UIApplicationDelegate,BTInquiryDelegate> {
|
||||||
UIWindow *window;
|
UIWindow *window;
|
||||||
BTInquiryViewController *inqView;
|
BTInquiryViewController *inqView;
|
||||||
bool inqActive;
|
bool inqActive;
|
||||||
|
@ -130,16 +130,16 @@ void showAlert(NSString *title, NSString *message){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
|
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
|
||||||
|
bt_flip_addr(event_addr, &data[3]);
|
||||||
|
BTDevice *dev = [self getDeviceForAddress:&event_addr];
|
||||||
|
if (!dev) break;
|
||||||
|
[dev setConnectionState:kBluetoothConnectionNotConnected];
|
||||||
if (data[2] == 0) {
|
if (data[2] == 0) {
|
||||||
bt_flip_addr(event_addr, &data[3]);
|
|
||||||
BTDevice *dev = [self getDeviceForAddress:&event_addr];
|
|
||||||
if (!dev) break;
|
|
||||||
[dev setConnectionState:kBluetoothConnectionNotConnected];
|
|
||||||
[dev setName:[NSString stringWithUTF8String:(const char *) &data[9]]];
|
[dev setName:[NSString stringWithUTF8String:(const char *) &data[9]]];
|
||||||
[[inqView tableView] reloadData];
|
|
||||||
remoteNameIndex++;
|
|
||||||
[self getNextRemoteName];
|
|
||||||
}
|
}
|
||||||
|
[[inqView tableView] reloadData];
|
||||||
|
remoteNameIndex++;
|
||||||
|
[self getNextRemoteName];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case L2CAP_EVENT_CHANNEL_OPENED:
|
case L2CAP_EVENT_CHANNEL_OPENED:
|
||||||
@ -187,6 +187,7 @@ void showAlert(NSString *title, NSString *message){
|
|||||||
inqView = [[BTInquiryViewController alloc] init];
|
inqView = [[BTInquiryViewController alloc] init];
|
||||||
devices = [[NSMutableArray alloc] init];
|
devices = [[NSMutableArray alloc] init];
|
||||||
[inqView setDevices:devices];
|
[inqView setDevices:devices];
|
||||||
|
[inqView setDelegate:self];
|
||||||
|
|
||||||
[window addSubview:[inqView view]];
|
[window addSubview:[inqView view]];
|
||||||
|
|
||||||
@ -201,7 +202,7 @@ void showAlert(NSString *title, NSString *message){
|
|||||||
if (res){
|
if (res){
|
||||||
[inqView setBluetoothState:HCI_STATE_OFF];
|
[inqView setBluetoothState:HCI_STATE_OFF];
|
||||||
showAlert(@"Bluetooth not accessible!",
|
showAlert(@"Bluetooth not accessible!",
|
||||||
@"The connection to BTstack failed!\n"
|
@"Connection to BTstack failed!\n"
|
||||||
"Please make sure that BTstack is installed correctly.");
|
"Please make sure that BTstack is installed correctly.");
|
||||||
} else {
|
} else {
|
||||||
bt_register_packet_handler(packet_handler);
|
bt_register_packet_handler(packet_handler);
|
||||||
@ -209,6 +210,11 @@ void showAlert(NSString *title, NSString *message){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** BTInquiryDelegate */
|
||||||
|
-(void) deviceChoosen:(BTInquiryViewController *) inqView device:(BTDevice*) device{
|
||||||
|
NSLog(@"deviceChoosen %@", [device toString]);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[window release];
|
[window release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user