1
0
mirror of https://github.com/mcgurk/Arduino-USB-HID-RetroJoystickAdapter synced 2024-11-25 10:32:19 -05:00

Added support for 2-buttons

This commit is contained in:
Jarno Lehtinen 2019-01-16 19:35:22 +02:00 committed by GitHub
parent fc24621cc1
commit 40ac0f5a28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,7 +33,6 @@ inline void translateState(uint8_t data, uint8_t *state) {
#define JOYSTICK_REPORT_ID 0x04 #define JOYSTICK_REPORT_ID 0x04
#define JOYSTICK2_REPORT_ID 0x05 #define JOYSTICK2_REPORT_ID 0x05
//#define JOYSTICK_DATA_SIZE 1
#define JOYSTICK_STATE_SIZE 3 #define JOYSTICK_STATE_SIZE 3
@ -85,14 +84,12 @@ class Joystick_ {
private: private:
uint8_t joystickId; uint8_t joystickId;
uint8_t reportId; uint8_t reportId;
//uint8_t olddata[JOYSTICK_DATA_SIZE];
uint8_t olddata; uint8_t olddata;
uint8_t state[JOYSTICK_STATE_SIZE]; uint8_t state[JOYSTICK_STATE_SIZE];
uint8_t flag; uint8_t flag;
public: public:
uint8_t type; uint8_t type;
//uint8_t data[JOYSTICK_DATA_SIZE];
uint8_t data; uint8_t data;
Joystick_(uint8_t initJoystickId, uint8_t initReportId) { Joystick_(uint8_t initJoystickId, uint8_t initReportId) {
@ -109,18 +106,13 @@ public:
joystickId = initJoystickId; joystickId = initJoystickId;
reportId = initReportId; reportId = initReportId;
//data[0] = 0;
//data[1] = 0;
data = 0; data = 0;
//memcpy(olddata, data, JOYSTICK_DATA_SIZE);
olddata = data; olddata = data;
translateState(data, state); translateState(data, state);
sendState(1); sendState(1);
} }
void updateState() { void updateState() {
//if (memcmp(olddata, data, JOYSTICK_DATA_SIZE)) {
//memcpy(olddata, data, JOYSTICK_DATA_SIZE);
if (olddata != data) { if (olddata != data) {
olddata = data; olddata = data;
translateState(data, state); translateState(data, state);
@ -153,12 +145,13 @@ Joystick_ Joystick[2] =
void setup() { void setup() {
//set all DB9-connector input signal pins as inputs with pullups
for (uint8_t i = 0; i < 9; i++) { for (uint8_t i = 0; i < 9; i++) {
if (inputPinsPort1[i] != 0) if (inputPinsPort1[i] != 0)
pinMode(inputPinsPort1[i], INPUT_PULLUP); pinMode(inputPinsPort1[i], INPUT_PULLUP);
if (inputPinsPort2[i] != 0) if (inputPinsPort2[i] != 0)
pinMode(inputPinsPort2[i], INPUT_PULLUP); pinMode(inputPinsPort2[i], INPUT_PULLUP);
} //without PULLUP every button are read as pressed down if controller is not connected. }
#ifdef DEBUG #ifdef DEBUG
Serial.begin(115200); Serial.begin(115200);
@ -178,10 +171,10 @@ void loop() {
bitWrite(Joystick[1].data, i, digitalRead(inputPinsPort2[i])); //AXES2 bitWrite(Joystick[1].data, i, digitalRead(inputPinsPort2[i])); //AXES2
} }
bitWrite(Joystick[0].data, 4, digitalRead(inputPinsPort1[5])); bitWrite(Joystick[0].data, 4, digitalRead(inputPinsPort1[5])); //JOY1:FIRE1
bitWrite(Joystick[0].data, 5, digitalRead(inputPinsPort1[8])); bitWrite(Joystick[0].data, 5, digitalRead(inputPinsPort1[8])); //JOY1:FIRE2
bitWrite(Joystick[1].data, 4, digitalRead(inputPinsPort2[5])); bitWrite(Joystick[1].data, 4, digitalRead(inputPinsPort2[5])); //JOY2:FIRE1
bitWrite(Joystick[1].data, 5, digitalRead(inputPinsPort2[8])); bitWrite(Joystick[1].data, 5, digitalRead(inputPinsPort2[8])); //JOY2:FIRE2
#ifdef DEBUG #ifdef DEBUG