Repository navigation
Expand file tree
/
Copy pathSensorLibrary.cpp
More file actions
122 lines (113 loc) · 3.04 KB
/
Copy pathSensorLibrary.cpp
File metadata and controls
122 lines (113 loc) · 3.04 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
112
113
114
115
116
117
118
119
120
121
122
#include "stdafx.h"
#include "SensorLibrary.h"
#include "Recorder.h"
//#include "MyGazeSensor.h"
#include "MyGazeGTWSensor.h"
#include "EnobioSensor.h"
//#include "ShimmerSensor.h"
#include "GazeOutputSensor.h"
namespace SensorLib
{
SensorLibrary::SensorLibrary(void) {
std::wstring outputFolder = L"C://sensordata";
if (CreateDirectory(outputFolder.c_str(), NULL) ||
ERROR_ALREADY_EXISTS == GetLastError())
{
std::cout << "SensorLibrary: Created data folder" << std::endl;
}
sensors.push_back(new MyGazeGTWSensor);
sensors.push_back(new EnobioSensor);
//sensors.push_back(new ShimmerSensor);
sensors.push_back(new GazeOutputSensor);
recorder = std::shared_ptr<Recorder>(new Recorder());
for (size_t i = 0; i < sensors.size(); i++) {
sensors[i]->connect();
sensors[i]->recorder = recorder;
sensors[i]->shouldRecord = true;
sensors[i]->registerStatusUpdateCallback(this);
}
}
SensorLibrary::~SensorLibrary(void) {
stopRecording();
for (size_t i = 0; i < sensors.size(); i++) {
delete sensors[i];
}
}
void SensorLibrary::printStatus() {
for (int i = 0; i < sensors.size(); i++) {
std::cout << "Sensor ID:" << i << "\tName:" << sensors[i]->name << "\tStatus" << sensors[i]->getStatus() << std::endl;
}
}
void SensorLibrary::startRecording()
{
for (int i = 0; i < sensors.size(); i++) {
sensors[i]->shouldRecord = true;
}
/*
std::wstring outputFolder = L"../data";
if (CreateDirectory(outputFolder.c_str(), NULL) ||
ERROR_ALREADY_EXISTS == GetLastError())
{
std::time_t t = std::time(0);
std::ostringstream oss;
oss << "../data/" << t << ".xdf";
//actual filename generated afterwards
// recorder->startRecording(oss.str(), sensors);
}
*/
}
void SensorLibrary::stopRecording() {
for (int i = 0; i < sensors.size(); i++) {
sensors[i]->shouldRecord = false;
}
int i = 0;
while (true) {
bool isRecording = false;
for (int i = 0; i < sensors.size(); i++) {
if (sensors[i]->getStatus() == RECORDING) {
isRecording = true;
}
}
if (isRecording == false) {
break;
}
Sleep(500);
i++;
if (i > 20) {
std::cout << "SensorLibrary: Could not stop recording shutting down anyway" << std::endl;
break;
}
}
}
void SensorLibrary::shutdownSensors() {
stopRecording();
for (int i = 0; i < sensors.size(); i++) {
sensors[i]->shouldShutDown = true;
}
int i = 0;
while(true) {
bool isRunning = false;
for (int i = 0; i < sensors.size(); i++) {
if (sensors[i]->threadRunning) {
isRunning = true;
}
}
if (isRunning == false) {
break;
}
Sleep(500);
i++;
if (i > 20) {
std::cout << "SensorLibrary: Could not shutdown sensors properly, shutting down anyway" << std::endl;
break;
}
}
for (int i = 0; i < sensors.size(); i++) {
std::cout << "SensorLibrary: Shutting down the sensors" << std::endl;
sensors[i]->shouldShutDown = true;
}
}
void SensorLibrary::sensorUpdate(Sensor *sensor, SensorStatus status) {
std::cout << sensor->name << ": status upd " << status << std::endl;
}
}