180 lines
4.3 KiB
C++
Raw Normal View History

2018-05-10 14:46:34 +08:00
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2018-10-27 21:24:04 +08:00
#include "mynteye/device/utils.h"
2018-04-20 12:44:23 +08:00
2018-11-05 12:17:35 +08:00
#include <cstdlib>
2018-09-04 15:12:04 +08:00
#include "mynteye/logger.h"
2018-04-20 12:44:23 +08:00
2018-10-27 21:24:04 +08:00
#include "mynteye/device/context.h"
#include "mynteye/device/device.h"
2018-04-20 12:44:23 +08:00
2018-11-16 16:30:13 +08:00
#include "mynteye/logger.h"
2018-04-20 12:44:23 +08:00
MYNTEYE_BEGIN_NAMESPACE
namespace device {
std::shared_ptr<Device> select() {
LOG(INFO) << "Detecting MYNT EYE devices";
Context context;
auto &&devices = context.devices();
std::size_t n = devices.size();
2018-05-15 22:01:15 +08:00
if (n <= 0) {
LOG(ERROR) << "No MYNT EYE devices :(";
return nullptr;
}
2018-12-18 10:44:26 +08:00
2018-04-20 12:44:23 +08:00
LOG(INFO) << "MYNT EYE devices:";
for (std::size_t i = 0; i < n; i++) {
2018-04-20 12:44:23 +08:00
auto &&device = devices[i];
2018-06-14 09:38:38 +08:00
LOG(INFO) << " index: " << i
<< ", name: " << device->GetInfo(Info::DEVICE_NAME)
<< ", sn: " << device->GetInfo(Info::SERIAL_NUMBER)
<< ", firmware: " << device->GetInfo(Info::FIRMWARE_VERSION);
2018-04-20 12:44:23 +08:00
}
2018-12-18 10:44:26 +08:00
2018-04-20 12:44:23 +08:00
std::shared_ptr<Device> device = nullptr;
if (n <= 1) {
device = devices[0];
LOG(INFO) << "Only one MYNT EYE device, select index: 0";
} else {
while (true) {
std::size_t i;
2018-04-20 12:44:23 +08:00
LOG(INFO) << "There are " << n << " MYNT EYE devices, select index: ";
std::cin >> i;
if (i >= n) {
LOG(WARNING) << "Index out of range :(";
continue;
}
device = devices[i];
break;
}
}
return device;
}
MYNTEYE_NAMESPACE::StreamRequest select_request(
const std::shared_ptr<Device> &device, bool *ok) {
auto &&requests = device->GetStreamRequests();
std::size_t n = requests.size();
// TODO(Kalman): Get request size by uvc enum
if (device->GetModel() == Model::STANDARD &&
device->GetInfo()->firmware_version < Version(2, 4)) {
n -= 1;
}
if (n <= 0) {
LOG(ERROR) << "No MYNT EYE devices :(";
*ok = false;
return {};
}
LOG(INFO) << "MYNT EYE requests:";
for (std::size_t i = 0; i < n; i++) {
auto &&request = requests[i];
LOG(INFO) << " index: " << i
<< ", request: " << request;
}
if (n <= 1) {
LOG(INFO) << "Only one stream request, select index: 0";
*ok = true;
return requests[0];
} else {
while (true) {
std::size_t i;
LOG(INFO) << "There are " << n << " stream requests, select index: ";
std::cin >> i;
if (i >= n) {
LOG(WARNING) << "Index out of range :(";
continue;
}
*ok = true;
return requests[i];
}
}
}
2018-04-20 12:44:23 +08:00
} // namespace device
2018-05-13 10:34:03 +08:00
namespace utils {
float get_real_exposure_time(
std::int32_t frame_rate, std::uint16_t exposure_time) {
float real_max = 0;
switch (frame_rate) {
case 10:
real_max = 18;
break;
case 15:
real_max = 18;
break;
case 20:
real_max = 18;
break;
case 25:
real_max = 18;
break;
case 30:
real_max = 18;
break;
case 35:
real_max = 18;
break;
case 40:
real_max = 18;
break;
case 45:
real_max = 18;
break;
case 50:
real_max = 17;
break;
case 55:
real_max = 16.325;
break;
case 60:
real_max = 15;
break;
default:
LOG(ERROR) << "Invalid frame rate: " << frame_rate;
return exposure_time;
}
return exposure_time * real_max / 480.f;
}
2018-11-05 12:17:35 +08:00
std::string get_sdk_root_dir() {
if (const char* root = std::getenv("MYNTEYES_SDK_ROOT")) {
// LOG(INFO) << "Environment variable MYNTEYES_SDK_ROOT found: " << root;
return std::string(root);
} else {
return std::string(MYNTEYE_SDK_ROOT_DIR);
}
}
std::string get_sdk_install_dir() {
if (const char* root = std::getenv("MYNTEYES_SDK_ROOT")) {
// LOG(INFO) << "Environment variable MYNTEYES_SDK_ROOT found: " << root;
return std::string(root);
} else {
return std::string(MYNTEYE_SDK_INSTALL_DIR);
}
}
2018-05-13 10:34:03 +08:00
} // namespace utils
2018-04-20 12:44:23 +08:00
MYNTEYE_END_NAMESPACE