3434#include "shared-bindings/digitalio/DigitalInOut.h"
3535#include "supervisor/shared/translate.h"
3636
37-
38- //| .. currentmodule:: gamepad
37+ //| class GamePad:
38+ //| """ .. currentmodule:: gamepad
3939//|
40- //| :class:`GamePad` -- Scan buttons for presses
41- //| ============================================
40+ //| :class:`GamePad` -- Scan buttons for presses
41+ //| ============================================
4242//|
43- //| Usage::
43+ //| Usage::
4444//|
45- //| import board
46- //| import digitalio
47- //| import gamepad
48- //| import time
45+ //| import board
46+ //| import digitalio
47+ //| import gamepad
48+ //| import time
4949//|
50- //| B_UP = 1 << 0
51- //| B_DOWN = 1 << 1
50+ //| B_UP = 1 << 0
51+ //| B_DOWN = 1 << 1
5252//|
5353//|
54- //| pad = gamepad.GamePad(
55- //| digitalio.DigitalInOut(board.D10),
56- //| digitalio.DigitalInOut(board.D11),
57- //| )
54+ //| pad = gamepad.GamePad(
55+ //| digitalio.DigitalInOut(board.D10),
56+ //| digitalio.DigitalInOut(board.D11),
57+ //| )
5858//|
59- //| y = 0
60- //| while True:
61- //| buttons = pad.get_pressed()
62- //| if buttons & B_UP:
63- //| y -= 1
64- //| print(y)
65- //| elif buttons & B_DOWN:
66- //| y += 1
67- //| print(y)
68- //| time.sleep(0.1)
69- //| while buttons:
70- //| # Wait for all buttons to be released.
59+ //| y = 0
60+ //| while True:
7161//| buttons = pad.get_pressed()
62+ //| if buttons & B_UP:
63+ //| y -= 1
64+ //| print(y)
65+ //| elif buttons & B_DOWN:
66+ //| y += 1
67+ //| print(y)
7268//| time.sleep(0.1)
69+ //| while buttons:
70+ //| # Wait for all buttons to be released.
71+ //| buttons = pad.get_pressed()
72+ //| time.sleep(0.1)"""
7373//|
7474
75- //| .. class:: GamePad([b1[ , b2[ , b3[ , b4[ , b5[ , b6[ , b7[ , b8]]]]]]]])
76- //|
77- //| Initializes button scanning routines.
78- //|
79- //| The ``b1``-``b8`` parameters are ``DigitalInOut`` objects, which
80- //| immediately get switched to input with a pull-up, (unless they already
81- //| were set to pull-down, in which case they remain so), and then scanned
82- //| regularly for button presses. The order is the same as the order of
83- //| bits returned by the ``get_pressed`` function. You can re-initialize
84- //| it with different keys, then the new object will replace the previous
85- //| one.
86- //|
87- //| The basic feature required here is the ability to poll the keys at
88- //| regular intervals (so that de-bouncing is consistent) and fast enough
89- //| (so that we don't miss short button presses) while at the same time
90- //| letting the user code run normally, call blocking functions and wait
91- //| on delays.
92- //|
93- //| They button presses are accumulated, until the ``get_pressed`` method
94- //| is called, at which point the button state is cleared, and the new
95- //| button presses start to be recorded .
75+ //| def __init__(self, b1: Any , b2: Any , b3: Any , b4: Any , b5: Any , b6: Any , b7: Any , b8: Any):
76+ //| """Initializes button scanning routines.
77+ //|
78+ //| The ``b1``-``b8`` parameters are ``DigitalInOut`` objects, which
79+ //| immediately get switched to input with a pull-up, (unless they already
80+ //| were set to pull-down, in which case they remain so), and then scanned
81+ //| regularly for button presses. The order is the same as the order of
82+ //| bits returned by the ``get_pressed`` function. You can re-initialize
83+ //| it with different keys, then the new object will replace the previous
84+ //| one.
85+ //|
86+ //| The basic feature required here is the ability to poll the keys at
87+ //| regular intervals (so that de-bouncing is consistent) and fast enough
88+ //| (so that we don't miss short button presses) while at the same time
89+ //| letting the user code run normally, call blocking functions and wait
90+ //| on delays.
91+ //|
92+ //| They button presses are accumulated, until the ``get_pressed`` method
93+ //| is called, at which point the button state is cleared, and the new
94+ //| button presses start to be recorded."""
95+ //| .. .
9696//|
9797STATIC mp_obj_t gamepad_make_new (const mp_obj_type_t * type , size_t n_args ,
9898 const mp_obj_t * args , mp_map_t * kw_args ) {
@@ -114,15 +114,15 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args,
114114 return MP_OBJ_FROM_PTR (gamepad_singleton );
115115}
116116
117- //| .. method:: get_pressed()
118- //|
119- //| Get the status of buttons pressed since the last call and clear it.
117+ //| def get_pressed(self, ) -> Any:
118+ //| """Get the status of buttons pressed since the last call and clear it.
120119//|
121120//| Returns an 8-bit number, with bits that correspond to buttons,
122121//| which have been pressed (or held down) since the last call to this
123122//| function set to 1, and the remaining bits set to 0. Then it clears
124123//| the button state, so that new button presses (or buttons that are
125- //| held down) can be recorded for the next call.
124+ //| held down) can be recorded for the next call."""
125+ //| ...
126126//|
127127STATIC mp_obj_t gamepad_get_pressed (mp_obj_t self_in ) {
128128 gamepad_obj_t * gamepad_singleton = MP_STATE_VM (gamepad_singleton );
@@ -133,9 +133,9 @@ STATIC mp_obj_t gamepad_get_pressed(mp_obj_t self_in) {
133133MP_DEFINE_CONST_FUN_OBJ_1 (gamepad_get_pressed_obj , gamepad_get_pressed );
134134
135135
136- //| .. method:: deinit()
137- //|
138- //| Disable button scanning .
136+ //| def deinit(self, ) -> Any:
137+ //| """Disable button scanning."""
138+ //| .. .
139139//|
140140STATIC mp_obj_t gamepad_deinit (mp_obj_t self_in ) {
141141 common_hal_gamepad_gamepad_deinit (self_in );
0 commit comments