Skip to content

Commit

Permalink
Added action_delayer
Browse files Browse the repository at this point in the history
  • Loading branch information
aangerma committed Jan 2, 2020
1 parent 600cbc0 commit 7703838
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/l500/l500-color.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,22 @@ namespace librealsense
return get_color_recommended_proccesing_blocks();
}

void start(frame_callback_ptr callback) override
{
_action_delayer.do_after_delay([&]() {
synthetic_sensor::start(callback);
});
}

void stop() override
{
_action_delayer.do_after_delay([&]() {
synthetic_sensor::stop();
});
}
private:
const l500_color* _owner;
action_delayer _action_delayer;
};

}
16 changes: 10 additions & 6 deletions src/l500/l500-depth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,20 @@ namespace librealsense

void l500_depth_sensor::start(frame_callback_ptr callback)
{
if(_depth_invalidation_enabled)
synthetic_sensor::start(std::make_shared<frame_validator>(shared_from_this(), callback, _user_requests, _validator_requests));
else
synthetic_sensor::start(callback);
_action_delayer.do_after_delay([&]() {
if (_depth_invalidation_enabled)
synthetic_sensor::start(std::make_shared<frame_validator>(shared_from_this(), callback, _user_requests, _validator_requests));
else
synthetic_sensor::start(callback);
});
}

void l500_depth_sensor::stop()
{
synthetic_sensor::stop();
_depth_invalidation_option->set_streaming(false);
_action_delayer.do_after_delay([&]() {
synthetic_sensor::stop();
_depth_invalidation_option->set_streaming(false);
});
}

void l500_depth_sensor::open(const stream_profiles& requests)
Expand Down
1 change: 1 addition & 0 deletions src/l500/l500-depth.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ namespace librealsense
void stop() override;
float get_depth_offset() const;
private:
action_delayer _action_delayer;
const l500_device* _owner;
float _depth_units;
stream_profiles _user_requests;
Expand Down
28 changes: 28 additions & 0 deletions src/l500/l500-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,32 @@ namespace librealsense
public:
notification decode(int value) override;
};

class action_delayer
{
public:

void do_after_delay(std::function<void()> action, int milliseconds = 2000)
{
wait(milliseconds);
action();
_last_update = std::chrono::system_clock::now();
}

private:
void wait(int milliseconds)
{
auto now = std::chrono::system_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(now - _last_update).count();

while (diff < milliseconds)
{
std::this_thread::sleep_for(std::chrono::milliseconds(5));
now = std::chrono::system_clock::now();
diff = std::chrono::duration_cast<std::chrono::milliseconds>(now - _last_update).count();
}
}

std::chrono::system_clock::time_point _last_update;
};
}

0 comments on commit 7703838

Please sign in to comment.