mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-28 19:20:54 +00:00
Show alert when BTstack open fails because of no BTdaemon
This commit is contained in:
parent
c35f2df118
commit
6c9a8e599c
@ -117,6 +117,9 @@ int mock_state = 0;
|
|||||||
if (bluetoothState == HCI_STATE_INITIALIZING){
|
if (bluetoothState == HCI_STATE_INITIALIZING){
|
||||||
label = @"Activating BTstack...";
|
label = @"Activating BTstack...";
|
||||||
cell.accessoryView = bluetoothActivity;
|
cell.accessoryView = bluetoothActivity;
|
||||||
|
} else if (bluetoothState == HCI_STATE_OFF){
|
||||||
|
label = @"BTstack not accessible!";
|
||||||
|
cell.accessoryView = nil;
|
||||||
} else {
|
} else {
|
||||||
switch (inquiryState){
|
switch (inquiryState){
|
||||||
case kInquiryInactive:
|
case kInquiryInactive:
|
||||||
|
@ -180,9 +180,26 @@ void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
|||||||
// start Bluetooth
|
// start Bluetooth
|
||||||
[inqView setBluetoothState:HCI_STATE_INITIALIZING];
|
[inqView setBluetoothState:HCI_STATE_INITIALIZING];
|
||||||
run_loop_init(RUN_LOOP_COCOA);
|
run_loop_init(RUN_LOOP_COCOA);
|
||||||
bt_open();
|
|
||||||
bt_register_packet_handler(packet_handler);
|
int res = bt_open();
|
||||||
bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
|
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];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
bt_register_packet_handler(packet_handler);
|
||||||
|
bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
|
9
TODO.txt
9
TODO.txt
@ -5,14 +5,15 @@ Last change: don't set name to empty string on error in CocoaTouch
|
|||||||
|
|
||||||
NEXT:
|
NEXT:
|
||||||
- CocoaTouch User Interface Components
|
- CocoaTouch User Interface Components
|
||||||
- Show alert when BTstack open fails because of no BTdaemon
|
|
||||||
- Show alert when BTstack init fails because of other stack
|
- Show alert when BTstack init fails because of other stack
|
||||||
- define delegate interface for select events
|
- define delegate interface for select events
|
||||||
- prepare WiiMoteDemo for release
|
- prepare WiiMoteDemo for release
|
||||||
- integrate new inquiry code
|
- integrate new inquiry code
|
||||||
- figure out why stack doesn't shut Bluetooth off when in sleep for a while
|
|
||||||
|
- 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
|
||||||
|
|
||||||
== Release Version 0.1
|
== Release Version 0.1
|
||||||
|
|
||||||
@ -20,8 +21,10 @@ NEXT:
|
|||||||
- incoming connections
|
- incoming connections
|
||||||
- list of supported PSM
|
- list of supported PSM
|
||||||
- commands and events
|
- commands and events
|
||||||
|
- RFCOMM implementation
|
||||||
|
- use switch on RFCOMM control field in rfcomm.c packet handler
|
||||||
- detect and handle iPhone sleep mode
|
- detect and handle iPhone sleep mode
|
||||||
- see iPhone imnsomnia project at http://code.google.com/p/iphone-insomnia/
|
- see iPhone imsomnia project at http://code.google.com/p/iphone-insomnia/
|
||||||
- can we get willGoToSleep event, should we turn off Bluetooth?
|
- can we get willGoToSleep event, should we turn off Bluetooth?
|
||||||
- would be nice, if we could get woken up by Bluetooth data
|
- would be nice, if we could get woken up by Bluetooth data
|
||||||
- CocoaTouch User Interface Components
|
- CocoaTouch User Interface Components
|
||||||
|
@ -100,6 +100,11 @@ void _bt_rfcomm_send_sabm(uint16_t source_cid, uint8_t initiator, uint8_t channe
|
|||||||
rfcomm_send_packet(source_cid, address, BT_RFCOMM_SABM, 0, NULL, 0);
|
rfcomm_send_packet(source_cid, address, BT_RFCOMM_SABM, 0, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _bt_rfcomm_send_uih_data(uint16_t source_cid, uint8_t initiator, uint8_t channel, uint8_t *data, uint16_t len) {
|
||||||
|
uint8_t address = (1 << 0) | (initiator << 1) | (initiator << 1) | (channel << 3);
|
||||||
|
rfcomm_send_packet(source_cid, address, BT_RFCOMM_UIH, 0, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
void _bt_rfcomm_send_uih_msc_cmd(uint16_t source_cid, uint8_t initiator, uint8_t channel, uint8_t signals)
|
void _bt_rfcomm_send_uih_msc_cmd(uint16_t source_cid, uint8_t initiator, uint8_t channel, uint8_t signals)
|
||||||
{
|
{
|
||||||
uint8_t address = (1 << 0) | (initiator << 1); // EA and C/R bit set - always server channel 0
|
uint8_t address = (1 << 0) | (initiator << 1); // EA and C/R bit set - always server channel 0
|
||||||
@ -112,11 +117,6 @@ void _bt_rfcomm_send_uih_msc_cmd(uint16_t source_cid, uint8_t initiator, uint8_t
|
|||||||
rfcomm_send_packet(source_cid, address, BT_RFCOMM_UIH, 0, (uint8_t *) payload, pos);
|
rfcomm_send_packet(source_cid, address, BT_RFCOMM_UIH, 0, (uint8_t *) payload, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _bt_rfcomm_send_uih_data(uint16_t source_cid, uint8_t initiator, uint8_t channel, uint8_t *data, uint16_t len) {
|
|
||||||
uint8_t address = (1 << 0) | (initiator << 1) | (initiator << 1) | (channel << 3);
|
|
||||||
rfcomm_send_packet(source_cid, address, BT_RFCOMM_UIH, 0, data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _bt_rfcomm_send_uih_pn_command(uint16_t source_cid, uint8_t initiator, uint8_t channel, uint16_t max_frame_size){
|
void _bt_rfcomm_send_uih_pn_command(uint16_t source_cid, uint8_t initiator, uint8_t channel, uint16_t max_frame_size){
|
||||||
uint8_t payload[10];
|
uint8_t payload[10];
|
||||||
uint8_t address = (1 << 0) | (initiator << 1); // EA and C/R bit set - always server channel 0
|
uint8_t address = (1 << 0) | (initiator << 1); // EA and C/R bit set - always server channel 0
|
||||||
|
@ -170,9 +170,21 @@ static int usb_open(void *transport_config){
|
|||||||
#endif
|
#endif
|
||||||
libusb_state = LIB_USB_KERNEL_DETACHED;
|
libusb_state = LIB_USB_KERNEL_DETACHED;
|
||||||
|
|
||||||
|
libusb_set_debug(0,3);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
int config = -1;
|
||||||
|
r = libusb_get_configuration(handle, &config);
|
||||||
|
printf("Get configuration %i (%i)\n", config, r);
|
||||||
|
// if (config != 1) {
|
||||||
|
// r= libusb_set_configuration(handle,0);
|
||||||
|
// }
|
||||||
|
printf("Set configuration = %u\n", r);
|
||||||
|
#endif
|
||||||
|
|
||||||
// reserve access to device
|
// reserve access to device
|
||||||
printf("claiming interface 0...\n");
|
printf("claiming interface 0...\n");
|
||||||
libusb_claim_interface(handle, 0);
|
r = libusb_claim_interface(handle, 0);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
fprintf(stderr, "usb_claim_interface error %d\n", r);
|
fprintf(stderr, "usb_claim_interface error %d\n", r);
|
||||||
usb_close();
|
usb_close();
|
||||||
@ -181,11 +193,10 @@ static int usb_open(void *transport_config){
|
|||||||
libusb_state = LIB_USB_INTERFACE_CLAIMED;
|
libusb_state = LIB_USB_INTERFACE_CLAIMED;
|
||||||
printf("claimed interface 0\n");
|
printf("claimed interface 0\n");
|
||||||
|
|
||||||
#if 0
|
// get endpoints - broken on OS X until libusb 1.0.3
|
||||||
// get endpoints - broken on OS X (libusb 1.0.2)
|
|
||||||
struct libusb_config_descriptor *config_descriptor;
|
struct libusb_config_descriptor *config_descriptor;
|
||||||
r = libusb_get_active_config_descriptor(dev, &config_descriptor);
|
r = libusb_get_active_config_descriptor(dev, &config_descriptor);
|
||||||
printf("configuration: %u interfacs\n", config_descriptor->bNumInterfaces);
|
printf("configuration: %u interfaces\n", config_descriptor->bNumInterfaces);
|
||||||
const struct libusb_interface *interface = config_descriptor->interface;
|
const struct libusb_interface *interface = config_descriptor->interface;
|
||||||
const struct libusb_interface_descriptor * interface0descriptor = interface->altsetting;
|
const struct libusb_interface_descriptor * interface0descriptor = interface->altsetting;
|
||||||
printf("interface 0: %u endpoints\n", interface0descriptor->bNumEndpoints);
|
printf("interface 0: %u endpoints\n", interface0descriptor->bNumEndpoints);
|
||||||
@ -193,8 +204,6 @@ static int usb_open(void *transport_config){
|
|||||||
for (r=0;r<interface0descriptor->bNumEndpoints;r++,endpoint++){
|
for (r=0;r<interface0descriptor->bNumEndpoints;r++,endpoint++){
|
||||||
printf("endpoint %x, attributes %x\n", endpoint->bEndpointAddress, endpoint->bmAttributes);
|
printf("endpoint %x, attributes %x\n", endpoint->bEndpointAddress, endpoint->bmAttributes);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
libusb_set_debug(0,3);
|
|
||||||
|
|
||||||
// allocation
|
// allocation
|
||||||
control_transfer = libusb_alloc_transfer(0); // 0 isochronous transfers CMDs
|
control_transfer = libusb_alloc_transfer(0); // 0 isochronous transfers CMDs
|
||||||
@ -205,6 +214,28 @@ static int usb_open(void *transport_config){
|
|||||||
}
|
}
|
||||||
libusb_state = LIB_USB_TRANSFERS_ALLOCATED;
|
libusb_state = LIB_USB_TRANSFERS_ALLOCATED;
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// data transfer
|
||||||
|
// get answer
|
||||||
|
|
||||||
|
// control
|
||||||
|
uint8_t hci_reset[] = { 0x03, 0x0c, 0x00 };
|
||||||
|
|
||||||
|
// synchronous
|
||||||
|
r = libusb_control_transfer (handle, LIBUSB_REQUEST_TYPE_CLASS,
|
||||||
|
0, 0, 0,
|
||||||
|
hci_reset, sizeof (hci_reset),
|
||||||
|
0);
|
||||||
|
|
||||||
|
int length = -1;
|
||||||
|
r = libusb_interrupt_transfer(handle, 0x81, hci_event_buffer, 100, &length, 0);
|
||||||
|
printf("received data len %u, r= %d\n", length, r);
|
||||||
|
for (r=0;r<length; r++) printf("0x%.x ", hci_event_buffer[r]);
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// interrupt (= HCI event) handler
|
// interrupt (= HCI event) handler
|
||||||
libusb_fill_interrupt_transfer(interrupt_transfer, handle, 0x81, hci_event_buffer, 260, event_callback, NULL, 3000) ;
|
libusb_fill_interrupt_transfer(interrupt_transfer, handle, 0x81, hci_event_buffer, 260, event_callback, NULL, 3000) ;
|
||||||
// interrupt_transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK;
|
// interrupt_transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK;
|
||||||
@ -231,32 +262,6 @@ static int usb_open(void *transport_config){
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// data transfer
|
|
||||||
// get answer
|
|
||||||
|
|
||||||
// control
|
|
||||||
uint8_t hci_reset[] = { 0x03, 0x0c, 0x00 };
|
|
||||||
|
|
||||||
// synchronous
|
|
||||||
// r = libusb_control_transfer (handle, LIBUSB_REQUEST_TYPE_CLASS,
|
|
||||||
// 0, 0, 0,
|
|
||||||
// hci_reset, sizeof (hci_reset),
|
|
||||||
// 0);
|
|
||||||
|
|
||||||
// int length = -1;
|
|
||||||
// r = libusb_interrupt_transfer(handle, 0x81, buffer, 100, &length, 0);
|
|
||||||
|
|
||||||
/* r = libusb_interrupt_transfer(handle, 0x81, buffer, 100, &length, 0);
|
|
||||||
printf("received data len %u, r= %d\n", length, r);
|
|
||||||
for (r=0;r<length; r++) printf("0x%.x ", buffer[r]);
|
|
||||||
printf("\n");
|
|
||||||
*/
|
|
||||||
|
|
||||||
//
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int usb_close(){
|
static int usb_close(){
|
||||||
// @TODO: remove all run loops!
|
// @TODO: remove all run loops!
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user