diff --git a/ios/RetroArch/BTStack/WiiMoteHelper.h b/ios/RetroArch/BTStack/WiiMoteHelper.h index 8964b5d61b..eef5dd6036 100644 --- a/ios/RetroArch/BTStack/WiiMoteHelper.h +++ b/ios/RetroArch/BTStack/WiiMoteHelper.h @@ -35,6 +35,7 @@ @interface WiiMoteHelper : NSObject + (WiiMoteHelper*)get; ++ (void)stopBluetooth; - (void)showDiscovery; @end diff --git a/ios/RetroArch/BTStack/WiiMoteHelper.m b/ios/RetroArch/BTStack/WiiMoteHelper.m index 83ce023447..1332a81762 100644 --- a/ios/RetroArch/BTStack/WiiMoteHelper.m +++ b/ios/RetroArch/BTStack/WiiMoteHelper.m @@ -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) { diff --git a/ios/RetroArch/RetroArch_iOS.m b/ios/RetroArch/RetroArch_iOS.m index cc9febac1e..6b5467dc84 100644 --- a/ios/RetroArch/RetroArch_iOS.m +++ b/ios/RetroArch/RetroArch_iOS.m @@ -26,7 +26,7 @@ #define ALMOST_INVISIBLE .021f -@interface RANavigator : UINavigationController +@interface RANavigator : UINavigationController @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