Implement "sliders as buttons" mode

In this mode, when the analog values of the L/R triggers exceed a
certain threshold, the corresponding L and R digital buttons are
triggered.
This commit is contained in:
Raphael Assenat 2017-08-05 17:13:21 -04:00
parent a9d5df2b8f
commit a041e8eaf8
1 changed files with 30 additions and 17 deletions

View File

@ -98,6 +98,7 @@ static void buildReportFromGC(const gc_pad_data *gc_data, unsigned char dstbuf[U
{ {
int16_t xval,yval,cxval,cyval,ltrig,rtrig; int16_t xval,yval,cxval,cyval,ltrig,rtrig;
uint16_t buttons; uint16_t buttons;
uint16_t gcbuttons = gc_data->buttons;
/* Force official range */ /* Force official range */
xval = minmax(gc_data->x, -100, 100); xval = minmax(gc_data->x, -100, 100);
@ -114,25 +115,37 @@ static void buildReportFromGC(const gc_pad_data *gc_data, unsigned char dstbuf[U
cxval *= 160; cxval *= 160;
cyval *= -160; cyval *= -160;
if (g_eeprom_data.cfg.flags & FLAG_GC_FULL_SLIDERS) { if (g_eeprom_data.cfg.flags & FLAG_GC_SLIDERS_AS_BUTTONS) {
int16_t lts = (int16_t)ltrig - 127; /* In this mode, the sliders control buttons */
int16_t rts = (int16_t)rtrig - 127; if (ltrig > 32)
lts *= 126; gcbuttons |= GC_BTN_L;
ltrig = lts; if (rtrig > 32)
rts *= 126; gcbuttons |= GC_BTN_R;
rtrig = rts;
} else { /* And the sliders analog values are fixed. */
/* Scale 0...255 to 0...16000 */ ltrig = rtrig = 0;
ltrig *= 63;
if (ltrig > 16000) ltrig=16000;
rtrig *= 63;
if (rtrig > 16000) rtrig=16000;
} }
else {
if (g_eeprom_data.cfg.flags & FLAG_GC_FULL_SLIDERS) {
int16_t lts = (int16_t)ltrig - 127;
int16_t rts = (int16_t)rtrig - 127;
lts *= 126;
ltrig = lts;
rts *= 126;
rtrig = rts;
if (g_eeprom_data.cfg.flags & FLAG_GC_INVERT_TRIGS) { } else {
ltrig = -ltrig; /* Scale 0...255 to 0...16000 */
rtrig = -rtrig; ltrig *= 63;
if (ltrig > 16000) ltrig=16000;
rtrig *= 63;
if (rtrig > 16000) rtrig=16000;
}
if (g_eeprom_data.cfg.flags & FLAG_GC_INVERT_TRIGS) {
ltrig = -ltrig;
rtrig = -rtrig;
}
} }
/* Unsign for HID report */ /* Unsign for HID report */
@ -159,7 +172,7 @@ static void buildReportFromGC(const gc_pad_data *gc_data, unsigned char dstbuf[U
dstbuf[11] = ((uint8_t*)&rtrig)[0]; dstbuf[11] = ((uint8_t*)&rtrig)[0];
dstbuf[12] = ((uint8_t*)&rtrig)[1]; dstbuf[12] = ((uint8_t*)&rtrig)[1];
buttons = mappings_do(MAPPING_GAMECUBE_DEFAULT, gc_data->buttons); buttons = mappings_do(MAPPING_GAMECUBE_DEFAULT, gcbuttons);
btnsToReport(buttons, dstbuf+13); btnsToReport(buttons, dstbuf+13);
} }