Skip to content

Commit 206fbaf

Browse files
author
Jason Duncan
committed
Moved some things around. Renamed the 'G' class to 'G27'. Cut the button count down to 24.
1 parent eabd5e6 commit 206fbaf

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

G27_Pedals_and_Shifter.ino

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
// Partially adapted from the work done by isrtv.com forums members pascalh and xxValiumxx:
55
// http://www.isrtv.com/forums/topic/13189-diy-g25-shifter-interface-with-h-pattern-sequential-and-handbrake-modes/
66

7-
#include "G27PedalsShifter.h"
7+
#include <HID.h>
8+
#include "./lib/G27PedalsShifter.h"
89

910
// for debugging, gives serial output rather than working as a joystick
1011
//#define DEBUG true
@@ -163,17 +164,17 @@ void describePedal(char* name, char* axisName, void* in) {
163164

164165
void setXAxis(void* in) {
165166
Pedal* input = (Pedal*)in;
166-
G.setXAxis(input->axis);
167+
G27.setXAxis(input->axis);
167168
}
168169

169170
void setYAxis(void* in) {
170171
Pedal* input = (Pedal*)in;
171-
G.setYAxis(input->axis);
172+
G27.setYAxis(input->axis);
172173
}
173174

174175
void setZAxis(void* in) {
175176
Pedal* input = (Pedal*)in;
176-
G.setZAxis(input->axis);
177+
G27.setZAxis(input->axis);
177178
}
178179

179180
void pedalColor(void* inGas, void* inBrake, void* inClutch){
@@ -269,15 +270,15 @@ int getCurrentGear(int shifterPosition[], int btns[]) {
269270
void setButtonStates(int buttons[], int gear) {
270271
// release virtual buttons for all gears
271272
for (byte i = 0; i < 7; ++i) {
272-
G.setButton(i, LOW);
273+
G27.setButton(i, LOW);
273274
}
274275

275276
if (gear > 0) {
276-
G.setButton(gear - 1, HIGH);
277+
G27.setButton(gear - 1, HIGH);
277278
}
278279

279280
for (byte i = BUTTON_RED_CENTERRIGHT; i <= BUTTON_DPAD_TOP; ++i) {
280-
G.setButton(buttonTable[i], buttons[i]);
281+
G27.setButton(buttonTable[i], buttons[i]);
281282
}
282283
}
283284

@@ -338,7 +339,7 @@ void describeButtonStates(int buttons[], int shifterPosition[], int gear) {
338339
void setup() {
339340
Serial.begin(38400);
340341
#if !defined(DEBUG_PEDALS) && !defined(DEBUG_SHIFTER)
341-
G.begin(false);
342+
G27.begin(false);
342343
#endif
343344

344345
// lights
@@ -398,7 +399,7 @@ void loop() {
398399
describeButtonStates(buttonStates, shifterPosition, gear);
399400
#else
400401
setButtonStates(buttonStates, gear);
401-
G.sendState();
402+
G27.sendState();
402403
#endif
403404

404405
#if defined(DEBUG_PEDALS) || defined(DEBUG_SHIFTER)

G27PedalsShifter/G27PedalsShifter.cpp renamed to lib/G27PedalsShifter.cpp

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@
2424

2525
#if defined(_USING_HID)
2626

27-
#define G_REPORT_ID 0x03
28-
#define G_STATE_SIZE 10
27+
#define G27_REPORT_ID 0x03
28+
#define G27_STATE_SIZE 9
2929

3030
static const uint8_t _hidReportDescriptor[] PROGMEM = {
3131
// Joystick
3232
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
3333
0x09, 0x04, // USAGE (Joystick)
3434
0xa1, 0x01, // COLLECTION (Application)
35-
0x85, G_REPORT_ID, // REPORT_ID (3)
35+
0x85, G27_REPORT_ID, // REPORT_ID (3)
3636

37-
// 32 Buttons
37+
// 24 Buttons
3838
0x05, 0x09, // USAGE_PAGE (Button)
3939
0x19, 0x01, // USAGE_MINIMUM (Button 1)
40-
0x29, 0x20, // USAGE_MAXIMUM (Button 32)
40+
0x29, 0x18, // USAGE_MAXIMUM (Button 24)
4141
0x15, 0x00, // LOGICAL_MINIMUM (0)
4242
0x25, 0x01, // LOGICAL_MAXIMUM (1)
4343
0x75, 0x01, // REPORT_SIZE (1)
44-
0x95, 0x20, // REPORT_COUNT (32)
44+
0x95, 0x18, // REPORT_COUNT (24)
4545
0x55, 0x00, // UNIT_EXPONENT (0)
4646
0x65, 0x00, // UNIT (None)
4747
0x81, 0x02, // INPUT (Data,Var,Abs)
@@ -63,7 +63,7 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
6363
0xc0 // END_COLLECTION
6464
};
6565

66-
G_::G_()
66+
G27_::G27_()
6767
{
6868
// Setup HID report structure
6969
static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
@@ -76,17 +76,17 @@ G_::G_()
7676
buttons = 0;
7777
}
7878

79-
void G_::begin(bool initAutoSendState)
79+
void G27_::begin(bool initAutoSendState)
8080
{
8181
autoSendState = initAutoSendState;
8282
sendState();
8383
}
8484

85-
void G_::end()
85+
void G27_::end()
8686
{
8787
}
8888

89-
void G_::setButton(uint8_t button, uint8_t value)
89+
void G27_::setButton(uint8_t button, uint8_t value)
9090
{
9191
if (value == 0)
9292
{
@@ -97,67 +97,65 @@ void G_::setButton(uint8_t button, uint8_t value)
9797
pressButton(button);
9898
}
9999
}
100-
void G_::pressButton(uint8_t button)
100+
void G27_::pressButton(uint8_t button)
101101
{
102102
bitSet(buttons, button);
103103
if (autoSendState) sendState();
104104
}
105-
void G_::releaseButton(uint8_t button)
105+
void G27_::releaseButton(uint8_t button)
106106
{
107107
bitClear(buttons, button);
108108
if (autoSendState) sendState();
109109
}
110110

111-
void G_::setXAxis(uint16_t value)
111+
void G27_::setXAxis(uint16_t value)
112112
{
113113
xAxis = value;
114114
if (autoSendState) sendState();
115115
}
116-
void G_::setYAxis(uint16_t value)
116+
void G27_::setYAxis(uint16_t value)
117117
{
118118
yAxis = value;
119119
if (autoSendState) sendState();
120120
}
121-
void G_::setZAxis(uint16_t value)
121+
void G27_::setZAxis(uint16_t value)
122122
{
123123
zAxis = value;
124124
if (autoSendState) sendState();
125125
}
126126

127-
void G_::sendState()
127+
void G27_::sendState()
128128
{
129-
uint8_t data[G_STATE_SIZE];
129+
uint8_t data[G27_STATE_SIZE];
130130
uint32_t tmp = buttons;
131131

132-
// Split 32 bit button-state into 4 bytes
132+
// Split 24 bit button-state into 3 bytes
133133
data[0] = tmp & 0xFF;
134134
tmp >>= 8;
135135
data[1] = tmp & 0xFF;
136136
tmp >>= 8;
137137
data[2] = tmp & 0xFF;
138-
tmp >>= 8;
139-
data[3] = tmp & 0xFF;
140138

141139
// axis get 2 bytes each
142140
tmp = xAxis;
143-
data[4] = tmp & 0xFF;
141+
data[3] = tmp & 0xFF;
144142
tmp >>=8;
145-
data[5] = tmp & 0xFF;
143+
data[4] = tmp & 0xFF;
146144

147145
tmp = yAxis;
148-
data[6] = tmp & 0xFF;
146+
data[5] = tmp & 0xFF;
149147
tmp >>=8;
150-
data[7] = tmp & 0xFF;
148+
data[6] = tmp & 0xFF;
151149

152150
tmp = zAxis;
153-
data[8] = tmp & 0xFF;
151+
data[7] = tmp & 0xFF;
154152
tmp >>=8;
155-
data[9] = tmp & 0xFF;
153+
data[8] = tmp & 0xFF;
156154

157155
// HID().SendReport(Report number, array of values in same order as HID descriptor, length)
158-
HID().SendReport(G_REPORT_ID, data, G_STATE_SIZE);
156+
HID().SendReport(G27_REPORT_ID, data, G27_STATE_SIZE);
159157
}
160158

161-
G_ G;
159+
G27_ G27;
162160

163161
#endif

G27PedalsShifter/G27PedalsShifter.h renamed to lib/G27PedalsShifter.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
// (stolen from Matthew Heironimus @ https://github.com/MHeironimus/ArduinoJoystickLibrary)
2222

23-
#ifndef G_h
24-
#define G_h
23+
#ifndef G27_h
24+
#define G27_h
2525

2626
#include "HID.h"
2727

@@ -35,7 +35,7 @@
3535
//================================================================================
3636
// G27 (Gamepad)
3737

38-
class G_
38+
class G27_
3939
{
4040
private:
4141
bool autoSendState;
@@ -45,7 +45,7 @@ class G_
4545
uint32_t buttons;
4646

4747
public:
48-
G_();
48+
G27_();
4949

5050
void begin(bool initAutoSendState = true);
5151
void end();
@@ -60,7 +60,7 @@ class G_
6060

6161
void sendState();
6262
};
63-
extern G_ G;
63+
extern G27_ G27;
6464

6565
#endif
6666
#endif

0 commit comments

Comments
 (0)