-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtcomm_test.c
executable file
·105 lines (88 loc) · 2.82 KB
/
btcomm_test.c
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
/* EV3 API
* Copyright (C) 2018-2019 Francisco Estrada and Lioudmila Tishkina
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Initial testing of a bare-bones BlueTooth communication
// library for the EV3 - Thank you Lego for changing everything
// from the NXT to the EV3!
#include "btcomm.h"
#include <time.h>
#include <ncurses.h>
#define debug
int main(int argc, char *argv[]) {
char test_msg[8] = {0x06, 0x00, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x01};
char reply[1024];
int tone_data[50][3];
// Reset tone data information
for (int i = 0; i < 50; i++) {
tone_data[i][0] = -1;
tone_data[i][1] = -1;
tone_data[i][2] = -1;
}
tone_data[0][0] = 262;
tone_data[0][1] = 250;
tone_data[0][2] = 1;
tone_data[1][0] = 330;
tone_data[1][1] = 250;
tone_data[1][2] = 25;
tone_data[2][0] = 392;
tone_data[2][1] = 250;
tone_data[2][2] = 50;
tone_data[3][0] = 523;
tone_data[3][1] = 250;
tone_data[3][2] = 63;
memset(&reply[0], 0, 1024);
// just uncomment your bot's hex key to compile for your bot, and comment the
// other ones out.
#ifndef HEXKEY
#define HEXKEY "00:16:53:56:56:03" // <--- SET UP YOUR EV3's HEX ID here
#endif
BT_open(HEXKEY);
// name must not contain spaces or special characters
// max name length is 12 characters
BT_setEV3name("R2D2");
//BT_play_tone_sequence(tone_data);
initscr();
cbreak();
//noecho();
nodelay(stdscr, TRUE);
//scrollok(stdscr, TRUE);
for (;;) {
int a = getch();
if (a == 'a') {
BT_timed_motor_port_start_v2(MOTOR_C, 70, 50);
} else if (a == 'd') {
BT_timed_motor_port_start_v2(MOTOR_C, -70, 50);
} else if (a == 's') {
BT_timed_motor_port_start_v2(MOTOR_A, 100, 50);
BT_motor_port_stop(MOTOR_A, 1); // Active braking
} else if (a == 'w') {
BT_timed_motor_port_start_v2(MOTOR_A, -100, 50);
//BT_motor_port_stop(MOTOR_A, 1); // Active braking
} else if (a == 'q') {
BT_timed_motor_port_start_v2(MOTOR_D, 60, 25);
} else if (a == 'e') {
BT_timed_motor_port_start_v2(MOTOR_D, -60, 25);
} else if (a == 'x') {
break;
}
refresh();
}
nocbreak();
//echo();
BT_all_stop(0); // Allow for free rotation of the motors
BT_close();
fprintf(stderr, "Done!\n");
}