2018-04-04 05:50:27 +03:00
|
|
|
#include "device/device.h"
|
|
|
|
|
|
|
|
#include <glog/logging.h>
|
|
|
|
|
2018-04-04 10:52:10 +03:00
|
|
|
#include "device/device_s.h"
|
|
|
|
#include "internal/config.h"
|
2018-04-04 06:38:36 +03:00
|
|
|
#include "internal/strings.h"
|
2018-04-04 10:52:10 +03:00
|
|
|
#include "internal/types.h"
|
2018-04-04 05:50:27 +03:00
|
|
|
#include "uvc/uvc.h"
|
|
|
|
|
|
|
|
MYNTEYE_BEGIN_NAMESPACE
|
|
|
|
|
2018-04-04 10:52:10 +03:00
|
|
|
Device::Device(const Model &model, std::shared_ptr<uvc::device> device)
|
|
|
|
: model_(model), device_(device) {
|
2018-04-04 05:50:27 +03:00
|
|
|
VLOG(2) << __func__;
|
2018-04-06 04:12:09 +03:00
|
|
|
ReadDeviceInfo();
|
2018-04-04 05:50:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Device::~Device() {
|
|
|
|
VLOG(2) << __func__;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Device> Device::Create(
|
|
|
|
const std::string &name, std::shared_ptr<uvc::device> device) {
|
2018-04-04 06:38:36 +03:00
|
|
|
if (name == "MYNTEYE") {
|
2018-04-04 10:52:10 +03:00
|
|
|
return std::make_shared<StandardDevice>(device);
|
2018-04-04 06:38:36 +03:00
|
|
|
} else if (strings::starts_with(name, "MYNT-EYE-")) {
|
|
|
|
// TODO(JohnZhao): Create different device by name, such as MYNT-EYE-S1000
|
|
|
|
}
|
2018-04-04 05:50:27 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-04 10:52:10 +03:00
|
|
|
bool Device::Supports(const Stream &stream) const {
|
|
|
|
auto &&supports = stream_supports_map.at(Model::STANDARD);
|
|
|
|
return supports.find(stream) != supports.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Device::Supports(const Capabilities &capability) const {
|
|
|
|
auto &&supports = capabilities_supports_map.at(Model::STANDARD);
|
|
|
|
return supports.find(capability) != supports.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Device::Supports(const Option &option) const {
|
|
|
|
auto &&supports = option_supports_map.at(Model::STANDARD);
|
|
|
|
return supports.find(option) != supports.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<DeviceInfo> Device::GetInfo() const {
|
|
|
|
return device_info_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Device::GetInfo(const Info &info) const {
|
|
|
|
CHECK_NOTNULL(device_info_);
|
|
|
|
switch (info) {
|
|
|
|
case Info::DEVICE_NAME: {
|
|
|
|
return device_info_->name;
|
|
|
|
} break;
|
|
|
|
case Info::SERIAL_NUMBER: {
|
|
|
|
return device_info_->serial_number;
|
|
|
|
} break;
|
|
|
|
case Info::FIRMWARE_VERSION: {
|
|
|
|
return device_info_->firmware_version.to_string();
|
|
|
|
} break;
|
|
|
|
case Info::HARDWARE_VERSION: {
|
|
|
|
return device_info_->hardware_version.to_string();
|
|
|
|
} break;
|
|
|
|
case Info::SPEC_VERSION: {
|
|
|
|
return device_info_->spec_version.to_string();
|
|
|
|
} break;
|
|
|
|
case Info::LENS_TYPE: {
|
|
|
|
return device_info_->lens_type.to_string();
|
|
|
|
} break;
|
|
|
|
case Info::IMU_TYPE: {
|
|
|
|
return device_info_->imu_type.to_string();
|
|
|
|
} break;
|
|
|
|
case Info::NOMINAL_BASELINE: {
|
|
|
|
return std::to_string(device_info_->nominal_baseline);
|
|
|
|
} break;
|
|
|
|
default: { LOG(FATAL) << "Unknown device info"; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 04:12:09 +03:00
|
|
|
ImgIntrinsics Device::GetImgIntrinsics() const {
|
|
|
|
return img_intrinsics_;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImgExtrinsics Device::GetImgExtrinsics() const {
|
|
|
|
return img_extrinsics_;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImuIntrinsics Device::GetImuIntrinsics() const {
|
|
|
|
return imu_intrinsics_;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImuExtrinsics Device::GetImuExtrinsics() const {
|
|
|
|
return imu_extrinsics_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Device::SetStreamCallback(
|
|
|
|
const Stream &stream, stream_callback_t callback) {
|
|
|
|
if (!Supports(stream)) {
|
|
|
|
LOG(WARNING) << "Unsupported stream: " << to_string(stream);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
stream_callbacks_[stream] = callback;
|
|
|
|
} else {
|
|
|
|
stream_callbacks_.erase(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Device::SetMotionCallback(motion_callback_t callback) {
|
|
|
|
motion_callback_ = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Device::ReadDeviceInfo() {
|
|
|
|
// TODO(JohnZhao): Read device info
|
|
|
|
}
|
|
|
|
|
|
|
|
void Device::WriteImgIntrinsics(const ImgIntrinsics &intrinsics) {
|
|
|
|
// TODO(JohnZhao): Write img intrinsics
|
|
|
|
UNUSED(intrinsics);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Device::WriteImgExtrinsics(const ImgExtrinsics &extrinsics) {
|
|
|
|
// TODO(JohnZhao): Write img extrinsics
|
|
|
|
UNUSED(extrinsics);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Device::WriteImuIntrinsics(const ImuIntrinsics &intrinsics) {
|
|
|
|
// TODO(JohnZhao): Write imu intrinsics
|
|
|
|
UNUSED(intrinsics);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Device::WriteImuExtrinsics(const ImuExtrinsics &extrinsics) {
|
|
|
|
// TODO(JohnZhao): Write imu extrinsics
|
|
|
|
UNUSED(extrinsics);
|
|
|
|
}
|
|
|
|
|
2018-04-04 05:50:27 +03:00
|
|
|
MYNTEYE_END_NAMESPACE
|