Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (68 loc) · 2.08 KB
/
Copy pathmain.cpp
File metadata and controls
74 lines (68 loc) · 2.08 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
#include <csignal>
#include <iostream>
#include <cstring>
#include "kinect2pipe.h"
static Kinect2Pipe* g_pipe = nullptr;
static int g_stop_count = 0;
void signalHandler(int signum) {
if (signum == SIGINT || signum == SIGTERM) {
g_stop_count++;
if (g_stop_count > 1) {
std::cout << "\nForce exiting..." << std::endl;
exit(0);
}
std::cout << "\nStopping kinect2pipe..." << std::endl;
if (g_pipe != nullptr) {
g_pipe->stop();
}
} else if (signum == SIGUSR1) {
if (g_pipe != nullptr) {
g_pipe->toggleNightVision();
}
} else if (signum == SIGUSR2) {
if (g_pipe != nullptr) {
g_pipe->toggleBoost();
}
}
}
/**
* Main is the entry point for the application. It takes a single argument which should be the path to the v4l2loopback
* device to watch.
* @param argc Number of command line arguments.
* @param argv Command line arguments.
* @return Exit status
*/
int main(int argc, char** argv) {
const char* devices[2] = {nullptr, nullptr};
int deviceCount = 0;
bool irShm = false;
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--ir") == 0) {
irShm = true;
} else if (argv[i][0] == '-' || deviceCount >= 2) {
deviceCount = -1;
break;
} else {
devices[deviceCount++] = argv[i];
}
}
if (deviceCount < 1) {
printf("usage: kinect2pipe [--ir] <primary v4l2 device> [secondary v4l2 device]\n");
printf(" --ir also stream raw IR + depth (512x424) to /dev/shm/kinect2pipe_ir_shm alongside color\n");
exit(-1);
}
struct sigaction sa{};
sa.sa_handler = signalHandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
sigaction(SIGUSR1, &sa, nullptr);
sigaction(SIGUSR2, &sa, nullptr);
g_pipe = new Kinect2Pipe(irShm);
g_pipe->openLoopback(devices[0], devices[1]);
g_pipe->run();
delete g_pipe;
g_pipe = nullptr;
return 0;
}