From 24cc0b5e4ddede62c7ec9d3b027f865da2cfee9a Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 5 Apr 2015 15:41:41 +0200 Subject: [PATCH] (iOS) Move files around for MFi gamepad code --- apple/common/apple_gamecontroller.h | 26 --- apple/common/apple_gamecontroller.m | 179 ------------------ apple/iOS/platform.m | 2 +- griffin/griffin_objc.m | 2 +- input/drivers_hid/btstack_hid.c | 2 +- .../inc}/GameController/GCController.h | 0 .../GameController/GCControllerAxisInput.h | 0 .../GameController/GCControllerButtonInput.h | 0 .../GameController/GCControllerDirectionPad.h | 0 .../inc}/GameController/GCControllerElement.h | 0 .../inc}/GameController/GCExtendedGamepad.h | 0 .../GCExtendedGamepadSnapshot.h | 0 .../inc}/GameController/GCGamepad.h | 0 .../inc}/GameController/GCGamepadSnapshot.h | 0 .../inc}/GameController/GameController.h | 0 15 files changed, 3 insertions(+), 208 deletions(-) delete mode 100644 apple/common/apple_gamecontroller.h delete mode 100644 apple/common/apple_gamecontroller.m rename {apple/common => input/inc}/GameController/GCController.h (100%) rename {apple/common => input/inc}/GameController/GCControllerAxisInput.h (100%) rename {apple/common => input/inc}/GameController/GCControllerButtonInput.h (100%) rename {apple/common => input/inc}/GameController/GCControllerDirectionPad.h (100%) rename {apple/common => input/inc}/GameController/GCControllerElement.h (100%) rename {apple/common => input/inc}/GameController/GCExtendedGamepad.h (100%) rename {apple/common => input/inc}/GameController/GCExtendedGamepadSnapshot.h (100%) rename {apple/common => input/inc}/GameController/GCGamepad.h (100%) rename {apple/common => input/inc}/GameController/GCGamepadSnapshot.h (100%) rename {apple/common => input/inc}/GameController/GameController.h (100%) diff --git a/apple/common/apple_gamecontroller.h b/apple/common/apple_gamecontroller.h deleted file mode 100644 index 7ec76493eb..0000000000 --- a/apple/common/apple_gamecontroller.h +++ /dev/null @@ -1,26 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2013-2014 - Jason Fetters - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#ifndef __APPLE_RARCH_GAMECONTROLLER_H__ -#define __APPLE_RARCH_GAMECONTROLLER_H__ - -#include "../../input/connect/joypad_connection.h" - -joypad_connection_t *slots; - -void apple_gamecontroller_init(void); -void apple_gamecontroller_poll_all(void); - -#endif diff --git a/apple/common/apple_gamecontroller.m b/apple/common/apple_gamecontroller.m deleted file mode 100644 index 171a6a98d3..0000000000 --- a/apple/common/apple_gamecontroller.m +++ /dev/null @@ -1,179 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2013-2014 - Jason Fetters - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include -#include "RetroArch_Apple.h" -#import "GameController/GameController.h" -#include "apple_gamecontroller.h" -#include "../../input/drivers/apple_input.h" - -enum -{ - GCCONTROLLER_PLAYER_INDEX_UNSET = -1, -}; - -static BOOL apple_gamecontroller_available(void) -{ - if (get_ios_version_major() <= 6) - return false; - /* by checking for extern symbols defined by the framework, we can check for its - * existence at runtime. This is the Apple endorsed way of dealing with this */ -#ifdef __IPHONE_7_0 - return (&GCControllerDidConnectNotification && &GCControllerDidDisconnectNotification); -#else - return false; -#endif -} - -static void apple_gamecontroller_poll(GCController *controller) -{ - uint32_t slot, pause; - driver_t *driver = driver_get_ptr(); - apple_input_data_t *apple = (apple_input_data_t*)driver->input_data; - if (!apple || !controller || controller.playerIndex == MAX_USERS) - return; - - slot = (uint32_t)controller.playerIndex; - /* retain the start (pause) value */ - pause = apple->buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START); - - apple->buttons[slot] = 0; - memset(apple->axes[slot], 0, sizeof(apple->axes[0])); - - apple->buttons[slot] |= pause; - - if (controller.extendedGamepad) - { - GCExtendedGamepad *gp = (GCExtendedGamepad *)controller.extendedGamepad; - apple->buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - apple->buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - apple->buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - apple->buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - apple->buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; - apple->buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; - apple->buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - apple->buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; - apple->buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; - apple->buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; - apple->buttons[slot] |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0; - apple->buttons[slot] |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0; - apple->axes[slot][0] = gp.leftThumbstick.xAxis.value * 32767.0f; - apple->axes[slot][1] = gp.leftThumbstick.yAxis.value * 32767.0f; - apple->axes[slot][2] = gp.rightThumbstick.xAxis.value * 32767.0f; - apple->axes[slot][3] = gp.rightThumbstick.yAxis.value * 32767.0f; - } - else if (controller.gamepad) - { - GCGamepad *gp = (GCGamepad *)controller.gamepad; - apple->buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - apple->buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - apple->buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - apple->buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - apple->buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; - apple->buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; - apple->buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - apple->buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; - apple->buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; - apple->buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; - } -} - -void apple_gamecontroller_poll_all(void) -{ - if (!apple_gamecontroller_available()) - return; - - for (GCController *controller in [GCController controllers]) - apple_gamecontroller_poll(controller); -} - -static void apple_gamecontroller_register(GCGamepad *gamepad) -{ - driver_t *driver = driver_get_ptr(); - apple_input_data_t *apple = (apple_input_data_t*)driver->input_data; - gamepad.valueChangedHandler = ^(GCGamepad *updateGamepad, GCControllerElement *element) { - apple_gamecontroller_poll(updateGamepad.controller); - }; - - gamepad.controller.controllerPausedHandler = ^(GCController *controller) { - - uint32_t slot = (uint32_t)controller.playerIndex; - - apple->buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_START); - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - apple->buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START); - }); - - }; - -} - -static int32_t apple_joypad_connect_gcapi(joypad_connection_t *joyconn) -{ - int pad = pad_connection_find_vacant_pad(joyconn); - - if (pad >= 0 && pad < MAX_USERS) - { - joypad_connection_t *s = (joypad_connection_t*)&joyconn[pad]; - - if (s) - s->connected = true; - } - - return pad; -} - -static void apple_gamecontroller_connect(GCController *controller) -{ - int32_t slot = apple_joypad_connect_gcapi(slots); - - controller.playerIndex = (slot >= 0 && slot < MAX_USERS) ? slot : GCCONTROLLER_PLAYER_INDEX_UNSET; - - if (controller.playerIndex == GCControllerPlayerIndexUnset) - return; - - apple_gamecontroller_register(controller.gamepad); -} - -static void apple_gamecontroller_disconnect(GCController* controller) -{ - unsigned pad = (uint32_t)controller.playerIndex; - if (pad == GCCONTROLLER_PLAYER_INDEX_UNSET) - return; - - pad_connection_pad_deinit(&slots[pad], pad); -} - -void apple_gamecontroller_init(void) -{ - if (!apple_gamecontroller_available()) - return; -#ifdef __IPHONE_7_0 - [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification - object:nil - queue:[NSOperationQueue mainQueue] - usingBlock:^(NSNotification *note) { - apple_gamecontroller_connect([note object]); - }]; - - [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification - object:nil - queue:[NSOperationQueue mainQueue] - usingBlock:^(NSNotification *note) { - apple_gamecontroller_disconnect([note object]); - } ]; -#endif -} diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index 6992edc828..01e2fb5da8 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -20,7 +20,7 @@ #include "../../input/drivers/apple_input.h" #include "../../settings.h" #ifdef HAVE_MFI -#include "../common/apple_gamecontroller.h" +#include "../../input/drivers_hid/mfi_hid.h" #endif #include "menu.h" #include "../../menu/menu.h" diff --git a/griffin/griffin_objc.m b/griffin/griffin_objc.m index c8f964fa15..a2f633e7b1 100644 --- a/griffin/griffin_objc.m +++ b/griffin/griffin_objc.m @@ -20,5 +20,5 @@ #endif #ifdef HAVE_MFI -#include "../apple/common/apple_gamecontroller.m" +#include "../input/drivers_hid/mfi_hid.m" #endif diff --git a/input/drivers_hid/btstack_hid.c b/input/drivers_hid/btstack_hid.c index 57af70f239..249f988805 100644 --- a/input/drivers_hid/btstack_hid.c +++ b/input/drivers_hid/btstack_hid.c @@ -23,7 +23,7 @@ #include #endif #ifdef HAVE_MFI -#include "../../apple/common/apple_gamecontroller.h" +#include "mfi_hid.h" #endif #include diff --git a/apple/common/GameController/GCController.h b/input/inc/GameController/GCController.h similarity index 100% rename from apple/common/GameController/GCController.h rename to input/inc/GameController/GCController.h diff --git a/apple/common/GameController/GCControllerAxisInput.h b/input/inc/GameController/GCControllerAxisInput.h similarity index 100% rename from apple/common/GameController/GCControllerAxisInput.h rename to input/inc/GameController/GCControllerAxisInput.h diff --git a/apple/common/GameController/GCControllerButtonInput.h b/input/inc/GameController/GCControllerButtonInput.h similarity index 100% rename from apple/common/GameController/GCControllerButtonInput.h rename to input/inc/GameController/GCControllerButtonInput.h diff --git a/apple/common/GameController/GCControllerDirectionPad.h b/input/inc/GameController/GCControllerDirectionPad.h similarity index 100% rename from apple/common/GameController/GCControllerDirectionPad.h rename to input/inc/GameController/GCControllerDirectionPad.h diff --git a/apple/common/GameController/GCControllerElement.h b/input/inc/GameController/GCControllerElement.h similarity index 100% rename from apple/common/GameController/GCControllerElement.h rename to input/inc/GameController/GCControllerElement.h diff --git a/apple/common/GameController/GCExtendedGamepad.h b/input/inc/GameController/GCExtendedGamepad.h similarity index 100% rename from apple/common/GameController/GCExtendedGamepad.h rename to input/inc/GameController/GCExtendedGamepad.h diff --git a/apple/common/GameController/GCExtendedGamepadSnapshot.h b/input/inc/GameController/GCExtendedGamepadSnapshot.h similarity index 100% rename from apple/common/GameController/GCExtendedGamepadSnapshot.h rename to input/inc/GameController/GCExtendedGamepadSnapshot.h diff --git a/apple/common/GameController/GCGamepad.h b/input/inc/GameController/GCGamepad.h similarity index 100% rename from apple/common/GameController/GCGamepad.h rename to input/inc/GameController/GCGamepad.h diff --git a/apple/common/GameController/GCGamepadSnapshot.h b/input/inc/GameController/GCGamepadSnapshot.h similarity index 100% rename from apple/common/GameController/GCGamepadSnapshot.h rename to input/inc/GameController/GCGamepadSnapshot.h diff --git a/apple/common/GameController/GameController.h b/input/inc/GameController/GameController.h similarity index 100% rename from apple/common/GameController/GameController.h rename to input/inc/GameController/GameController.h