summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Ruben Bakke <glennbakke@gmail.com>2017-04-04 21:25:28 +0200
committerGlenn Ruben Bakke <glennbakke@gmail.com>2017-04-04 21:25:28 +0200
commit587c6277c421f210e9d08ba2d2712388312ac5fb (patch)
tree7fb1ef0436300a852e6aae40cb6a956ffdc9c343
parent31feea45114fe1a881271001bb58fede65efe360 (diff)
nrf5/modules/ubluepy: Adding method Peripheral object to stop any ongoing advertisment. Adding compile guard to only include advertise and advertise_stop if peripheral role is compiled in.
-rw-r--r--nrf5/modules/ubluepy/ubluepy_peripheral.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/nrf5/modules/ubluepy/ubluepy_peripheral.c b/nrf5/modules/ubluepy/ubluepy_peripheral.c
index d038b3a96..3d434ad88 100644
--- a/nrf5/modules/ubluepy/ubluepy_peripheral.c
+++ b/nrf5/modules/ubluepy/ubluepy_peripheral.c
@@ -163,6 +163,8 @@ STATIC mp_obj_t peripheral_set_conn_handler(mp_obj_t self_in, mp_obj_t func) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_conn_handler_obj, peripheral_set_conn_handler);
+#if MICROPY_PY_UBLUEPY_PERIPHERAL
+
/// \method advertise(device_name, [service=[service1, service2, ...]], [data=bytearray], [connectable=True])
/// Start advertising. Connectable advertisment type by default.
///
@@ -231,6 +233,22 @@ STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args,
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_advertise_obj, 0, peripheral_advertise);
+/// \method advertise_stop()
+/// Stop advertisment if any onging advertisment.
+///
+STATIC mp_obj_t peripheral_advertise_stop(mp_obj_t self_in) {
+ ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
+
+ (void)self;
+
+ ble_drv_advertise_stop();
+
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_advertise_stop_obj, peripheral_advertise_stop);
+
+#endif // MICROPY_PY_UBLUEPY_PERIPHERAL
+
/// \method disconnect()
/// disconnect connection.
///
@@ -406,6 +424,7 @@ STATIC const mp_map_elem_t ubluepy_peripheral_locals_dict_table[] = {
#endif // MICROPY_PY_UBLUEPY_CENTRAL
#if MICROPY_PY_UBLUEPY_PERIPHERAL
{ MP_OBJ_NEW_QSTR(MP_QSTR_advertise), (mp_obj_t)(&ubluepy_peripheral_advertise_obj) },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_advertise_stop), (mp_obj_t)(&ubluepy_peripheral_advertise_stop_obj) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_disconnect), (mp_obj_t)(&ubluepy_peripheral_disconnect_obj) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_addService), (mp_obj_t)(&ubluepy_peripheral_add_service_obj) },
#if 0