(iOS) Start adding analog stick support (PS3 only, for now)

This commit is contained in:
meancoot 2013-03-30 22:23:45 -04:00
parent e60ad5021b
commit 27b8c21eff
9 changed files with 94 additions and 5 deletions

View File

@ -38,6 +38,14 @@ uint32_t btpad_get_buttons()
return result;
}
int16_t btpad_get_axis(unsigned axis)
{
pthread_mutex_lock(&btpad_lock);
int16_t result = (btpad_device && btpad_iface) ? btpad_iface->get_axis(btpad_device, axis) : 0;
pthread_mutex_unlock(&btpad_lock);
return result;
}
void btpad_set_pad_type(bool wiimote)
{
pthread_mutex_lock(&btpad_lock);

View File

@ -17,6 +17,7 @@
#define __IOS_RARCH_BTPAD_H__
uint32_t btpad_get_buttons();
int16_t btpad_get_axis(unsigned axis);
void btpad_set_pad_type(bool wiimote);
// Private interface
@ -27,6 +28,7 @@ struct btpad_interface
void (*set_leds)(void* device, unsigned leds);
uint32_t (*get_buttons)(void* device);
int16_t (*get_axis)(void* device, unsigned axis);
void (*packet_handler)(void* device, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
};

View File

@ -80,6 +80,18 @@ static uint32_t btpad_ps3_get_buttons(struct btpad_ps3_data* device)
return (device->state == BTPAD_PS3_CONNECTED) ? device->data[3] | (device->data[4] << 8) : 0;
}
static int16_t btpad_ps3_get_axis(struct btpad_ps3_data* device, unsigned axis)
{
if (axis < 4)
{
int val = device->data[7 + axis];
val = (val << 8) - 0x8000;
return (abs(val) > 0x1000) ? val : 0;
}
return 0;
}
static void btpad_ps3_packet_handler(struct btpad_ps3_data* device, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
{
if (packet_type == HCI_EVENT_PACKET)
@ -181,5 +193,6 @@ struct btpad_interface btpad_ps3 =
(void*)&btpad_ps3_disconnect,
(void*)&btpad_ps3_setleds,
(void*)&btpad_ps3_get_buttons,
(void*)&btpad_ps3_get_axis,
(void*)&btpad_ps3_packet_handler
};

View File

@ -68,6 +68,25 @@ static uint32_t btpad_wii_get_buttons(struct btpad_wii_data* device)
return (device->state == BTPAD_WII_CONNECTED) ? device->wiimote.btns | (device->wiimote.exp.classic.btns << 16) : 0;
}
static int16_t btpad_wii_get_axis(struct btpad_wii_data* device, unsigned axis)
{
/* TODO
if (device->.exp.type == EXP_CLASSIC)
{
switch (axis)
{
case 0: return device->wiimote.exp.classic.ljs.rx * 0x7FFF;
case 1: return device->wiimote.exp.classic.ljs.ry * 0x7FFF;
case 2: return device->wiimote.exp.classic.rjs.rx * 0x7FFF;
case 3: return device->wiimote.exp.classic.rjs.ry * 0x7FFF;
default: return 0;
}
}
*/
return 0;
}
static void btpad_wii_packet_handler(struct btpad_wii_data* device, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
{
if (packet_type == HCI_EVENT_PACKET && packet[0] == HCI_EVENT_PIN_CODE_REQUEST)
@ -241,5 +260,6 @@ struct btpad_interface btpad_wii =
(void*)&btpad_wii_disconnect,
(void*)&btpad_wii_setleds,
(void*)&btpad_wii_get_buttons,
(void*)&btpad_wii_get_axis,
(void*)&btpad_wii_packet_handler
};

View File

@ -107,6 +107,9 @@ static int16_t ios_input_state(void *data, const struct retro_keybind **binds, u
case RETRO_DEVICE_JOYPAD:
return (id < RARCH_BIND_LIST_END) ? ios_is_pressed(port, &binds[port][id]) : false;
case RETRO_DEVICE_ANALOG:
return input_joypad_analog(g_joydriver, port, index, id, binds[port]);
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
{

View File

@ -47,7 +47,22 @@ static bool ios_joypad_button(unsigned port, uint16_t joykey)
static int16_t ios_joypad_axis(unsigned port, uint32_t joyaxis)
{
return 0;
if (joyaxis == AXIS_NONE)
return 0;
int16_t val = 0;
if (AXIS_NEG_GET(joyaxis) < 4)
{
val = btpad_get_axis(AXIS_NEG_GET(joyaxis));
val = (val < 0) ? val : 0;
}
else if(AXIS_POS_GET(joyaxis) < 4)
{
val = btpad_get_axis(AXIS_POS_GET(joyaxis));
val = (val > 0) ? val : 0;
}
return val;
}
static void ios_joypad_poll(void)

View File

@ -94,7 +94,7 @@ static const struct
message:_value.label
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Clear Keyboard", @"Clear Joystick", nil];
otherButtonTitles:@"Clear Keyboard", @"Clear Joystick", @"Clear Axis", nil];
[_alert show];
_btTimer = [NSTimer scheduledTimerWithTimeInterval:.05f target:self selector:@selector(checkInput) userInfo:nil repeats:YES];
@ -122,6 +122,8 @@ static const struct
_value.msubValues[0] = @"";
else if(buttonIndex == _alert.firstOtherButtonIndex + 1)
_value.msubValues[1] = @"";
else if(buttonIndex == _alert.firstOtherButtonIndex + 2)
_value.msubValues[2] = @"";
[self finish];
}
@ -139,7 +141,7 @@ static const struct
}
}
// WiiMote
// Pad Buttons
uint32_t buttons = btpad_get_buttons();
for (int i = 0; buttons && i != sizeof(buttons) * 8; i ++)
@ -151,6 +153,19 @@ static const struct
return;
}
}
// Pad Axis
for (int i = 0; i != 4; i ++)
{
int16_t value = btpad_get_axis(i);
if (abs(value) > 0x1000)
{
_value.msubValues[2] = [NSString stringWithFormat:@"%s%d", (value > 0x1000) ? "+" : "-", i];
[self finish];
break;
}
}
}
@end

