Skip to content

Commit fde9cd2

Browse files
committed
Add header and reformat example
1 parent a297f4a commit fde9cd2

File tree

1 file changed

+69
-41
lines changed

1 file changed

+69
-41
lines changed
Lines changed: 69 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,80 @@
1+
/*******************************************************************************
2+
* This file is part of PsxNewLib. *
3+
* *
4+
* Copyright (C) 2019-2021 by SukkoPera <software@sukkology.net> *
5+
* *
6+
* PsxNewLib is free software: you can redistribute it and/or *
7+
* modify it under the terms of the GNU General Public License as published by *
8+
* the Free Software Foundation, either version 3 of the License, or *
9+
* (at your option) any later version. *
10+
* *
11+
* PsxNewLib is distributed in the hope that it will be useful, *
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14+
* GNU General Public License for more details. *
15+
* *
16+
* You should have received a copy of the GNU General Public License *
17+
* along with PsxNewLib. If not, see http://www.gnu.org/licenses. *
18+
*******************************************************************************
19+
*
20+
* This sketch was contributed by Kate (@katemonster33) and showcases Rumble
21+
* functionalities.
22+
*/
23+
124
#include <PsxControllerHwSpi.h>
225
#include <PsxNewLib.h>
326

4-
PsxControllerHwSpi<4> psxCtrl;
27+
PsxControllerHwSpi<10> psxCtrl;
528

629
boolean connected = false;
730
boolean axisConfigPossible = true;
831
boolean axisSticksEnabled = false;
932

10-
void setup() {
11-
psxCtrl.begin();
33+
void setup () {
34+
psxCtrl.begin ();
1235
}
1336

14-
void loop() {
15-
if(connected && axisConfigPossible && !axisSticksEnabled){
16-
Serial.println("Attempting to enable axis sticks & rumble!");
17-
psxCtrl.setRumble(false, 0x00);
18-
if(psxCtrl.enterConfigMode() && psxCtrl.enableAnalogSticks(true, true)){
19-
psxCtrl.enableRumble();
20-
psxCtrl.exitConfigMode();
21-
Serial.println("Axis sticks enabled! Rumble enabled!");
22-
axisSticksEnabled = true;
23-
}
24-
else{
25-
Serial.println("Failed to enable axis sticks!");
26-
axisConfigPossible = false; // don't retry
27-
}
28-
}
29-
// put your main code here, to run repeatedly:
30-
if(psxCtrl.read()) {
31-
if(!connected && Serial) Serial.println("Found controller!");
32-
connected = true;
33-
if(axisSticksEnabled) {
34-
if(psxCtrl.buttonChanged(PSB_CROSS)) {
35-
if(psxCtrl.buttonPressed(PSB_CROSS)) {
36-
Serial.println("Rumbling...");
37-
psxCtrl.setRumble(true, 0xFF);
38-
}
39-
else {
40-
Serial.println("Ending rumble.");
41-
psxCtrl.setRumble(false, 0x00);
42-
}
43-
}
44-
}
45-
}
46-
else {
47-
if(connected && Serial) Serial.println("Lost controller!");
48-
connected = false;
49-
axisSticksEnabled = false;
50-
axisConfigPossible = true;
51-
}
37+
void loop () {
38+
if (connected && axisConfigPossible && !axisSticksEnabled) {
39+
Serial.println ("Attempting to enable axis sticks & rumble!");
40+
psxCtrl.setRumble (false, 0x00);
41+
42+
if (psxCtrl.enterConfigMode() && psxCtrl.enableAnalogSticks (true, true)) {
43+
psxCtrl.enableRumble ();
44+
psxCtrl.exitConfigMode ();
45+
Serial.println ("Axis sticks enabled! Rumble enabled!");
46+
axisSticksEnabled = true;
47+
} else {
48+
Serial.println ("Failed to enable axis sticks!");
49+
axisConfigPossible = false; // don't retry
50+
}
51+
}
52+
53+
if (psxCtrl.read ()) {
54+
if (!connected && Serial) {
55+
Serial.println ("Found controller!");
56+
}
57+
58+
connected = true;
59+
60+
if (axisSticksEnabled) {
61+
if (psxCtrl.buttonChanged (PSB_CROSS)) {
62+
if (psxCtrl.buttonPressed (PSB_CROSS)) {
63+
Serial.println ("Rumbling...");
64+
psxCtrl.setRumble (true, 0xFF);
65+
} else {
66+
Serial.println ("Ending rumble.");
67+
psxCtrl.setRumble (false, 0x00);
68+
}
69+
}
70+
}
71+
} else {
72+
if (connected && Serial) {
73+
Serial.println ("Lost controller!");
74+
}
75+
76+
connected = false;
77+
axisSticksEnabled = false;
78+
axisConfigPossible = true;
79+
}
5280
}

0 commit comments

Comments
 (0)