forked from joshmarvel/MorseItBLE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BluefruitRoutines.h
58 lines (53 loc) · 1.52 KB
/
BluefruitRoutines.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
/* This is all the blueprint specific code for all of our
* iOS switch control example code. We have moved it here to make
* the main source code more legible.
*/
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "BluefruitConfig.h"
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
/* Set to 1 to factory reset and forget all paired devices.
* Make sure to set it back to one after upload, otherwise the unit
* won't remember paired devices. Useful to keep enabled during
* testing however.
*/
#define FACTORYRESET_ENABLE 0
//Debug output routines
#if (MY_DEBUG)
#define MESSAGE(m) Serial.println(m);
#define FATAL(m) {MESSAGE(m); while (1);}
#else
#define MESSAGE(m) {}
#define FATAL(m) while (1);
#endif
void initializeBluefruit (void) {
//Initialize Bluetooth
if ( !ble.begin(MY_DEBUG))
{
FATAL(F("NO BLE?"));
}
if ( FACTORYRESET_ENABLE )
{
// Perform a factory reset
Serial.println(F("Performing a factory reset: "));
if ( ! ble.factoryReset() ){
FATAL(F("err: reset failed"));
}
}
//Rename device
if (! ble.sendCommandCheckOK(F( "AT+GAPDEVNAME=MorseKey" )) ) {
FATAL(F("err:rename fail"));
}
//Enable HID keyboard
if(!ble.sendCommandCheckOK(F( "AT+BleHIDEn=On" ))) {
FATAL(F("err:enable Kb"));
}
if (! ble.sendCommandCheckOK(F( "AT+BleKeyboardEn=On" ))) {
FATAL(F("err: enable Kb"));
}
//Add or remove service requires a reset
if (! ble.reset() ) {
FATAL(F("err:SW reset"));
}
}