Move select device to utils
This commit is contained in:
parent
a3f90d31c7
commit
3899b020b8
|
@ -74,6 +74,7 @@ set(MYNTEYE_PUBLIC_H
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/glog_init.h
|
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/glog_init.h
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/include/mynteye/mynteye.h
|
${CMAKE_CURRENT_BINARY_DIR}/include/mynteye/mynteye.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/types.h
|
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/types.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/utils.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/device/context.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/device/context.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/device/device.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/device/device.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/internal/files.h
|
${CMAKE_CURRENT_SOURCE_DIR}/src/internal/files.h
|
||||||
|
@ -106,6 +107,7 @@ set(MYNTEYE_SRCS
|
||||||
src/internal/strings.cc
|
src/internal/strings.cc
|
||||||
src/internal/types.cc
|
src/internal/types.cc
|
||||||
src/public/types.cc
|
src/public/types.cc
|
||||||
|
src/public/utils.cc
|
||||||
src/device/context.cc
|
src/device/context.cc
|
||||||
src/device/device.cc
|
src/device/device.cc
|
||||||
src/device/device_s.cc
|
src/device/device_s.cc
|
||||||
|
|
22
include/mynteye/utils.h
Normal file
22
include/mynteye/utils.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef MYNTEYE_UTILS_H_ // NOLINT
|
||||||
|
#define MYNTEYE_UTILS_H_
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "mynteye/mynteye.h"
|
||||||
|
|
||||||
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
|
||||||
|
namespace device {
|
||||||
|
|
||||||
|
/** Detecting MYNT EYE devices and prompt user to select one */
|
||||||
|
std::shared_ptr<Device> select();
|
||||||
|
|
||||||
|
} // namespace device
|
||||||
|
|
||||||
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // MYNTEYE_UTILS_H_ NOLINT
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
#include "mynteye/glog_init.h"
|
#include "mynteye/glog_init.h"
|
||||||
|
|
||||||
#include "mynteye/context.h"
|
|
||||||
#include "mynteye/device.h"
|
#include "mynteye/device.h"
|
||||||
|
#include "mynteye/utils.h"
|
||||||
|
|
||||||
#include "mynteye/times.h"
|
#include "mynteye/times.h"
|
||||||
|
|
||||||
|
@ -13,38 +13,7 @@ MYNTEYE_USE_NAMESPACE
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
glog_init _(argc, argv);
|
glog_init _(argc, argv);
|
||||||
|
|
||||||
LOG(INFO) << "Detecting MYNT EYE devices";
|
auto &&device = device::select();
|
||||||
Context context;
|
|
||||||
auto &&devices = context.devices();
|
|
||||||
|
|
||||||
size_t n = devices.size();
|
|
||||||
LOG_IF(FATAL, n <= 0) << "No MYNT EYE devices :(";
|
|
||||||
|
|
||||||
LOG(INFO) << "MYNT EYE devices:";
|
|
||||||
for (size_t i = 0; i < n; i++) {
|
|
||||||
auto &&device = devices[i];
|
|
||||||
auto &&name = device->GetInfo(Info::DEVICE_NAME);
|
|
||||||
LOG(INFO) << " index: " << i << ", name: " << name;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
size_t i;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
{ // auto-exposure
|
{ // auto-exposure
|
||||||
device->SetOptionValue(Option::EXPOSURE_MODE, 0);
|
device->SetOptionValue(Option::EXPOSURE_MODE, 0);
|
||||||
|
|
50
src/public/utils.cc
Normal file
50
src/public/utils.cc
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#include "mynteye/utils.h"
|
||||||
|
|
||||||
|
#include <glog/logging.h>
|
||||||
|
|
||||||
|
#include "device/context.h"
|
||||||
|
#include "device/device.h"
|
||||||
|
|
||||||
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
namespace device {
|
||||||
|
|
||||||
|
std::shared_ptr<Device> select() {
|
||||||
|
LOG(INFO) << "Detecting MYNT EYE devices";
|
||||||
|
Context context;
|
||||||
|
auto &&devices = context.devices();
|
||||||
|
|
||||||
|
size_t n = devices.size();
|
||||||
|
LOG_IF(FATAL, n <= 0) << "No MYNT EYE devices :(";
|
||||||
|
|
||||||
|
LOG(INFO) << "MYNT EYE devices:";
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
auto &&device = devices[i];
|
||||||
|
auto &&name = device->GetInfo(Info::DEVICE_NAME);
|
||||||
|
LOG(INFO) << " index: " << i << ", name: " << name;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
size_t i;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace device
|
||||||
|
|
||||||
|
MYNTEYE_END_NAMESPACE
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
#include "mynteye/glog_init.h"
|
#include "mynteye/glog_init.h"
|
||||||
|
|
||||||
#include "mynteye/context.h"
|
|
||||||
#include "mynteye/device.h"
|
#include "mynteye/device.h"
|
||||||
|
#include "mynteye/utils.h"
|
||||||
|
|
||||||
#include "mynteye/times.h"
|
#include "mynteye/times.h"
|
||||||
|
|
||||||
|
@ -15,38 +15,7 @@ MYNTEYE_USE_NAMESPACE
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
glog_init _(argc, argv);
|
glog_init _(argc, argv);
|
||||||
|
|
||||||
LOG(INFO) << "Detecting MYNT EYE devices";
|
auto &&device = device::select();
|
||||||
Context context;
|
|
||||||
auto &&devices = context.devices();
|
|
||||||
|
|
||||||
size_t n = devices.size();
|
|
||||||
LOG_IF(FATAL, n <= 0) << "No MYNT EYE devices :(";
|
|
||||||
|
|
||||||
LOG(INFO) << "MYNT EYE devices:";
|
|
||||||
for (size_t i = 0; i < n; i++) {
|
|
||||||
auto &&device = devices[i];
|
|
||||||
auto &&name = device->GetInfo(Info::DEVICE_NAME);
|
|
||||||
LOG(INFO) << " index: " << i << ", name: " << name;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
size_t i;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
{ // auto-exposure
|
{ // auto-exposure
|
||||||
device->SetOptionValue(Option::EXPOSURE_MODE, 0);
|
device->SetOptionValue(Option::EXPOSURE_MODE, 0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user