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