@@ -48,6 +48,27 @@ void sigint_handler(int s)
4848 protonect_shutdown = true ;
4949}
5050
51+ bool protonect_paused = false ;
52+ libfreenect2::Freenect2Device *devtopause;
53+
54+ // Doing non-trivial things in signal handler is bad. If you want to pause,
55+ // do it in another thread.
56+ // Though libusb operations are generally thread safe, I cannot guarantee
57+ // everything above is thread safe when calling start()/stop() while
58+ // waitForNewFrame().
59+ void sigusr1_handler (int s)
60+ {
61+ if (devtopause == 0 )
62+ return ;
63+ // / [pause]
64+ if (protonect_paused)
65+ devtopause->start ();
66+ else
67+ devtopause->stop ();
68+ protonect_paused = !protonect_paused;
69+ // / [pause]
70+ }
71+
5172// The following demostrates how to create a custom logger
5273// / [logger]
5374#include < fstream>
@@ -91,6 +112,7 @@ int main(int argc, char *argv[])
91112 std::string program_path (argv[0 ]);
92113 std::cerr << " Environment variables: LOGFILE=<protonect.log>" << std::endl;
93114 std::cerr << " Usage: " << program_path << " [gl | cl | cpu] [<device serial>] [-noviewer]" << std::endl;
115+ std::cerr << " To pause and unpause: pkill -USR1 Protonect" << std::endl;
94116 size_t executable_name_idx = program_path.rfind (" Protonect" );
95117
96118 std::string binpath = " /" ;
@@ -193,7 +215,12 @@ int main(int argc, char *argv[])
193215 return -1 ;
194216 }
195217
218+ devtopause = dev;
219+
196220 signal (SIGINT,sigint_handler);
221+ #ifdef SIGUSR1
222+ signal (SIGUSR1, sigusr1_handler);
223+ #endif
197224 protonect_shutdown = false ;
198225
199226// / [listeners]
0 commit comments