From 287f9f01fb2173cb56670dc9adfd9fb351daa842 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sun, 18 Oct 2009 09:21:54 +0000 Subject: [PATCH] Show alert when BTstack init fails because of other stack --- CocoaTouch/src/BTInquiryViewController.m | 2 +- CocoaTouch/src/BTstackCocoaAppDelegate.m | 31 +++++++++++++++--------- TODO.txt | 1 - 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CocoaTouch/src/BTInquiryViewController.m b/CocoaTouch/src/BTInquiryViewController.m index 1cee5a426..dce29ae32 100644 --- a/CocoaTouch/src/BTInquiryViewController.m +++ b/CocoaTouch/src/BTInquiryViewController.m @@ -118,7 +118,7 @@ int mock_state = 0; label = @"Activating BTstack..."; cell.accessoryView = bluetoothActivity; } else if (bluetoothState == HCI_STATE_OFF){ - label = @"BTstack not accessible!"; + label = @"Bluetooth not accessible!"; cell.accessoryView = nil; } else { switch (inquiryState){ diff --git a/CocoaTouch/src/BTstackCocoaAppDelegate.m b/CocoaTouch/src/BTstackCocoaAppDelegate.m index bdc13a5f3..1ffd5d7b2 100644 --- a/CocoaTouch/src/BTstackCocoaAppDelegate.m +++ b/CocoaTouch/src/BTstackCocoaAppDelegate.m @@ -22,6 +22,15 @@ void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ [ ((BTstackCocoaAppDelegate *)[[UIApplication sharedApplication] delegate]) handlePacketWithType:packet_type data:packet len:size]; } +void showAlert(NSString *title, NSString *message){ + NSLog(@"Alert: %@ - %@", title, message); + UIAlertView* alertView = [[UIAlertView alloc] init]; + alertView.title = title; + alertView.message = message; + [alertView addButtonWithTitle:@"Dismiss"]; + [alertView show]; +} + @implementation BTstackCocoaAppDelegate @synthesize window; @@ -88,6 +97,13 @@ void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ } break; + case BTSTACK_EVENT_POWERON_FAILED: + [inqView setBluetoothState:HCI_STATE_OFF]; + showAlert(@"Bluetooth not accessible!", + @"Hardware initialization failed!\n" + "Make sure you have turned off Bluetooth in the System Settings."); + break; + case HCI_EVENT_INQUIRY_RESULT: case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI: { @@ -183,19 +199,10 @@ void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){ int res = bt_open(); if (res){ - NSString * error = @"Connecting to BTdaemon failed!\n" - "Please make sure it is\n" - "a) stalled and\n" - "b) that it's either running or can that it can be started by launchd."; - NSLog(@"%@", error); [inqView setBluetoothState:HCI_STATE_OFF]; - - UIAlertView* alertView = [[UIAlertView alloc] init]; - alertView.title = @"BTstack not accessible!"; - alertView.message = error; - [alertView addButtonWithTitle:@"Dismiss"]; - [alertView show]; - + showAlert(@"Bluetooth not accessible!", + @"The connection to BTstack failed!\n" + "Please make sure that BTstack is installed correctly."); } else { bt_register_packet_handler(packet_handler); bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON ); diff --git a/TODO.txt b/TODO.txt index 47bff575b..9c750f91f 100644 --- a/TODO.txt +++ b/TODO.txt @@ -5,7 +5,6 @@ Last change: don't set name to empty string on error in CocoaTouch NEXT: - CocoaTouch User Interface Components - - Show alert when BTstack init fails because of other stack - define delegate interface for select events - prepare WiiMoteDemo for release - integrate new inquiry code