From 56c253c9c9ec51d22d4ef5977a6fac5267632fff Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sun, 20 Sep 2009 15:49:42 +0000 Subject: [PATCH] use SpringBoardAccess extension to signal Bluetooth state --- TODO.txt | 6 +-- project.xcodeproj/project.pbxproj | 10 ++--- src/Makefile.am | 69 +++++++++++++++++-------------- src/hci.c | 2 +- src/platform_iphone.c | 35 ++++++++++++++++ src/platform_iphone.m | 45 -------------------- 6 files changed, 80 insertions(+), 87 deletions(-) create mode 100644 src/platform_iphone.c delete mode 100644 src/platform_iphone.m diff --git a/TODO.txt b/TODO.txt index a6958e1ba..4bc1763b7 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,9 +3,9 @@ Last milestone reached: BTdaemon automatically started by launchd on Mac and iPhone NEXT: -- add code to toggle status bar icons via the SpringBoardAcess extension -- clean up debug output: seperate messages from errors -- decide on error reporting +- check why test.c does not start up instantly when Bluetooth is already turned on +- clean up debug output: messages to stdou, errors to stderr +- decide on error reporting from BTdaemon - command_status_event with custom errors - hci open failed - btstack error diff --git a/project.xcodeproj/project.pbxproj b/project.xcodeproj/project.pbxproj index 617b69881..143a20570 100644 --- a/project.xcodeproj/project.pbxproj +++ b/project.xcodeproj/project.pbxproj @@ -18,9 +18,9 @@ 9C1F0E9A0FDAE023008F472F /* run_loop.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C1F0E980FDAE023008F472F /* run_loop.c */; }; 9C2071F310014D3200A07EA4 /* hci_transport_usb.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C2071F210014D3200A07EA4 /* hci_transport_usb.c */; }; 9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */; }; - 9C6459E01037554B0081A00B /* platform_iphone.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C6459DF1037554B0081A00B /* platform_iphone.m */; }; 9C77E7511066680800F39DCF /* SpringBoardAccessExtension.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9C77E7501066680800F39DCF /* SpringBoardAccessExtension.mm */; }; 9C77E75510666B5D00F39DCF /* SpringBoardAccess.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C77E75310666B5D00F39DCF /* SpringBoardAccess.c */; }; + 9C77E79210667F0600F39DCF /* platform_iphone.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C77E79110667F0600F39DCF /* platform_iphone.c */; }; 9C7B5AC0100BD3340065D87E /* linked_list.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7B5ABF100BD3340065D87E /* linked_list.c */; }; 9C7B5D01100FC9AE0065D87E /* btstack.c in Sources */ = {isa = PBXBuildFile; fileRef = 9CC813A10FFC0774002816F9 /* btstack.c */; }; 9C7B5D03100FC9BB0065D87E /* test.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7B5B7E100D04450065D87E /* test.c */; }; @@ -66,17 +66,16 @@ 9C46FC370FA906F700ABEF05 /* hci_transport_h4.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport_h4.h; path = src/hci_transport_h4.h; sourceTree = ""; }; 9C46FC380FA906F700ABEF05 /* hci_transport.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport.h; path = src/hci_transport.h; sourceTree = ""; }; 9C6459DE1037554B0081A00B /* platform_iphone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = platform_iphone.h; path = src/platform_iphone.h; sourceTree = ""; }; - 9C6459DF1037554B0081A00B /* platform_iphone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = platform_iphone.m; path = src/platform_iphone.m; sourceTree = ""; }; 9C77E36410618B1D00F39DCF /* Makefile.in */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; name = Makefile.in; path = SpringBoardAccess/Makefile.in; sourceTree = ""; }; 9C77E36710618C6500F39DCF /* SpringBoardAccess-test.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = "SpringBoardAccess-test.c"; path = "SpringBoardAccess/SpringBoardAccess-test.c"; sourceTree = ""; }; 9C77E4AE10634E3100F39DCF /* launch.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = launch.h; sourceTree = ""; }; 9C77E4AF10634E3100F39DCF /* libsubstrate.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libsubstrate.dylib; sourceTree = ""; }; 9C77E4B010634E3100F39DCF /* README */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = README; sourceTree = ""; }; - 9C77E4B110634E3100F39DCF /* SpringBoard.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = SpringBoard.h; sourceTree = ""; }; 9C77E4B210634E3100F39DCF /* substrate.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = substrate.h; sourceTree = ""; }; 9C77E7501066680800F39DCF /* SpringBoardAccessExtension.mm */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.cpp.objcpp; name = SpringBoardAccessExtension.mm; path = SpringBoardAccess/SpringBoardAccessExtension.mm; sourceTree = ""; }; 9C77E75310666B5D00F39DCF /* SpringBoardAccess.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = SpringBoardAccess.c; path = SpringBoardAccess/SpringBoardAccess.c; sourceTree = ""; }; 9C77E75410666B5D00F39DCF /* SpringBoardAccess.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = SpringBoardAccess.h; path = SpringBoardAccess/SpringBoardAccess.h; sourceTree = ""; }; + 9C77E79110667F0600F39DCF /* platform_iphone.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = platform_iphone.c; path = src/platform_iphone.c; sourceTree = ""; }; 9C78A04A103C6734003B2950 /* Default_BTstack.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default_BTstack.png; path = resources/Default_BTstack.png; sourceTree = ""; }; 9C78A04B103C6734003B2950 /* Default_BTstackActive.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default_BTstackActive.png; path = resources/Default_BTstackActive.png; sourceTree = ""; }; 9C78A04C103C6734003B2950 /* FSO_BTstack.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = FSO_BTstack.png; path = resources/FSO_BTstack.png; sourceTree = ""; }; @@ -167,8 +166,8 @@ 9C00F7311017ACC3008DAB17 /* socket_connection.h */, 9C00F86210191097008DAB17 /* utils.c */, 9C00F86310191097008DAB17 /* utils.h */, + 9C77E79110667F0600F39DCF /* platform_iphone.c */, 9C6459DE1037554B0081A00B /* platform_iphone.h */, - 9C6459DF1037554B0081A00B /* platform_iphone.m */, ); name = Source; sourceTree = ""; @@ -201,7 +200,6 @@ 9C77E4AE10634E3100F39DCF /* launch.h */, 9C77E4AF10634E3100F39DCF /* libsubstrate.dylib */, 9C77E4B010634E3100F39DCF /* README */, - 9C77E4B110634E3100F39DCF /* SpringBoard.h */, 9C77E4B210634E3100F39DCF /* substrate.h */, ); path = 3rdparty; @@ -309,10 +307,10 @@ 9C00F86510191097008DAB17 /* utils.c in Sources */, 9C00F87410191130008DAB17 /* l2cap_signaling.c in Sources */, 9CCE6CEA1025BD0000FCE9F4 /* hci.c in Sources */, - 9C6459E01037554B0081A00B /* platform_iphone.m in Sources */, 9C1813F81042FCCA00C68F09 /* mitm.c in Sources */, 9C77E7511066680800F39DCF /* SpringBoardAccessExtension.mm in Sources */, 9C77E75510666B5D00F39DCF /* SpringBoardAccess.c in Sources */, + 9C77E79210667F0600F39DCF /* platform_iphone.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/Makefile.am b/src/Makefile.am index 0f4f7c868..c2ab682bd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,37 +2,42 @@ if HAVE_LIBUSB usb_support = hci_transport_usb.c endif +if USE_SPRINGBOARD + springboard_support = ../SpringBoardAccess/SpringBoardAccess.c +endif + bin_PROGRAMS = BTdaemon -BTdaemon_SOURCES = \ - bt_control_iphone.c \ - daemon.c \ - hci.c \ - hci_cmds.c \ - hci_dump.c \ - hci_transport_h4.c \ - $(usb_support) \ - l2cap.c \ - l2cap_signaling.c \ - platform_iphone.m \ - linked_list.c \ - run_loop.c \ - socket_connection.c \ - utils.c - -include_HEADERS = \ - bt_control.h \ - bt_control_iphone.h \ - hci.h \ - hci_cmds.h \ - hci_dump.h \ - hci_transport.h \ - hci_transport_h4.h \ - hci_transport_usb.h \ - linked_list.h \ - l2cap.h \ - l2cap_signaling.h \ - platform_iphone.h \ - run_loop.h \ - socket_connection.h \ - utils.h +BTdaemon_SOURCES = \ + bt_control_iphone.c \ + daemon.c \ + hci.c \ + hci_cmds.c \ + hci_dump.c \ + hci_transport_h4.c \ + $(usb_support) \ + l2cap.c \ + l2cap_signaling.c \ + platform_iphone.c \ + linked_list.c \ + run_loop.c \ + socket_connection.c \ + $(springboard_support) \ + utils.c + +include_HEADERS = \ + bt_control.h \ + bt_control_iphone.h \ + hci.h \ + hci_cmds.h \ + hci_dump.h \ + hci_transport.h \ + hci_transport_h4.h \ + hci_transport_usb.h \ + linked_list.h \ + l2cap.h \ + l2cap_signaling.h \ + platform_iphone.h \ + run_loop.h \ + socket_connection.h \ + utils.h diff --git a/src/hci.c b/src/hci.c index ffd294caa..81b9d5705 100644 --- a/src/hci.c +++ b/src/hci.c @@ -98,7 +98,7 @@ static hci_connection_t * connection_for_address(bd_addr_t address){ * count connections */ static int nr_hci_connections(){ - int count; + int count = 0; linked_item_t *it; for (it = (linked_item_t *) hci_stack.connections; it ; it = it->next, count++); return count; diff --git a/src/platform_iphone.c b/src/platform_iphone.c new file mode 100644 index 000000000..2b4d12179 --- /dev/null +++ b/src/platform_iphone.c @@ -0,0 +1,35 @@ +// +// platform_iphone.c +// +// Created by Matthias Ringwald on 8/15/09. +// + +#include "../config.h" + +#include "platform_iphone.h" + +#include "../SpringBoardAccess/SpringBoardAccess.h" + +#ifdef USE_SPRINGBOARD + +// update SpringBoard icons +void platform_iphone_status_handler(BLUETOOTH_STATE state){ + switch (state) { + case BLUETOOTH_OFF: + SBA_removeStatusBarImage("BTstack"); + SBA_removeStatusBarImage("BTstackActive"); + break; + case BLUETOOTH_ON: + SBA_removeStatusBarImage("BTstackActive"); + SBA_addStatusBarImage("BTstack"); + break; + case BLUETOOTH_ACTIVE: + SBA_removeStatusBarImage("BTstack"); + SBA_addStatusBarImage("BTstackActive"); + break; + default: + break; + } +} + +#endif \ No newline at end of file diff --git a/src/platform_iphone.m b/src/platform_iphone.m deleted file mode 100644 index 21dc2c088..000000000 --- a/src/platform_iphone.m +++ /dev/null @@ -1,45 +0,0 @@ -// -// platform_iphone.m -// -// Created by Matthias Ringwald on 8/15/09. -// - -#include "../config.h" - -#import "platform_iphone.h" - -#ifdef USE_SPRINGBOARD - -#ifdef __OBJC__ -#import -#import -#endif - -@interface UIApplication (privateStatusBarIconAPI) -- (void)addStatusBarImageNamed:(id)fp8 removeOnAbnormalExit:(BOOL)fp12; -- (void)addStatusBarImageNamed:(id)fp8; -- (void)removeStatusBarImageNamed:(id)fp8; -// iPhoneOS >= 2.2 -- (void)addStatusBarImageNamed:(id)fp8 removeOnExit:(BOOL)fp12; -@end - -// update SpringBoard icon -void platform_iphone_status_handler(BLUETOOTH_STATE state){ - printf("iphone state %u\n", state); - UIApplication *theApp = [UIApplication sharedApplication]; - printf("the app %u\n", (int) theApp); - [theApp addStatusBarImageNamed:@"BluetoothActive"]; - - switch (state) { - case BLUETOOTH_OFF: - break; - case BLUETOOTH_ON: - break; - case BLUETOOTH_ACTIVE: - break; - default: - break; - } -} - -#endif \ No newline at end of file