Skip to content

Commit 4f33a20

Browse files
committed
Added gamepad, gamepadshift, and i2cslave
1 parent a3d5adb commit 4f33a20

File tree

6 files changed

+149
-152
lines changed

6 files changed

+149
-152
lines changed

shared-bindings/gamepad/GamePad.c

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,65 +34,65 @@
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
//|
9797
STATIC 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
//|
127127
STATIC 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) {
133133
MP_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
//|
140140
STATIC mp_obj_t gamepad_deinit(mp_obj_t self_in) {
141141
common_hal_gamepad_gamepad_deinit(self_in);

shared-bindings/gamepad/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "shared-bindings/gamepad/GamePad.h"
3030
#include "shared-bindings/util.h"
3131

32-
//| :mod:`gamepad` --- Button handling
32+
//| """:mod:`gamepad` --- Button handling
3333
//| ==================================
3434
//|
3535
//| .. module:: gamepad
@@ -39,7 +39,7 @@
3939
//| .. toctree::
4040
//| :maxdepth: 3
4141
//|
42-
//| GamePad
42+
//| GamePad"""
4343
//|
4444
STATIC const mp_rom_map_elem_t gamepad_module_globals_table[] = {
4545
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepad) },

shared-bindings/gamepadshift/GamePadShift.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,25 @@
3232
#include "shared-bindings/gamepadshift/__init__.h"
3333
#include "supervisor/shared/translate.h"
3434

35-
//| .. currentmodule:: gamepadshift
35+
//| class GamePadShift:
36+
//| """.. currentmodule:: gamepadshift
3637
//|
37-
//| :class:`GamePadShift` -- Scan buttons for presses through a shift register
38-
//| ===========================================================================
38+
//| :class:`GamePadShift` -- Scan buttons for presses through a shift register
39+
//| ==========================================================================="""
3940
//|
40-
//| .. class:: GamePadShift(clock, data, latch)
41+
//| def __init__(self, clock: Any, data: Any, latch: Any):
42+
//| """Initializes button scanning routines.
4143
//|
42-
//| Initializes button scanning routines.
44+
//| The ``clock``, ``data`` and ``latch`` parameters are ``DigitalInOut``
45+
//| objects connected to the shift register controlling the buttons.
4346
//|
44-
//| The ``clock``, ``data`` and ``latch`` parameters are ``DigitalInOut``
45-
//| objects connected to the shift register controlling the buttons.
47+
//| They button presses are accumulated, until the ``get_pressed`` method
48+
//| is called, at which point the button state is cleared, and the new
49+
//| button presses start to be recorded.
4650
//|
47-
//| They button presses are accumulated, until the ``get_pressed`` method
48-
//| is called, at which point the button state is cleared, and the new
49-
//| button presses start to be recorded.
50-
//|
51-
//| Only one gamepad (`gamepad.GamePad` or `gamepadshift.GamePadShift`)
52-
//| may be used at a time.
51+
//| Only one gamepad (`gamepad.GamePad` or `gamepadshift.GamePadShift`)
52+
//| may be used at a time."""
53+
//| ...
5354
//|
5455
STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args,
5556
const mp_obj_t *pos_args, mp_map_t *kw_args) {
@@ -81,15 +82,15 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args,
8182
return MP_OBJ_FROM_PTR(gamepad_singleton);
8283
}
8384

84-
//| .. method:: get_pressed()
85-
//|
86-
//| Get the status of buttons pressed since the last call and clear it.
85+
//| def get_pressed(self, ) -> Any:
86+
//| """Get the status of buttons pressed since the last call and clear it.
8787
//|
8888
//| Returns an 8-bit number, with bits that correspond to buttons,
8989
//| which have been pressed (or held down) since the last call to this
9090
//| function set to 1, and the remaining bits set to 0. Then it clears
9191
//| the button state, so that new button presses (or buttons that are
92-
//| held down) can be recorded for the next call.
92+
//| held down) can be recorded for the next call."""
93+
//| ...
9394
//|
9495
STATIC mp_obj_t gamepadshift_get_pressed(mp_obj_t self_in) {
9596
gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
@@ -99,9 +100,9 @@ STATIC mp_obj_t gamepadshift_get_pressed(mp_obj_t self_in) {
99100
}
100101
MP_DEFINE_CONST_FUN_OBJ_1(gamepadshift_get_pressed_obj, gamepadshift_get_pressed);
101102

102-
//| .. method:: deinit()
103-
//|
104-
//| Disable button scanning.
103+
//| def deinit(self, ) -> Any:
104+
//| """Disable button scanning."""
105+
//| ...
105106
//|
106107
STATIC mp_obj_t gamepadshift_deinit(mp_obj_t self_in) {
107108
common_hal_gamepadshift_gamepadshift_deinit(self_in);

shared-bindings/gamepadshift/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "shared-bindings/digitalio/DigitalInOut.h"
3131
#include "shared-bindings/util.h"
3232

33-
//| :mod:`gamepadshift` --- Tracks button presses read through a shift register
33+
//| """:mod:`gamepadshift` --- Tracks button presses read through a shift register
3434
//| ===========================================================================
3535
//|
3636
//| .. module:: gamepadshift
@@ -40,7 +40,7 @@
4040
//| .. toctree::
4141
//| :maxdepth: 3
4242
//|
43-
//| GamePadShift
43+
//| GamePadShift"""
4444
//|
4545
STATIC const mp_rom_map_elem_t gamepadshift_module_globals_table[] = {
4646
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepadshift) },

0 commit comments

Comments
 (0)