-
-
Notifications
You must be signed in to change notification settings - Fork 736
/
jswrap_bluetooth.h
106 lines (94 loc) · 5.14 KB
/
jswrap_bluetooth.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
*
* Copyright (C) 2016 Gordon Williams <gw@pur3.co.uk>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* ----------------------------------------------------------------------------
* Contains JavaScript interface for nRF51/52 bluetooth
* ----------------------------------------------------------------------------
*/
#include "jspin.h"
// ------------------------------------------------------------------------------
typedef enum {
BLETASK_NONE,
BLETASK_REQUEST_DEVICE, ///< Waiting for requestDevice to finish
BLETASK_CENTRAL_START, // =========================================== Start of central tasks
BLETASK_CONNECT = BLETASK_CENTRAL_START, ///< Connect in central mode
BLETASK_PRIMARYSERVICE, ///< Find primary service
BLETASK_CHARACTERISTIC, ///< Find characteristics
BLETASK_CHARACTERISTIC_WRITE, ///< Write to a characteristic
BLETASK_CHARACTERISTIC_READ, ///< Read from a characteristic
BLETASK_CHARACTERISTIC_DESC_AND_STARTNOTIFY, ///< Discover descriptors and start notifications
BLETASK_CHARACTERISTIC_NOTIFY, ///< Setting whether notifications are on or off
BLETASK_BONDING, ///< Try and bond in central mode
BLETASK_CENTRAL_END = BLETASK_CHARACTERISTIC_NOTIFY // ============= End of central tasks
} BleTask;
// Is this task related to BLE central mode?
#define BLETASK_IS_CENTRAL(x) ((x)>=BLETASK_CENTRAL_START && ((x)<=BLETASK_CENTRAL_END))
extern JsVar *bleTaskInfo; // info related to the current task
bool bleInTask(BleTask task);
BleTask bleGetCurrentTask();
bool bleNewTask(BleTask task, JsVar *taskInfo);
void bleCompleteTaskSuccess(BleTask task, JsVar *data);
void bleCompleteTaskSuccessAndUnLock(BleTask task, JsVar *data);
void bleCompleteTaskFail(BleTask task, JsVar *data);
void bleCompleteTaskFailAndUnLock(BleTask task, JsVar *data);
void bleSwitchTask(BleTask task);
#ifdef NRF52
// Set the currently active GATT server
void bleSetActiveBluetoothGattServer(JsVar *var);
// Get the currently active GATT server (the return value needs unlocking)
JsVar *bleGetActiveBluetoothGattServer();
#endif
// ------------------------------------------------------------------------------
void jswrap_nrf_init();
bool jswrap_nrf_idle();
void jswrap_nrf_kill();
// Used to dump bluetooth initialisation info for 'dump'
void jswrap_nrf_dumpBluetoothInitialisation(vcbprintf_callback user_callback, void *user_data);
/** Reconfigure the softdevice (on init or after restart) to have all the services/advertising we need */
void jswrap_nrf_reconfigure_softdevice();
// ------------------------------------------------------------------------------
void jswrap_nrf_bluetooth_disconnect();
void jswrap_nrf_bluetooth_sleep();
void jswrap_nrf_bluetooth_wake();
void jswrap_nrf_bluetooth_restart();
JsVar *jswrap_nrf_bluetooth_getAddress();
JsVarFloat jswrap_nrf_bluetooth_getBattery();
void jswrap_nrf_bluetooth_setAdvertising(JsVar *data, JsVar *options);
JsVar *jswrap_nrf_bluetooth_getAdvertisingData(JsVar *data, JsVar *options);
void jswrap_nrf_bluetooth_setScanResponse(JsVar *data);
void jswrap_nrf_bluetooth_setServices(JsVar *data, JsVar *options);
void jswrap_nrf_bluetooth_updateServices(JsVar *data);
void jswrap_nrf_bluetooth_setScan(JsVar *callback);
void jswrap_nrf_bluetooth_findDevices(JsVar *callback, JsVar *timeout);
void jswrap_nrf_bluetooth_setRSSIHandler(JsVar *callback);
void jswrap_nrf_bluetooth_setTxPower(JsVarInt pwr);
void jswrap_nrf_bluetooth_setLowPowerConnection(bool lowPower);
void jswrap_nrf_nfcURL(JsVar *url);
void jswrap_nrf_nfcRaw(JsVar *payload);
JsVar *jswrap_nrf_nfcStart(JsVar *payload);
void jswrap_nrf_nfcStop();
void jswrap_nrf_nfcSend(JsVar *payload);
void jswrap_nrf_sendHIDReport(JsVar *data, JsVar *callback);
JsVar *jswrap_nrf_bluetooth_requestDevice(JsVar *options);
JsVar *jswrap_nrf_bluetooth_connect(JsVar *mac);
void jswrap_nrf_setWhitelist(bool whitelist);
JsVar *jswrap_BluetoothDevice_gatt(JsVar *parent);
JsVar *jswrap_nrf_BluetoothRemoteGATTServer_connect(JsVar *parent);
void jswrap_BluetoothRemoteGATTServer_disconnect(JsVar *parent);
JsVar *jswrap_nrf_BluetoothRemoteGATTServer_startBonding(JsVar *parent, bool forceRePair);
JsVar *jswrap_nrf_BluetoothRemoteGATTServer_getSecurityStatus(JsVar *parent);
JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryService(JsVar *parent, JsVar *service);
JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryServices(JsVar *parent);
void jswrap_BluetoothRemoteGATTServer_setRSSIHandler(JsVar *parent, JsVar *callback);
JsVar *jswrap_BluetoothRemoteGATTService_getCharacteristic(JsVar *parent, JsVar *characteristic);
JsVar *jswrap_BluetoothRemoteGATTService_getCharacteristics(JsVar *parent);
JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_writeValue(JsVar *characteristic, JsVar *data);
JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_readValue(JsVar *characteristic);
JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_startNotifications(JsVar *characteristic);
JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_stopNotifications(JsVar *characteristic);