diff --git a/epicardium/ble/epic_ble_api.c b/epicardium/ble/epic_ble_api.c index c812c9b92f64dd0647849061bd719fe0085c46ee..9d27fe3b1a545468ba863305c2c5d8cc9d5582f2 100644 --- a/epicardium/ble/epic_ble_api.c +++ b/epicardium/ble/epic_ble_api.c @@ -10,6 +10,7 @@ #include "FreeRTOS.h" #include "queue.h" +#include "timers.h" #include <stdint.h> #include <string.h> @@ -24,8 +25,11 @@ static StaticQueue_t ble_event_queue_data; static uint8_t adv_data_buf[HCI_ADV_DATA_LEN]; static uint8_t sr_data_buf[HCI_ADV_DATA_LEN]; -static dmEvt_t connection_open_event; +static TimerHandle_t dm_timer; +static StaticTimer_t dm_timer_data; + +static dmEvt_t connection_open_event; static bool connection_open; int epic_ble_free_event(struct epic_ble_event *e) @@ -147,14 +151,39 @@ int epic_ble_is_connection_open(void) return AppConnIsOpen(); } +void vDmTimerCallback() +{ + send_dm_event(&connection_open_event); +} + int epic_ble_init(void) { + if (dm_timer == NULL) { + dm_timer = xTimerCreateStatic( + "dmtimer", + 1, + pdFALSE, /* one-shot */ + 0, + vDmTimerCallback, + &dm_timer_data); + } + epic_interrupt_enable(EPIC_INT_BLE); + + if (connection_open) { + // Give pycardium a bit of time and then let it + // know that there already is an open connection + int millis = 100; + int ticks = millis * (configTICK_RATE_HZ / 1000); + xTimerChangePeriod(dm_timer, ticks, 0); + } + return 0; } int epic_ble_deinit(void) { + xTimerStop(dm_timer, 0); epic_interrupt_disable(EPIC_INT_BLE); return 0; }