-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathRFduinoBLE.cpp
More file actions
129 lines (106 loc) · 3.88 KB
/
RFduinoBLE.cpp
File metadata and controls
129 lines (106 loc) · 3.88 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Copyright (c) 2013 OpenSourceRF.com. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "Arduino.h"
#include "RFduinoBLE.h"
volatile int& RFduinoBLEClass::radioActive = RFduinoBLE_radioActive;
RFduinoBLEClass::RFduinoBLEClass()
{
::RFduinoBLE_used = 1;
customUUID = "";
deviceName = "RFduino";
advertisementData = "sketch";
iBeacon = false;
// iBeacon Proximity UUID
uint8_t uuid[16] = {0xE2, 0xC5, 0x6D, 0xB5, 0xDF, 0xFB, 0x48, 0xD2, 0xB0, 0x60, 0xD0, 0xF5, 0xA7, 0x10, 0x96, 0xE0};
memcpy(iBeaconUUID, uuid, sizeof(iBeaconUUID));
iBeaconMajor = 0;
iBeaconMinor = 0;
iBeaconMeasuredPower = 0xC5;
advertisementInterval = 80;
txPowerLevel = +4;
connectable = true;
}
int RFduinoBLEClass::begin()
{
// declared in variant.h
extern bool override_uart_limit;
if (! override_uart_limit)
{
if (UART0_State != UART0_State_NotStarted && UART0_BaudRate() > 9600)
{
const char *error = "BLE + UART > 9600 baud not permitted due to critical BLE timing requirements.\r\n"
"To override, add: override_uart_limit = true; to the top of setup() in your sketch.";
// attempt to notify user of error condition
const char *p = error;
while (*p)
UART0_TX(*p++);
// don't continue
while (1)
;
}
}
RFduinoBLE_custom_uuid = customUUID;
RFduinoBLE_device_name = deviceName;
RFduinoBLE_advertisement_data = advertisementData;
RFduinoBLE_ibeacon = iBeacon;
memcpy(RFduinoBLE_ibeacon_uuid, iBeaconUUID, sizeof(RFduinoBLE_ibeacon_uuid));
RFduinoBLE_ibeacon_major = iBeaconMajor;
RFduinoBLE_ibeacon_minor = iBeaconMinor;
RFduinoBLE_ibeacon_measured_power = iBeaconMeasuredPower;
RFduinoBLE_advertisement_interval = advertisementInterval;
RFduinoBLE_tx_power_level = txPowerLevel;
RFduinoBLE_connectable = connectable;
return RFduinoBLE_begin();
}
void RFduinoBLEClass::end()
{
RFduinoBLE_end();
}
bool RFduinoBLEClass::send(char data)
{
return RFduinoBLE_send(&data, 1);
}
bool RFduinoBLEClass::send(const char *data, int len)
{
return RFduinoBLE_send(data, len);
}
bool RFduinoBLEClass::sendByte(uint8_t data)
{
return RFduinoBLE_send((char*)&data, 1);
}
bool RFduinoBLEClass::sendInt(int data)
{
return RFduinoBLE_send((char*)&data, sizeof(int));
}
bool RFduinoBLEClass::sendFloat(float data)
{
return RFduinoBLE_send((char*)&data, sizeof(float));
}
void RFduinoBLEClass::updateConnInterval(int min_conn_interval_ms, int max_conn_interval_ms)
{
RFduinoBLE_update_conn_interval(min_conn_interval_ms, max_conn_interval_ms);
}
int RFduinoBLEClass::getConnInterval(void)
{
return RFduinoBLE_get_conn_interval();
}
RFduinoBLEClass RFduinoBLE;