[QUOTE=Frozen_Fish;38656]I’m trying to write a driver for my Qanba Q4RAF arcade stick. I was able to get the left stick axis working without much trouble, but no matter what I do I can’t get the buttons or d-pad to work (The Q4RAF has a switch that swaps the single physical joystick between controlling the left stick and the d-pad FYI).
Here’s the info from HIDTest:
80 7F 80 7F 0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Left Stick Horizontal (Byte 00):
Range = 00 - FF
Left = 00
Centre = 80
Right = FF
Left Stick Vertical (Byte 01):
Range = 00 - FF
Up = 00
Centre = 7F
Down = FF
Right Stick Horizontal (Byte 02):
Physically inaccessible
Right Stick Vertical (Byte 03):
Physically inaccessible
Hat (Byte 04):
Neutral = 0F
Up = 00
UpRight = 01
Right = 02
RightDown = 03
Down = 04
DownLeft = 05
Left = 06
LeftUp = 07
Face Buttons (Byte 05):
None = 00
A = 01
B = 02
X = 04
Y = 08
RB = 10
LB = 20
RT = 40
LT = 80
Other Buttons (Byte 06):
None = 00
Select = 01
Start = 02
Home = 10
Here’s what I have so far:
/* 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_qanbaq4raf_data
{
struct pad_connection* connection;
uint8_t data[64];
uint32_t slot;
uint64_t buttons;
};
static void* hidpad_qanbaq4raf_init(void *data, uint32_t slot, send_control_t ptr)
{
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_qanbaq4raf_data* device = (struct hidpad_qanbaq4raf_data*)
calloc(1, sizeof(struct hidpad_qanbaq4raf_data));
if (!device)
return NULL;
if (!connection)
{
free(device);
return NULL;
}
device->connection = connection;
device->slot = slot;
return device;
}
static void hidpad_qanbaq4raf_deinit(void *data)
{
struct hidpad_qanbaq4raf_data *device = (struct hidpad_qanbaq4raf_data*)data;
if (device)
free(device);
}
static uint64_t hidpad_qanbaq4raf_get_buttons(void *data)
{
struct hidpad_qanbaq4raf_data *device = (struct hidpad_qanbaq4raf_data*)data;
if (!device)
return 0;
return device->buttons;
}
static int16_t hidpad_qanbaq4raf_get_axis(void *data, unsigned axis)
{
int val;
struct hidpad_qanbaq4raf_data *device = (struct hidpad_qanbaq4raf_data*)data;
if (!device || axis >= 2)
return 0;
val = device->data[1 + axis];
val = (val << 8) - 0x8000;
return (abs(val) > 0x1000) ? val : 0;
}
#define Q4_H_GET(a) (a & 0x0F) /*HAT MASK = 0x0F */
#define Q4_H_LEFT(a) (a == 0x05) || (a == 0x06) || (a == 0x07)
#define Q4_H_RIGHT(a) (a == 0x01) || (a == 0x02) || (a == 0x03)
#define Q4_H_UP(a) (a == 0x07) || (a == 0x00) || (a == 0x01)
#define Q4_H_DOWN(a) (a == 0x03) || (a == 0x04) || (a == 0x05)
static void hidpad_qanbaq4raf_packet_handler(void *data, uint8_t *packet, uint16_t size)
{
uint32_t i, pressed_keys;
//int16_t hat_value;
static const uint32_t button_mapping[13] =
{
RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_X,
RETRO_DEVICE_ID_JOYPAD_Y,
RETRO_DEVICE_ID_JOYPAD_R,
RETRO_DEVICE_ID_JOYPAD_L,
RETRO_DEVICE_ID_JOYPAD_R2,
RETRO_DEVICE_ID_JOYPAD_L2,
RETRO_DEVICE_ID_JOYPAD_SELECT,
RETRO_DEVICE_ID_JOYPAD_START,
NO_BTN,
NO_BTN,
16,
};
struct hidpad_qanbaq4raf_data *device = (struct hidpad_qanbaq4raf_data*)data;
if (!device)
return;
memcpy(device->data, packet, size);
device->buttons = 0;
pressed_keys = device->data[6] | (device->data[7] << 8);
for (i = 0; i < 13; i ++)
if (button_mapping[i] != NO_BTN)
device->buttons |= (pressed_keys & (1 << i)) ? (UINT64_C(1) << button_mapping[i]) : 0;
/* Now process the hat values as if they were pad buttons */
//hat_value = Q4_H_GET(device->data[5]);
//device->buttons |= Q4_H_LEFT(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
//device->buttons |= Q4_H_RIGHT(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
//device->buttons |= Q4_H_UP(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
//device->buttons |= Q4_H_DOWN(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
}
static void hidpad_qanbaq4raf_set_rumble(void *data,
enum retro_rumble_effect effect, uint16_t strength)
{
(void)data;
(void)effect;
(void)strength;
}
const char * hidpad_qanbaq4raf_get_name(void *data)
{
(void)data;
/* For now we return a single static name */
return "QanBa Joystick Plus";
}
pad_connection_interface_t pad_connection_qanbaq4raf = {
hidpad_qanbaq4raf_init,
hidpad_qanbaq4raf_deinit,
hidpad_qanbaq4raf_packet_handler,
hidpad_qanbaq4raf_set_rumble,
hidpad_qanbaq4raf_get_buttons,
hidpad_qanbaq4raf_get_axis,
hidpad_qanbaq4raf_get_name,
};
I’ve done as netux79 suggested and added 1 to the actual index of each byte I want to read. No button inputs are detected and if I uncomment the hat processing code, I get a constant up press in the Retroarch menu, meaning device->data[5] is 0x00 when I’d expect it to be 0x0F. I’ve also tried every value from 0 - 8 as indexes for the hat switch and none have worked.
Any help is appreciated.[/QUOTE]
hi Frozen_Fish, I will give it a look later and give you some input to see if we can make it work… I see you provided the info from the Nintendont tool to see the values from the buttons so it should not be a problem.