@@ -39,17 +39,22 @@ public enum Alliance
39
39
} ;
40
40
41
41
//Private Fields
42
- private readonly HALJoystickAxes [ ] m_joystickAxes = new HALJoystickAxes [ JoystickPorts ] ;
43
- private readonly HALJoystickPOVs [ ] m_joystickPOVs = new HALJoystickPOVs [ JoystickPorts ] ;
44
- private readonly HALJoystickButtons [ ] m_joystickButtons = new HALJoystickButtons [ JoystickPorts ] ;
45
- private readonly HALJoystickDescriptor [ ] m_joystickDescriptors = new HALJoystickDescriptor [ JoystickPorts ] ;
42
+ private HALJoystickAxes [ ] m_joystickAxes = new HALJoystickAxes [ JoystickPorts ] ;
43
+ private HALJoystickPOVs [ ] m_joystickPOVs = new HALJoystickPOVs [ JoystickPorts ] ;
44
+ private HALJoystickButtons [ ] m_joystickButtons = new HALJoystickButtons [ JoystickPorts ] ;
45
+ private HALJoystickDescriptor [ ] m_joystickDescriptors = new HALJoystickDescriptor [ JoystickPorts ] ;
46
+
47
+ private HALJoystickAxes [ ] m_joystickAxesCache = new HALJoystickAxes [ JoystickPorts ] ;
48
+ private HALJoystickPOVs [ ] m_joystickPOVsCache = new HALJoystickPOVs [ JoystickPorts ] ;
49
+ private HALJoystickButtons [ ] m_joystickButtonsCache = new HALJoystickButtons [ JoystickPorts ] ;
50
+ private HALJoystickDescriptor [ ] m_joystickDescriptorsCache = new HALJoystickDescriptor [ JoystickPorts ] ;
46
51
47
52
//Pointers to the semaphores to the HAL and FPGA
48
53
private readonly object m_dataSem ;
49
54
50
55
private readonly IntPtr m_packetDataAvailableMutex ;
51
56
private readonly IntPtr m_packetDataAvailableSem ;
52
-
57
+
53
58
//New Control Data Fast Semaphore Lock
54
59
private readonly object m_newControlDataLock = new object ( ) ;
55
60
private bool m_newControlData = false ;
@@ -94,6 +99,14 @@ protected DriverStation()
94
99
m_joystickDescriptors [ i ] . isXbox = 0 ;
95
100
m_joystickDescriptors [ i ] . type = 0xFF ;
96
101
m_joystickDescriptors [ i ] . name . byte0 = 0 ;
102
+
103
+ m_joystickButtonsCache [ i ] . count = 0 ;
104
+ m_joystickAxesCache [ i ] . count = 0 ;
105
+ m_joystickPOVsCache [ i ] . count = 0 ;
106
+ m_joystickDescriptorsCache [ i ] = new HALJoystickDescriptor ( ) ;
107
+ m_joystickDescriptorsCache [ i ] . isXbox = 0 ;
108
+ m_joystickDescriptorsCache [ i ] . type = 0xFF ;
109
+ m_joystickDescriptorsCache [ i ] . name . byte0 = 0 ;
97
110
}
98
111
99
112
m_readWriteLock = new ReaderWriterLockSlim ( LockRecursionPolicy . SupportsRecursion ) ;
@@ -185,17 +198,34 @@ public void WaitForData(int timeout = Timeout.Infinite)
185
198
/// </summary>
186
199
protected void GetData ( )
187
200
{
201
+ for ( byte stick = 0 ; stick < JoystickPorts ; stick ++ )
202
+ {
203
+ HALGetJoystickAxes ( stick , ref m_joystickAxesCache [ stick ] ) ;
204
+ HALGetJoystickPOVs ( stick , ref m_joystickPOVsCache [ stick ] ) ;
205
+ HALGetJoystickButtons ( stick , ref m_joystickButtonsCache [ stick ] ) ;
206
+ HALGetJoystickDescriptor ( stick , ref m_joystickDescriptorsCache [ stick ] ) ;
207
+ }
188
208
bool lockEntered = false ;
189
209
try
190
210
{
191
211
m_readWriteLock . EnterWriteLock ( ) ;
192
212
lockEntered = true ;
193
- for ( byte stick = 0 ; stick < JoystickPorts ; stick ++ )
194
- {
195
- HALGetJoystickAxes ( stick , ref m_joystickAxes [ stick ] ) ;
196
- HALGetJoystickPOVs ( stick , ref m_joystickPOVs [ stick ] ) ;
197
- HALGetJoystickButtons ( stick , ref m_joystickButtons [ stick ] ) ;
198
- HALGetJoystickDescriptor ( stick , ref m_joystickDescriptors [ stick ] ) ; }
213
+
214
+ HALJoystickAxes [ ] currentAxes = m_joystickAxes ;
215
+ m_joystickAxes = m_joystickAxesCache ;
216
+ m_joystickAxesCache = currentAxes ;
217
+
218
+ HALJoystickButtons [ ] currentButtons = m_joystickButtons ;
219
+ m_joystickButtons = m_joystickButtonsCache ;
220
+ m_joystickButtonsCache = currentButtons ;
221
+
222
+ HALJoystickPOVs [ ] currentPOVs = m_joystickPOVs ;
223
+ m_joystickPOVs = m_joystickPOVsCache ;
224
+ m_joystickPOVsCache = currentPOVs ;
225
+
226
+ HALJoystickDescriptor [ ] currentDescriptor = m_joystickDescriptors ;
227
+ m_joystickDescriptors = m_joystickDescriptorsCache ;
228
+ m_joystickDescriptorsCache = currentDescriptor ;
199
229
}
200
230
finally
201
231
{
0 commit comments