-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBLEPad_UART.cpp
59 lines (46 loc) · 1.2 KB
/
BLEPad_UART.cpp
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
#include "BLEPad_UART.h"
#define PIN_WAKEUP 8
#define PIN_CONFIG 5
#define PIN_SELECT_MODE 11
BLEPad_UART::BLEPad_UART(HardwareSerial &s) {
hs = &s;
};
void BLEPad_UART::begin(unsigned long baud) {
pinMode(PIN_WAKEUP, OUTPUT);
digitalWrite(PIN_WAKEUP, LOW);
hs->begin(baud);
}
void BLEPad_UART::end(void) {
digitalWrite(PIN_WAKEUP, HIGH);
hs->end();
}
size_t BLEPad_UART::write(uint8_t c) {
return hs->write(c);
}
void BLEPad_UART::println(const char data[]) {
hs->println(data);
}
size_t BLEPad_UART::println(int n, int base) {
return hs->println(n, base);
}
int BLEPad_UART::read() {
return hs->read();
}
int BLEPad_UART::available() {
return hs->available();
}
void BLEPad_UART::flush(void) {
hs->flush();
}
int BLEPad_UART::peek(void) {
return hs->peek();
}
void BLEPad_UART::setConfigMode(bool mode) {
pinMode(PIN_CONFIG, OUTPUT);
digitalWrite(PIN_CONFIG, mode ? LOW : HIGH);
}
// Work only for firmware version >= 5.0
void BLEPad_UART::setRole(int role) {
pinMode(PIN_SELECT_MODE, OUTPUT);
digitalWrite(PIN_SELECT_MODE, role == BLEPAD_SLAVE_MODE ? HIGH : LOW);
}