Blink LED fast when advertising or scanning and then slow when connection occurs
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/36b864a1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/36b864a1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/36b864a1 Branch: refs/heads/master Commit: 36b864a185d593195bb97bb45e2c813703855319 Parents: 5376a6f Author: wes3 <w...@micosa.io> Authored: Wed Feb 3 13:05:48 2016 -0800 Committer: wes3 <w...@micosa.io> Committed: Wed Feb 3 13:06:42 2016 -0800 ---------------------------------------------------------------------- project/bletest/src/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/36b864a1/project/bletest/src/main.c ---------------------------------------------------------------------- diff --git a/project/bletest/src/main.c b/project/bletest/src/main.c index 9c16a23..76a00d7 100755 --- a/project/bletest/src/main.c +++ b/project/bletest/src/main.c @@ -66,9 +66,9 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE]; #define BLETEST_ROLE_ADVERTISER (0) #define BLETEST_ROLE_SCANNER (1) #define BLETEST_ROLE_INITIATOR (2) -//#define BLETEST_CFG_ROLE (BLETEST_ROLE_INITIATOR) +#define BLETEST_CFG_ROLE (BLETEST_ROLE_INITIATOR) //#define BLETEST_CFG_ROLE (BLETEST_ROLE_ADVERTISER) -#define BLETEST_CFG_ROLE (BLETEST_ROLE_SCANNER) +//#define BLETEST_CFG_ROLE (BLETEST_ROLE_SCANNER) #define BLETEST_CFG_FILT_DUP_ADV (0) #define BLETEST_CFG_ADV_ITVL (60000 / BLE_HCI_ADV_ITVL) #define BLETEST_CFG_ADV_TYPE BLE_HCI_ADV_TYPE_ADV_IND @@ -362,6 +362,9 @@ bletest_execute_initiator(void) if (g_bletest_current_conns < BLETEST_CFG_CONCURRENT_CONNS) { handle = g_bletest_current_conns + 1; if (ble_ll_conn_find_active_conn(handle)) { + /* Set LED to slower blink rate */ + g_bletest_led_rate = OS_TICKS_PER_SEC; + /* Set next os time to start the connection update */ g_next_os_time = 0; @@ -509,6 +512,9 @@ bletest_execute_advertiser(void) if (g_bletest_current_conns < BLETEST_CFG_CONCURRENT_CONNS) { handle = g_bletest_current_conns + 1; if (ble_ll_conn_find_active_conn(handle)) { + /* Set LED to slower blink rate */ + g_bletest_led_rate = OS_TICKS_PER_SEC; + /* advertising better be stopped! */ assert(ble_ll_adv_enabled() == 0); @@ -606,7 +612,7 @@ bletest_execute(void) /* Toggle LED at set rate */ if ((int32_t)(os_time_get() - g_bletest_next_led_time) >= 0) { gpio_toggle(LED_BLINK_PIN); - g_bletest_next_led_time = g_bletest_led_rate; + g_bletest_next_led_time = os_time_get() + g_bletest_led_rate; } #if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER) bletest_execute_advertiser();