From 0384d8c19b0627094e91b9f3f27b80ae1b28c037 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Sun, 31 Jan 2021 20:38:24 +0100 Subject: [PATCH] feat(mp-ble): Implement to stop advertising --- epicardium/ble/epic_ble_api.c | 6 ++++++ epicardium/epicardium.h | 2 ++ pycardium/modules/modbluetooth_card10.c | 18 +++++++++--------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/epicardium/ble/epic_ble_api.c b/epicardium/ble/epic_ble_api.c index bc50a72b6..cf27adc0f 100644 --- a/epicardium/ble/epic_ble_api.c +++ b/epicardium/ble/epic_ble_api.c @@ -158,3 +158,9 @@ int epic_ble_advertise( } return 0; } + +int epic_ble_advertise_stop(void) +{ + ble_adv_stop(); + return 0; +} diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 62d7d01e6..75901978e 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -181,6 +181,7 @@ typedef _Bool bool; #define API_BLE_GET_DEVICE_NAME 0x183 #define API_BLE_GET_ADDRESS 0x184 #define API_BLE_ADVERTISE 0x185 +#define API_BLE_ADVERTISE_STOP 0x186 /* clang-format on */ @@ -2663,6 +2664,7 @@ API(API_BLE_GET_DEVICE_NAME, int epic_ble_get_device_name(uint8_t **buf, uint16_ API(API_BLE_GET_ADDRESS, void epic_ble_get_address(uint8_t *addr)); API(API_BLE_ADVERTISE, int epic_ble_advertise(int interval_us, const uint8_t *adv_data, size_t adv_data_len, const uint8_t *sr_data, size_t sr_data_len, bool connectable)); +API(API_BLE_ADVERTISE_STOP, int epic_ble_advertise_stop(void)); #endif /* _EPICARDIUM_H */ diff --git a/pycardium/modules/modbluetooth_card10.c b/pycardium/modules/modbluetooth_card10.c index 3c3bbdbc8..4a659f93d 100644 --- a/pycardium/modules/modbluetooth_card10.c +++ b/pycardium/modules/modbluetooth_card10.c @@ -12,9 +12,6 @@ enum notification_status { NOTIFICATION_STATUS_OVERFLOW }; -const char *const not_implemented_message = - "Not (yet) implemented on card10. See https://git.card10.badge.events.ccc.de/card10/firmware/-/issues/8"; - typedef struct _mp_bluetooth_card10_root_pointers_t { // Characteristic (and descriptor) value storage. mp_gatts_db_t gatts_db; @@ -54,11 +51,6 @@ gatts_status_lookup(mp_gatts_db_t db, uint16_t handle) return MP_OBJ_TO_PTR(elem->value); } -static void raise(void) -{ - mp_raise_NotImplementedError(not_implemented_message); -} - static void clear_events(void) { struct epic_ble_event ble_event; @@ -238,7 +230,7 @@ int mp_bluetooth_gap_advertise_start( // Stop advertisement. No-op when already stopped. void mp_bluetooth_gap_advertise_stop(void) { - raise(); + epic_ble_advertise_stop(); } // Start adding services. Must be called before mp_bluetooth_register_service. @@ -506,6 +498,14 @@ int mp_bluetooth_gap_disconnect(uint16_t conn_handle) } #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE +const char *const not_implemented_message = + "Not (yet) implemented on card10. See https://git.card10.badge.events.ccc.de/card10/firmware/-/issues/8"; + +static void raise(void) +{ + mp_raise_NotImplementedError(not_implemented_message); +} + // Start a discovery (scan). Set duration to zero to run continuously. int mp_bluetooth_gap_scan_start( int32_t duration_ms, int32_t interval_us, int32_t window_us -- GitLab