Skip to content

Commit b9edf65

Browse files
committed
pybricks.messaging: Add empty module.
This will be used for wired and wireless messaging functions and classes. This name was originally introduced in Pybricks 2.0 but was not included in Pybricks 3.0 since it was not used on Powered Up. It makes a comeback now, with backwards compatible classes.
1 parent 16f6f0b commit b9edf65

File tree

8 files changed

+50
-0
lines changed

8 files changed

+50
-0
lines changed

bricks/_common/qstrdefs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Q(pybricks.hubs)
2727
Q(pybricks.iodevices)
2828
#endif
2929

30+
#if PYBRICKS_PY_MESSAGING
31+
Q(pybricks.messaging)
32+
#endif
33+
3034
#if PYBRICKS_PY_NXTDEVICES
3135
Q(pybricks.nxtdevices)
3236
#endif

bricks/_common/sources.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ PYBRICKS_PYBRICKS_SRC_C = $(addprefix pybricks/,\
5151
iodevices/pb_type_iodevices_pupdevice.c \
5252
iodevices/pb_type_iodevices_xbox_controller.c \
5353
iodevices/pb_type_uart_device.c \
54+
messaging/pb_module_messaging.c \
5455
nxtdevices/pb_module_nxtdevices.c \
5556
nxtdevices/pb_type_nxtdevices_colorsensor.c \
5657
nxtdevices/pb_type_nxtdevices_energymeter.c \

bricks/essentialhub/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define PYBRICKS_PY_IODEVICES_PUP_DEVICE (1)
3939
#define PYBRICKS_PY_IODEVICES_UART_DEVICE (1)
4040
#define PYBRICKS_PY_IODEVICES_XBOX_CONTROLLER (1)
41+
#define PYBRICKS_PY_MESSAGING (1)
4142
#define PYBRICKS_PY_NXTDEVICES (0)
4243
#define PYBRICKS_PY_PARAMETERS (1)
4344
#define PYBRICKS_PY_PARAMETERS_BUTTON (1)

bricks/ev3/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define PYBRICKS_PY_IODEVICES_PUP_DEVICE (1)
4343
#define PYBRICKS_PY_IODEVICES_UART_DEVICE (1)
4444
#define PYBRICKS_PY_IODEVICES_XBOX_CONTROLLER (0)
45+
#define PYBRICKS_PY_MESSAGING (1)
4546
#define PYBRICKS_PY_NXTDEVICES (1)
4647
#define PYBRICKS_PY_PARAMETERS (1)
4748
#define PYBRICKS_PY_PARAMETERS_BUTTON (1)

bricks/primehub/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define PYBRICKS_PY_IODEVICES_PUP_DEVICE (1)
3636
#define PYBRICKS_PY_IODEVICES_XBOX_CONTROLLER (1)
3737
#define PYBRICKS_PY_MEDIA_IMAGE (0)
38+
#define PYBRICKS_PY_MESSAGING (1)
3839
#define PYBRICKS_PY_NXTDEVICES (0)
3940
#define PYBRICKS_PY_PARAMETERS (1)
4041
#define PYBRICKS_PY_PARAMETERS_BUTTON (1)

bricks/virtualhub/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define PYBRICKS_PY_IODEVICES_PUP_DEVICE (0)
3939
#define PYBRICKS_PY_IODEVICES_UART_DEVICE (0)
4040
#define PYBRICKS_PY_IODEVICES_XBOX_CONTROLLER (1)
41+
#define PYBRICKS_PY_MESSAGING (1)
4142
#define PYBRICKS_PY_NXTDEVICES (0)
4243
#define PYBRICKS_PY_PARAMETERS (1)
4344
#define PYBRICKS_PY_PARAMETERS_BUTTON (1)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2018-2021 The Pybricks Authors
3+
4+
#include "py/mpconfig.h"
5+
6+
#if PYBRICKS_PY_MESSAGING
7+
8+
#include "py/mphal.h"
9+
#include "py/obj.h"
10+
#include "py/objstr.h"
11+
#include "py/runtime.h"
12+
#include "py/mperrno.h"
13+
14+
#include <pbio/util.h>
15+
16+
#include <pybricks/util_mp/pb_obj_helper.h>
17+
#include <pybricks/util_mp/pb_kwarg_helper.h>
18+
19+
#include <pybricks/util_pb/pb_error.h>
20+
21+
static const mp_rom_map_elem_t messaging_globals_table[] = {
22+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_messaging) },
23+
};
24+
static MP_DEFINE_CONST_DICT(pb_module_messaging_globals, messaging_globals_table);
25+
26+
const mp_obj_module_t pb_module_messaging = {
27+
.base = { &mp_type_module },
28+
.globals = (mp_obj_dict_t *)&pb_module_messaging_globals,
29+
};
30+
31+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
32+
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_messaging, pb_module_messaging);
33+
#endif
34+
35+
#endif // PYBRICKS_PY_MESSAGING

pybricks/pybricks.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ extern const mp_obj_module_t pb_module_pupdevices;
6666
#if PYBRICKS_PY_IODEVICES
6767
extern const mp_obj_module_t pb_module_iodevices;
6868
#endif
69+
#if PYBRICKS_PY_MESSAGING
70+
extern const mp_obj_module_t pb_module_messaging;
71+
#endif
6972
#if PYBRICKS_PY_PARAMETERS
7073
extern const mp_obj_module_t pb_module_parameters;
7174
#endif
@@ -99,6 +102,9 @@ static const mp_rom_map_elem_t pybricks_globals_table[] = {
99102
#if PYBRICKS_PY_IODEVICES
100103
{ MP_ROM_QSTR(MP_QSTR_iodevices), MP_ROM_PTR(&pb_module_iodevices) },
101104
#endif
105+
#if PYBRICKS_PY_MESSAGING
106+
{ MP_ROM_QSTR(MP_QSTR_messaging), MP_ROM_PTR(&pb_module_messaging) },
107+
#endif
102108
#if PYBRICKS_PY_PARAMETERS
103109
{ MP_ROM_QSTR(MP_QSTR_parameters), MP_ROM_PTR(&pb_module_parameters) },
104110
#endif

0 commit comments

Comments
 (0)