Browse Source

Implement gamecube C-Stick and triggers

pull/5/head
Raphael Assenat 7 years ago
parent
commit
ca574cc71f
  1. 3
      gamepads.h
  2. 32
      usbpad.c

3
gamepads.h

@ -35,7 +35,8 @@ typedef struct _n64_pad_data { @@ -35,7 +35,8 @@ typedef struct _n64_pad_data {
typedef struct _gc_pad_data {
unsigned char pad_type; // PAD_TYPE_GAMECUBE
char x,y,cx,cy,lt,rt;
char x,y,cx,cy;
unsigned char lt,rt;
unsigned short buttons;
unsigned char raw_data[GC_RAW_SIZE];
} gc_pad_data;

32
usbpad.c

@ -53,28 +53,54 @@ static void buildIdleReport(unsigned char dstbuf[REPORT_SIZE]) @@ -53,28 +53,54 @@ static void buildIdleReport(unsigned char dstbuf[REPORT_SIZE])
static void buildReportFromGC(const gc_pad_data *gc_data, unsigned char dstbuf[REPORT_SIZE])
{
int16_t xval,yval;
int16_t xval,yval,cxval,cyval,ltrig,rtrig;
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);
cxval = minmax(gc_data->cx, -100, 100);
cyval = minmax(gc_data->cy, -100, 100);
ltrig = gc_data->lt;
rtrig = gc_data->rt;
/* Scale -100 ... + 1000 to -16000 ... +16000 */
xval *= 160;
yval *= 160;
// TODO : Is C-stick different?
cxval *= 160;
cyval *= 160;
/* Scane 0...255 to 0...16000 */
ltrig *= 63;
if (ltrig > 16000) ltrig=16000;
rtrig *= 63;
if (rtrig > 16000) rtrig=16000;
/* Unsign for HID report */
xval += 16000;
yval += 16000;
cxval += 16000;
cyval += 16000;
ltrig += 16000;
rtrig += 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];
dstbuf[5] = ((uint8_t*)&cxval)[0];
dstbuf[6] = ((uint8_t*)&cxval)[1];
dstbuf[7] = ((uint8_t*)&cyval)[0];
dstbuf[8] = ((uint8_t*)&cyval)[1];
dstbuf[9] = ((uint8_t*)&ltrig)[0];
dstbuf[10] = ((uint8_t*)&ltrig)[1];
dstbuf[11] = ((uint8_t*)&rtrig)[0];
dstbuf[12] = ((uint8_t*)&rtrig)[1];
buttons = mappings_do(MAPPING_GAMECUBE_DEFAULT, gc_data->buttons);
btnsToReport(buttons, dstbuf+13);
}

Loading…
Cancel
Save