1
- using System ;
2
- using System . IO ;
1
+ using HAL . Base ;
2
+ using System ;
3
+ using System . Runtime . CompilerServices ;
3
4
using System . Threading ;
4
- using HAL . Base ;
5
- using static WPILib . Timer ;
6
5
using static HAL . Base . HAL ;
7
6
using static HAL . Base . HAL . DriverStationConstants ;
8
- using static WPILib . Utility ;
9
7
using static HAL . Base . HALDriverStation ;
8
+ using static WPILib . Timer ;
9
+ using static WPILib . Utility ;
10
10
using HALPower = HAL . Base . HALPower ;
11
- using System . Runtime . CompilerServices ;
12
- using System . Text ;
13
11
14
12
namespace WPILib
15
13
{
@@ -239,7 +237,7 @@ protected void GetData()
239
237
UpdateControlWord ( true , out controlWord ) ;
240
238
241
239
lock ( m_joystickDataMutex )
242
- {
240
+ {
243
241
244
242
HALJoystickAxes [ ] currentAxes = m_joystickAxes ;
245
243
m_joystickAxes = m_joystickAxesCache ;
@@ -369,17 +367,8 @@ public int GetStickAxisCount(int stick)
369
367
$ "Joystick index is out of range, should be 0-{ JoystickPorts } ") ;
370
368
}
371
369
372
- bool lockEntered = false ;
373
- try
374
- {
375
- Monitor . Enter ( m_joystickDataMutex , ref lockEntered ) ;
370
+ lock ( m_joystickDataMutex )
376
371
return m_joystickAxes [ stick ] . count ;
377
- }
378
- finally
379
- {
380
- if ( lockEntered ) Monitor . Exit ( m_joystickDataMutex ) ;
381
- }
382
-
383
372
}
384
373
385
374
/// <summary>
@@ -441,17 +430,9 @@ public int GetStickPOVCount(int stick)
441
430
throw new ArgumentOutOfRangeException ( nameof ( stick ) ,
442
431
$ "Joystick Index is out of range, should be 0-{ JoystickPorts } ") ;
443
432
}
444
- bool lockEntered = false ;
445
- try
446
- {
447
- Monitor . Enter ( m_joystickDataMutex , ref lockEntered ) ;
448
433
434
+ lock ( m_joystickDataMutex )
449
435
return m_joystickPOVs [ stick ] . count ;
450
- }
451
- finally
452
- {
453
- if ( lockEntered ) Monitor . Exit ( m_joystickDataMutex ) ;
454
- }
455
436
456
437
}
457
438
@@ -464,23 +445,14 @@ public int GetStickPOVCount(int stick)
464
445
/// Thrown if the stick is out of range.</exception>
465
446
public int GetStickButtons ( int stick )
466
447
{
467
-
468
448
if ( stick < 0 || stick >= JoystickPorts )
469
449
{
470
450
throw new ArgumentOutOfRangeException ( nameof ( stick ) ,
471
451
$ "Joystick Index is out of range, should be 0-{ JoystickPorts } ") ;
472
452
}
473
- bool lockEntered = false ;
474
- try
475
- {
476
- Monitor . Enter ( m_joystickDataMutex , ref lockEntered ) ;
477
- return ( int ) m_joystickButtons [ stick ] . buttons ;
478
- }
479
- finally
480
- {
481
- if ( lockEntered ) Monitor . Exit ( m_joystickDataMutex ) ;
482
- }
483
453
454
+ lock ( m_joystickDataMutex )
455
+ return ( int ) m_joystickButtons [ stick ] . buttons ;
484
456
}
485
457
486
458
/// <summary>
@@ -536,22 +508,14 @@ public bool GetStickButton(int stick, int button)
536
508
/// Thrown if the stick is out of range.</exception>
537
509
public int GetStickButtonCount ( int stick )
538
510
{
539
-
540
511
if ( stick < 0 || stick >= JoystickPorts )
541
512
{
542
513
throw new ArgumentOutOfRangeException ( nameof ( stick ) ,
543
514
$ "Joystick Index is out of range, should be 0-{ JoystickPorts } ") ;
544
515
}
545
- bool lockEntered = false ;
546
- try
547
- {
548
- Monitor . Enter ( m_joystickDataMutex , ref lockEntered ) ;
516
+
517
+ lock ( m_joystickDataMutex )
549
518
return m_joystickButtons [ stick ] . count ;
550
- }
551
- finally
552
- {
553
- if ( lockEntered ) Monitor . Exit ( m_joystickDataMutex ) ;
554
- }
555
519
}
556
520
557
521
/// <summary>
@@ -568,16 +532,8 @@ public bool GetJoystickIsXbox(int stick)
568
532
throw new ArgumentOutOfRangeException ( nameof ( stick ) ,
569
533
$ "Joystick Index is out of range, should be 0-{ JoystickPorts } ") ;
570
534
}
571
- bool lockEntered = false ;
572
- try
573
- {
574
- Monitor . Enter ( m_joystickDataMutex , ref lockEntered ) ;
535
+ lock ( m_joystickDataMutex )
575
536
return m_joystickDescriptors [ stick ] . isXbox != 0 ;
576
- }
577
- finally
578
- {
579
- if ( lockEntered ) Monitor . Exit ( m_joystickDataMutex ) ;
580
- }
581
537
582
538
}
583
539
@@ -595,16 +551,8 @@ public int GetJoystickType(int stick)
595
551
throw new ArgumentOutOfRangeException ( nameof ( stick ) ,
596
552
$ "Joystick Index is out of range, should be 0-{ JoystickPorts } ") ;
597
553
}
598
- bool lockEntered = false ;
599
- try
600
- {
601
- Monitor . Enter ( m_joystickDataMutex , ref lockEntered ) ;
554
+ lock ( m_joystickDataMutex )
602
555
return m_joystickDescriptors [ stick ] . type ;
603
- }
604
- finally
605
- {
606
- if ( lockEntered ) Monitor . Exit ( m_joystickDataMutex ) ;
607
- }
608
556
}
609
557
610
558
/// <summary>
@@ -622,16 +570,8 @@ public string GetJoystickName(int stick)
622
570
$ "Joystick Index is out of range, should be 0-{ JoystickPorts } ") ;
623
571
}
624
572
625
- bool lockEntered = false ;
626
- try
627
- {
628
- Monitor . Enter ( m_joystickDataMutex , ref lockEntered ) ;
573
+ lock ( m_joystickDataMutex )
629
574
return m_joystickDescriptors [ stick ] . name . ToString ( ) ;
630
- }
631
- finally
632
- {
633
- if ( lockEntered ) Monitor . Exit ( m_joystickDataMutex ) ;
634
- }
635
575
}
636
576
637
577
/// <summary>
@@ -856,7 +796,7 @@ public bool FMSAttached
856
796
/// <summary>
857
797
/// Gets if the DS is attached.
858
798
/// </summary>
859
- public bool DSAtached
799
+ public bool DSAttached
860
800
{
861
801
get
862
802
{
@@ -865,6 +805,11 @@ public bool DSAtached
865
805
return word . GetDSAttached ( ) ;
866
806
}
867
807
}
808
+ /// <summary>
809
+ /// Gets if the DS is attached.
810
+ /// </summary>
811
+ [ Obsolete ( "DSAtached is deprecated, use DSAttached instead." ) ]
812
+ public bool DSAtached => DSAttached ;
868
813
869
814
private void UpdateControlWord ( bool force , out HALControlWord controlWord )
870
815
{
0 commit comments