-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest.cpp
More file actions
executable file
·111 lines (85 loc) · 3.29 KB
/
test.cpp
File metadata and controls
executable file
·111 lines (85 loc) · 3.29 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
#include "bitalino.h"
#include <stdio.h>
#ifdef _WIN32
#include <conio.h>
bool keypressed(void)
{
return (_kbhit() != 0);
}
#else // Linux or Mac OS
#include <sys/select.h>
bool keypressed(void)
{
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(0, &readfds);
timeval readtimeout;
readtimeout.tv_sec = 0;
readtimeout.tv_usec = 0;
return (select(FD_SETSIZE, &readfds, NULL, NULL, &readtimeout) == 1);
}
#endif
int main()
{
try
{
// uncomment this block to search for Bluetooth devices (Windows and Linux)
/*
BITalino::VDevInfo devs = BITalino::find();
for(int i = 0; i < devs.size(); i++)
printf("%s - %s\n", devs[i].macAddr.c_str(), devs[i].name.c_str());
return 0;
*/
puts("Connecting to device...");
// use one of the lines below
BITalino dev("98:D3:31:B2:11:6B"); // device MAC address (Windows and Linux)
//BITalino dev("COM5"); // Bluetooth virtual COM port or USB-UART COM port (Windows)
//BITalino dev("/dev/ttyUSB0"); // USB-UART device (Linux)
//BITalino dev("/dev/rfcomm0"); // Bluetooth virtual serial port (Linux)
//BITalino dev("/dev/tty.usbserial-A1000QIz"); // USB-UART device (Mac OS)
//BITalino dev("/dev/tty.bitalino-DevB"); // Bluetooth virtual serial port (Mac OS)
puts("Connected to device. Press Enter to exit.");
std::string ver = dev.version(); // get device version string
printf("BITalino version: %s\n", ver.c_str());
dev.battery(10); // set battery threshold (optional)
dev.start(1000, {0, 1, 2, 3, 4, 5}); // start acquisition of all channels at 1000 Hz
// use block below if your compiler doesn't support vector initializer lists
/*
BITalino::Vint chans;
chans.push_back(0);
chans.push_back(1);
chans.push_back(2);
chans.push_back(3);
chans.push_back(4);
chans.push_back(5);
dev.start(1000, chans);
*/
//dev.trigger({false, false, true, false}); // for original BITalino
//dev.trigger({true, false}); // for BITalino 2
// use block below if your compiler doesn't support vector initializer lists
/*
BITalino::Vbool outputs;
outputs.push_back(false);
outputs.push_back(false);
outputs.push_back(true);
outputs.push_back(false);
dev.trigger(outputs);
*/
BITalino::VFrame frames(100); // initialize the frames vector with 100 frames
do
{
dev.read(frames); // get 100 frames from device
const BITalino::Frame &f = frames[0]; // get a reference to the first frame of each 100 frames block
printf("%d : %d %d %d %d ; %d %d %d %d %d %d\n", // dump the first frame
f.seq,
f.digital[0], f.digital[1], f.digital[2], f.digital[3],
f.analog[0], f.analog[1], f.analog[2], f.analog[3], f.analog[4], f.analog[5]);
} while (!keypressed()); // until a key is pressed
dev.stop(); // stop acquisition
} // dev is destroyed here (it goes out of scope)
catch(BITalino::Exception &e)
{
printf("BITalino exception: %s\n", e.getDescription());
}
return 0;
}