ios: Add a Stop Bluetooth button to the navigation bar.

This commit is contained in:
meancoot 2013-02-28 20:15:10 -05:00
parent f73511baa0
commit b9dcfca071
3 changed files with 51 additions and 15 deletions

View File

@ -35,6 +35,7 @@
@interface WiiMoteHelper : NSObject<BTDiscoveryDelegate, BTstackManagerDelegate, BTstackManagerListener>
+ (WiiMoteHelper*)get;
+ (void)stopBluetooth;
- (void)showDiscovery;
@end

View File

@ -44,10 +44,11 @@
#import "btstack/run_loop.h"
#import "btstack/hci_cmds.h"
static BTDevice *device;
static uint16_t wiiMoteConHandle = 0;
static bool btOK;
static BTDiscoveryViewController* discoveryView;
static WiiMoteHelper* instance;
static BTDevice *device;
static bool btOK;
@implementation WiiMoteHelper
+ (WiiMoteHelper*)get
@ -60,6 +61,23 @@ static WiiMoteHelper* instance;
return instance;
}
+ (void)stopBluetooth
{
instance = nil;
myosd_num_of_joys = 0;
if (btOK)
{
BTstackManager* bt = [BTstackManager sharedInstance];
[bt removeListener:discoveryView];
discoveryView = nil;
[[BTstackManager sharedInstance] deactivate];
btOK = false;
}
}
- (id)init
{
if (!btOK)
@ -74,20 +92,17 @@ static WiiMoteHelper* instance;
return self;
}
- (void)dealloc
{
// TODO: Any other cleanup needed
[[BTstackManager sharedInstance] deactivate];
}
- (void)showDiscovery
{
BTDiscoveryViewController* vc = [BTDiscoveryViewController new];
[vc setDelegate:self];
if (!discoveryView)
{
discoveryView = [BTDiscoveryViewController new];
[discoveryView setDelegate:self];
[[BTstackManager sharedInstance] addListener:vc];
[[BTstackManager sharedInstance] addListener:discoveryView];
}
[[RetroArch_iOS get] pushViewController:vc isGame:NO];
[[RetroArch_iOS get] pushViewController:discoveryView isGame:NO];
}
// BTStackManagerListener
@ -233,7 +248,7 @@ static WiiMoteHelper* instance;
bt_flip_addr(event_addr, &packet[3]);
uint16_t psm = READ_BT_16(packet, 11);
uint16_t source_cid = READ_BT_16(packet, 13);
wiiMoteConHandle = READ_BT_16(packet, 9);
uint16_t wiiMoteConHandle = READ_BT_16(packet, 9);
if (psm == 0x13)
{

View File

@ -26,7 +26,7 @@
#define ALMOST_INVISIBLE .021f
@interface RANavigator : UINavigationController
@interface RANavigator : UINavigationController<UINavigationControllerDelegate>
@end
@implementation RANavigator
@ -37,6 +37,7 @@
- (id)initWithAppDelegate:(RetroArch_iOS*)delegate
{
self = [super init];
self.delegate = self;
assert(delegate);
_delegate = delegate;
@ -59,6 +60,18 @@
[_delegate performSelector:@selector(screenDidRotate) withObject:nil afterDelay:.01f];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
#ifdef WIIMOTE
UIBarButtonItem* bbi = [[UIBarButtonItem alloc]
initWithTitle:@"Stop Bluetooth"
style:UIBarButtonItemStyleBordered
target:[RetroArch_iOS get]
action:@selector(stopBluetooth)];
navigationController.topViewController.navigationItem.rightBarButtonItem = bbi;
#endif
}
@end
@implementation RetroArch_iOS
@ -357,5 +370,12 @@
#endif
}
- (IBAction)stopBluetooth
{
#ifdef WIIMOTE
[WiiMoteHelper stopBluetooth];
#endif
}
@end