Skip to content

Commit 627c426

Browse files
committed
wip
1 parent b815164 commit 627c426

File tree

13 files changed

+340
-249
lines changed

13 files changed

+340
-249
lines changed

locale/circuitpython.pot

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,18 @@ msgstr ""
9595
msgid "%q must be 1-255"
9696
msgstr ""
9797

98+
#: shared-bindings/keypad/Event.c
99+
msgid "%q must be > 0"
100+
msgstr ""
101+
98102
#: shared-bindings/memorymonitor/AllocationAlarm.c
99103
msgid "%q must be >= 0"
100104
msgstr ""
101105

102106
#: shared-bindings/_bleio/CharacteristicBuffer.c
103107
#: shared-bindings/_bleio/PacketBuffer.c shared-bindings/displayio/Group.c
104-
#: shared-bindings/displayio/Shape.c
108+
#: shared-bindings/displayio/Shape.c shared-bindings/keypad/KeyMatrix.c
109+
#: shared-bindings/keypad/Keys.c
105110
#: shared-bindings/memorymonitor/AllocationAlarm.c
106111
#: shared-bindings/vectorio/Circle.c shared-bindings/vectorio/Rectangle.c
107112
msgid "%q must be >= 1"
@@ -116,7 +121,8 @@ msgid "%q must be a tuple of length 2"
116121
msgstr ""
117122

118123
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
119-
#: shared-bindings/canio/Match.c shared-bindings/keypad/Keys.c
124+
#: shared-bindings/canio/Match.c shared-bindings/keypad/KeyMatrix.c
125+
#: shared-bindings/keypad/Keys.c
120126
msgid "%q out of range"
121127
msgstr ""
122128

@@ -905,8 +911,7 @@ msgstr ""
905911

906912
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c py/enum.c
907913
#: shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
908-
#: shared-bindings/busio/SPI.c shared-bindings/keypad/Keys.c
909-
#: shared-bindings/microcontroller/Pin.c
914+
#: shared-bindings/busio/SPI.c shared-bindings/microcontroller/Pin.c
910915
#: shared-bindings/neopixel_write/__init__.c
911916
#: shared-bindings/terminalio/Terminal.c
912917
msgid "Expected a %q"

py/circuitpy_defns.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,9 @@ SRC_SHARED_MODULE_ALL = \
516516
ipaddress/IPv4Address.c \
517517
ipaddress/__init__.c \
518518
keypad/__init__.c \
519+
keypad/Event.c \
520+
keypad/KeyMatrix.c \
519521
keypad/Keys.c \
520-
keypad/State.c \
521522
sdcardio/SDCard.c \
522523
sdcardio/__init__.c \
523524
gamepad/GamePad.c \