View File

@ -50,6 +50,7 @@ static RASettingData* button_setting(config_file_t* config, NSString* name, NSSt
result.msubValues = [NSMutableArray arrayWithObjects:
get_value_from_config(config, name, defaultValue),
get_value_from_config(config, [name stringByAppendingString:@"_btn"], @""),
get_value_from_config(config, [name stringByAppendingString:@"_axis"], @""),
nil];
return result;
}
@ -185,6 +186,15 @@ static RASettingData* custom_action(NSString* action)
button_setting(config, @"input_player1_r2", @"R2", @""),
button_setting(config, @"input_player1_l3", @"L3", @""),
button_setting(config, @"input_player1_r3", @"R3", @""),
button_setting(config, @"input_player1_l_y_minus", @"Left Stick Up", @""),
button_setting(config, @"input_player1_l_y_plus", @"Left Stick Down", @""),
button_setting(config, @"input_player1_l_x_minus", @"Left Stick Left", @""),
button_setting(config, @"input_player1_l_x_plus", @"Left Stick Right", @""),
button_setting(config, @"input_player1_r_y_minus", @"Right Stick Up", @""),
button_setting(config, @"input_player1_r_y_plus", @"Right Stick Down", @""),
button_setting(config, @"input_player1_r_x_minus", @"Right Stick Left", @""),
button_setting(config, @"input_player1_r_x_plus", @"Right Stick Right", @""),
nil],
nil]),
group_setting(@"System Keys", [NSArray arrayWithObjects:

View File

@ -70,6 +70,8 @@ static const char* const SETTINGID = "SETTING";
config_set_string(config, [setting.name UTF8String], [setting.msubValues[0] UTF8String]);
if (setting.msubValues[1])
config_set_string(config, [[setting.name stringByAppendingString:@"_btn"] UTF8String], [setting.msubValues[1] UTF8String]);
if (setting.msubValues[2])
config_set_string(config, [[setting.name stringByAppendingString:@"_axis"] UTF8String], [setting.msubValues[2] UTF8String]);
break;
case AspectSetting:
@ -217,9 +219,10 @@ static const char* const SETTINGID = "SETTING";
if (setting.type != ButtonSetting)
cell.detailTextLabel.text = setting.value;
else
cell.detailTextLabel.text = [NSString stringWithFormat:@"[KB:%@] [JS:%@]",
cell.detailTextLabel.text = [NSString stringWithFormat:@"[KB:%@] [JS:%@] [AX:%@]",
[setting.msubValues[0] length] ? setting.msubValues[0] : @"N/A",
[setting.msubValues[1] length] ? setting.msubValues[1] : @"N/A"];
[setting.msubValues[1] length] ? setting.msubValues[1] : @"N/A",
[setting.msubValues[2] length] ? setting.msubValues[2] : @"N/A"];
return cell;
}