|
@@ -12,45 +12,174 @@
|
12
|
12
|
|
13
|
13
|
#include "hid_parser.h"
|
14
|
14
|
|
|
15
|
+//#define DEBUG_OUTPUT_RAW
|
|
16
|
+#define DEBUG_OUTPUT
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+/*
|
|
20
|
+ * Uuuhhh TODO!!
|
|
21
|
+ * This is not a deadzone, this is something like sensitivity.
|
|
22
|
+ * For deadzone, we need to only apply it from the center outwards.
|
|
23
|
+ */
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+JoystickEvents::JoystickEvents()
|
|
27
|
+ : lastData(0), lastMouseX(0), lastMouseY(0), deadZone(0) {
|
|
28
|
+ deadZone.X = 0;
|
|
29
|
+ deadZone.Y = 0;
|
|
30
|
+ deadZone.Z = 0;
|
|
31
|
+ deadZone.Rx = 0;
|
|
32
|
+ deadZone.Ry = 0;
|
|
33
|
+ deadZone.Rz = 50;
|
|
34
|
+ deadZoneMouseX = 0;
|
|
35
|
+ deadZoneMouseY = 0;
|
|
36
|
+}
|
|
37
|
+
|
15
|
38
|
void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) {
|
|
39
|
+#ifdef DEBUG_OUTPUT_RAW
|
16
|
40
|
Serial.print("X: ");
|
17
|
41
|
PrintHex<uint16_t > (evt->X, 0x80);
|
18
|
|
- Serial.print("\tY: ");
|
|
42
|
+ Serial.print(" Y: ");
|
19
|
43
|
PrintHex<uint16_t > (evt->Y, 0x80);
|
20
|
|
- Serial.print("\tZ: ");
|
|
44
|
+ Serial.print(" Z: ");
|
21
|
45
|
PrintHex<uint8_t > (evt->Z, 0x80);
|
22
|
|
- Serial.print("\tRx: ");
|
|
46
|
+ Serial.print(" Rx: ");
|
23
|
47
|
PrintHex<uint8_t > (evt->Rx, 0x80);
|
24
|
|
- Serial.print("\tRy: ");
|
|
48
|
+ Serial.print(" Ry: ");
|
25
|
49
|
PrintHex<uint8_t > (evt->Ry, 0x80);
|
26
|
|
- Serial.print("\tRz: ");
|
|
50
|
+ Serial.print(" Rz: ");
|
27
|
51
|
PrintHex<uint16_t > (evt->Rz, 0x80);
|
28
|
|
- Serial.print("\tSlider: ");
|
|
52
|
+ Serial.print(" S: ");
|
29
|
53
|
PrintHex<uint8_t > (evt->Slider, 0x80);
|
30
|
54
|
Serial.println("");
|
|
55
|
+#endif
|
|
56
|
+
|
|
57
|
+ GamePadEventData newData = lastData;
|
|
58
|
+ uint8_t updated = 0;
|
|
59
|
+
|
|
60
|
+ if ((evt->X > (lastData.X + deadZone.X))
|
|
61
|
+ || (evt->X < (lastData.X - deadZone.X))) {
|
|
62
|
+ newData.X = evt->X;
|
|
63
|
+ updated = 1;
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ if ((evt->Y > (lastData.Y + deadZone.Y))
|
|
67
|
+ || (evt->Y < (lastData.Y - deadZone.Y))) {
|
|
68
|
+ newData.Y = evt->Y;
|
|
69
|
+ updated = 1;
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ if ((evt->Z > (lastData.Z + deadZone.Z))
|
|
73
|
+ || (evt->Z < (lastData.Z - deadZone.Z))) {
|
|
74
|
+ newData.Z = evt->Z;
|
|
75
|
+ updated = 1;
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ if ((evt->Rx > (lastData.Rx + deadZone.Rx))
|
|
79
|
+ || (evt->Rx < (lastData.Rx - deadZone.Rx))) {
|
|
80
|
+ newData.Rx = evt->Rx;
|
|
81
|
+ updated = 1;
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ if ((evt->Ry > (lastData.Ry + deadZone.Ry))
|
|
85
|
+ || (evt->Ry < (lastData.Ry - deadZone.Ry))) {
|
|
86
|
+ newData.Ry = evt->Ry;
|
|
87
|
+ updated = 1;
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ if ((evt->Rz > (lastData.Rz + deadZone.Rz))
|
|
91
|
+ || (evt->Rz < (lastData.Rz - deadZone.Rz))) {
|
|
92
|
+ newData.Rz = evt->Rz;
|
|
93
|
+ updated = 1;
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ if ((evt->Slider > (lastData.Slider + deadZone.Slider))
|
|
97
|
+ || (evt->Slider < (lastData.Slider - deadZone.Slider))) {
|
|
98
|
+ newData.Slider = evt->Slider;
|
|
99
|
+ updated = 1;
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ if (updated) {
|
|
103
|
+#ifdef DEBUG_OUTPUT
|
|
104
|
+ Serial.print("X: ");
|
|
105
|
+ PrintHex<uint16_t > (newData.X, 0x80);
|
|
106
|
+ Serial.print(" Y: ");
|
|
107
|
+ PrintHex<uint16_t > (newData.Y, 0x80);
|
|
108
|
+ Serial.print(" Z: ");
|
|
109
|
+ PrintHex<uint8_t > (newData.Z, 0x80);
|
|
110
|
+ Serial.print(" Rx: ");
|
|
111
|
+ PrintHex<uint8_t > (newData.Rx, 0x80);
|
|
112
|
+ Serial.print(" Ry: ");
|
|
113
|
+ PrintHex<uint8_t > (newData.Ry, 0x80);
|
|
114
|
+ Serial.print(" Rz: ");
|
|
115
|
+ PrintHex<uint16_t > (newData.Rz, 0x80);
|
|
116
|
+ Serial.print(" S: ");
|
|
117
|
+ PrintHex<uint8_t > (newData.Slider, 0x80);
|
|
118
|
+ Serial.println("");
|
|
119
|
+#endif
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+ lastData = *evt;
|
31
|
123
|
}
|
32
|
124
|
|
33
|
125
|
void JoystickEvents::OnHatSwitch(uint8_t hat) {
|
|
126
|
+#ifdef DEBUG_OUTPUT
|
34
|
127
|
Serial.print("Hat Switch: ");
|
35
|
128
|
PrintHex<uint8_t > (hat, 0x80);
|
36
|
129
|
Serial.println("");
|
|
130
|
+#endif
|
37
|
131
|
}
|
38
|
132
|
|
39
|
133
|
void JoystickEvents::OnButtonUp(uint8_t but_id) {
|
|
134
|
+#ifdef DEBUG_OUTPUT
|
40
|
135
|
Serial.print("Up: ");
|
41
|
136
|
Serial.println(but_id, DEC);
|
|
137
|
+#endif
|
42
|
138
|
}
|
43
|
139
|
|
44
|
140
|
void JoystickEvents::OnButtonDn(uint8_t but_id) {
|
45
|
|
- Serial.print("Dn: ");
|
|
141
|
+#ifdef DEBUG_OUTPUT
|
|
142
|
+ Serial.print("Down: ");
|
46
|
143
|
Serial.println(but_id, DEC);
|
|
144
|
+#endif
|
47
|
145
|
}
|
48
|
146
|
|
49
|
147
|
void JoystickEvents::OnMouseMoved(uint8_t x, uint8_t y) {
|
|
148
|
+#ifdef DEBUG_OUTPUT_RAW
|
50
|
149
|
Serial.print("Mouse X: ");
|
51
|
150
|
PrintHex<uint8_t >(x, 0x80);
|
52
|
151
|
Serial.print("\tY: ");
|
53
|
152
|
PrintHex<uint8_t >(y, 0x80);
|
54
|
153
|
Serial.println("");
|
|
154
|
+#endif
|
|
155
|
+
|
|
156
|
+ uint8_t newX = lastMouseX;
|
|
157
|
+ uint8_t newY = lastMouseY;
|
|
158
|
+ uint8_t updated = 0;
|
|
159
|
+
|
|
160
|
+ if ((x > (lastMouseX + deadZoneMouseX))
|
|
161
|
+ || (x < (lastMouseX - deadZoneMouseX))) {
|
|
162
|
+ newX = x;
|
|
163
|
+ updated = 1;
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ if ((y > (lastMouseY + deadZoneMouseY))
|
|
167
|
+ || (y < (lastMouseY - deadZoneMouseY))) {
|
|
168
|
+ newY = y;
|
|
169
|
+ updated = 1;
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+ if (updated) {
|
|
173
|
+#ifdef DEBUG_OUTPUT
|
|
174
|
+ Serial.print("Mouse X: ");
|
|
175
|
+ PrintHex<uint8_t >(newX, 0x80);
|
|
176
|
+ Serial.print("\tY: ");
|
|
177
|
+ PrintHex<uint8_t >(newY, 0x80);
|
|
178
|
+ Serial.println("");
|
|
179
|
+#endif
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ lastMouseX = x;
|
|
183
|
+ lastMouseY = y;
|
55
|
184
|
}
|
56
|
185
|
|