(iOS) Some cleanup

This commit is contained in:
meancoot 2013-06-21 21:39:36 -04:00
parent 9743cada8b
commit 9cb5513e59
6 changed files with 29 additions and 74 deletions

View File

@ -26,9 +26,6 @@
- (void)refreshConfig; - (void)refreshConfig;
- (void)refreshSystemConfig; - (void)refreshSystemConfig;
- (IBAction)startBluetooth;
- (IBAction)stopBluetooth;
@property (strong, nonatomic) NSString* documentsDirectory; // e.g. /var/mobile/Documents @property (strong, nonatomic) NSString* documentsDirectory; // e.g. /var/mobile/Documents
@property (strong, nonatomic) NSString* systemDirectory; // e.g. /var/mobile/Documents/.RetroArch @property (strong, nonatomic) NSString* systemDirectory; // e.g. /var/mobile/Documents/.RetroArch
@property (strong, nonatomic) NSString* systemConfigPath; // e.g. /var/mobile/Documents/.RetroArch/frontend.cfg @property (strong, nonatomic) NSString* systemConfigPath; // e.g. /var/mobile/Documents/.RetroArch/frontend.cfg
@ -37,3 +34,4 @@
// utility.m // utility.m
extern NSString* ios_get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue); extern NSString* ios_get_value_from_config(config_file_t* config, NSString* name, NSString* defaultValue);
extern bool path_make_and_check_directory(const char* path, mode_t mode, int amode);

View File

@ -64,7 +64,7 @@ static bool btstack_loaded;
static bool btstack_open; static bool btstack_open;
static bool btstack_poweron; static bool btstack_poweron;
bool btstack_load() bool btstack_try_load()
{ {
assert(sizeof(void**) == sizeof(void(*)())); assert(sizeof(void**) == sizeof(void(*)()));
@ -108,47 +108,28 @@ bool btstack_load()
return true; return true;
} }
void btstack_start() void btstack_set_poweron(bool on)
{ {
if (!btstack_load()) if (!btstack_try_load())
return; return;
if (!btstack_open) if (!btstack_open && bt_open_ptr())
{ {
if (bt_open_ptr()) ios_add_log_message("BTstack: bt_open failed");
{ btstack_loaded = false;
ios_add_log_message("BTstack: bt_open failed"); return;
btstack_loaded = false;
return;
}
} }
btstack_open = true; btstack_open = true;
if (!btstack_poweron) if (on != btstack_poweron)
{ {
ios_add_log_message("BTstack: Turning on"); btstack_poweron = on;
bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_ON); ios_add_log_message("BTstack: Turning %s", on ? "on" : "off");
btstack_poweron = true; bt_send_cmd_ptr(btstack_set_power_mode_ptr, on ? HCI_POWER_ON : HCI_POWER_OFF);
} }
}
void btstack_stop()
{
if (btstack_load() && btstack_open && btstack_poweron)
{
ios_add_log_message("BTstack: Turning off");
bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_OFF);
btstack_poweron = false;
}
}
bool btstack_is_loaded()
{
return btstack_load();
} }
bool btstack_is_running() bool btstack_is_running()
{ {
return btstack_poweron; return btstack_poweron;
} }

View File

@ -20,10 +20,8 @@
#include "btstack/utils.h" #include "btstack/utils.h"
#include "btstack/btstack.h" #include "btstack/btstack.h"
bool btstack_load(); bool btstack_try_load();
void btstack_start(); void btstack_set_poweron(bool on);
void btstack_stop();
bool btstack_is_loaded();
bool btstack_is_running(); bool btstack_is_running();
#ifndef BUILDING_BTDYNAMIC #ifndef BUILDING_BTDYNAMIC

View File

