Skip to content

Commit 2b69cfe

Browse files
committed
Fixed indentation in PS4Parser.cpp
1 parent 6373ebe commit 2b69cfe

File tree

1 file changed

+67
-67
lines changed

1 file changed

+67
-67
lines changed

PS4Parser.cpp

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -36,89 +36,89 @@ bool PS4Parser::checkDpad(ButtonEnum b) {
3636
}
3737

3838
bool PS4Parser::getButtonPress(ButtonEnum b) {
39-
if (b <= LEFT) // Dpad
40-
return checkDpad(b);
41-
else {
42-
uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
43-
uint8_t index = button < 8 ? 0 : button < 16 ? 1 : 2;
44-
uint8_t mask = 1 << (button - 8 * index);
45-
return ps4Data.btn.val[index] & mask;
46-
}
39+
if (b <= LEFT) // Dpad
40+
return checkDpad(b);
41+
else {
42+
uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
43+
uint8_t index = button < 8 ? 0 : button < 16 ? 1 : 2;
44+
uint8_t mask = 1 << (button - 8 * index);
45+
return ps4Data.btn.val[index] & mask;
46+
}
4747
}
4848

4949
bool PS4Parser::getButtonClick(ButtonEnum b) {
50-
uint8_t mask, index = 0;
51-
if (b <= LEFT) // Dpad
52-
mask = 1 << b;
53-
else {
54-
uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
55-
index = button < 8 ? 0 : button < 16 ? 1 : 2;
56-
mask = 1 << (button - 8 * index);
57-
}
58-
59-
bool click = buttonClickState.val[index] & mask;
60-
buttonClickState.val[index] &= ~mask; // Clear "click" event
61-
return click;
50+
uint8_t mask, index = 0;
51+
if (b <= LEFT) // Dpad
52+
mask = 1 << b;
53+
else {
54+
uint8_t button = pgm_read_byte(&PS4_BUTTONS[(uint8_t)b]);
55+
index = button < 8 ? 0 : button < 16 ? 1 : 2;
56+
mask = 1 << (button - 8 * index);
57+
}
58+
59+
bool click = buttonClickState.val[index] & mask;
60+
buttonClickState.val[index] &= ~mask; // Clear "click" event
61+
return click;
6262
}
6363

6464
uint8_t PS4Parser::getAnalogButton(ButtonEnum b) {
65-
if (b == L2) // These are the only analog buttons on the controller
66-
return ps4Data.trigger[0];
67-
else if (b == R2)
68-
return ps4Data.trigger[1];
69-
return 0;
65+
if (b == L2) // These are the only analog buttons on the controller
66+
return ps4Data.trigger[0];
67+
else if (b == R2)
68+
return ps4Data.trigger[1];
69+
return 0;
7070
}
7171

7272
uint8_t PS4Parser::getAnalogHat(AnalogHatEnum a) {
73-
return ps4Data.hatValue[(uint8_t)a];
73+
return ps4Data.hatValue[(uint8_t)a];
7474
}
7575

7676
void PS4Parser::Parse(uint8_t len, uint8_t *buf) {
77-
if (len > 0 && buf) {
77+
if (len > 0 && buf) {
7878
#ifdef PRINTREPORT
79-
Notify(PSTR("\r\n"), 0x80);
80-
for (uint8_t i = 0; i < len; i++) {
81-
D_PrintHex<uint8_t > (buf[i], 0x80);
82-
Notify(PSTR(" "), 0x80);
83-
}
79+
Notify(PSTR("\r\n"), 0x80);
80+
for (uint8_t i = 0; i < len; i++) {
81+
D_PrintHex<uint8_t > (buf[i], 0x80);
82+
Notify(PSTR(" "), 0x80);
83+
}
8484
#endif
8585

8686

87-
if (buf[0] == 0x01) // Check report ID
88-
memcpy(&ps4Data, buf + 1, min(len - 1, sizeof(ps4Data)));
89-
else if (buf[0] == 0x11) // This report is send via Bluetooth, it has an offset of 2 compared to the USB data
90-
memcpy(&ps4Data, buf + 3, min(len - 3, sizeof(ps4Data)));
91-
else {
87+
if (buf[0] == 0x01) // Check report ID
88+
memcpy(&ps4Data, buf + 1, min(len - 1, sizeof(ps4Data)));
89+
else if (buf[0] == 0x11) // This report is send via Bluetooth, it has an offset of 2 compared to the USB data
90+
memcpy(&ps4Data, buf + 3, min(len - 3, sizeof(ps4Data)));
91+
else {
9292
#ifdef DEBUG_USB_HOST
93-
Notify(PSTR("\r\nUnknown report id: "), 0x80);
94-
D_PrintHex<uint8_t > (buf[0], 0x80);
93+
Notify(PSTR("\r\nUnknown report id: "), 0x80);
94+
D_PrintHex<uint8_t > (buf[0], 0x80);
9595
#endif
96-
return;
97-
}
98-
99-
for (uint8_t i = 0; i < sizeof(ps4Data.btn); i++) {
100-
if (ps4Data.btn.val[i] != oldButtonState.val[i]) { // Check if anything has changed
101-
buttonClickState.val[i] = ps4Data.btn.val[i] & ~oldButtonState.val[i]; // Update click state variable
102-
oldButtonState.val[i] = ps4Data.btn.val[i];
103-
if (i == 0) { // The DPAD buttons does not set the different bits, but set a value corresponding to the buttons pressed, we will simply set the bits ourself
104-
uint8_t newDpad = 0;
105-
if (checkDpad(UP))
106-
newDpad |= 1 << UP;
107-
if (checkDpad(RIGHT))
108-
newDpad |= 1 << RIGHT;
109-
if (checkDpad(DOWN))
110-
newDpad |= 1 << DOWN;
111-
if (checkDpad(LEFT))
112-
newDpad |= 1 << LEFT;
113-
if (newDpad != oldDpad) {
114-
buttonClickState.dpad = newDpad & ~oldDpad; // Override values
115-
oldDpad = newDpad;
116-
}
117-
}
118-
}
119-
}
120-
}
121-
122-
if (ps4Output.reportChanged)
123-
sendOutputReport(&ps4Output); // Send output report
96+
return;
97+
}
98+
99+
for (uint8_t i = 0; i < sizeof(ps4Data.btn); i++) {
100+
if (ps4Data.btn.val[i] != oldButtonState.val[i]) { // Check if anything has changed
101+
buttonClickState.val[i] = ps4Data.btn.val[i] & ~oldButtonState.val[i]; // Update click state variable
102+
oldButtonState.val[i] = ps4Data.btn.val[i];
103+
if (i == 0) { // The DPAD buttons does not set the different bits, but set a value corresponding to the buttons pressed, we will simply set the bits ourself
104+
uint8_t newDpad = 0;
105+
if (checkDpad(UP))
106+
newDpad |= 1 << UP;
107+
if (checkDpad(RIGHT))
108+
newDpad |= 1 << RIGHT;
109+
if (checkDpad(DOWN))
110+
newDpad |= 1 << DOWN;
111+
if (checkDpad(LEFT))
112+
newDpad |= 1 << LEFT;
113+
if (newDpad != oldDpad) {
114+
buttonClickState.dpad = newDpad & ~oldDpad; // Override values
115+
oldDpad = newDpad;
116+
}
117+
}
118+
}
119+
}
120+
}
121+
122+
if (ps4Output.reportChanged)
123+
sendOutputReport(&ps4Output); // Send output report
124124
}

0 commit comments

Comments
 (0)