diff --git a/epicardium/ble/ble_adv.c b/epicardium/ble/ble_adv.c index 51ff30918fd5e6b2c1792d19e8bd04060a661b52..6b129c50ace26a4babea13fa51d2e436121d75a5 100644 --- a/epicardium/ble/ble_adv.c +++ b/epicardium/ble/ble_adv.c @@ -137,11 +137,6 @@ void ble_adv_proc_msg(bleMsg_t *pMsg) } void ble_adv_init(void) -{ - pAppAdvCfg = (appAdvCfg_t *)&bleAdvCfg; -} - -void ble_adv_setup(void) { char buf[32]; char a, b, c, d, e, f, K; @@ -163,6 +158,11 @@ void ble_adv_setup(void) } /* clang-format on */ + pAppAdvCfg = (appAdvCfg_t *)&bleAdvCfg; +} + +void ble_adv_setup(void) +{ /* set advertising and scan response data for discoverable mode */ if (config_get_boolean_with_default("ble_hid_enable", false)) { AppAdvSetData( @@ -202,7 +202,7 @@ void ble_adv_stop(void) } } -void ble_adv_start(uint8_t mode) +static void adv_start(uint8_t mode) { if (advertising_mode != APP_MODE_NONE) { /* We need to stop advertising in between or the @@ -219,21 +219,29 @@ void ble_adv_start(uint8_t mode) advertising_mode_target = mode; AppAdvStart(advertising_mode); } + tainted = false; +} + +void ble_adv_start(uint8_t mode) +{ + adv_start(mode); + tainted = true; } void ble_adv_discoverable(bool discoverable) { if (discoverable) { - if (advertising_mode != APP_MODE_DISCOVERABLE) { + if (advertising_mode != APP_MODE_DISCOVERABLE || tainted) { LOG_INFO("ble", "Making bondable and discoverable"); - ble_adv_start(APP_MODE_DISCOVERABLE); + adv_start(APP_MODE_DISCOVERABLE); } } else { /* TODO: This does way more than the function name indicates */ if (AppDbCheckBonded()) { - if (advertising_mode != APP_MODE_CONNECTABLE) { + if (advertising_mode != APP_MODE_CONNECTABLE || + tainted) { LOG_INFO("ble", "Bonded. Making connectable"); - ble_adv_start(APP_MODE_CONNECTABLE); + adv_start(APP_MODE_CONNECTABLE); } } else { LOG_INFO("ble", "Not bonded. Stop advertising"); diff --git a/epicardium/modules/hardware.c b/epicardium/modules/hardware.c index fb413958ee0e090251e423e3661426c6fe3dfa85..de0d9d215c833b886ea89aeafa46043e5e38fa19 100644 --- a/epicardium/modules/hardware.c +++ b/epicardium/modules/hardware.c @@ -14,6 +14,7 @@ #include "pmic.h" #include "portexpander.h" #include "max86150.h" +#include "ble/ble_api.h" #include "gpio.h" #include "i2c.h" @@ -288,6 +289,11 @@ int hardware_reset(void) /* * BLE */ + + /* Reset advertisement data */ + ble_adv_setup(); + + /* Start advertising again if needed */ epic_ble_set_mode(false, false); return 0;