pybricks.parameters: Add Xbox buttons.

This commit is contained in:
Laurens Valk
2024-03-05 14:10:29 +01:00
parent e3b2e6edca
commit 079b108680
4 changed files with 118 additions and 37 deletions
+4
View File
@@ -4,6 +4,10 @@
## Unreleased
## Changed
- Updates for v3.4.0b3 firmware.
## 3.4.0b4 - 2024-02-14
## Added
+5 -5
View File
@@ -17,11 +17,11 @@ Xbox Controller
Buttons include:
* ``"A"``, ``"B"``, ``"X"``, ``"Y"``.
* ``"LB"`` and ``"RB"`` (bumpers).
* ``"LJ"`` and ``"RJ"`` (pressing the joysticks).
* ``"VIEW"``, ``"MENU"``, ``"GUIDE"`` (the Xbox logo), and ``"UPLOAD"``.
* ``"P1"``, ``"P2"``, ``"P3"``, and ``"P4"`` (Elite Series 2 only).
* ``Button.A``, ``Button.B``, ``Button.X``, ``Button.Y``.
* ``Button.LB`` and ``Button.RB`` (bumpers).
* ``Button.LJ`` and ``Button.RJ`` (pressing the joysticks).
* ``Button.VIEW``, ``Button.MENU``, ``Button.GUIDE`` (the Xbox logo), and ``Button.UPLOAD``.
* ``Button.P1``, ``Button.P2``, ``Button.P3``, and ``Button.P4`` (Elite Series 2 only).
Pressing the paddles may also be detected as other button presses,
depending on the currently active profile.
+92 -30
View File
@@ -5,46 +5,108 @@ Button
.. class:: Button
Buttons on a hub or remote.
.. autoattribute:: pybricks.parameters.Button.LEFT_DOWN
:annotation:
.. rubric:: Remote and hub buttons
.. autoattribute:: pybricks.parameters.Button.LEFT_MINUS
:annotation:
.. autoattribute:: pybricks.parameters.Button.DOWN
:annotation:
.. autoattribute:: pybricks.parameters.Button.RIGHT_DOWN
:annotation:
.. autoattribute:: pybricks.parameters.Button.RIGHT_MINUS
:annotation:
.. autoattribute:: pybricks.parameters.Button.LEFT
:annotation:
.. autoattribute:: pybricks.parameters.Button.CENTER
:annotation:
.. autoattribute:: pybricks.parameters.Button.RIGHT
:annotation:
.. autoattribute:: pybricks.parameters.Button.LEFT_UP
:annotation:
Powered Up Remote only.
.. autoattribute:: pybricks.parameters.Button.LEFT_PLUS
:annotation:
.. autoattribute:: pybricks.parameters.Button.UP
Powered Up Remote only.
.. autoattribute:: pybricks.parameters.Button.RIGHT_MINUS
:annotation:
.. autoattribute:: pybricks.parameters.Button.BEACON
:annotation:
.. autoattribute:: pybricks.parameters.Button.RIGHT_UP
:annotation:
Powered Up Remote only.
.. autoattribute:: pybricks.parameters.Button.RIGHT_PLUS
:annotation:
Powered Up Remote only.
.. autoattribute:: pybricks.parameters.Button.CENTER
:annotation:
Powered Up Remote (green button) or hub power button.
.. autoattribute:: pybricks.parameters.Button.LEFT
:annotation:
Powered Up Remote (left red button) and Prime/Inventor Hub (left button).
.. autoattribute:: pybricks.parameters.Button.RIGHT
:annotation:
Powered Up Remote (right red button) and Prime/Inventor Hub (right button).
.. autoattribute:: pybricks.parameters.Button.BLUETOOTH
:annotation:
Prime/Inventor Hub button with Bluetooth icon.
.. rubric:: Xbox controller buttons
.. autoattribute:: pybricks.parameters.Button.A
:annotation:
.. autoattribute:: pybricks.parameters.Button.B
:annotation:
.. autoattribute:: pybricks.parameters.Button.X
:annotation:
.. autoattribute:: pybricks.parameters.Button.Y
:annotation:
.. autoattribute:: pybricks.parameters.Button.LB
:annotation:
The left bumper.
.. autoattribute:: pybricks.parameters.Button.RB
:annotation:
The right bumper.
.. autoattribute:: pybricks.parameters.Button.LJ
:annotation:
Pressing the left joystick.
.. autoattribute:: pybricks.parameters.Button.RJ
:annotation:
Pressing the right joystick.
.. autoattribute:: pybricks.parameters.Button.GUIDE
:annotation:
The Xbox button in the center of the controller.
.. autoattribute:: pybricks.parameters.Button.MENU
:annotation:
.. autoattribute:: pybricks.parameters.Button.UPLOAD
:annotation:
Only available on newer Xbox controllers.
.. autoattribute:: pybricks.parameters.Button.VIEW
:annotation:
.. rubric:: Xbox Elite Series 2 controller paddles
.. autoattribute:: pybricks.parameters.Button.P1
:annotation:
.. autoattribute:: pybricks.parameters.Button.P2
:annotation:
.. autoattribute:: pybricks.parameters.Button.P3
:annotation:
.. autoattribute:: pybricks.parameters.Button.P4
:annotation:
+17 -2
View File
@@ -115,8 +115,7 @@ class Color:
def __repr__(self):
return "Color(h={}, s={}, v={})".format(self.h, self.s, self.v)
def __eq__(self, other: Color) -> bool:
...
def __eq__(self, other: Color) -> bool: ...
def __mul__(self, scale: float) -> Color:
v = max(0, min(self.v * scale, 100))
@@ -222,6 +221,22 @@ class Button(_PybricksEnum):
RIGHT_UP: Button = 9
RIGHT_PLUS: Button = 9
BLUETOOTH: Button = 9
A: Button = 0
B: Button = 0
X: Button = 0
Y: Button = 0
LB: Button = 0
RB: Button = 0
LJ: Button = 0
RJ: Button = 0
P1: Button = 0
P2: Button = 0
P3: Button = 0
P4: Button = 0
GUIDE: Button = 0
MENU: Button = 0
UPLOAD: Button = 0
VIEW: Button = 0
class Side(_PybricksEnum):