Add device model & config

This commit is contained in:
John Zhao 2018-04-04 15:52:10 +08:00
parent c7390993dc
commit d1740c625e
10 changed files with 186 additions and 2 deletions

View File

@ -91,11 +91,13 @@ endif()
set(MYNTEYE_SRCS
${UVC_SRC}
src/internal/config.cc
src/internal/strings.cc
src/internal/types.cc
src/public/types.cc
src/device/context.cc
src/device/device.cc
src/device/device_s.cc
)
set(MYNTEYE_LINKLIBS

View File

@ -16,6 +16,17 @@ MYNTEYE_BEGIN_NAMESPACE
* @brief Public enumeration types.
*/
/**
* @ingroup enumerations
* @brief Device model.
*/
enum class Model : std::uint8_t {
/** Standard */
STANDARD,
/** Last guard */
LAST
};
/**
* @ingroup enumerations
* @brief Streams define different type of data.
@ -154,6 +165,7 @@ enum class Option : std::uint8_t {
return os << static_cast<utype>(value); \
}
MYNTEYE_ENUM_HELPERS(Model)
MYNTEYE_ENUM_HELPERS(Stream)
MYNTEYE_ENUM_HELPERS(Capabilities)
MYNTEYE_ENUM_HELPERS(Info)

View File

@ -2,12 +2,16 @@
#include <glog/logging.h>
#include "device/device_s.h"
#include "internal/config.h"
#include "internal/strings.h"
#include "internal/types.h"
#include "uvc/uvc.h"
MYNTEYE_BEGIN_NAMESPACE
Device::Device() {
Device::Device(const Model &model, std::shared_ptr<uvc::device> device)
: model_(model), device_(device) {
VLOG(2) << __func__;
}
@ -18,10 +22,61 @@ Device::~Device() {
std::shared_ptr<Device> Device::Create(
const std::string &name, std::shared_ptr<uvc::device> device) {
if (name == "MYNTEYE") {
return std::make_shared<StandardDevice>(device);
} else if (strings::starts_with(name, "MYNT-EYE-")) {
// TODO(JohnZhao): Create different device by name, such as MYNT-EYE-S1000
}
return nullptr;
}
bool Device::Supports(const Stream &stream) const {
auto &&supports = stream_supports_map.at(Model::STANDARD);
return supports.find(stream) != supports.end();
}
bool Device::Supports(const Capabilities &capability) const {
auto &&supports = capabilities_supports_map.at(Model::STANDARD);
return supports.find(capability) != supports.end();
}
bool Device::Supports(const Option &option) const {
auto &&supports = option_supports_map.at(Model::STANDARD);
return supports.find(option) != supports.end();
}
std::shared_ptr<DeviceInfo> Device::GetInfo() const {
return device_info_;
}
std::string Device::GetInfo(const Info &info) const {
CHECK_NOTNULL(device_info_);
switch (info) {
case Info::DEVICE_NAME: {
return device_info_->name;
} break;
case Info::SERIAL_NUMBER: {
return device_info_->serial_number;
} break;
case Info::FIRMWARE_VERSION: {
return device_info_->firmware_version.to_string();
} break;
case Info::HARDWARE_VERSION: {
return device_info_->hardware_version.to_string();
} break;
case Info::SPEC_VERSION: {
return device_info_->spec_version.to_string();
} break;
case Info::LENS_TYPE: {
return device_info_->lens_type.to_string();
} break;
case Info::IMU_TYPE: {
return device_info_->imu_type.to_string();
} break;
case Info::NOMINAL_BASELINE: {
return std::to_string(device_info_->nominal_baseline);
} break;
default: { LOG(FATAL) << "Unknown device info"; }
}
}
MYNTEYE_END_NAMESPACE

View File

@ -6,6 +6,7 @@
#include <string>
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
MYNTEYE_BEGIN_NAMESPACE
@ -15,15 +16,36 @@ struct device;
} // namespace uvc
struct DeviceInfo;
class Device {
public:
Device();
Device(const Model &model, std::shared_ptr<uvc::device> device);
virtual ~Device();
static std::shared_ptr<Device> Create(
const std::string &name, std::shared_ptr<uvc::device> device);
bool Supports(const Stream &stream) const;
bool Supports(const Capabilities &capability) const;
bool Supports(const Option &option) const;
std::shared_ptr<DeviceInfo> GetInfo() const;
std::string GetInfo(const Info &info) const;
Model model() const {
return model_;
}
protected:
std::shared_ptr<uvc::device> device() const {
return device_;
}
private:
Model model_;
std::shared_ptr<uvc::device> device_;
std::shared_ptr<DeviceInfo> device_info_;
};
MYNTEYE_END_NAMESPACE

16
src/device/device_s.cc Normal file
View File

@ -0,0 +1,16 @@
#include "device/device_s.h"
#include <glog/logging.h>
MYNTEYE_BEGIN_NAMESPACE
StandardDevice::StandardDevice(std::shared_ptr<uvc::device> device)
: Device(Model::STANDARD, device) {
VLOG(2) << __func__;
}
StandardDevice::~StandardDevice() {
VLOG(2) << __func__;
}
MYNTEYE_END_NAMESPACE

19
src/device/device_s.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef MYNTEYE_DEVICE_S_H_ // NOLINT
#define MYNTEYE_DEVICE_S_H_
#pragma once
#include <memory>
#include "device/device.h"
MYNTEYE_BEGIN_NAMESPACE
class StandardDevice : public Device {
public:
explicit StandardDevice(std::shared_ptr<uvc::device> device);
virtual ~StandardDevice();
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_DEVICE_S_H_ NOLINT

18
src/internal/config.cc Normal file
View File

@ -0,0 +1,18 @@
#include "internal/config.h"
MYNTEYE_BEGIN_NAMESPACE
const std::map<Model, StreamSupports> stream_supports_map = {
{Model::STANDARD, {Stream::LEFT, Stream::RIGHT}}};
const std::map<Model, CapabilitiesSupports> capabilities_supports_map = {
{Model::STANDARD, {Capabilities::STEREO, Capabilities::IMU}}};
const std::map<Model, OptionSupports> option_supports_map = {
{Model::STANDARD,
{Option::GAIN, Option::BRIGHTNESS, Option::CONTRAST, Option::FRAME_RATE,
Option::IMU_FREQUENCY, Option::EXPOSURE_MODE, Option::MAX_GAIN,
Option::MAX_EXPOSURE_TIME, Option::DESIRED_BRIGHTNESS, Option::IR_CONTROL,
Option::HDR_MODE, Option::ZERO_DRIFT_CALIBRATION, Option::ERASE_CHIP}}};
MYNTEYE_END_NAMESPACE

23
src/internal/config.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef MYNTEYE_INTERNAL_CONFIG_H_ // NOLINT
#define MYNTEYE_INTERNAL_CONFIG_H_
#pragma once
#include <map>
#include <set>
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
MYNTEYE_BEGIN_NAMESPACE
using StreamSupports = std::set<Stream>;
using CapabilitiesSupports = std::set<Capabilities>;
using OptionSupports = std::set<Option>;
extern const std::map<Model, StreamSupports> stream_supports_map;
extern const std::map<Model, CapabilitiesSupports> capabilities_supports_map;
extern const std::map<Model, OptionSupports> option_supports_map;
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_INTERNAL_CONFIG_H_ NOLINT

View File

@ -4,6 +4,19 @@
MYNTEYE_BEGIN_NAMESPACE
const char *to_string(const Model &value) {
#define CASE(X) \
case Model::X: \
return "Model::" #X;
switch (value) {
CASE(STANDARD)
default:
CHECK(is_valid(value));
return "Model::UNKNOWN";
}
#undef CASE
}
const char *to_string(const Stream &value) {
#define CASE(X) \
case Stream::X: \

View File

@ -4,6 +4,10 @@
MYNTEYE_USE_NAMESPACE
TEST(Model, VerifyToString) {
EXPECT_STREQ("Model::STANDARD", to_string(Model::STANDARD));
}
TEST(Stream, VerifyToString) {
EXPECT_STREQ("Stream::LEFT", to_string(Stream::LEFT));
EXPECT_STREQ("Stream::RIGHT", to_string(Stream::RIGHT));