From 8c0605255bb1de8ca56a1f92a81f2a86810e8032 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Tue, 10 Apr 2018 13:58:37 +0800 Subject: [PATCH] Complete options get set --- samples/device/camera.cc | 17 +++++++++ src/device/device.cc | 16 +++++++- src/internal/channels.cc | 79 ++++++++++++++++++++++++++++++++-------- src/internal/channels.h | 3 ++ 4 files changed, 98 insertions(+), 17 deletions(-) diff --git a/samples/device/camera.cc b/samples/device/camera.cc index 0544960..f415a41 100644 --- a/samples/device/camera.cc +++ b/samples/device/camera.cc @@ -42,6 +42,23 @@ int main(int argc, char *argv[]) { } } + /* + { // auto-exposure + device->SetOptionValue(Option::EXPOSURE_MODE, 0); + device->SetOptionValue(Option::MAX_GAIN, 40); // [0.48] + device->SetOptionValue(Option::MAX_EXPOSURE_TIME, 120); // [0,240] + device->SetOptionValue(Option::DESIRED_BRIGHTNESS, 200); // [0,255] + } + */ + /* + { // manual-exposure + device->SetOptionValue(Option::EXPOSURE_MODE, 1); + device->SetOptionValue(Option::GAIN, 20); // [0.48] + device->SetOptionValue(Option::BRIGHTNESS, 20); // [0,240] + device->SetOptionValue(Option::CONTRAST, 20); // [0,255] + } + device->SetOptionValue(Option::IR_CONTROL, 80); + */ device->LogOptionInfos(); std::size_t left_count = 0; diff --git a/src/device/device.cc b/src/device/device.cc index 268361d..3dbd9bd 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -58,7 +58,7 @@ bool Device::Supports(const Option &option) const { const std::vector &Device::GetStreamRequests( const Capabilities &capability) const { if (!Supports(capability)) { - LOG(FATAL) << "Unsupported capability: " << to_string(capability); + LOG(FATAL) << "Unsupported capability: " << capability; } try { auto &&cap_requests = stream_requests_map.at(model_); @@ -132,15 +132,27 @@ ImuExtrinsics Device::GetImuExtrinsics() const { } OptionInfo Device::GetOptionInfo(const Option &option) const { + if (!Supports(option)) { + LOG(WARNING) << "Unsupported option: " << option; + return {0, 0, 0}; + } auto &&info = channels_->GetControlInfo(option); return {info.min, info.max, info.def}; } std::int32_t Device::GetOptionValue(const Option &option) const { + if (!Supports(option)) { + LOG(WARNING) << "Unsupported option: " << option; + return -1; + } return channels_->GetControlValue(option); } void Device::SetOptionValue(const Option &option, std::int32_t value) { + if (!Supports(option)) { + LOG(WARNING) << "Unsupported option: " << option; + return; + } channels_->SetControlValue(option, value); } @@ -151,7 +163,7 @@ void Device::LogOptionInfos() const { void Device::SetStreamCallback( const Stream &stream, stream_callback_t callback) { if (!Supports(stream)) { - LOG(WARNING) << "Unsupported stream: " << to_string(stream); + LOG(WARNING) << "Unsupported stream: " << stream; return; } if (callback) { diff --git a/src/internal/channels.cc b/src/internal/channels.cc index 43ece39..5b18002 100644 --- a/src/internal/channels.cc +++ b/src/internal/channels.cc @@ -43,7 +43,22 @@ int XuCamCtrlId(Option option) { Channels::Channels(std::shared_ptr device) : device_(device) { VLOG(2) << __func__; + UpdateControlInfos(); +} +Channels::~Channels() { + VLOG(2) << __func__; +} + +void Channels::LogControlInfos() const { + for (auto &&it = control_infos_.begin(); it != control_infos_.end(); it++) { + LOG(INFO) << it->first << ": min=" << it->second.min + << ", max=" << it->second.max << ", def=" << it->second.def + << ", cur=" << GetControlValue(it->first); + } +} + +void Channels::UpdateControlInfos() { for (auto &&option : std::vector