My gamepad sends 8 Bytes of data
80 80 00 00 00 00 00 00
The first Byte is the X-Axis, the second one the Y-Axis. The third byte are all buttons. Bit one to eight are (A, B, X, Y, L, R, Select, Start). It also has two buttons on the third byte, 0x10 and 0x20 (CLEAR Button, I want to use this one as MENU).
PID is: 8288 dec
VID is: 1411 dec
I modified the “connect_snesusb.c” so that I don’t have to the griffin.c yet.
My connect_snesusb.c looks like this:
/* RetroArch - A frontend for libretro. * Copyright (C) 2013-2014 - Jason Fetters
* Copyright (C) 2011-2016 - 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 <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <boolean.h>
#include "joypad_connection.h"
#include "../input_defines.h"
struct hidpad_snesusb_data
{
struct pad_connection* connection;
uint8_t data[64];
uint32_t slot;
uint64_t buttons;
};
static void* hidpad_snesusb_init(void *data, uint32_t slot, send_control_t ptr)
{
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_snesusb_data* device = (struct hidpad_snesusb_data*)
calloc(1, sizeof(struct hidpad_snesusb_data));
if (!device)
return NULL;
if (!connection)
{
free(device);
return NULL;
}
device->connection = connection;
device->slot = slot;
return device;
}
static void hidpad_snesusb_deinit(void *data)
{
struct hidpad_snesusb_data *device = (struct hidpad_snesusb_data*)data;
if (device)
free(device);
}
static uint64_t hidpad_snesusb_get_buttons(void *data)
{
struct hidpad_snesusb_data *device = (struct hidpad_snesusb_data*)data;
if (!device)
return 0;
return device->buttons;
}
static int16_t hidpad_snesusb_get_axis(void *data, unsigned axis)
{
int val;
struct hidpad_snesusb_data *device = (struct hidpad_snesusb_data*)data;
if (!device || axis >= 2)
return 0;
[B]val = device->data[0 + axis];[/B] // Unter Umständen sind hier hier Achsen vertauscht!!
val = (val << 8) - 0x8000;
return (abs(val) > 0x1000) ? val : 0; // Unter Umständen ist hier die Richtung vertauscht!!
}
static void hidpad_snesusb_packet_handler(void *data, uint8_t *packet, uint16_t size)
{
uint32_t i, pressed_keys;
static const uint32_t button_mapping[17] =
{
// RETRO_DEVICE_ID_JOYPAD_L,
// RETRO_DEVICE_ID_JOYPAD_R,
// NO_BTN,
// NO_BTN,
// RETRO_DEVICE_ID_JOYPAD_SELECT,
// RETRO_DEVICE_ID_JOYPAD_START,
// NO_BTN,
// NO_BTN,
// NO_BTN,
// NO_BTN,
// NO_BTN,
// NO_BTN,
// RETRO_DEVICE_ID_JOYPAD_X,
// RETRO_DEVICE_ID_JOYPAD_A,
// RETRO_DEVICE_ID_JOYPAD_B,
// RETRO_DEVICE_ID_JOYPAD_Y,
// 16, /* HOME BUTTON when pressing SELECT+START */
[B] RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_X,
RETRO_DEVICE_ID_JOYPAD_Y,
RETRO_DEVICE_ID_JOYPAD_L,
RETRO_DEVICE_ID_JOYPAD_R,
RETRO_DEVICE_ID_JOYPAD_SELECT,
RETRO_DEVICE_ID_JOYPAD_START,
NO_BTN,
NO_BTN,
NO_BTN,
NO_BTN,
NO_BTN,
NO_BTN,
NO_BTN,
NO_BTN,
16 /* HOME BUTTON when pressing CLEAR Button */ [/B]
};
struct hidpad_snesusb_data *device = (struct hidpad_snesusb_data*)data;
if (!device)
return;
memcpy(device->data, packet, size);
device->buttons = 0;
[B] pressed_keys = device->data[2] |
(((device->data[3] & 0x20) == 0x20) ? (1 << 16) : 0); /* CLEAR-BUTTON = MENU TOGGLE */[/B]
for (i = 0; i < 17; i ++)
if (button_mapping[i] != NO_BTN)
device->buttons |= (pressed_keys & (1 << i)) ? (UINT64_C(1) << button_mapping[i]) : 0;
}
static void hidpad_snesusb_set_rumble(void *data,
enum retro_rumble_effect effect, uint16_t strength)
{
(void)data;
(void)effect;
(void)strength;
}
const char * hidpad_snesusb_get_name(void *data)
{
(void)data;
/* For now we return a single static name */
return[B] "iBuffalo [/B]SNES USB Controller";
}
pad_connection_interface_t pad_connection_snesusb = {
hidpad_snesusb_init,
hidpad_snesusb_deinit,
hidpad_snesusb_packet_handler,
hidpad_snesusb_set_rumble,
hidpad_snesusb_get_buttons,
hidpad_snesusb_get_axis,
hidpad_snesusb_get_name,
};
So as you can see, I edited the following
- “hidpad_snesusb_get_axis” because my axes data is in Data[0] and data[1]
- “hidpad_snesusb_packet_handler” because my buttons are in a different order
- variable “pressed_keys” because, again, the key data is in different placed of the data array
- “hidpad_snesusb_get_name” to return “iBuffalo” instead of “Generic” in the name
My cfg looks as follows:
input_device = "iBuffalo SNES USB Controller"
input_driver = "hid"
input_vendor_id = 1411
input_product_id = 8288
input_b_btn = "1"
input_y_btn = "3"
input_select_btn = "6"
input_start_btn = "7"
input_a_btn = "0"
input_x_btn = "2"
input_l_btn = "4"
input_r_btn = "5"
input_l_x_plus_axis = "+0"
input_l_x_minus_axis = "-0"
input_l_y_plus_axis = "+1"
input_l_y_minus_axis = "-1"
input_menu_toggle_btn = "16"
input_b_btn_label = "B"
input_y_btn_label = "Y"
input_select_btn_label = "Select"
input_start_btn_label = "Start"
input_a_btn_label = "A"
input_x_btn_label = "X"
input_l_btn_label = "L"
input_r_btn_label = "R"
input_l_x_plus_axis_label = "D Pad Right"
input_l_x_minus_axis_label = "D Pad Left"
input_l_y_plus_axis_label = "D Pad Down"
input_l_y_minus_axis_label = "D Pad Up"
input_menu_toggle_btn_label = "CLEAR"
I renamed the Controller and switched the input numbers around.
It does not work. The controller does not even get recognized upon plugging in. What am I missing here??
EDIT:
Oh, my joypad_connection.c looks as follows:
pad_connection_pad_init(joypad_connection_t *joyconn, const char* name, uint16_t vid, uint16_t pid,
void *data, send_control_t ptr)
{
static const struct
{
const char* name;
uint16_t vid;
uint16_t pid;
pad_connection_interface_t *iface;
} pad_map[] =
{
{ "Nintendo RVL-CNT-01", 1406, 816, &pad_connection_wii },
{ "Nintendo RVL-CNT-01-UC", 1406, 816, &pad_connection_wiiupro },
{ "Wireless Controller", 1356, 1476, &pad_connection_ps4 },
{ "PLAYSTATION(R)3 Controller", 1356, 616, &pad_connection_ps3 },
{ "PLAYSTATION(R)3 Controller", 787, 8406, &pad_connection_ps3 },
[B] { "iBuffalo SNES USB Controller", 1411, 8288, &pad_connection_snesusb },[/B]
{ "Generic NES USB Controller", 121, 17, &pad_connection_nesusb },
{ "Wii U GC Controller Adapter", 1406, 823, &pad_connection_wiiugca },
{ "PS2/PSX Controller Adapter", 2064, 1, &pad_connection_ps2adapter },
{ 0, 0}
};
joypad_connection_t *s = NULL;
int pad = pad_connection_find_vacant_pad(joyconn);
if (pad == -1)
return -1;
s = &joyconn[pad];
if (s)
{
unsigned i;
for (i = 0; name && pad_map[i].name; i++)
{
const char *name_match = strstr(pad_map[i].name, name);
/* Never change, Nintendo. */
if(pad_map[i].vid == 1406 && pad_map[i].pid == 816)
{
if(!string_is_equal(pad_map[i].name, name))
continue;
}
if (name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid))
{
s->iface = pad_map[i].iface;
s->data = s->iface->init(data, pad, ptr);
s->connected = true;
break;
}
}
}
return pad;
}