diff options
| author | Dan Halbert <halbert@halwitz.org> | 2019-01-03 21:42:42 -0500 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2019-01-03 21:42:42 -0500 |
| commit | a77b2363eff14ae5b19c50a7d25b3db4ef6b200c (patch) | |
| tree | 3b27fef3faf091e584b9990bf4a6f51cc1edb2c4 /ports/nrf | |
| parent | 8dea6f53bbba5b76a5ed0965b44ad1bde4640609 (diff) | |
evt handler list bugs; unique evt handler names; remove uuid128_reference
Diffstat (limited to 'ports/nrf')
| -rw-r--r-- | ports/nrf/bluetooth/ble_drv.c | 23 | ||||
| -rw-r--r-- | ports/nrf/common-hal/bleio/Characteristic.c | 8 | ||||
| -rw-r--r-- | ports/nrf/common-hal/bleio/Peripheral.c | 4 |
3 files changed, 15 insertions, 20 deletions
diff --git a/ports/nrf/bluetooth/ble_drv.c b/ports/nrf/bluetooth/ble_drv.c index 62820289b..7082b1e59 100644 --- a/ports/nrf/bluetooth/ble_drv.c +++ b/ports/nrf/bluetooth/ble_drv.c @@ -53,27 +53,22 @@ void ble_drv_reset() { } void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param) { - event_handler_t *handler = m_new_ll(event_handler_t, 1); - handler->next = NULL; - handler->param = param; - handler->func = func; - - if (m_event_handlers == NULL) { - m_event_handlers = handler; - return; - } - event_handler_t *it = m_event_handlers; - while (it->next != NULL) { + while (it != NULL) { + // If event handler and its corresponding param are already on the list, don't add again. if ((it->func == func) && (it->param == param)) { - m_free(handler); return; } - it = it->next; } - it->next = handler; + // Add a new handler to the front of the list + event_handler_t *handler = m_new_ll(event_handler_t, 1); + handler->next = m_event_handlers; + handler->param = param; + handler->func = func; + + m_event_handlers = handler; } void SD_EVT_IRQHandler(void) { diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 9d7007d7d..a955395bd 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -55,7 +55,7 @@ STATIC uint16_t get_cccd(bleio_characteristic_obj_t *characteristic) { // CCCD is not set, so say that neither Notify nor Indicate is enabled. cccd = 0; } else if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg_varg(translate("Failed to read CCD value, err 0x%04x"), err_code); + mp_raise_OSError_msg_varg(translate("Failed to read CCCD value, err 0x%04x"), err_code); } return cccd; @@ -126,7 +126,7 @@ STATIC void gatts_notify_indicate(bleio_characteristic_obj_t *characteristic, mp const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); const uint32_t err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params); if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg_varg(translate("Failed to notify attribute value, err %0x04x"), err_code); + mp_raise_OSError_msg_varg(translate("Failed to notify or indicate attribute value, err %0x04x"), err_code); } m_tx_in_progress += 1; @@ -188,7 +188,7 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in } } -STATIC void on_ble_evt(ble_evt_t *ble_evt, void *param) { +STATIC void characteristic_on_ble_evt(ble_evt_t *ble_evt, void *param) { switch (ble_evt->header.evt_id) { case BLE_GATTS_EVT_HVN_TX_COMPLETE: m_tx_in_progress -= ble_evt->evt.gatts_evt.params.hvn_tx_complete.count; @@ -211,7 +211,7 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *param) { } void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self) { - ble_drv_add_event_handler(on_ble_evt, NULL); + ble_drv_add_event_handler(characteristic_on_ble_evt, NULL); } void common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self) { diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index d2eef596d..7d5d6a6a6 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -221,7 +221,7 @@ STATIC uint32_t set_advertisement_data(bleio_peripheral_obj_t *self, bool connec return err_code; } -STATIC void on_ble_evt(ble_evt_t *ble_evt, void *self_in) { +STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { bleio_peripheral_obj_t *self = (bleio_peripheral_obj_t*)self_in; switch (ble_evt->header.evt_id) { @@ -311,7 +311,7 @@ bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self) { void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *raw_data) { if (connectable) { - ble_drv_add_event_handler(on_ble_evt, self); + ble_drv_add_event_handler(peripheral_on_ble_evt, self); } const uint32_t err_code = set_advertisement_data(self, connectable, raw_data); |
