prevent BTdaemon from stalling when Preferences.app with BTstack Prefs enters suspend mode

This commit is contained in:
matthias.ringwald@gmail.com 2012-04-04 16:19:26 +00:00
parent 8bb321cf59
commit d34a6e86ce
4 changed files with 57 additions and 46 deletions

View File

@ -100,7 +100,7 @@ static BluetoothController* sharedInstance = nil;
NSLog(@"Cannot connect to BTdaemon!"); NSLog(@"Cannot connect to BTdaemon!");
return NO; return NO;
} }
NSLog(@"Connected to BTdaemon!"); // NSLog(@"Connected to BTdaemon!");
isConnected = YES; isConnected = YES;
} }
@ -111,7 +111,7 @@ static BluetoothController* sharedInstance = nil;
} }
-(void)connectionBroke { -(void)connectionBroke {
NSLog(@"BTstack stopped"); // NSLog(@"BTstack stopped");
[self resetState]; [self resetState];
[self open]; [self open];
[listener bluetoothStateChanged]; [listener bluetoothStateChanged];
@ -119,7 +119,7 @@ static BluetoothController* sharedInstance = nil;
-(void)close{ -(void)close{
if (isConnected) { if (isConnected) {
NSLog(@"Disconnected from BTdaemon!"); // NSLog(@"Disconnected from BTdaemon!");
bt_close(); bt_close();
} }
[self resetState]; [self resetState];
@ -165,7 +165,7 @@ static BluetoothController* sharedInstance = nil;
return; return;
} }
NSLog(@"bluetoothStateChanged %u", type); // NSLog(@"bluetoothStateChanged %u", type);
state = kIdle; state = kIdle;
@ -180,11 +180,11 @@ static BluetoothController* sharedInstance = nil;
switch(packet[0]){ switch(packet[0]){
case BTSTACK_EVENT_STATE: case BTSTACK_EVENT_STATE:
hci_state = packet[2]; hci_state = packet[2];
NSLog(@"new BTSTACK_EVENT_STATE %u", hci_state); // NSLog(@"new BTSTACK_EVENT_STATE %u", hci_state);
break; break;
case BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED: case BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED:
system_bluetooth = packet[2]; system_bluetooth = packet[2];
NSLog(@"new BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED %u", system_bluetooth); // NSLog(@"new BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED %u", system_bluetooth);
break; break;
default: default:
break; break;
@ -214,16 +214,16 @@ static BluetoothController* sharedInstance = nil;
case kW4BTstackOffToEnableSystem: case kW4BTstackOffToEnableSystem:
if (packet[0] == BTSTACK_EVENT_STATE) { if (packet[0] == BTSTACK_EVENT_STATE) {
if (hci_state == HCI_STATE_OFF) { if (hci_state == HCI_STATE_OFF) {
NSLog(@"Sending set system bluetooth enable A"); // NSLog(@"Sending set system bluetooth enable A");
bt_send_cmd(&btstack_set_system_bluetooth_enabled, 1); bt_send_cmd(&btstack_set_system_bluetooth_enabled, 1);
} }
} }
if (packet[0] == BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED) { if (packet[0] == BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED) {
if (system_bluetooth == 0){ if (system_bluetooth == 0){
NSLog(@"Sending set system bluetooth enable B"); // NSLog(@"Sending set system bluetooth enable B");
bt_send_cmd(&btstack_set_system_bluetooth_enabled, 1); bt_send_cmd(&btstack_set_system_bluetooth_enabled, 1);
} else { } else {
NSLog(@"Sending set system bluetooth enable DONE"); // NSLog(@"Sending set system bluetooth enable DONE");
state = kIdle; state = kIdle;
} }
} }
@ -238,7 +238,7 @@ static BluetoothController* sharedInstance = nil;
} }
-(void)requestType:(BluetoothType_t)bluetoothType{ -(void)requestType:(BluetoothType_t)bluetoothType{
NSLog(@"bluetoothChangeRequested: old %u, new %u", [self bluetoothType], bluetoothType); // NSLog(@"bluetoothChangeRequested: old %u, new %u", [self bluetoothType], bluetoothType);
// ignore taps during transition // ignore taps during transition
if (state != kIdle) { if (state != kIdle) {

View File

@ -61,7 +61,7 @@
} }
-(void) loggingSwitchToggled { -(void) loggingSwitchToggled {
NSLog(@"Logging: %u", loggingSwitch.on); // NSLog(@"Logging: %u", loggingSwitch.on);
CFPropertyListRef on; CFPropertyListRef on;
if (loggingSwitch.on){ if (loggingSwitch.on){
on = kCFBooleanTrue; on = kCFBooleanTrue;
@ -98,7 +98,7 @@
BluetoothType_t bluetoothType = [[BluetoothController sharedInstance] targetType]; BluetoothType_t bluetoothType = [[BluetoothController sharedInstance] targetType];
BOOL activity = [[BluetoothController sharedInstance] isActive]; BOOL activity = [[BluetoothController sharedInstance] isActive];
NSLog(@"tableView update: type %u, active %u", bluetoothType, activity); // NSLog(@"tableView update: type %u, active %u", bluetoothType, activity);
switch ([indexPath section]) { switch ([indexPath section]) {
case 0: case 0:

View File

@ -1,3 +1,4 @@
export TARGET=iphone:latest:4.0
include $(THEOS)/makefiles/common.mk include $(THEOS)/makefiles/common.mk
BUNDLE_NAME = BTstack BUNDLE_NAME = BTstack

View File

@ -52,15 +52,13 @@
BluetoothController *bluetoothController; BluetoothController *bluetoothController;
UIView *_wrapperView; // for < 3.2 UIView *_wrapperView; // for < 3.2
UITableView *tableView; UITableView *tableView;
BOOL initialized;
@end @end
@implementation BluetoothPSViewController @implementation BluetoothPSViewController
- (id)initForContentSize:(CGSize)size - (id)initForContentSize:(CGSize)size
{ {
NSLog(@"initForContentSize"); // NSLog(@"initForContentSize");
initialized = NO;
if ([PSViewController instancesRespondToSelector:@selector(initForContentSize:)]) { if ([PSViewController instancesRespondToSelector:@selector(initForContentSize:)]) {
if ((self = [super initForContentSize:size])) { if ((self = [super initForContentSize:size])) {
CGRect frame; CGRect frame;
@ -77,8 +75,9 @@
- (void)dealloc - (void)dealloc
{ {
NSLog(@"dealloc"); // NSLog(@"dealloc");
[[BluetoothController sharedInstance] close];
[[BluetoothController sharedInstance] setListener:nil]; [[BluetoothController sharedInstance] setListener:nil];
[tableViewAdapter release]; [tableViewAdapter release];
@ -88,8 +87,6 @@
[_wrapperView release]; [_wrapperView release];
initialized = NO;
[super dealloc]; [super dealloc];
} }
@ -98,19 +95,38 @@
return [super view] ? [super view] : _wrapperView; return [super view] ? [super view] : _wrapperView;
} }
-(void)myInit{ -(void)didEnterBackground:(id)object{
// NSLog(@"didEnterBackground");
// close connection to BTdaemon
[[BluetoothController sharedInstance] close];
}
if (initialized) return; -(void)willEnterForeground:(id)object{
// NSLog(@"willEnterForeground");
// open connection to BTdaemon
[[BluetoothController sharedInstance] open];
}
initialized = YES; -(void)viewWillAppear:(BOOL)animated {
// NSLog(@"viewWillAppear");
// open connection to BTdaemon
[[BluetoothController sharedInstance] open];
}
NSLog(@"myInit"); -(void) viewDidDisappear:(BOOL)animated {
// NSLog(@"viewDidDisappear");
// close connection to BTdaemon
[[BluetoothController sharedInstance] close];
}
-(void)viewDidLoad {
// setup view
// NSLog(@"initialize");
((UINavigationItem*)[super navigationItem]).title = @"BTstack"; ((UINavigationItem*)[super navigationItem]).title = @"BTstack";
UIView *view = [self view]; UIView *view = [self view];
tableView = [[UITableView alloc] initWithFrame:view.bounds style:UITableViewStyleGrouped]; tableView = [[UITableView alloc] initWithFrame:view.bounds style:UITableViewStyleGrouped];
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@ -120,27 +136,21 @@
[view addSubview:tableView]; [view addSubview:tableView];
// setup Bluetooth Controller
[[BluetoothController sharedInstance] setListener:tableViewAdapter]; [[BluetoothController sharedInstance] setListener:tableViewAdapter];
[[BluetoothController sharedInstance] open];
// register for backrounding events
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(didEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(willEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
} }
-(void)viewDidLoad
{
NSLog(@"viewDidLoad");
[super viewDidLoad];
[self myInit];
}
- (void)viewWillBecomeVisible:(void *)source
{
NSLog(@"viewWillBecomeVisible %@", source);
[self myInit];
[super viewWillBecomeVisible:source];
}
- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"viewWillAppear");
[self myInit];
}
@end @end