mirror of
https://github.com/MickGyver/DaemonBite-Retro-Controllers-USB
synced 2024-08-13 17:03:48 -04:00
Rework spinner and paddle support in mrSpinner and JogCon.
This commit is contained in:
parent
4506896e7d
commit
481b0349d9
@ -52,15 +52,22 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
|
|||||||
0x75, 0x08, // REPORT_SIZE (8)
|
0x75, 0x08, // REPORT_SIZE (8)
|
||||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
0xc0, // END_COLLECTION
|
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)
|
0x15, 0x00, // Logical Minimum (0)
|
||||||
0x25, 0x07, // Logical Maximum (7)
|
0x25, 0x07, // Logical Maximum (7)
|
||||||
0x35, 0x00, // Physical Minimum (0)
|
0x35, 0x00, // Physical Minimum (0)
|
||||||
@ -68,8 +75,6 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
|
|||||||
0x75, 0x08, // Report Size (8)
|
0x75, 0x08, // Report Size (8)
|
||||||
0x95, 0x01, // Report Count (1)
|
0x95, 0x01, // Report Count (1)
|
||||||
0x65, 0x14, // Unit (20)
|
0x65, 0x14, // Unit (20)
|
||||||
0x05, 0x01, // Usage Page (Generic Desktop)
|
|
||||||
0x09, 0x39, // Usage (Hat switch)
|
|
||||||
0x81, 0x42, // Input (variable,absolute,null_state)
|
0x81, 0x42, // Input (variable,absolute,null_state)
|
||||||
|
|
||||||
0xc0, // END_COLLECTION
|
0xc0, // END_COLLECTION
|
||||||
@ -152,7 +157,8 @@ void Gamepad_::reset()
|
|||||||
{
|
{
|
||||||
_GamepadReport.X = 0;
|
_GamepadReport.X = 0;
|
||||||
_GamepadReport.Y = 0;
|
_GamepadReport.Y = 0;
|
||||||
_GamepadReport.dial = 0;
|
_GamepadReport.spinner = 0;
|
||||||
|
_GamepadReport.paddle = 0;
|
||||||
_GamepadReport.hat = 15;
|
_GamepadReport.hat = 15;
|
||||||
_GamepadReport.buttons = 0;
|
_GamepadReport.buttons = 0;
|
||||||
this->send();
|
this->send();
|
||||||
|
@ -59,7 +59,8 @@ typedef struct {
|
|||||||
|
|
||||||
int8_t X;
|
int8_t X;
|
||||||
int8_t Y;
|
int8_t Y;
|
||||||
int8_t dial;
|
int8_t spinner;
|
||||||
|
int8_t paddle;
|
||||||
uint8_t hat;
|
uint8_t hat;
|
||||||
|
|
||||||
} GamepadReport;
|
} GamepadReport;
|
||||||
|
@ -161,7 +161,7 @@ void setup()
|
|||||||
|
|
||||||
sp_step = EEPROM.read(2);
|
sp_step = EEPROM.read(2);
|
||||||
if(sp_step > 8) sp_step = 8;
|
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_div = EEPROM.read(3) ? 1 : 2;
|
||||||
sp_max = SP_MAX/sp_div;
|
sp_max = SP_MAX/sp_div;
|
||||||
@ -278,27 +278,19 @@ void loop()
|
|||||||
|
|
||||||
if(mode == 2) ff = 1;
|
if(mode == 2) ff = 1;
|
||||||
|
|
||||||
if(!(Gamepad._GamepadReport.buttons&3))
|
int16_t val = ((int16_t)(cleancnt - prevcnt))/sp_step;
|
||||||
{
|
if(val>127) val = 127; else if(val<-127) val = -127;
|
||||||
int16_t diff = cleancnt - prevcnt;
|
prevcnt += val*sp_step;
|
||||||
if(diff >= sp_step)
|
int8_t spinner = val;
|
||||||
{
|
|
||||||
newbtn |= 2;
|
uint8_t paddle = ((pdlpos*255)/sp_max);
|
||||||
prevcnt += sp_step;
|
|
||||||
}
|
|
||||||
else if(diff <= -sp_step)
|
|
||||||
{
|
|
||||||
newbtn |= 1;
|
|
||||||
prevcnt -= sp_step;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t dial = ((pdlpos*255)/sp_max);
|
if(oldbtn != newbtn || Gamepad._GamepadReport.paddle != paddle || Gamepad._GamepadReport.spinner != spinner)
|
||||||
if(oldbtn != newbtn || Gamepad._GamepadReport.dial != dial)
|
|
||||||
{
|
{
|
||||||
oldbtn = newbtn;
|
oldbtn = newbtn;
|
||||||
Gamepad._GamepadReport.buttons = (newbtn & 0xF) | ((newbtn>>4) & ~0xF);
|
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._GamepadReport.hat = dpad2hat(newbtn>>4);
|
||||||
Gamepad.send();
|
Gamepad.send();
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
|
|||||||
|
|
||||||
0x05, 0x09, // USAGE_PAGE (Button)
|
0x05, 0x09, // USAGE_PAGE (Button)
|
||||||
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||||
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
|
0x29, 0x01, // USAGE_MAXIMUM (Button 1)
|
||||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||||
0x95, 0x08, // REPORT_COUNT (8)
|
0x95, 0x08, // REPORT_COUNT (8)
|
||||||
@ -42,15 +42,20 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
|
|||||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
|
||||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
0x09, 0x01, // USAGE (pointer)
|
|
||||||
0xa1, 0x00, // COLLECTION (Physical)
|
0x09, 0x37, // USAGE (Dial)
|
||||||
0x09, 0x37, // USAGE (Dial)
|
0x15, 0x80, // LOGICAL_MINIMUM (-128)
|
||||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
0x25, 0x7F, // LOGICAL_MAXIMUM (127)
|
||||||
0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM (255)
|
0x95, 0x01, // REPORT_COUNT (1)
|
||||||
0x95, 0x01, // REPORT_COUNT (1)
|
0x75, 0x08, // REPORT_SIZE (8)
|
||||||
0x75, 0x08, // REPORT_SIZE (8)
|
0x81, 0x06, // INPUT (Data,Var,Rel)
|
||||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
|
||||||
0xc0, // END_COLLECTION
|
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
|
||||||
0xc0, // END_COLLECTION
|
0xc0, // END_COLLECTION
|
||||||
@ -130,7 +135,8 @@ bool Gamepad_::setup(USBSetup& setup)
|
|||||||
|
|
||||||
void Gamepad_::reset()
|
void Gamepad_::reset()
|
||||||
{
|
{
|
||||||
_GamepadReport.dial = 0;
|
_GamepadReport.paddle = 0;
|
||||||
|
_GamepadReport.spinner = 0;
|
||||||
_GamepadReport.buttons = 0;
|
_GamepadReport.buttons = 0;
|
||||||
this->send();
|
this->send();
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,8 @@ typedef struct {
|
|||||||
uint8_t buttons;
|
uint8_t buttons;
|
||||||
};
|
};
|
||||||
|
|
||||||
int8_t dial;
|
int8_t spinner;
|
||||||
|
int8_t paddle;
|
||||||
|
|
||||||
} GamepadReport;
|
} GamepadReport;
|
||||||
|
|
||||||
|
@ -196,49 +196,40 @@ void loop()
|
|||||||
{
|
{
|
||||||
analog[idx].update();
|
analog[idx].update();
|
||||||
rep.buttons = 0;
|
rep.buttons = 0;
|
||||||
rep.dial = 0;
|
rep.paddle = 0;
|
||||||
|
rep.spinner = 0;
|
||||||
|
|
||||||
// paddle button
|
// paddle button
|
||||||
if(!digitalRead(pbtnpin[idx]))
|
if(!digitalRead(pbtnpin[idx]))
|
||||||
{
|
{
|
||||||
pdlena[idx] = 1;
|
pdlena[idx] = 1;
|
||||||
rep.b2 = 1;
|
rep.b0 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// spinner button
|
// spinner button
|
||||||
if(!digitalRead(dbtnpin[idx]))
|
if(!digitalRead(dbtnpin[idx]))
|
||||||
{
|
{
|
||||||
pdlena[idx] = 0;
|
pdlena[idx] = 0;
|
||||||
rep.b2 = 1;
|
rep.b0 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pdlena[idx])
|
if(pdlena[idx])
|
||||||
{
|
{
|
||||||
rep.dial = (analog[idx].getValue()>>2);
|
rep.paddle = (analog[idx].getValue()>>2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef PADDLE_EMU
|
#ifdef PADDLE_EMU
|
||||||
rep.dial = ((sp_clamp[idx]*255)/sp_max);
|
rep.paddle = ((sp_clamp[idx]*255)/sp_max);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Gamepad[idx]._GamepadReport.b0 && !Gamepad[idx]._GamepadReport.b1)
|
// spinner rotation
|
||||||
{
|
static uint16_t prev[2] = {0,0};
|
||||||
static uint16_t prev[2] = {0,0};
|
int16_t val = ((int16_t)(drvpos[idx] - prev[idx]))/sp_step;
|
||||||
int16_t diff = drvpos[idx] - prev[idx];
|
if(val>127) val = 127; else if(val<-127) val = -127;
|
||||||
|
rep.spinner = val;
|
||||||
if(diff >= sp_step)
|
prev[idx] += val*sp_step;
|
||||||
{
|
|
||||||
rep.b1 = 1;
|
|
||||||
prev[idx] += sp_step;
|
|
||||||
}
|
|
||||||
else if(diff <= -sp_step)
|
|
||||||
{
|
|
||||||
rep.b0 = 1;
|
|
||||||
prev[idx] -= sp_step;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only report controller state if it has changed
|
// Only report controller state if it has changed
|
||||||
if (memcmp(&Gamepad[idx]._GamepadReport, &rep, sizeof(GamepadReport)))
|
if (memcmp(&Gamepad[idx]._GamepadReport, &rep, sizeof(GamepadReport)))
|
||||||
|
Loading…
Reference in New Issue
Block a user