mirror of
https://github.com/MickGyver/DaemonBite-Retro-Controllers-USB
synced 2024-11-14 05:15:24 -05:00
mr.Spinner: refactoring for unification, swap spinner phases according to A2600 spinner pinout.
This commit is contained in:
parent
f812ceff60
commit
e86d17dc30
@ -30,30 +30,29 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x04, // USAGE (Joystick) (Maybe change to gamepad? I don't think so but...)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
0xa1, 0x00, // COLLECTION (Physical)
|
||||
0xa1, 0x00, // COLLECTION (Physical)
|
||||
|
||||
0x05, 0x09, // USAGE_PAGE (Button)
|
||||
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||
0x29, 0x05, // USAGE_MAXIMUM (Button 5)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||
0x95, 0x08, // REPORT_COUNT (8)
|
||||
0x75, 0x01, // REPORT_SIZE (1)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0x05, 0x09, // USAGE_PAGE (Button)
|
||||
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||
0x95, 0x08, // REPORT_COUNT (8)
|
||||
0x75, 0x01, // REPORT_SIZE (1)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x01, // USAGE (pointer)
|
||||
0xa1, 0x00, // COLLECTION (Physical)
|
||||
0x09, 0x30, // USAGE (X)
|
||||
0x09, 0x31, // USAGE (Y)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM (255)
|
||||
0x95, 0x02, // REPORT_COUNT (2)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0xc0, // END_COLLECTION
|
||||
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
|
||||
|
||||
0xc0, // END_COLLECTION
|
||||
0xc0, // END_COLLECTION
|
||||
0xc0, // END_COLLECTION
|
||||
};
|
||||
|
||||
@ -131,8 +130,7 @@ bool Gamepad_::setup(USBSetup& setup)
|
||||
|
||||
void Gamepad_::reset()
|
||||
{
|
||||
_GamepadReport.X = 0;
|
||||
_GamepadReport.Y = 0;
|
||||
_GamepadReport.dial = 0;
|
||||
_GamepadReport.buttons = 0;
|
||||
this->send();
|
||||
}
|
||||
|
@ -31,32 +31,26 @@
|
||||
|
||||
extern const char* gp_serial;
|
||||
|
||||
// NOTE: To make this work on the MiSTer (or possibly other Linux distros),
|
||||
// you need to edit USBDesc.h like follows. Change:
|
||||
// #define ISERIAL 3
|
||||
// to
|
||||
// #define ISERIAL 0
|
||||
|
||||
// The numbers after colon are bit fields, meaning how many bits the field uses.
|
||||
// Remove those if there are problems
|
||||
typedef struct {
|
||||
union
|
||||
{
|
||||
struct {
|
||||
bool b0: 1 ;
|
||||
bool b1: 1 ;
|
||||
bool b2: 1 ;
|
||||
bool b3: 1 ;
|
||||
bool b4: 1 ;
|
||||
bool b5: 1 ;
|
||||
bool b6: 1 ;
|
||||
bool b7: 1 ;
|
||||
bool b0: 1;
|
||||
bool b1: 1;
|
||||
bool b2: 1;
|
||||
bool b3: 1;
|
||||
bool b4: 1;
|
||||
bool b5: 1;
|
||||
bool b6: 1;
|
||||
bool b7: 1;
|
||||
};
|
||||
uint8_t buttons;
|
||||
};
|
||||
int8_t X ;
|
||||
int8_t Y ;
|
||||
|
||||
int8_t dial;
|
||||
|
||||
} GamepadReport;
|
||||
|
||||
|
||||
|
@ -134,12 +134,12 @@ void drv_proc(int8_t idx)
|
||||
int8_t spval = (b << 1) | (b^a);
|
||||
int8_t diff = (prev[idx] - spval)&3;
|
||||
|
||||
if(diff == 3)
|
||||
if(diff == 1)
|
||||
{
|
||||
drvpos[idx] += 10;
|
||||
if(sp_clamp[idx] < sp_max) sp_clamp[idx]++;
|
||||
}
|
||||
if(diff == 1)
|
||||
if(diff == 3)
|
||||
{
|
||||
drvpos[idx] -= 10;
|
||||
if(sp_clamp[idx] > 0) sp_clamp[idx]--;
|
||||
@ -183,6 +183,7 @@ void setup()
|
||||
}
|
||||
}
|
||||
|
||||
GamepadReport rep;
|
||||
const int16_t sp_step = (SPINNER_PPR*10)/(20*SPINNER_SENSITIVITY);
|
||||
void loop()
|
||||
{
|
||||
@ -192,63 +193,55 @@ void loop()
|
||||
for(int idx=0; idx<DEV_NUM; idx++)
|
||||
{
|
||||
analog[idx].update();
|
||||
rep.buttons = 0;
|
||||
rep.dial = 0;
|
||||
|
||||
// paddle
|
||||
int8_t newA = !digitalRead(pbtnpin[idx]);
|
||||
//int8_t newB = 0; // reserved for paddles mixed in a single USB controller.
|
||||
int8_t newX = 0;
|
||||
int8_t newY = 0;
|
||||
|
||||
// spinner
|
||||
int8_t newC = !digitalRead(dbtnpin[idx]);
|
||||
int8_t newR = 0;
|
||||
int8_t newL = 0;
|
||||
|
||||
if(newA) pdlena[idx] = 1;
|
||||
if(newC) pdlena[idx] = 0;
|
||||
|
||||
// paddle button
|
||||
if(!digitalRead(pbtnpin[idx]))
|
||||
{
|
||||
pdlena[idx] = 1;
|
||||
rep.b2 = 1;
|
||||
}
|
||||
|
||||
// spinner button
|
||||
if(!digitalRead(dbtnpin[idx]))
|
||||
{
|
||||
pdlena[idx] = 0;
|
||||
rep.b2 = 1;
|
||||
}
|
||||
|
||||
if(pdlena[idx])
|
||||
{
|
||||
newX = (analog[idx].getValue()>>2);
|
||||
rep.dial = (analog[idx].getValue()>>2);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef PADDLE_EMU
|
||||
newX = ((sp_clamp[idx]*255)/sp_max);
|
||||
rep.dial = ((sp_clamp[idx]*255)/sp_max);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(!Gamepad[idx]._GamepadReport.b3 && !Gamepad[idx]._GamepadReport.b4)
|
||||
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)
|
||||
{
|
||||
newR = 1;
|
||||
rep.b1 = 1;
|
||||
prev[idx] += sp_step;
|
||||
}
|
||||
else if(diff <= -sp_step)
|
||||
{
|
||||
newL = 1;
|
||||
rep.b0 = 1;
|
||||
prev[idx] -= sp_step;
|
||||
}
|
||||
}
|
||||
|
||||
int8_t diff = newX - Gamepad[idx]._GamepadReport.X;
|
||||
|
||||
// Only report controller state if it has changed
|
||||
if (diff
|
||||
|| ((Gamepad[idx]._GamepadReport.b0 ^ newA) & 1)
|
||||
|| ((Gamepad[idx]._GamepadReport.b2 ^ newC) & 1)
|
||||
|| ((Gamepad[idx]._GamepadReport.b3 ^ newL) & 1)
|
||||
|| ((Gamepad[idx]._GamepadReport.b4 ^ newR) & 1))
|
||||
if (memcmp(&Gamepad[idx]._GamepadReport, &rep, sizeof(GamepadReport)))
|
||||
{
|
||||
Gamepad[idx]._GamepadReport.X = newX;
|
||||
Gamepad[idx]._GamepadReport.b0 = newA;
|
||||
Gamepad[idx]._GamepadReport.b2 = newC;
|
||||
Gamepad[idx]._GamepadReport.b3 = newL;
|
||||
Gamepad[idx]._GamepadReport.b4 = newR;
|
||||
Gamepad[idx]._GamepadReport = rep;
|
||||
Gamepad[idx].send();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user