shared-bindings/keypad/Event.c

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 Dan Halbert for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/obj.h"
28+
#include "py/objproperty.h"
29+
#include "py/runtime.h"
30+
31+
#include "shared-bindings/keypad/Event.h"
32+
33+
//| class Event:
34+
//| """A key transition event."""
35+
//| def __init__(self, key_num: int, pressed: bool) -> None:
36+
//| """Create a key transition event, which reports a key-pressed or key-released transition.
37+
//|
38+
//| :param int key_num: the key number
39+
//| :param bool pressed: ``True`` if the key was pressed; ``False`` if it was released.
40+
//| """
41+
//| ...
42+
//|
43+
44+
STATIC mp_obj_t keypad_event_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
45+
keypad_event_obj_t *self = m_new_obj(keypad_event_obj_t);
46+
self->base.type = &keypad_event_type;
47+
enum { ARG_key_num, ARG_pressed };
48+
static const mp_arg_t allowed_args[] = {
49+
{ MP_QSTR_key_num, MP_ARG_REQUIRED | MP_ARG_INT },
50+
{ MP_QSTR_pressed, MP_ARG_REQUIRED | MP_ARG_BOOL },
51+
};
52+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
53+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
54+
55+
const mp_int_t key_num = args[ARG_key_num].u_int;
56+
if (key_num < 0) {
57+
mp_raise_ValueError_varg(translate("%q must be > 0"), MP_QSTR_key_num);
58+
}
59+
60+
common_hal_keypad_event_construct(self, (mp_uint_t)key_num, args[ARG_pressed].u_bool);
61+
return MP_OBJ_FROM_PTR(self);
62+
}
63+
64+
//| key_num: int
65+
//| """The key number."""
66+
//|
67+
STATIC mp_obj_t keypad_event_obj_get_key_num(mp_obj_t self_in) {
68+
keypad_event_obj_t *self = MP_OBJ_TO_PTR(self_in);
69+
return MP_OBJ_NEW_SMALL_INT(common_hal_keypad_event_get_key_num(self));
70+
}
71+
MP_DEFINE_CONST_FUN_OBJ_1(keypad_event_get_key_num_obj, keypad_event_obj_get_key_num);
72+
73+
const mp_obj_property_t keypad_event_key_num_obj = {
74+
.base.type = &mp_type_property,
75+
.proxy = {(mp_obj_t)&keypad_event_get_key_num_obj,
76+
MP_ROM_NONE,
77+
MP_ROM_NONE},
78+
};
79+
80+
//| pressed: bool
81+
//| """True if event represents a key down (pressed) transition."""
82+
//|
83+
STATIC mp_obj_t keypad_event_obj_get_pressed(mp_obj_t self_in) {
84+
keypad_event_obj_t *self = MP_OBJ_TO_PTR(self_in);
85+
return mp_obj_new_bool(common_hal_keypad_event_get_pressed(self));
86+
}
87+
MP_DEFINE_CONST_FUN_OBJ_1(keypad_event_get_pressed_obj, keypad_event_obj_get_pressed);
88+
89+
const mp_obj_property_t keypad_event_pressed_obj = {
90+
.base.type = &mp_type_property,
91+
.proxy = {(mp_obj_t)&keypad_event_get_pressed_obj,
92+
MP_ROM_NONE,
93+
MP_ROM_NONE},
94+
};
95+
96+
//| released: bool
97+
//| """True if event represents a key up (released) transition."""
98+
//|
99+
STATIC mp_obj_t keypad_event_obj_get_released(mp_obj_t self_in) {
100+
keypad_event_obj_t *self = MP_OBJ_TO_PTR(self_in);
101+
return mp_obj_new_bool(common_hal_keypad_event_get_released(self));
102+
}
103+
MP_DEFINE_CONST_FUN_OBJ_1(keypad_event_get_released_obj, keypad_event_obj_get_released);
104+
105+
const mp_obj_property_t keypad_event_released_obj = {
106+
.base.type = &mp_type_property,
107+
.proxy = {(mp_obj_t)&keypad_event_get_released_obj,
108+
MP_ROM_NONE,
109+
MP_ROM_NONE},
110+
};
111+
112+
STATIC const mp_rom_map_elem_t keypad_event_locals_dict_table[] = {
113+
// Properties
114+
{ MP_ROM_QSTR(MP_QSTR_key_num), MP_ROM_PTR(&keypad_event_key_num_obj) },
115+
{ MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&keypad_event_pressed_obj) },
116+
{ MP_ROM_QSTR(MP_QSTR_released), MP_ROM_PTR(&keypad_event_released_obj) },
117+
};
118+
STATIC MP_DEFINE_CONST_DICT(keypad_event_locals_dict, keypad_event_locals_dict_table);
119+
120+
const mp_obj_type_t keypad_event_type = {
121+
{ &mp_type_type },
122+
.name = MP_QSTR_UART,
123+
.make_new = keypad_event_make_new,
124+
.locals_dict = (mp_obj_dict_t *)&keypad_event_locals_dict,
125+
};

shared-bindings/keypad/Event.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 Dan Halbert for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_EVENT__H
28+
#define MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_EVENT__H
29+
30+
#include "py/obj.h"
31+
#include "shared-module/keypad/Event.h"
32+
33+
extern const mp_obj_type_t keypad_event_type;
34+
35+
void common_hal_keypad_event_construct(keypad_event_obj_t *self, uint16_t key_num, bool pressed);
36+
mp_int_t common_hal_keypad_event_get_key_num(keypad_event_obj_t *self);
37+
bool common_hal_keypad_event_get_pressed(keypad_event_obj_t *self);
38+
bool common_hal_keypad_event_get_released(keypad_event_obj_t *self);
39+
40+
41+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_KEYPAD_EVENT__H

0 commit comments

Comments
 (0)