stop device correctly

parent d47ca0b0
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <thread>
using namespace std; using namespace std;
using namespace cv; using namespace cv;
...@@ -44,6 +45,7 @@ std::function<void(std::string, int)> *faceCheckCallback; ...@@ -44,6 +45,7 @@ std::function<void(std::string, int)> *faceCheckCallback;
FaceDetection::Mode newMode; FaceDetection::Mode newMode;
bool started=false; bool started=false;
bool looping=false;
struct facePosition {int x, y, width, height; }; struct facePosition {int x, y, width, height; };
...@@ -71,7 +73,7 @@ void FaceDetector::Start( ...@@ -71,7 +73,7 @@ void FaceDetector::Start(
faceCheckCallback = &checkCallback; faceCheckCallback = &checkCallback;
faceFrameReadyCallback = &faceCallback; faceFrameReadyCallback = &faceCallback;
if(!started) if (!looping)
{ {
started = true; started = true;
Loop(); Loop();
...@@ -80,8 +82,9 @@ void FaceDetector::Start( ...@@ -80,8 +82,9 @@ void FaceDetector::Start(
/// ///
/// ///
void FaceDetector::Stop() { void FaceDetector::Stop()
started=false; {
started = false;
} }
/// ///
...@@ -145,6 +148,7 @@ int Loop() ...@@ -145,6 +148,7 @@ int Loop()
device->start(); device->start();
int trainClock = 0; int trainClock = 0;
looping = true;
while (started) while (started)
{ {
FaceDetection::Mode currentMode = newMode; FaceDetection::Mode currentMode = newMode;
...@@ -251,7 +255,7 @@ int Loop() ...@@ -251,7 +255,7 @@ int Loop()
{ {
writePLY(model, filename.c_str()); writePLY(model, filename.c_str());
printf("train switch, filename: %s\n",filename.c_str()); printf("train switch, filename: %s\n", filename.c_str());
(*faceSaveCallback)(filename); (*faceSaveCallback)(filename);
printf("callback fired"); printf("callback fired");
newMode = IDLE; newMode = IDLE;
...@@ -282,7 +286,18 @@ int Loop() ...@@ -282,7 +286,18 @@ int Loop()
} }
} }
if (device->is_streaming())
device->stop(); device->stop();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
for (int j = 0; j < 4; ++j)
{
auto s = (rs::stream) j;
if (device->is_stream_enabled(s)) device->disable_stream(s);
}
looping = false;
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment