6
6
class Toggle :
7
7
"""Utility class for joystick button toggle
8
8
9
- Usage::
9
+ Usage::
10
10
11
- foo = Toggle(joystick, 3)
11
+ foo = Toggle(joystick, 3)
12
12
13
- if foo:
14
- toggleFunction()
13
+ if foo:
14
+ toggleFunction()
15
15
16
- if foo.on:
17
- onToggle()
16
+ if foo.on:
17
+ onToggle()
18
18
19
- if foo.off:
20
- offToggle()
19
+ if foo.off:
20
+ offToggle()
21
21
"""
22
22
class _SteadyDebounce :
23
23
"""
@@ -29,7 +29,7 @@ class _SteadyDebounce:
29
29
used with Toggle
30
30
"""
31
31
32
- def __init__ (self , joystick , button , period = 0.5 ):
32
+ def __init__ (self , joystick : wpilib . Joystick , button : int , period : float ):
33
33
"""
34
34
:param joystick: Joystick object
35
35
:type joystick: :class:`wpilib.Joystick`
@@ -46,10 +46,6 @@ def __init__(self, joystick, button, period=0.5):
46
46
self .latest = - self .debounce_period # Negative latest prevents get from returning true until joystick is presed for the first time
47
47
self .enabled = False
48
48
49
- def set_debounce_period (self , period ):
50
- """Set number of seconds to hold return value"""
51
- self .debounce_period = float (period )
52
-
53
49
def get (self ):
54
50
"""
55
51
:returns: The value of the joystick button. Once the button is pressed,
@@ -66,18 +62,18 @@ def get(self):
66
62
else :
67
63
return False
68
64
69
- def __init__ (self , joystick : wpilib .Joystick , button : int , debounce_period = None ):
65
+ def __init__ (self , joystick : wpilib .Joystick , button : int , debounce_period : float = None ):
70
66
"""
71
67
:param joystick: :class:`wpilib.Joystick` that contains the button to toggle
72
68
:param button: Number of button that will act as toggle. Same value used in `getRawButton()`
73
- :param debounce_period: Period to wait before registering a new button press.
69
+ :param debounce_period: Period in seconds to wait before registering a new button press.
74
70
"""
75
71
76
72
if debounce_period is not None :
77
- self .joystick = Toggle ._SteadyDebounce (joystick , button , debounce_period )
73
+ self .joystickget = Toggle ._SteadyDebounce (joystick , button , debounce_period ). get
78
74
else :
79
75
self .joystick = joystick
80
- self .joystick . get = partial (self .joystick .getRawButton , button )
76
+ self .joystickget = partial (self .joystick .getRawButton , button )
81
77
82
78
self .released = False
83
79
self .toggle = False
@@ -88,7 +84,7 @@ def get(self):
88
84
:return: State of toggle
89
85
:rtype: bool
90
86
"""
91
- current_state = self .joystick . get ()
87
+ current_state = self .joystickget ()
92
88
93
89
if current_state and not self .released :
94
90
self .released = True
0 commit comments