feat(src): added feature of syncing timestamp for 200B

This commit is contained in:
Osenberg 2019-08-08 15:01:32 +08:00
parent 37b98e0d33
commit 190d066ddf
8 changed files with 104 additions and 2 deletions

View File

@ -252,6 +252,11 @@ class MYNTEYE_API API {
*/
void SetOptionValue(const Option &option, std::int32_t value);
/**
* Set the option value.
*/
bool SetOptionValue(const Option &option, std::uint64_t value);
/**
* Run the option action.
*/

View File

@ -223,6 +223,10 @@ class MYNTEYE_API Device {
* Set the option value.
*/
void SetOptionValue(const Option &option, std::int32_t value);
/**
* Set the option value.
*/
bool SetOptionValue(const Option &option, std::uint64_t value);
/**
* Run the option action.

View File

@ -125,6 +125,7 @@ make_executable2(ctrl_imu_low_pass_filter SRCS control/imu_low_pass_filter.cc WI
make_executable2(ctrl_imu_range SRCS control/imu_range.cc WITH_OPENCV)
make_executable2(ctrl_infrared SRCS control/infrared.cc WITH_OPENCV)
make_executable2(ctrl_iic_adress SRCS control/iic_address.cc WITH_OPENCV)
make_executable2(ctrl_sync_timestamp SRCS control/sync_timestamp.cc WITH_OPENCV)
make_executable2(ctrl_auto_exposure
SRCS control/auto_exposure.cc util/cv_painter.cc
WITH_OPENCV

View File

@ -0,0 +1,56 @@
#include <opencv2/highgui/highgui.hpp>
#include "mynteye/logger.h"
#include "mynteye/api/api.h"
MYNTEYE_USE_NAMESPACE
int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv);
if (!api) return 1;
bool ok;
auto &&request = api->SelectStreamRequest(&ok);
if (!ok) return 1;
api->ConfigStreamRequest(request);
Model model = api->GetModel();
if (model != Model::STANDARD200B) {
LOG(INFO) << "Sorry, This device don't support sync timestamp";
return 0;
}
if (model == Model::STANDARD200B) {
std::uint64_t value = 10;
auto ok = api->SetOptionValue(Option::SYNC_TIMESTAMP, value);
if (ok) {
LOG(INFO) << "Set timestamp is successful.";
} else {
LOG(INFO) << "Set timestamp is failed.";
}
}
api->Start(Source::VIDEO_STREAMING);
cv::namedWindow("frame");
while (true) {
api->WaitForStreams();
auto &&left_data = api->GetStreamData(Stream::LEFT);
auto &&right_data = api->GetStreamData(Stream::RIGHT);
cv::Mat img;
cv::hconcat(left_data.frame, right_data.frame, img);
cv::imshow("frame", img);
char key = static_cast<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::VIDEO_STREAMING);
return 0;
}

View File

@ -368,6 +368,10 @@ void API::SetOptionValue(const Option &option, std::int32_t value) {
device_->SetOptionValue(option, value);
}
bool API::SetOptionValue(const Option &option, std::uint64_t value) {
return device_->SetOptionValue(option, value);
}
bool API::RunOptionAction(const Option &option) const {
return device_->RunOptionAction(option);
}

View File

@ -97,7 +97,7 @@ int XuHalfDuplexId(Option option) {
return 1;
break;
case Option::SYNC_TIMESTAMP:
return 2;
return 3;
break;
default:
LOG(FATAL) << "No half duplex id for " << option;
@ -332,7 +332,7 @@ bool Channels::SetControlValue(const Option &option, std::uint64_t value) {
LOG(WARNING) << option << " set value useless";
break;
case Option::SYNC_TIMESTAMP:
return XuHalfDuplexSet(option, XU_SYNC_TIMESTAMP);
return XuHalfDuplexSet(option, value);
break;
default:
LOG(ERROR) << "Unsupported option " << option;
@ -719,6 +719,29 @@ bool Channels::XuHalfDuplexSet(Option option, xu_cmd_t cmd) const {
}
}
bool Channels::XuHalfDuplexSet(Option option, std::uint64_t value) const {
int id = XuHalfDuplexId(option);
std::uint8_t data[20] = {static_cast<std::uint8_t>(id & 0xFF),
static_cast<std::uint8_t>(value & 0xFF),
static_cast<std::uint8_t>((value >> 8) & 0xFF),
static_cast<std::uint8_t>((value >> 16) & 0xFF),
static_cast<std::uint8_t>((value >> 24) & 0xFF),
static_cast<std::uint8_t>((value >> 32) & 0xFF),
static_cast<std::uint8_t>((value >> 40) & 0xFF),
static_cast<std::uint8_t>((value >> 48) & 0xFF),
static_cast<std::uint8_t>((value >> 56) & 0xFF)};
if (XuControlQuery(CHANNEL_HALF_DUPLEX, uvc::XU_QUERY_SET, 20, data)) {
VLOG(2) << "XuHalfDuplexSet value (0x" << std::hex << std::uppercase << value
<< ") of " << option << " success";
return true;
} else {
LOG(WARNING) << "XuHalfDuplexSet value (0x" << std::hex << std::uppercase
<< value << ") of " << option << " failed";
return false;
}
}
bool Channels::XuImuWrite(const ImuReqPacket &req) const {
auto &&data = req.to_data();
if (XuControlQuery(

View File

@ -112,6 +112,7 @@ class MYNTEYE_API Channels {
void XuCamCtrlSet(Option option, std::int32_t value) const;
bool XuHalfDuplexSet(Option option, xu_cmd_t cmd) const;
bool XuHalfDuplexSet(Option option, std::uint64_t value) const;
bool XuImuWrite(const ImuReqPacket &req) const;
bool XuImuRead(ImuResPacket *res) const;

View File

@ -381,6 +381,14 @@ void Device::SetOptionValue(const Option &option, std::int32_t value) {
channels_->SetControlValue(option, value);
}
bool Device::SetOptionValue(const Option &option, std::uint64_t value) {
if (!Supports(option)) {
LOG(WARNING) << "Unsupported option: " << option;
return false;
}
return channels_->SetControlValue(option, value);
}
bool Device::RunOptionAction(const Option &option) const {
if (!Supports(option)) {
LOG(WARNING) << "Unsupported option: " << option;