mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-07 16:20:19 +00:00
auto-select Wiimote with name 'Nintendo RVL-CNT-01', disable selection button
This commit is contained in:
parent
edeeb1de6a
commit
4f8ed4b8d4
@ -27,12 +27,20 @@ typedef enum {
|
|||||||
UIFont * deviceNameFont;
|
UIFont * deviceNameFont;
|
||||||
UIFont * macAddressFont;
|
UIFont * macAddressFont;
|
||||||
id<BTInquiryDelegate> delegate;
|
id<BTInquiryDelegate> delegate;
|
||||||
|
bool allowSelection;
|
||||||
|
|
||||||
|
// hack
|
||||||
|
bool stopRemoteNameGathering;
|
||||||
}
|
}
|
||||||
- (void) startInquiry;
|
- (void) startInquiry;
|
||||||
|
- (void) stopInquiry;
|
||||||
|
|
||||||
|
@property (nonatomic, assign) bool allowSelection;
|
||||||
@property (nonatomic, retain) NSMutableArray *devices;
|
@property (nonatomic, retain) NSMutableArray *devices;
|
||||||
@property (nonatomic, retain) id<BTInquiryDelegate> delegate;
|
@property (nonatomic, retain) id<BTInquiryDelegate> delegate;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@protocol BTInquiryDelegate
|
@protocol BTInquiryDelegate
|
||||||
- (void) deviceChoosen:(BTInquiryViewController *) inqView device:(BTDevice*) device;
|
- (void) deviceChoosen:(BTInquiryViewController *) inqView device:(BTDevice*) device;
|
||||||
|
- (void) deviceDetected:(BTInquiryViewController *) inqView device:(BTDevice*) device;
|
||||||
@end
|
@end
|
||||||
|
@ -30,6 +30,26 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
|
|
||||||
@synthesize devices;
|
@synthesize devices;
|
||||||
@synthesize delegate;
|
@synthesize delegate;
|
||||||
|
@synthesize allowSelection;
|
||||||
|
|
||||||
|
- (id) init {
|
||||||
|
self = [super initWithStyle:UITableViewStyleGrouped];
|
||||||
|
bluetoothState = HCI_STATE_OFF;
|
||||||
|
inquiryState = kInquiryInactive;
|
||||||
|
allowSelection = false;
|
||||||
|
|
||||||
|
macAddressFont = [UIFont fontWithName:@"Courier New" size:[UIFont labelFontSize]];
|
||||||
|
deviceNameFont = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
|
||||||
|
|
||||||
|
deviceActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
||||||
|
[deviceActivity startAnimating];
|
||||||
|
bluetoothActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
||||||
|
[bluetoothActivity startAnimating];
|
||||||
|
|
||||||
|
devices = [[NSMutableArray alloc] init];
|
||||||
|
inqView = self;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) handlePacket:(uint8_t) packet_type channel:(uint16_t) channel packet:(uint8_t*) packet size:(uint16_t) size {
|
- (void) handlePacket:(uint8_t) packet_type channel:(uint16_t) channel packet:(uint8_t*) packet size:(uint16_t) size {
|
||||||
static bool inquiryDone = 0;
|
static bool inquiryDone = 0;
|
||||||
@ -92,6 +112,10 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
hexdump(packet, size);
|
hexdump(packet, size);
|
||||||
NSLog(@"adding %@", [dev toString] );
|
NSLog(@"adding %@", [dev toString] );
|
||||||
[devices addObject:dev];
|
[devices addObject:dev];
|
||||||
|
|
||||||
|
if (delegate) {
|
||||||
|
[delegate deviceDetected:self device:dev];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[[inqView tableView] reloadData];
|
[[inqView tableView] reloadData];
|
||||||
@ -104,6 +128,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
[dev setConnectionState:kBluetoothConnectionNotConnected];
|
[dev setConnectionState:kBluetoothConnectionNotConnected];
|
||||||
if (packet[2] == 0) {
|
if (packet[2] == 0) {
|
||||||
[dev setName:[NSString stringWithUTF8String:(const char *) &packet[9]]];
|
[dev setName:[NSString stringWithUTF8String:(const char *) &packet[9]]];
|
||||||
|
if (delegate) {
|
||||||
|
[delegate deviceDetected:self device:dev];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[[self tableView] reloadData];
|
[[self tableView] reloadData];
|
||||||
remoteNameIndex++;
|
remoteNameIndex++;
|
||||||
@ -119,6 +146,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
NSLog(@"Inquiry stopped");
|
NSLog(@"Inquiry stopped");
|
||||||
if (inquiryState == kInquiryActive){
|
if (inquiryState == kInquiryActive){
|
||||||
remoteNameIndex = 0;
|
remoteNameIndex = 0;
|
||||||
|
stopRemoteNameGathering = false;
|
||||||
[self getNextRemoteName];
|
[self getNextRemoteName];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -148,7 +176,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
|
|
||||||
- (bool) getNextRemoteName{
|
- (bool) getNextRemoteName{
|
||||||
BTDevice *remoteDev = nil;
|
BTDevice *remoteDev = nil;
|
||||||
for (remoteNameIndex = 0; remoteNameIndex < [devices count] ; remoteNameIndex++){
|
|
||||||
|
for (remoteNameIndex = 0; !stopRemoteNameGathering && remoteNameIndex < [devices count]; remoteNameIndex++){
|
||||||
BTDevice *dev = [devices objectAtIndex:remoteNameIndex];
|
BTDevice *dev = [devices objectAtIndex:remoteNameIndex];
|
||||||
if (![dev name]){
|
if (![dev name]){
|
||||||
remoteDev = dev;
|
remoteDev = dev;
|
||||||
@ -161,38 +190,40 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
bt_send_cmd(&hci_remote_name_request, [remoteDev address], [remoteDev pageScanRepetitionMode], 0, [remoteDev clockOffset] | 0x8000);
|
bt_send_cmd(&hci_remote_name_request, [remoteDev address], [remoteDev pageScanRepetitionMode], 0, [remoteDev clockOffset] | 0x8000);
|
||||||
} else {
|
} else {
|
||||||
inquiryState = kInquiryInactive;
|
inquiryState = kInquiryInactive;
|
||||||
[[self tableView] reloadData];
|
|
||||||
// inquiry done.
|
// inquiry done.
|
||||||
}
|
}
|
||||||
return remoteDev;
|
[[self tableView] reloadData];
|
||||||
}
|
|
||||||
|
|
||||||
- (id) init {
|
|
||||||
self = [super initWithStyle:UITableViewStyleGrouped];
|
|
||||||
bluetoothState = HCI_STATE_OFF;
|
|
||||||
inquiryState = kInquiryInactive;
|
|
||||||
|
|
||||||
macAddressFont = [UIFont fontWithName:@"Courier New" size:[UIFont labelFontSize]];
|
|
||||||
deviceNameFont = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
|
|
||||||
|
|
||||||
deviceActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
return remoteDev;
|
||||||
[deviceActivity startAnimating];
|
|
||||||
bluetoothActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
|
||||||
[bluetoothActivity startAnimating];
|
|
||||||
|
|
||||||
devices = [[NSMutableArray alloc] init];
|
|
||||||
inqView = self;
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) startInquiry {
|
- (void) startInquiry {
|
||||||
// put into loop
|
// put into loop
|
||||||
|
|
||||||
|
// @TODO: cannot be called a second time!
|
||||||
clientHandler = bt_register_packet_handler(packet_handler);
|
clientHandler = bt_register_packet_handler(packet_handler);
|
||||||
|
|
||||||
bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
|
|
||||||
bluetoothState = HCI_STATE_INITIALIZING;
|
bluetoothState = HCI_STATE_INITIALIZING;
|
||||||
[[self tableView] reloadData];
|
[[self tableView] reloadData];
|
||||||
|
|
||||||
|
bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) stopInquiry {
|
||||||
|
switch (inquiryState) {
|
||||||
|
case kInquiryActive:
|
||||||
|
// just stop inquiry
|
||||||
|
bt_send_cmd(&hci_inquiry_cancel);
|
||||||
|
break;
|
||||||
|
case kInquiryInactive:
|
||||||
|
NSLog(@"stop inquiry called although inquiry inactive?");
|
||||||
|
break;
|
||||||
|
case kInquiryRemoteName:
|
||||||
|
stopRemoteNameGathering = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -355,6 +386,12 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
|
if (allowSelection) {
|
||||||
|
return indexPath;
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
16
TODO.txt
16
TODO.txt
@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
NEXT:
|
NEXT:
|
||||||
- prepare WiiMoteDemo for release
|
- prepare WiiMoteDemo for release
|
||||||
- on device select:
|
- auto-select Wiimote with name "Nintendo RVL-CNT-01"
|
||||||
- if name != WiiMote
|
- disable selection button
|
||||||
- show alert: need wiimote
|
- disable back button in GL view somehow
|
||||||
- set flag to connecting for WiiMote
|
|
||||||
- on connect, switch view
|
|
||||||
- on back button, disconnect device
|
|
||||||
- improve user experience of BTstack Inquiry View
|
- improve user experience of BTstack Inquiry View
|
||||||
- shorter inquiry interval
|
- shorter inquiry interval
|
||||||
- repeat inquiry while BT on
|
- repeat inquiry while BT on
|
||||||
- allow to select device and stop inquiry
|
- allow to select device and stop inquiry
|
||||||
- figure out why stack doesn't shut Bluetooth off when in sleep for a while/after wakeup
|
- CocoaTouch user interface
|
||||||
|
- add bluetooth on/off toggle
|
||||||
|
- on iPhone sleep, just turn off Bluetooth and disconnect all connections
|
||||||
|
- and figure out why stack doesn't shut Bluetooth off when in sleep for a while/after wakeup
|
||||||
- provide test version by setting up APT repository within BTstack SVN
|
- provide test version by setting up APT repository within BTstack SVN
|
||||||
- instructions: http://www.saurik.com/id/7
|
- instructions: http://www.saurik.com/id/7
|
||||||
- prepend all source files with 'new BSD' copyright header
|
- prepend all source files with 'new BSD' copyright header
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
- (void)startDemo;
|
- (void)startDemo;
|
||||||
|
|
||||||
|
|
||||||
@property (nonatomic, retain) UIWindow *window;
|
@property (nonatomic, retain) UIWindow *window;
|
||||||
@property (nonatomic, retain) UINavigationController *navControl;
|
@property (nonatomic, retain) UINavigationController *navControl;
|
||||||
@property (nonatomic, retain) UIViewController *glViewControl;
|
@property (nonatomic, retain) UIViewController *glViewControl;
|
||||||
|
@ -102,6 +102,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -137,6 +138,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
|||||||
// create inq controller
|
// create inq controller
|
||||||
inqViewControl = [[BTInquiryViewController alloc] init];
|
inqViewControl = [[BTInquiryViewController alloc] init];
|
||||||
[inqViewControl setTitle:@"BTstack Device Selector"];
|
[inqViewControl setTitle:@"BTstack Device Selector"];
|
||||||
|
[inqViewControl setAllowSelection:NO];
|
||||||
|
|
||||||
// create nav view controller
|
// create nav view controller
|
||||||
navControl = [[UINavigationController alloc] initWithRootViewController:inqViewControl];
|
navControl = [[UINavigationController alloc] initWithRootViewController:inqViewControl];
|
||||||
|
|
||||||
@ -169,13 +172,21 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
|||||||
|
|
||||||
-(void) deviceChoosen:(BTInquiryViewController *) inqView device:(BTDevice*) selectedDevice{
|
-(void) deviceChoosen:(BTInquiryViewController *) inqView device:(BTDevice*) selectedDevice{
|
||||||
NSLog(@"deviceChoosen %@", [device toString]);
|
NSLog(@"deviceChoosen %@", [device toString]);
|
||||||
|
|
||||||
device = selectedDevice;
|
|
||||||
[device setConnectionState:kBluetoothConnectionConnecting];
|
|
||||||
[[inqView tableView] reloadData];
|
|
||||||
bt_send_cmd(&l2cap_create_channel, [device address], 0x13);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) deviceDetected:(BTInquiryViewController *) inqView device:(BTDevice*) selectedDevice {
|
||||||
|
NSLog(@"deviceDetected %@", [device toString]);
|
||||||
|
if ([selectedDevice name] && [[selectedDevice name] caseInsensitiveCompare:@"Nintendo RVL-CNT-01"] == NSOrderedSame){
|
||||||
|
NSLog(@"WiiMote found with address %@", [BTDevice stringForAddress:[selectedDevice address]]);
|
||||||
|
device = selectedDevice;
|
||||||
|
[inqViewControl stopInquiry];
|
||||||
|
|
||||||
|
// connect to device
|
||||||
|
[device setConnectionState:kBluetoothConnectionConnecting];
|
||||||
|
[[[theMainApp inqViewControl] tableView] reloadData];
|
||||||
|
bt_send_cmd(&l2cap_create_channel, [device address], 0x13);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[window release];
|
[window release];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user