Repository navigation
Expand file tree
/
Copy pathEnobioSensor.cpp
More file actions
84 lines (77 loc) · 2.27 KB
/
Copy pathEnobioSensor.cpp
File metadata and controls
84 lines (77 loc) · 2.27 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
#include "EnobioSensor.h"
using namespace SensorLib;
__declspec(dllexport) EnobioSensor::EnobioSensor(void) {
type = EEG;
name = "enobio";
status = NOT_CONNECTED;
lslrunning = false;
numChannels = 8;
samplingRate = 500;
}
EnobioSensor::~EnobioSensor(void) {
}
SensorStatus EnobioSensor::getStatus() {
return status;
}
__declspec(dllexport) void EnobioSensor::connect() {
status = BUSY;
lslrunning = true;
lsl_thread = new std::thread(&EnobioSensor::lsl_worker, this);
std::cout << "Enobio: Searching for stream.." << std::endl;
}
__declspec(dllexport) void EnobioSensor::disconnect() {
lslrunning = false;
}
//LSL inlet will be provided by NIC application, this just checks if it is available
void EnobioSensor::lsl_worker() {
SensorStatus tempStatus;
threadRunning = true;
while (!shouldShutDown) {
Sleep(2000);
std::vector<lsl::stream_info> results = lsl::resolve_stream("type", "EEG",1,5);
tempStatus = NOT_CONNECTED;
for (size_t i = 0; i < results.size(); i++) {
if (!strcmp(results[i].name().c_str(), "enobio")) {
if (!currentRecording && shouldRecord) {
std::cout << "Enobio: Starting recording" << std::endl;
currentRecording = recorder->startRecording(this);
statusUpdate(STREAMING);
tempStatus = RECORDING;
}
else if (currentRecording && !shouldRecord) {
statusUpdate(STREAMING);
tempStatus = STREAMING;
std::cout << "Enobio: Stopping recording" << std::endl;
delete currentRecording;
currentRecording = NULL;
}
else if (currentRecording && shouldRecord) {
std::cout << "Enobio: Recording" << std::endl;
statusUpdate(RECORDING);
tempStatus = RECORDING;
}
else {
statusUpdate(STREAMING);
tempStatus = STREAMING;
}
break;
}
}
if (status == NOT_CONNECTED) {
std::cout << "Enobio: Stream does not exist" << std::endl;
if (currentRecording) {
std::cout << "Enobio: Stopping recording since stream ceased to exist" << std::endl;
delete currentRecording;
currentRecording = NULL;
}
}
}
status = NOT_CONNECTED;
std::cout << "Enobio: Shutting down.." << std::endl;
if (currentRecording) {
std::cout << "Enobio: Stopping recording before shutting down" << std::endl;
delete currentRecording;
currentRecording = NULL;
}
threadRunning = false;
}