Skip to content

Commit 079b108

Browse files
committed
pybricks.parameters: Add Xbox buttons.
1 parent e3b2e6e commit 079b108

File tree

4 files changed

+102
-21
lines changed

4 files changed

+102
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
## Unreleased
66

7+
## Changed
8+
9+
- Updates for v3.4.0b3 firmware.
10+
711
## 3.4.0b4 - 2024-02-14
812

913
## Added

doc/main/iodevices/xboxcontroller.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ Xbox Controller
1717

1818
Buttons include:
1919

20-
* ``"A"``, ``"B"``, ``"X"``, ``"Y"``.
21-
* ``"LB"`` and ``"RB"`` (bumpers).
22-
* ``"LJ"`` and ``"RJ"`` (pressing the joysticks).
23-
* ``"VIEW"``, ``"MENU"``, ``"GUIDE"`` (the Xbox logo), and ``"UPLOAD"``.
24-
* ``"P1"``, ``"P2"``, ``"P3"``, and ``"P4"`` (Elite Series 2 only).
20+
* ``Button.A``, ``Button.B``, ``Button.X``, ``Button.Y``.
21+
* ``Button.LB`` and ``Button.RB`` (bumpers).
22+
* ``Button.LJ`` and ``Button.RJ`` (pressing the joysticks).
23+
* ``Button.VIEW``, ``Button.MENU``, ``Button.GUIDE`` (the Xbox logo), and ``Button.UPLOAD``.
24+
* ``Button.P1``, ``Button.P2``, ``Button.P3``, and ``Button.P4`` (Elite Series 2 only).
2525
Pressing the paddles may also be detected as other button presses,
2626
depending on the currently active profile.
2727

doc/main/parameters/button.rst

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,108 @@ Button
55

66
.. class:: Button
77

8-
Buttons on a hub or remote.
9-
10-
.. autoattribute:: pybricks.parameters.Button.LEFT_DOWN
11-
:annotation:
8+
.. rubric:: Remote and hub buttons
129

1310
.. autoattribute:: pybricks.parameters.Button.LEFT_MINUS
1411
:annotation:
1512

16-
.. autoattribute:: pybricks.parameters.Button.DOWN
17-
:annotation:
13+
Powered Up Remote only.
1814

19-
.. autoattribute:: pybricks.parameters.Button.RIGHT_DOWN
15+
.. autoattribute:: pybricks.parameters.Button.LEFT_PLUS
2016
:annotation:
2117

18+
Powered Up Remote only.
19+
2220
.. autoattribute:: pybricks.parameters.Button.RIGHT_MINUS
2321
:annotation:
2422

25-
.. autoattribute:: pybricks.parameters.Button.LEFT
23+
Powered Up Remote only.
24+
25+
.. autoattribute:: pybricks.parameters.Button.RIGHT_PLUS
2626
:annotation:
2727

28+
Powered Up Remote only.
29+
2830
.. autoattribute:: pybricks.parameters.Button.CENTER
2931
:annotation:
3032

33+
Powered Up Remote (green button) or hub power button.
34+
35+
.. autoattribute:: pybricks.parameters.Button.LEFT
36+
:annotation:
37+
38+
Powered Up Remote (left red button) and Prime/Inventor Hub (left button).
39+
3140
.. autoattribute:: pybricks.parameters.Button.RIGHT
3241
:annotation:
3342

34-
.. autoattribute:: pybricks.parameters.Button.LEFT_UP
43+
Powered Up Remote (right red button) and Prime/Inventor Hub (right button).
44+
45+
.. autoattribute:: pybricks.parameters.Button.BLUETOOTH
3546
:annotation:
3647

37-
.. autoattribute:: pybricks.parameters.Button.LEFT_PLUS
48+
Prime/Inventor Hub button with Bluetooth icon.
49+
50+
.. rubric:: Xbox controller buttons
51+
52+
.. autoattribute:: pybricks.parameters.Button.A
3853
:annotation:
3954

40-
.. autoattribute:: pybricks.parameters.Button.UP
55+
.. autoattribute:: pybricks.parameters.Button.B
4156
:annotation:
4257

43-
.. autoattribute:: pybricks.parameters.Button.BEACON
58+
.. autoattribute:: pybricks.parameters.Button.X
4459
:annotation:
4560

46-
.. autoattribute:: pybricks.parameters.Button.RIGHT_UP
61+
.. autoattribute:: pybricks.parameters.Button.Y
4762
:annotation:
4863

49-
.. autoattribute:: pybricks.parameters.Button.RIGHT_PLUS
64+
.. autoattribute:: pybricks.parameters.Button.LB
65+
:annotation:
66+
67+
The left bumper.
68+
69+
.. autoattribute:: pybricks.parameters.Button.RB
70+
:annotation:
71+
72+
The right bumper.
73+
74+
.. autoattribute:: pybricks.parameters.Button.LJ
75+
:annotation:
76+
77+
Pressing the left joystick.
78+
79+
.. autoattribute:: pybricks.parameters.Button.RJ
80+
:annotation:
81+
82+
Pressing the right joystick.
83+
84+
.. autoattribute:: pybricks.parameters.Button.GUIDE
85+
:annotation:
86+
87+
The Xbox button in the center of the controller.
88+
89+
.. autoattribute:: pybricks.parameters.Button.MENU
90+
:annotation:
91+
92+
.. autoattribute:: pybricks.parameters.Button.UPLOAD
93+
:annotation:
94+
95+
Only available on newer Xbox controllers.
96+
97+
.. autoattribute:: pybricks.parameters.Button.VIEW
98+
:annotation:
99+
100+
.. rubric:: Xbox Elite Series 2 controller paddles
101+
102+
.. autoattribute:: pybricks.parameters.Button.P1
103+
:annotation:
104+
105+
.. autoattribute:: pybricks.parameters.Button.P2
106+
:annotation:
107+
108+
.. autoattribute:: pybricks.parameters.Button.P3
109+
:annotation:
110+
111+
.. autoattribute:: pybricks.parameters.Button.P4
50112
:annotation:

src/pybricks/parameters.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ def __init__(self, h: Number, s: Number = 100, v: Number = 100):
115115
def __repr__(self):
116116
return "Color(h={}, s={}, v={})".format(self.h, self.s, self.v)
117117

118-
def __eq__(self, other: Color) -> bool:
119-
...
118+
def __eq__(self, other: Color) -> bool: ...
120119

121120
def __mul__(self, scale: float) -> Color:
122121
v = max(0, min(self.v * scale, 100))
@@ -222,6 +221,22 @@ class Button(_PybricksEnum):
222221
RIGHT_UP: Button = 9
223222
RIGHT_PLUS: Button = 9
224223
BLUETOOTH: Button = 9
224+
A: Button = 0
225+
B: Button = 0
226+
X: Button = 0
227+
Y: Button = 0
228+
LB: Button = 0
229+
RB: Button = 0
230+
LJ: Button = 0
231+
RJ: Button = 0
232+
P1: Button = 0
233+
P2: Button = 0
234+
P3: Button = 0
235+
P4: Button = 0
236+
GUIDE: Button = 0
237+
MENU: Button = 0
238+
UPLOAD: Button = 0
239+
VIEW: Button = 0
225240

226241

227242
class Side(_PybricksEnum):

0 commit comments

Comments
 (0)