-
Notifications
You must be signed in to change notification settings - Fork 0
/
PS3Update.h
160 lines (143 loc) · 3.96 KB
/
PS3Update.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <PS3BT.h>
#include <usbhub.h>
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
USB usb;
BTD btd(&usb);
PS3BT PS3(&btd, 0x00, 0x1A, 0x7D, 0xDA, 0x71, 0x13); // new
class PS3Comm {
public:
//digital buttons
bool up;
bool down;
bool left;
bool right;
bool L1;
bool L3;
bool R1;
bool R3;
bool square;
bool circle;
bool cross;
bool tri;
bool start;
bool select;
bool ps;
//analog buttons
uint8_t L2 = -1;
uint8_t R2 = -1;
uint8_t LeftHatX = -1;
uint8_t LeftHatY = -1;
uint8_t RightHatX = -1;
uint8_t RightHatY = -1;
};
PS3Comm ps3;
void resetAnalog () {
ps3.L2 = -1;
ps3.R2 = -1;
ps3.LeftHatX = -1;
ps3.LeftHatY = -1;
ps3.RightHatX = -1;
ps3.RightHatY = -1;
}
void PS3Setup () {
#if !defined(_MIPSEL_)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (usb.Init() == -1) {
Serial.println("OSC did not found");
while (1); //halt
}
Serial.println("PS3 bluetooth library started");
while (!PS3.PS3Connected) {
Serial.print("\nPS3 connection status: ");
Serial.print(PS3.PS3Connected);
Serial.print('\n');
usb.Task();
}
}
void getPS3Data () {
usb.Task();
//digital buttons
ps3.up = PS3.getButtonPress(UP);
ps3.right = PS3.getButtonPress(RIGHT);
ps3.down = PS3.getButtonPress(DOWN);
ps3.left = PS3.getButtonPress(LEFT);
ps3.select = PS3.getButtonPress(SELECT);
ps3.L3 = PS3.getButtonPress(L3);
ps3.R3 = PS3.getButtonPress(R3);
ps3.start = PS3.getButtonPress(START);
ps3.L1 = PS3.getButtonPress(L1);
ps3.R1 = PS3.getButtonPress(R1);
ps3.tri = PS3.getButtonPress(TRIANGLE);
ps3.circle = PS3.getButtonPress(CIRCLE);
ps3.cross = PS3.getButtonPress(CROSS);
ps3.square = PS3.getButtonPress(SQUARE);
ps3.ps = PS3.getButtonClick(PS);
//analog buttons
ps3.LeftHatX = PS3.getAnalogHat(LeftHatX);
ps3.LeftHatY = PS3.getAnalogHat(LeftHatY);
ps3.RightHatX = PS3.getAnalogHat(RightHatX);
ps3.RightHatY = PS3.getAnalogHat(RightHatY);
ps3.L2 = PS3.getAnalogButton(L2);
ps3.R2 = PS3.getAnalogButton(R2);
}
void printKey (char * str) {
Serial.print("pressed button: ");
Serial.print(str);
Serial.println();
}
void printAnalogPress (char * str, int8_t value) {
Serial.print(str);
Serial.print(value);
if (str == "PS3.L2: " || str == "PS3.R2: ") {
Serial.print("\n");
} else {
Serial.print("\t");
}
}
void printPressedKey (PS3Comm & ps3) {
if (ps3.up == true) {
printKey("UP");
} else if (ps3.down == true) {
printKey("DOWN");
} else if (ps3.left == true) {
printKey("LEFT");
} else if (ps3.right == true) {
printKey("RIGHT");
} else if (ps3.tri == true) {
printKey("TRIANGLE");
} else if (ps3.circle == true) {
printKey("CIRCLE");
} else if (ps3.square == true) {
printKey("SQUARE");
} else if (ps3.cross == true) {
printKey("CROSS");
} else if (ps3.select == true) {
printKey("SELECT");
} else if (ps3.start == true) {
printKey("START");
} else if (ps3.L1 == true) {
printKey("L1");
} else if (ps3.R1 == true) {
printKey("R1");
} else if (ps3.L3 == true) {
printKey("L3");
} else if (ps3.R3 == true) {
printKey("R3");
} else if (ps3.ps == true) {
printKey("PS");
} else if (ps3.L2) {
printAnalogPress("PS3.L2: ", ps3.L2);
} if (ps3.R2) {
printAnalogPress("PS3.R2: ", ps3.R2);
}
// Navigation joystick
printAnalogPress("LeftHatX: ", PS3.getAnalogHat(LeftHatX));
printAnalogPress("LeftHatY: ", PS3.getAnalogHat(LeftHatY));
printAnalogPress("RightHatX: ", PS3.getAnalogHat(RightHatX));
printAnalogPress("RightHatY: ", PS3.getAnalogHat(RightHatY));
Serial.print("\n");
}