From 3899b020b826f6c340fc2d23ff3d9e208501e998 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Fri, 20 Apr 2018 12:44:23 +0800 Subject: [PATCH] Move select device to utils --- CMakeLists.txt | 2 ++ include/mynteye/utils.h | 22 ++++++++++++++++++ samples/device/camera.cc | 35 ++-------------------------- src/public/utils.cc | 50 ++++++++++++++++++++++++++++++++++++++++ tools/dataset/record.cc | 35 ++-------------------------- 5 files changed, 78 insertions(+), 66 deletions(-) create mode 100644 include/mynteye/utils.h create mode 100644 src/public/utils.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 053fa63..ffe909b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ set(MYNTEYE_PUBLIC_H ${CMAKE_CURRENT_SOURCE_DIR}/include/mynteye/glog_init.h ${CMAKE_CURRENT_BINARY_DIR}/include/mynteye/mynteye.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/device.h ${CMAKE_CURRENT_SOURCE_DIR}/src/internal/files.h @@ -106,6 +107,7 @@ set(MYNTEYE_SRCS src/internal/strings.cc src/internal/types.cc src/public/types.cc + src/public/utils.cc src/device/context.cc src/device/device.cc src/device/device_s.cc diff --git a/include/mynteye/utils.h b/include/mynteye/utils.h new file mode 100644 index 0000000..a3c05a4 --- /dev/null +++ b/include/mynteye/utils.h @@ -0,0 +1,22 @@ +#ifndef MYNTEYE_UTILS_H_ // NOLINT +#define MYNTEYE_UTILS_H_ +#pragma once + +#include + +#include "mynteye/mynteye.h" + +MYNTEYE_BEGIN_NAMESPACE + +class Device; + +namespace device { + +/** Detecting MYNT EYE devices and prompt user to select one */ +std::shared_ptr select(); + +} // namespace device + +MYNTEYE_END_NAMESPACE + +#endif // MYNTEYE_UTILS_H_ NOLINT diff --git a/samples/device/camera.cc b/samples/device/camera.cc index 434882f..d7e3b95 100644 --- a/samples/device/camera.cc +++ b/samples/device/camera.cc @@ -3,8 +3,8 @@ #include "mynteye/glog_init.h" -#include "mynteye/context.h" #include "mynteye/device.h" +#include "mynteye/utils.h" #include "mynteye/times.h" @@ -13,38 +13,7 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { glog_init _(argc, argv); - 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 = 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 &&device = device::select(); /* { // auto-exposure device->SetOptionValue(Option::EXPOSURE_MODE, 0); diff --git a/src/public/utils.cc b/src/public/utils.cc new file mode 100644 index 0000000..6e3d862 --- /dev/null +++ b/src/public/utils.cc @@ -0,0 +1,50 @@ +#include "mynteye/utils.h" + +#include + +#include "device/context.h" +#include "device/device.h" + +MYNTEYE_BEGIN_NAMESPACE + +namespace device { + +std::shared_ptr 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 = 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 diff --git a/tools/dataset/record.cc b/tools/dataset/record.cc index 8c191cd..23f85b7 100644 --- a/tools/dataset/record.cc +++ b/tools/dataset/record.cc @@ -3,8 +3,8 @@ #include "mynteye/glog_init.h" -#include "mynteye/context.h" #include "mynteye/device.h" +#include "mynteye/utils.h" #include "mynteye/times.h" @@ -15,38 +15,7 @@ MYNTEYE_USE_NAMESPACE int main(int argc, char *argv[]) { glog_init _(argc, argv); - 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 = 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 &&device = device::select(); /* { // auto-exposure device->SetOptionValue(Option::EXPOSURE_MODE, 0);