mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2025-01-30 23:00:11 -05:00
Use button mapping framework
This commit is contained in:
parent
c07beb0734
commit
a1a2c4ba68
59
usbpad.c
59
usbpad.c
@ -1,10 +1,14 @@
|
||||
#include <stdint.h>
|
||||
#include "gamepads.h"
|
||||
#include "usbpad.h"
|
||||
#include "mappings.h"
|
||||
|
||||
#define REPORT_ID 1
|
||||
#define REPORT_SIZE 15
|
||||
|
||||
|
||||
|
||||
|
||||
void usbpad_init(void)
|
||||
{
|
||||
}
|
||||
@ -14,6 +18,22 @@ int usbpad_getReportSize(void)
|
||||
return REPORT_SIZE;
|
||||
}
|
||||
|
||||
static int16_t minmax(int16_t input, int16_t min, int16_t max)
|
||||
{
|
||||
if (input > max)
|
||||
return max;
|
||||
if (input < min)
|
||||
return min;
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
static void btnsToReport(unsigned short buttons, unsigned char dstbuf[2])
|
||||
{
|
||||
dstbuf[0] = buttons & 0xff;
|
||||
dstbuf[1] = buttons >> 8;
|
||||
}
|
||||
|
||||
static void buildIdleReport(unsigned char dstbuf[REPORT_SIZE])
|
||||
{
|
||||
int i;
|
||||
@ -33,19 +53,40 @@ static void buildIdleReport(unsigned char dstbuf[REPORT_SIZE])
|
||||
|
||||
static void buildReportFromGC(const gc_pad_data *gc_data, unsigned char dstbuf[REPORT_SIZE])
|
||||
{
|
||||
buildIdleReport(dstbuf);
|
||||
int16_t xval,yval;
|
||||
uint16_t buttons;
|
||||
|
||||
// printf("GC x: %4d, y: %4d\r\n", gc_data->x, gc_data->y);
|
||||
|
||||
/* Force official range */
|
||||
xval = minmax(gc_data->x, -100, 100);
|
||||
yval = minmax(gc_data->y, -100, 100);
|
||||
|
||||
/* Scale -100 ... + 1000 to -16000 ... +16000 */
|
||||
xval *= 160;
|
||||
yval *= 160;
|
||||
|
||||
/* Unsign for HID report */
|
||||
xval += 16000;
|
||||
yval += 16000;
|
||||
|
||||
dstbuf[1] = ((uint8_t*)&xval)[0];
|
||||
dstbuf[2] = ((uint8_t*)&xval)[1];
|
||||
dstbuf[3] = ((uint8_t*)&yval)[0];
|
||||
dstbuf[4] = ((uint8_t*)&yval)[1];
|
||||
|
||||
buttons = mappings_do(MAPPING_GAMECUBE_DEFAULT, gc_data->buttons);
|
||||
btnsToReport(buttons, dstbuf+13);
|
||||
}
|
||||
|
||||
static void buildReportFromN64(const n64_pad_data *n64_data, unsigned char dstbuf[REPORT_SIZE])
|
||||
{
|
||||
int16_t xval, yval;
|
||||
|
||||
xval = n64_data->x;
|
||||
yval = n64_data->y;
|
||||
uint16_t buttons;
|
||||
|
||||
/* Force official range */
|
||||
if (xval>80) xval = 80; else if (xval<-80) xval = -80;
|
||||
if (yval>80) yval = 80; else if (yval<-80) yval = -80;
|
||||
xval = minmax(n64_data->x, -80, 80);
|
||||
yval = minmax(n64_data->y, -80, 80);
|
||||
|
||||
/* Scale -80 ... +80 to -16000 ... +16000 */
|
||||
xval *= 200;
|
||||
@ -61,10 +102,8 @@ static void buildReportFromN64(const n64_pad_data *n64_data, unsigned char dstbu
|
||||
dstbuf[3] = ((uint8_t*)&yval)[0];
|
||||
dstbuf[4] = ((uint8_t*)&yval)[1];
|
||||
|
||||
/* TODO : Button mapping */
|
||||
|
||||
dstbuf[13] = n64_data->raw_data[0];
|
||||
dstbuf[14] = n64_data->raw_data[1];
|
||||
buttons = mappings_do(MAPPING_N64_DEFAULT, n64_data->buttons);
|
||||
btnsToReport(buttons, dstbuf+13);
|
||||
}
|
||||
|
||||
void usbpad_buildReport(const gamepad_data *pad_data, unsigned char dstbuf[REPORT_SIZE])
|
||||
|
Loading…
Reference in New Issue
Block a user