1
0
mirror of https://github.com/MickGyver/DaemonBite-Retro-Controllers-USB synced 2024-11-15 22:05:03 -05:00

Rework spinner and paddle support in mrSpinner and JogCon.

This commit is contained in:
sorgelig 2020-03-02 02:02:06 +08:00
parent 4506896e7d
commit 481b0349d9
6 changed files with 61 additions and 64 deletions

View File

@ -52,15 +52,22 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
0xa1, 0x00, // COLLECTION (Physical)
0x09, 0x37, // USAGE (Dial)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM (255)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
0x09, 0x37, // USAGE (Dial)
0x15, 0x80, // LOGICAL_MINIMUM (-128)
0x25, 0x7F, // LOGICAL_MAXIMUM (127)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x06, // INPUT (Data,Var,Rel)
0x09, 0x38, // USAGE (Wheel)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM (255)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x09, 0x39, // Usage (Hat switch)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x07, // Logical Maximum (7)
0x35, 0x00, // Physical Minimum (0)
@ -68,8 +75,6 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x65, 0x14, // Unit (20)
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x39, // Usage (Hat switch)
0x81, 0x42, // Input (variable,absolute,null_state)
0xc0, // END_COLLECTION
@ -152,7 +157,8 @@ void Gamepad_::reset()
{
_GamepadReport.X = 0;
_GamepadReport.Y = 0;
_GamepadReport.dial = 0;
_GamepadReport.spinner = 0;
_GamepadReport.paddle = 0;
_GamepadReport.hat = 15;
_GamepadReport.buttons = 0;
this->send();

View File

@ -59,7 +59,8 @@ typedef struct {
int8_t X;
int8_t Y;
int8_t dial;
int8_t spinner;
int8_t paddle;
uint8_t hat;
} GamepadReport;

View File

@ -161,7 +161,7 @@ void setup()
sp_step = EEPROM.read(2);
if(sp_step > 8) sp_step = 8;
if(sp_step < 1) sp_step = 4;
if(sp_step < 1) sp_step = 1;
sp_div = EEPROM.read(3) ? 1 : 2;
sp_max = SP_MAX/sp_div;
@ -278,27 +278,19 @@ void loop()
if(mode == 2) ff = 1;
if(!(Gamepad._GamepadReport.buttons&3))
{
int16_t diff = cleancnt - prevcnt;
if(diff >= sp_step)
{
newbtn |= 2;
prevcnt += sp_step;
}
else if(diff <= -sp_step)
{
newbtn |= 1;
prevcnt -= sp_step;
}
}
int16_t val = ((int16_t)(cleancnt - prevcnt))/sp_step;
if(val>127) val = 127; else if(val<-127) val = -127;
prevcnt += val*sp_step;
int8_t spinner = val;
uint8_t paddle = ((pdlpos*255)/sp_max);
uint8_t dial = ((pdlpos*255)/sp_max);
if(oldbtn != newbtn || Gamepad._GamepadReport.dial != dial)
if(oldbtn != newbtn || Gamepad._GamepadReport.paddle != paddle || Gamepad._GamepadReport.spinner != spinner)
{
oldbtn = newbtn;
Gamepad._GamepadReport.buttons = (newbtn & 0xF) | ((newbtn>>4) & ~0xF);
Gamepad._GamepadReport.dial = dial;
Gamepad._GamepadReport.paddle = paddle;
Gamepad._GamepadReport.spinner = spinner;
Gamepad._GamepadReport.hat = dpad2hat(newbtn>>4);
Gamepad.send();
}

View File

@ -34,7 +34,7 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
0x29, 0x01, // USAGE_MAXIMUM (Button 1)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x08, // REPORT_COUNT (8)
@ -42,15 +42,20 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
0x81, 0x02, // INPUT (Data,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x01, // USAGE (pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x09, 0x37, // USAGE (Dial)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM (255)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
0x09, 0x37, // USAGE (Dial)
0x15, 0x80, // LOGICAL_MINIMUM (-128)
0x25, 0x7F, // LOGICAL_MAXIMUM (127)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x06, // INPUT (Data,Var,Rel)
0x09, 0x38, // USAGE (Wheel)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM (255)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
0xc0, // END_COLLECTION
@ -130,7 +135,8 @@ bool Gamepad_::setup(USBSetup& setup)
void Gamepad_::reset()
{
_GamepadReport.dial = 0;
_GamepadReport.paddle = 0;
_GamepadReport.spinner = 0;
_GamepadReport.buttons = 0;
this->send();
}

View File

@ -49,7 +49,8 @@ typedef struct {
uint8_t buttons;
};
int8_t dial;
int8_t spinner;
int8_t paddle;
} GamepadReport;

View File

@ -196,49 +196,40 @@ void loop()
{
analog[idx].update();
rep.buttons = 0;
rep.dial = 0;
rep.paddle = 0;
rep.spinner = 0;
// paddle button
if(!digitalRead(pbtnpin[idx]))
{
pdlena[idx] = 1;
rep.b2 = 1;
rep.b0 = 1;
}
// spinner button
if(!digitalRead(dbtnpin[idx]))
{
pdlena[idx] = 0;
rep.b2 = 1;
rep.b0 = 1;
}
if(pdlena[idx])
{
rep.dial = (analog[idx].getValue()>>2);
rep.paddle = (analog[idx].getValue()>>2);
}
else
{
#ifdef PADDLE_EMU
rep.dial = ((sp_clamp[idx]*255)/sp_max);
rep.paddle = ((sp_clamp[idx]*255)/sp_max);
#endif
}
if(!Gamepad[idx]._GamepadReport.b0 && !Gamepad[idx]._GamepadReport.b1)
{
static uint16_t prev[2] = {0,0};
int16_t diff = drvpos[idx] - prev[idx];
if(diff >= sp_step)
{
rep.b1 = 1;
prev[idx] += sp_step;
}
else if(diff <= -sp_step)
{
rep.b0 = 1;
prev[idx] -= sp_step;
}
}
// spinner rotation
static uint16_t prev[2] = {0,0};
int16_t val = ((int16_t)(drvpos[idx] - prev[idx]))/sp_step;
if(val>127) val = 127; else if(val<-127) val = -127;
rep.spinner = val;
prev[idx] += val*sp_step;
// Only report controller state if it has changed
if (memcmp(&Gamepad[idx]._GamepadReport, &rep, sizeof(GamepadReport)))