mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
oops - re-add central capabilitties after refactor
This commit is contained in:
parent
5af5fcea35
commit
9c30ff729a
@ -701,6 +701,7 @@ void jswrap_nrf_bluetooth_setTxPower(JsVarInt pwr) {
|
||||
"type" : "staticmethod",
|
||||
"class" : "NRF",
|
||||
"name" : "connect",
|
||||
"#ifdef" : "NRF52",
|
||||
"generate" : "jswrap_nrf_bluetooth_connect",
|
||||
"params" : [
|
||||
["mac","JsVar","The MAC address to connect to"]
|
||||
@ -719,22 +720,7 @@ void jswrap_nrf_bluetooth_connect(JsVar *mac) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t err_code;
|
||||
ble_gap_scan_params_t m_scan_param;
|
||||
m_scan_param.active = 0; // Active scanning set.
|
||||
m_scan_param.interval = SCAN_INTERVAL;// Scan interval.
|
||||
m_scan_param.window = SCAN_WINDOW; // Scan window.
|
||||
m_scan_param.timeout = 0x0000; // No timeout.
|
||||
|
||||
ble_gap_conn_params_t gap_conn_params;
|
||||
gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
|
||||
gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
|
||||
gap_conn_params.slave_latency = SLAVE_LATENCY;
|
||||
gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;
|
||||
|
||||
err_code = sd_ble_gap_connect(&peer_addr, &m_scan_param, &gap_conn_params);
|
||||
if (err_code)
|
||||
jsExceptionHere(JSET_ERROR, "Got BLE error code %d", err_code);
|
||||
jsble_central_connect(peer_addr);
|
||||
#else
|
||||
jsExceptionHere(JSET_ERROR, "Unimplemented");
|
||||
#endif
|
||||
|
||||
@ -44,15 +44,6 @@
|
||||
// -----------------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------
|
||||
|
||||
#ifdef NRF52
|
||||
// nRF52 gets the ability to connect to other
|
||||
#define CENTRAL_LINK_COUNT 1 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
#else
|
||||
#define CENTRAL_LINK_COUNT 0 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
#endif
|
||||
|
||||
#if (NRF_SD_BLE_API_VERSION == 3)
|
||||
#define NRF_BLE_MAX_MTU_SIZE GATT_MTU_SIZE_DEFAULT /**< MTU size used in the softdevice enabling and to reply to a BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST event. */
|
||||
#endif
|
||||
@ -1189,3 +1180,25 @@ void jsble_nfc_start(const uint8_t *data, size_t len) {
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if CENTRAL_LINK_COUNT>0
|
||||
void jsble_central_connect(ble_gap_addr_t peer_addr) {
|
||||
uint32_t err_code;
|
||||
ble_gap_scan_params_t m_scan_param;
|
||||
m_scan_param.active = 0; // Active scanning set.
|
||||
m_scan_param.interval = SCAN_INTERVAL;// Scan interval.
|
||||
m_scan_param.window = SCAN_WINDOW; // Scan window.
|
||||
m_scan_param.timeout = 0x0000; // No timeout.
|
||||
|
||||
ble_gap_conn_params_t gap_conn_params;
|
||||
gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
|
||||
gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
|
||||
gap_conn_params.slave_latency = SLAVE_LATENCY;
|
||||
gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;
|
||||
|
||||
err_code = sd_ble_gap_connect(&peer_addr, &m_scan_param, &gap_conn_params);
|
||||
if (err_code)
|
||||
jsExceptionHere(JSET_ERROR, "Got BLE error code %d", err_code);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -15,6 +15,15 @@
|
||||
#include "ble.h"
|
||||
#include "ble_advdata.h"
|
||||
|
||||
#ifdef NRF52
|
||||
// nRF52 gets the ability to connect to other
|
||||
#define CENTRAL_LINK_COUNT 1 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
#else
|
||||
#define CENTRAL_LINK_COUNT 0 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
#endif
|
||||
|
||||
#define APP_TIMER_OP_QUEUE_SIZE 1 /**< Size of timer operation queues. */
|
||||
#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
|
||||
|
||||
@ -94,3 +103,7 @@ void jsble_setup_advdata(ble_advdata_t *advdata);
|
||||
void jsble_nfc_stop();
|
||||
void jsble_nfc_start(const uint8_t *data, size_t len);
|
||||
#endif
|
||||
|
||||
#if CENTRAL_LINK_COUNT>0
|
||||
void jsble_central_connect(ble_gap_addr_t peer_addr);
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user