From 9ade0a8a7f5a7e0086c63e6e8b4c8f60ee366e3e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 2 Apr 2015 00:20:28 +0200 Subject: [PATCH] (HID) Create null_hid --- Makefile.common | 1 + griffin/griffin.c | 9 ++- input/drivers_hid/null_hid.c | 115 ++++++++++++++++++++++++++++ input/input_hid_driver.c | 1 + input/input_hid_driver.h | 1 + tools/retroarch-joyconfig-griffin.c | 1 + 6 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 input/drivers_hid/null_hid.c diff --git a/Makefile.common b/Makefile.common index 4bb6f2bc12..223eea3f3a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -164,6 +164,7 @@ OBJ += frontend/frontend.o \ gfx/drivers/nullgfx.o \ audio/drivers/nullaudio.o \ input/drivers/nullinput.o \ + input/drivers_hid/null_hid.o \ input/drivers_joypad/nullinput_joypad.o \ input/drivers_joypad/hid_joypad.o \ playlist.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index 4fed17aa60..710a4cb858 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -343,15 +343,18 @@ INPUT #include "../input/drivers_joypad/hid_joypad.c" +#include "../input/drivers_hid/null_hid.c" + +#ifdef HAVE_HID +#include "../input/drivers_hid/apple_hid.c" +#endif + #if defined(__APPLE__) #include "../input/connect/joypad_connection.c" #include "../input/connect/connect_ps3.c" #include "../input/connect/connect_ps4.c" #include "../input/connect/connect_wii.c" -#ifdef HAVE_HID -#include "../input/drivers_hid/apple_hid.c" -#endif #ifdef IOS #include "../apple/iOS/bluetooth/btdynamic.c" diff --git a/input/drivers_hid/null_hid.c b/input/drivers_hid/null_hid.c new file mode 100644 index 0000000000..71849aa827 --- /dev/null +++ b/input/drivers_hid/null_hid.c @@ -0,0 +1,115 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2013-2014 - Jason Fetters + * Copyright (C) 2011-2015 - Daniel De Matteis + * + * 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 "../drivers/apple_input.h" +#include "../input_hid_driver.h" + +typedef struct null_hid +{ + void *empty; +} null_hid_t; + +static bool null_hid_joypad_query(void *data, unsigned pad) +{ + return pad < MAX_USERS; +} + +static const char *null_hid_joypad_name(void *data, unsigned pad) +{ + /* TODO/FIXME - implement properly */ + if (pad >= MAX_USERS) + return NULL; + + return NULL; +} + +static uint64_t null_hid_joypad_get_buttons(void *data, unsigned port) +{ + (void)data; + (void)port; + + return 0; +} + +static bool null_hid_joypad_button(void *data, unsigned port, uint16_t joykey) +{ + (void)data; + (void)port; + (void)joykey; + + return false; +} + +static bool null_hid_joypad_rumble(void *data, unsigned pad, + enum retro_rumble_effect effect, uint16_t strength) +{ + (void)data; + (void)pad; + (void)effect; + (void)strength; + + return false; +} + +static int16_t null_hid_joypad_axis(void *data, unsigned port, uint32_t joyaxis) +{ + (void)data; + (void)port; + (void)joyaxis; + + return 0; +} + +static void *null_hid_init(void) +{ + null_hid_t *hid_null = (null_hid_t*)calloc(1, sizeof(*hid_null)); + + if (!hid_null) + goto error; + + return hid_null; + +error: + if (hid_null) + free(hid_null); + return hid_null; +} + +static void null_hid_free(void *data) +{ + null_hid_t *hid_null = (null_hid_t*)data; + + if (hid_null) + free(hid_null); +} + +static void null_hid_poll(void *data) +{ + (void)data; +} + +hid_driver_t null_hid = { + null_hid_init, + null_hid_joypad_query, + null_hid_free, + null_hid_joypad_button, + null_hid_joypad_get_buttons, + null_hid_joypad_axis, + null_hid_poll, + null_hid_joypad_rumble, + null_hid_joypad_name, + "null", +}; diff --git a/input/input_hid_driver.c b/input/input_hid_driver.c index d0228539af..6b831926b5 100644 --- a/input/input_hid_driver.c +++ b/input/input_hid_driver.c @@ -26,6 +26,7 @@ static hid_driver_t *hid_drivers[] = { #ifdef __APPLE__ &apple_hid, #endif + &null_hid, NULL, }; diff --git a/input/input_hid_driver.h b/input/input_hid_driver.h index 240619e00d..8e357cc1df 100644 --- a/input/input_hid_driver.h +++ b/input/input_hid_driver.h @@ -44,6 +44,7 @@ struct hid_driver }; extern hid_driver_t apple_hid; +extern hid_driver_t null_hid; /** * hid_driver_find_handle: diff --git a/tools/retroarch-joyconfig-griffin.c b/tools/retroarch-joyconfig-griffin.c index 3d8dea90c0..ae8a0a6d02 100644 --- a/tools/retroarch-joyconfig-griffin.c +++ b/tools/retroarch-joyconfig-griffin.c @@ -48,6 +48,7 @@ #include "../libretro-common/compat/compat.c" #include "../input/drivers/nullinput.c" +#include "../input/drivers_hid/null_hid.c" #include "../input/drivers_joypad/hid_joypad.c" #include "../input/drivers_joypad/nullinput_joypad.c"