Commit 25626ba3 authored by schneider's avatar schneider

fix(ble): Correctly switch between ADV modes

parent 8458ce6e
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
#include "modules/log.h" #include "modules/log.h"
static bool active; static bool active;
static uint8_t advertising_mode = APP_MODE_NONE;
static uint8_t advertising_mode_target = APP_MODE_NONE;
static enum ble_event_type ble_event; static enum ble_event_type ble_event;
/************************************************************************************************** /**************************************************************************************************
...@@ -355,15 +357,9 @@ static void bleSetup(bleMsg_t *pMsg) ...@@ -355,15 +357,9 @@ static void bleSetup(bleMsg_t *pMsg)
AppAdvSetData(APP_ADV_DATA_CONNECTABLE, 0, NULL); AppAdvSetData(APP_ADV_DATA_CONNECTABLE, 0, NULL);
AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, 0, NULL); AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, 0, NULL);
/* We only want to be bondable when the appropriate dialog is open */
AppSetBondable(FALSE);
/* TODO: Sadly, not advertising leads to a higher current consumption... */
if(AppDbCheckBonded() == FALSE) {
AppAdvStop();
} else {
AppAdvStart(APP_MODE_CONNECTABLE);
}
active = true; active = true;
/* TODO: Sadly, not advertising leads to a higher current consumption... */
epic_ble_set_bondable(false);
} }
void epic_ble_set_bondable(bool bondable) void epic_ble_set_bondable(bool bondable)
...@@ -373,18 +369,47 @@ void epic_ble_set_bondable(bool bondable) ...@@ -373,18 +369,47 @@ void epic_ble_set_bondable(bool bondable)
} }
if(bondable) { if(bondable) {
LOG_INFO("ble", "Making bondable and discoverable");
/* We need to stop advertising in between or the /* We need to stop advertising in between or the
* adv set will not be changed... */ * adv set will not be changed.
AppAdvStop(); * Also need to wait for the stop operation to finish
* before we can start again
* Also need to set the variables first as we don't
* have a lock on the stack.*/
AppSetBondable(TRUE); AppSetBondable(TRUE);
AppAdvStart(APP_MODE_DISCOVERABLE); if(advertising_mode != APP_MODE_DISCOVERABLE) {
LOG_INFO("ble", "Making bondable and discoverable");
if(advertising_mode != APP_MODE_NONE) {
advertising_mode_target = APP_MODE_DISCOVERABLE;
advertising_mode = APP_MODE_NONE;
AppAdvStop();
} else {
advertising_mode = APP_MODE_DISCOVERABLE;
advertising_mode_target = APP_MODE_DISCOVERABLE;
AppAdvStart(advertising_mode);
}
}
} else { } else {
LOG_INFO("ble", "Making connectable");
AppAdvStop();
AppSetBondable(FALSE); AppSetBondable(FALSE);
if(AppDbCheckBonded()) { if(AppDbCheckBonded()) {
AppAdvStart(APP_MODE_CONNECTABLE); if(advertising_mode != APP_MODE_CONNECTABLE) {
LOG_INFO("ble", "Bonded. Making connectable");
if(advertising_mode != APP_MODE_NONE) {
advertising_mode_target = APP_MODE_CONNECTABLE;
advertising_mode = APP_MODE_NONE;
AppAdvStop();
} else {
advertising_mode = APP_MODE_CONNECTABLE;
advertising_mode_target = APP_MODE_CONNECTABLE;
AppAdvStart(advertising_mode);
}
}
} else {
if(advertising_mode != APP_MODE_NONE) {
LOG_INFO("ble", "Not bonded. Stop advertising");
advertising_mode = APP_MODE_NONE;
advertising_mode_target = APP_MODE_NONE;
AppAdvStop();
}
} }
} }
} }
...@@ -475,7 +500,11 @@ static void bleProcMsg(bleMsg_t *pMsg) ...@@ -475,7 +500,11 @@ static void bleProcMsg(bleMsg_t *pMsg)
break; break;
case DM_ADV_STOP_IND: case DM_ADV_STOP_IND:
LOG_INFO("ble", "Advertisement stopped"); LOG_INFO("ble", "Advertisement stopped %u %u", advertising_mode, advertising_mode_target);
if(advertising_mode != advertising_mode_target) {
advertising_mode = advertising_mode_target;
AppAdvStart(advertising_mode);
}
break; break;
case DM_CONN_OPEN_IND: case DM_CONN_OPEN_IND:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment