2018-05-10 09:46:34 +03: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-04-20 07:44:23 +03:00
|
|
|
#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
|