@ -13,7 +13,6 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <sys/stat.h>
#include <pthread.h> #include <pthread.h>
#include <string.h> #include <string.h>
@ -37,14 +36,6 @@ static bool enable_btstack;
static bool use_icade; static bool use_icade;
static uint32_t icade_buttons; static uint32_t icade_buttons;
bool path_make_and_check_directory(const char* path, mode_t mode, int amode)
{
if (!path_is_directory(path) && mkdir(path, mode) != 0)
return false;
return access(path, amode) == 0;
}
// Input helpers // Input helpers
void ios_copy_input(ios_input_data_t* data) void ios_copy_input(ios_input_data_t* data)
{ {
@ -445,10 +436,7 @@ static void event_reload_config(void* userdata)
config_get_bool(conf, "ios_use_icade", &use_icade); config_get_bool(conf, "ios_use_icade", &use_icade);
config_get_bool(conf, "ios_use_btstack", &enable_btstack); config_get_bool(conf, "ios_use_btstack", &enable_btstack);
if (enable_btstack) btstack_set_poweron(enable_btstack);
[self startBluetooth];
else
[self stopBluetooth];
config_file_free(conf); config_file_free(conf);
} }
@ -542,19 +530,6 @@ static void event_reload_config(void* userdata)
[self pushViewController:[RASystemSettingsList new] animated:YES]; [self pushViewController:[RASystemSettingsList new] animated:YES];
} }
#pragma mark Bluetooth Helpers
- (IBAction)startBluetooth
{
if (btstack_is_loaded() && !btstack_is_running())
btstack_start();
}
- (IBAction)stopBluetooth
{
if (btstack_is_loaded())
btstack_stop();
}
@end @end
void ios_rarch_exited(void* result) void ios_rarch_exited(void* result)

View File

@ -351,7 +351,7 @@ static NSArray* build_input_port_group(config_file_t* config, uint32_t player)
[NSArray arrayWithObjects:@"Bluetooth", [NSArray arrayWithObjects:@"Bluetooth",
// TODO: Note that with this turned off the native bluetooth is expected to be a real keyboard // TODO: Note that with this turned off the native bluetooth is expected to be a real keyboard
boolean_setting(config, @"ios_use_icade", @"Native BT is iCade", @"false"), boolean_setting(config, @"ios_use_icade", @"Native BT is iCade", @"false"),
btstack_is_loaded() ? boolean_setting(config, @"ios_use_btstack", @"Enable BTstack", @"false") : nil, btstack_try_load() ? boolean_setting(config, @"ios_use_btstack", @"Enable BTstack", @"false") : nil,
nil], nil],
[NSArray arrayWithObjects:@"Orientations", [NSArray arrayWithObjects:@"Orientations",
boolean_setting(config, @"ios_allow_portrait", @"Portrait", @"true"), boolean_setting(config, @"ios_allow_portrait", @"Portrait", @"true"),
@ -392,16 +392,9 @@ static NSArray* build_input_port_group(config_file_t* config, uint32_t player)
if ([@"Diagnostic Log" isEqualToString:setting.label]) if ([@"Diagnostic Log" isEqualToString:setting.label])
[[RetroArch_iOS get] pushViewController:[RALogView new] animated:YES]; [[RetroArch_iOS get] pushViewController:[RALogView new] animated:YES];
else if ([@"Enable BTstack" isEqualToString:setting.label]) else if ([@"Enable BTstack" isEqualToString:setting.label])
{ btstack_set_poweron([setting.value isEqualToString:@"true"]);
if ([@"true" isEqualToString:setting.value])
[RetroArch_iOS.get startBluetooth];
else
[RetroArch_iOS.get stopBluetooth];
}
else if([@"Global Core Config" isEqualToString:setting.label]) else if([@"Global Core Config" isEqualToString:setting.label])
{
[RetroArch_iOS.get pushViewController:[[RASettingsList alloc] initWithModule:nil] animated:YES]; [RetroArch_iOS.get pushViewController:[[RASettingsList alloc] initWithModule:nil] animated:YES];
}
else else
{ {
RAModuleInfo* data = (RAModuleInfo*)objc_getAssociatedObject(setting, "USERDATA"); RAModuleInfo* data = (RAModuleInfo*)objc_getAssociatedObject(setting, "USERDATA");

View File

@ -13,6 +13,7 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "file.h"
#import "views.h" #import "views.h"
// Fetch a value from a config file, returning defaultValue if the value is not present // Fetch a value from a config file, returning defaultValue if the value is not present
@ -27,6 +28,15 @@ NSString* ios_get_value_from_config(config_file_t* config, NSString* name, NSStr
return result; return result;
} }
// Ensures a directory exists and has correct permissions
bool path_make_and_check_directory(const char* path, mode_t mode, int amode)
{
if (!path_is_directory(path) && mkdir(path, mode) != 0)
return false;
return access(path, amode) == 0;
}
// Simple class to reduce code duplication for fixed table views // Simple class to reduce code duplication for fixed table views
@implementation RATableViewController @implementation RATableViewController