mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-24 22:43:35 +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 * macAddressFont;
|
||||
id<BTInquiryDelegate> delegate;
|
||||
bool allowSelection;
|
||||
|
||||
// hack
|
||||
bool stopRemoteNameGathering;
|
||||
}
|
||||
- (void) startInquiry;
|
||||
- (void) stopInquiry;
|
||||
|
||||
@property (nonatomic, assign) bool allowSelection;
|
||||
@property (nonatomic, retain) NSMutableArray *devices;
|
||||
@property (nonatomic, retain) id<BTInquiryDelegate> delegate;
|
||||
@end
|
||||
|
||||
@protocol BTInquiryDelegate
|
||||
- (void) deviceChoosen:(BTInquiryViewController *) inqView device:(BTDevice*) device;
|
||||
- (void) deviceDetected:(BTInquiryViewController *) inqView device:(BTDevice*) device;
|
||||
@end
|
||||
|
@ -30,6 +30,26 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
|
||||
@synthesize devices;
|
||||
@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 {
|
||||
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);
|
||||
NSLog(@"adding %@", [dev toString] );
|
||||
[devices addObject:dev];
|
||||
|
||||
if (delegate) {
|
||||
[delegate deviceDetected:self device:dev];
|
||||
}
|
||||
}
|
||||
}
|
||||
[[inqView tableView] reloadData];
|
||||
@ -104,6 +128,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
[dev setConnectionState:kBluetoothConnectionNotConnected];
|
||||
if (packet[2] == 0) {
|
||||
[dev setName:[NSString stringWithUTF8String:(const char *) &packet[9]]];
|
||||
if (delegate) {
|
||||
[delegate deviceDetected:self device:dev];
|
||||
}
|
||||
}
|
||||
[[self tableView] reloadData];
|
||||
remoteNameIndex++;
|
||||
@ -119,6 +146,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
NSLog(@"Inquiry stopped");
|
||||
if (inquiryState == kInquiryActive){
|
||||
remoteNameIndex = 0;
|
||||
stopRemoteNameGathering = false;
|
||||
[self getNextRemoteName];
|
||||
}
|
||||
break;
|
||||
@ -148,7 +176,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
|
||||
- (bool) getNextRemoteName{
|
||||
BTDevice *remoteDev = nil;
|
||||
for (remoteNameIndex = 0; remoteNameIndex < [devices count] ; remoteNameIndex++){
|
||||
|
||||
for (remoteNameIndex = 0; !stopRemoteNameGathering && remoteNameIndex < [devices count]; remoteNameIndex++){
|
||||
BTDevice *dev = [devices objectAtIndex:remoteNameIndex];
|
||||
if (![dev name]){
|
||||
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);
|
||||
} else {
|
||||
inquiryState = kInquiryInactive;
|
||||
[[self tableView] reloadData];
|
||||
// inquiry done.
|
||||
}
|
||||
return remoteDev;
|
||||
}
|
||||
|
||||
- (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]];
|
||||
[[self tableView] reloadData];
|
||||
|
||||
deviceActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
||||
[deviceActivity startAnimating];
|
||||
bluetoothActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
||||
[bluetoothActivity startAnimating];
|
||||
|
||||
devices = [[NSMutableArray alloc] init];
|
||||
inqView = self;
|
||||
return self;
|
||||
return remoteDev;
|
||||
}
|
||||
|
||||
- (void) startInquiry {
|
||||
// put into loop
|
||||
|
||||
// @TODO: cannot be called a second time!
|
||||
clientHandler = bt_register_packet_handler(packet_handler);
|
||||
|
||||
bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
|
||||
bluetoothState = HCI_STATE_INITIALIZING;
|
||||
[[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
|
||||
|
||||
|
16
TODO.txt
16
TODO.txt
@ -2,17 +2,17 @@
|
||||
|
||||
NEXT:
|
||||
- prepare WiiMoteDemo for release
|
||||
- on device select:
|
||||
- if name != WiiMote
|
||||
- show alert: need wiimote
|
||||
- set flag to connecting for WiiMote
|
||||
- on connect, switch view
|
||||
- on back button, disconnect device
|
||||
- auto-select Wiimote with name "Nintendo RVL-CNT-01"
|
||||
- disable selection button
|
||||
- disable back button in GL view somehow
|
||||
- improve user experience of BTstack Inquiry View
|
||||
- shorter inquiry interval
|
||||
- repeat inquiry while BT on
|
||||
- allow to select device and stop inquiry
|
||||
- figure out why stack doesn't shut Bluetooth off when in sleep for a while/after wakeup
|
||||
- allow to select device and stop inquiry
|
||||
- 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
|
||||
- instructions: http://www.saurik.com/id/7
|
||||
- prepend all source files with 'new BSD' copyright header
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
- (void)startDemo;
|
||||
|
||||
|
||||
@property (nonatomic, retain) UIWindow *window;
|
||||
@property (nonatomic, retain) UINavigationController *navControl;
|
||||
@property (nonatomic, retain) UIViewController *glViewControl;
|
||||
|
@ -102,6 +102,7 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@ -137,6 +138,8 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint
|
||||
// create inq controller
|
||||
inqViewControl = [[BTInquiryViewController alloc] init];
|
||||
[inqViewControl setTitle:@"BTstack Device Selector"];
|
||||
[inqViewControl setAllowSelection:NO];
|
||||
|
||||
// create nav view controller
|
||||
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{
|
||||
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 {
|
||||
[window release];
|
||||
|
Loading…
x
Reference in New Issue
Block a user