amiro-os / components / bluetooth / bluetooth.cpp @ 0f37fb41
History | View | Annotate | Download (1.843 KB)
1 | 58fe0e0b | Thomas Schöpping | #include <ch.hpp> |
---|---|---|---|
2 | #include <hal.h> |
||
3 | |||
4 | #include <string.h> |
||
5 | |||
6 | #include <amiro/bluetooth/bluetooth.hpp> |
||
7 | |||
8 | using namespace chibios_rt; |
||
9 | using namespace amiro; |
||
10 | |||
11 | /*
|
||
12 | * Class constructor
|
||
13 | */
|
||
14 | BLUETOOTH::BLUETOOTH(UARTDriver* uart) : iwrap(uart) { |
||
15 | } |
||
16 | |||
17 | /*
|
||
18 | * Member functions
|
||
19 | */
|
||
20 | void BLUETOOTH::bluetoothStart() {
|
||
21 | iwrap.start(NORMALPRIO); |
||
22 | BaseThread::sleep(MS2ST(1000));
|
||
23 | // Reset bluetooth chip to get the first msg. (cmd/data mode or mux Mode)
|
||
24 | bluetoothReset(); |
||
25 | } |
||
26 | |||
27 | void BLUETOOTH::bluetoothReset() {
|
||
28 | palWritePad(GPIOC, GPIOC_BT_RST, 1);
|
||
29 | BaseThread::sleep(MS2ST(10));
|
||
30 | palWritePad(GPIOC, GPIOC_BT_RST, 0);
|
||
31 | iwrap.transport.bluetoothTransportResetState(); |
||
32 | BaseThread::sleep(MS2ST(1000));
|
||
33 | } |
||
34 | |||
35 | void BLUETOOTH::bluetoothEnableMux() {
|
||
36 | iwrap.bluetoothIwrapSendCommand("SET CONTROL MUX 1");
|
||
37 | } |
||
38 | |||
39 | void BLUETOOTH::bluetoothDisableMux() {
|
||
40 | iwrap.bluetoothIwrapSendCommand("SET CONTROL MUX 0");
|
||
41 | } |
||
42 | |||
43 | void BLUETOOTH::bluetoothDiscoverDevices() {
|
||
44 | iwrap.bluetoothIwrapSendCommand("INQUIRY 5");
|
||
45 | BaseThread::sleep(MS2ST(6000));
|
||
46 | } |
||
47 | |||
48 | void BLUETOOTH::bluetoothListAllConnections() {
|
||
49 | iwrap.bluetoothIwrapSendCommand("List");
|
||
50 | } |
||
51 | |||
52 | void BLUETOOTH::bluetoothSetName(const char *name) { |
||
53 | int size = strlen(name) + 14; |
||
54 | char cmd[size];
|
||
55 | strcpy(cmd, "SET BT NAME ");
|
||
56 | strcat(cmd, name); |
||
57 | iwrap.bluetoothIwrapSendCommand(cmd); |
||
58 | } |
||
59 | |||
60 | void BLUETOOTH::bluetoothSetPin(const char *pin) { |
||
61 | int size = strlen(pin) + 15; |
||
62 | char cmd[size];
|
||
63 | strcpy(cmd, "SET BT AUTH * ");
|
||
64 | strcat(cmd, pin); |
||
65 | iwrap.bluetoothIwrapSendCommand(cmd); |
||
66 | } |
||
67 | |||
68 | void BLUETOOTH::bluetoothCloseConnection(uint8_t linkid) {
|
||
69 | char cmd[8]; |
||
70 | strcpy(cmd, "CLOSE ");
|
||
71 | cmd[6] = linkid + '0'; |
||
72 | cmd[7]= '\0'; |
||
73 | iwrap.bluetoothIwrapSendCommand(cmd); |
||
74 | } |
||
75 | |||
76 | void BLUETOOTH::bluetoothSendCommand(const char *cmd) { |
||
77 | iwrap.bluetoothIwrapSendCommand(cmd); |
||
78 | } |
||
79 | |||
80 | bool BLUETOOTH::bluetoothIsMuxMode() {
|
||
81 | return iwrap.transport.bluetoothTransportIsMuxMode();
|
||
82 | } |