From e86d17dc30104dd6c2d6bf9877fc97fe207dfdc9 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sat, 29 Feb 2020 00:18:11 +0800 Subject: [PATCH] mr.Spinner: refactoring for unification, swap spinner phases according to A2600 spinner pinout. --- PaddleTwoControllersUSB/Gamepad.cpp | 44 +++++++------- PaddleTwoControllersUSB/Gamepad.h | 26 ++++---- .../PaddleTwoControllersUSB.ino | 59 ++++++++----------- 3 files changed, 57 insertions(+), 72 deletions(-) diff --git a/PaddleTwoControllersUSB/Gamepad.cpp b/PaddleTwoControllersUSB/Gamepad.cpp index 6f3db68..f81c619 100644 --- a/PaddleTwoControllersUSB/Gamepad.cpp +++ b/PaddleTwoControllersUSB/Gamepad.cpp @@ -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(); } diff --git a/PaddleTwoControllersUSB/Gamepad.h b/PaddleTwoControllersUSB/Gamepad.h index 9a29c03..c5c69b3 100644 --- a/PaddleTwoControllersUSB/Gamepad.h +++ b/PaddleTwoControllersUSB/Gamepad.h @@ -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; diff --git a/PaddleTwoControllersUSB/PaddleTwoControllersUSB.ino b/PaddleTwoControllersUSB/PaddleTwoControllersUSB.ino index 4d04025..9c7c65d 100644 --- a/PaddleTwoControllersUSB/PaddleTwoControllersUSB.ino +++ b/PaddleTwoControllersUSB/PaddleTwoControllersUSB.ino @@ -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>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(); } }