Making ANCS mode configurable via NRF.setServices({},{ancs:true})

This commit is contained in:
Gordon Williams 2021-05-17 15:34:35 +01:00
parent cff03201a0
commit 17eea39deb
3 changed files with 35 additions and 6 deletions

View File

@ -32,6 +32,9 @@
#define BLE_NAME_GATT_SERVER "BLE_GATTS"
#define BLE_NAME_SECURITY "BLE_SEC"
#define BLE_NAME_MAC_ADDRESS "BLE_MAC"
#if ESPR_BLUETOOTH_ANCS
#define BLE_NAME_ANCS "BLE_ANCS"
#endif
typedef enum {
BLE_FLAGS_NONE = 0,

View File

@ -1195,6 +1195,9 @@ void jswrap_ble_setServices(JsVar *data, JsVar *options) {
JsVar *use_hid = 0;
#endif
bool use_uart = true;
#if ESPR_BLUETOOTH_ANCS
bool use_ancs = false;
#endif
JsVar *advertise = 0;
jsvConfigObject configs[] = {
@ -1202,6 +1205,9 @@ void jswrap_ble_setServices(JsVar *data, JsVar *options) {
{"hid", JSV_ARRAY, &use_hid},
#endif
{"uart", JSV_BOOLEAN, &use_uart},
#if ESPR_BLUETOOTH_ANCS
{"ancs", JSV_BOOLEAN, &use_ancs},
#endif
{"advertise", JSV_ARRAY, &advertise},
};
if (!jsvReadConfigObject(options, configs, sizeof(configs) / sizeof(jsvConfigObject))) {
@ -1231,6 +1237,17 @@ void jswrap_ble_setServices(JsVar *data, JsVar *options) {
bleStatus |= BLE_NEEDS_SOFTDEVICE_RESTART;
jsvObjectSetChildAndUnLock(execInfo.hiddenRoot, BLE_NAME_NUS, jsvNewFromBool(false));
}
#if ESPR_BLUETOOTH_ANCS
if (use_ancs) {
if (!(bleStatus & BLE_ANCS_INITED))
bleStatus |= BLE_NEEDS_SOFTDEVICE_RESTART;
jsvObjectSetChildAndUnLock(execInfo.hiddenRoot, BLE_NAME_ANCS, jsvNewFromBool(true));
} else {
if (bleStatus & BLE_ANCS_INITED)
bleStatus |= BLE_NEEDS_SOFTDEVICE_RESTART;
jsvObjectRemoveChild(execInfo.hiddenRoot, BLE_NAME_ANCS);
}
#endif
// Save the current service data and options
jsvObjectSetOrRemoveChild(execInfo.hiddenRoot, BLE_NAME_SERVICE_DATA, data);

View File

@ -1121,7 +1121,8 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context) {
/*if (p_ble_evt->header.evt_id != 87) // ignore write complete
jsiConsolePrintf("[%d %d]\n", p_ble_evt->header.evt_id, p_ble_evt->evt.gattc_evt.params.hvx.handle );*/
#if ESPR_BLUETOOTH_ANCS
ble_ancs_on_ble_evt(p_ble_evt);
if (bleStatus & BLE_ANCS_INITED)
ble_ancs_on_ble_evt(p_ble_evt);
#endif
uint32_t err_code;
@ -1760,7 +1761,8 @@ static void pm_evt_handler(pm_evt_t const * p_evt) {
// You should check on what kind of white list policy your application should use.
}
#if ESPR_BLUETOOTH_ANCS
ble_ancs_bonding_succeeded(p_evt->conn_handle);
if (bleStatus & BLE_ANCS_INITED)
ble_ancs_bonding_succeeded(p_evt->conn_handle);
#endif
} break;
@ -2341,6 +2343,13 @@ static void services_init() {
}
jsvUnLock(hidReport);
#endif
#if ESPR_BLUETOOTH_ANCS
bool useANCS = jsvGetBoolAndUnLock(jsvObjectGetChild(execInfo.hiddenRoot, BLE_NAME_ANCS, 0));
if (useANCS) {
ble_ancs_init();
bleStatus |= BLE_ANCS_INITED;
}
#endif
}
uint32_t app_ram_base;
@ -2657,10 +2666,6 @@ void jsble_advertising_stop() {
services_init();
conn_params_init();
#if ESPR_BLUETOOTH_ANCS
ble_ancs_init();
#endif
// reset the status for things that aren't happening now we're rebooted
bleStatus &= ~BLE_RESET_ON_SOFTDEVICE_START;
@ -2674,6 +2679,10 @@ bool jsble_kill() {
bleStatus &= ~BLE_NUS_INITED;
// BLE HID doesn't need deinitialising (no ble_hids_kill)
bleStatus &= ~BLE_HID_INITED;
#if ESPR_BLUETOOTH_ANCS
// BLE ANCS doesn't need deinitialising
bleStatus &= ~BLE_ANCS_INITED;
#endif
uint32_t err_code;
#if NRF_SD_BLE_API_VERSION < 5
err_code = sd_softdevice_disable();