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!");
return NO;
}
NSLog(@"Connected to BTdaemon!");
// NSLog(@"Connected to BTdaemon!");
isConnected = YES;
}
@ -111,7 +111,7 @@ static BluetoothController* sharedInstance = nil;
}
-(void)connectionBroke {
NSLog(@"BTstack stopped");
// NSLog(@"BTstack stopped");
[self resetState];
[self open];
[listener bluetoothStateChanged];
@ -119,7 +119,7 @@ static BluetoothController* sharedInstance = nil;
-(void)close{
if (isConnected) {
NSLog(@"Disconnected from BTdaemon!");
// NSLog(@"Disconnected from BTdaemon!");
bt_close();
}
[self resetState];
@ -165,7 +165,7 @@ static BluetoothController* sharedInstance = nil;
return;
}
NSLog(@"bluetoothStateChanged %u", type);
// NSLog(@"bluetoothStateChanged %u", type);
state = kIdle;
@ -180,11 +180,11 @@ static BluetoothController* sharedInstance = nil;
switch(packet[0]){
case BTSTACK_EVENT_STATE:
hci_state = packet[2];
NSLog(@"new BTSTACK_EVENT_STATE %u", hci_state);
// NSLog(@"new BTSTACK_EVENT_STATE %u", hci_state);
break;
case BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED:
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;
default:
break;
@ -214,16 +214,16 @@ static BluetoothController* sharedInstance = nil;
case kW4BTstackOffToEnableSystem:
if (packet[0] == BTSTACK_EVENT_STATE) {
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);
}
}
if (packet[0] == BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED) {
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);
} else {
NSLog(@"Sending set system bluetooth enable DONE");
// NSLog(@"Sending set system bluetooth enable DONE");
state = kIdle;
}
}
@ -238,7 +238,7 @@ static BluetoothController* sharedInstance = nil;
}
-(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
if (state != kIdle) {

View File

@ -61,7 +61,7 @@
}
-(void) loggingSwitchToggled {
NSLog(@"Logging: %u", loggingSwitch.on);
// NSLog(@"Logging: %u", loggingSwitch.on);
CFPropertyListRef on;
if (loggingSwitch.on){
on = kCFBooleanTrue;
@ -98,7 +98,7 @@
BluetoothType_t bluetoothType = [[BluetoothController sharedInstance] targetType];
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]) {
case 0:

View File

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

View File

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