Update types & add callbacks
This commit is contained in:
parent
d1740c625e
commit
3e56de0a45
|
@ -101,7 +101,7 @@ enum class Info : std::uint8_t {
|
||||||
/** Nominal baseline */
|
/** Nominal baseline */
|
||||||
NOMINAL_BASELINE,
|
NOMINAL_BASELINE,
|
||||||
/** Last guard */
|
/** Last guard */
|
||||||
LAST,
|
LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,7 +146,7 @@ enum class Option : std::uint8_t {
|
||||||
/** Erase chip */
|
/** Erase chip */
|
||||||
ERASE_CHIP,
|
ERASE_CHIP,
|
||||||
/** Last guard */
|
/** Last guard */
|
||||||
LAST,
|
LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MYNTEYE_ENUM_HELPERS(TYPE) \
|
#define MYNTEYE_ENUM_HELPERS(TYPE) \
|
||||||
|
@ -173,6 +173,43 @@ MYNTEYE_ENUM_HELPERS(Option)
|
||||||
|
|
||||||
#undef MYNTEYE_ENUM_HELPERS
|
#undef MYNTEYE_ENUM_HELPERS
|
||||||
|
|
||||||
|
#define MYNTEYE_FOURCC(a, b, c, d) \
|
||||||
|
((std::uint32_t)(a) | ((std::uint32_t)(b) << 8) | \
|
||||||
|
((std::uint32_t)(c) << 16) | ((std::uint32_t)(d) << 24)) // NOLINT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup enumerations
|
||||||
|
* @brief Formats define how each stream can be encoded.
|
||||||
|
*/
|
||||||
|
enum class Format : std::uint32_t {
|
||||||
|
/** YUV 4:2:2, 16 bits per pixel */
|
||||||
|
YUYV = MYNTEYE_FOURCC('Y', 'U', 'Y', 'V'),
|
||||||
|
/** Last guard */
|
||||||
|
LAST
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef MYNTEYE_FOURCC
|
||||||
|
|
||||||
|
const char *to_string(const Format &value);
|
||||||
|
|
||||||
|
inline std::ostream &operator<<(std::ostream &os, const Format &value) {
|
||||||
|
return os << to_string(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stream request.
|
||||||
|
*/
|
||||||
|
struct MYNTEYE_API StreamRequest {
|
||||||
|
/** width in pixels */
|
||||||
|
std::uint16_t width;
|
||||||
|
/** height in pixels */
|
||||||
|
std::uint16_t height;
|
||||||
|
/** stream pixel format */
|
||||||
|
Format format;
|
||||||
|
/** frames per second */
|
||||||
|
std::uint16_t fps;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup calibration Intrinsics & Extrinsics
|
* @defgroup calibration Intrinsics & Extrinsics
|
||||||
* @brief Intrinsic and extrinsic properties.
|
* @brief Intrinsic and extrinsic properties.
|
||||||
|
@ -180,9 +217,9 @@ MYNTEYE_ENUM_HELPERS(Option)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup calibration
|
* @ingroup calibration
|
||||||
* Video stream intrinsics.
|
* Image intrinsics.
|
||||||
*/
|
*/
|
||||||
struct MYNTEYE_API Intrinsics {
|
struct MYNTEYE_API ImgIntrinsics {
|
||||||
/** width of the image in pixels */
|
/** width of the image in pixels */
|
||||||
std::uint16_t width;
|
std::uint16_t width;
|
||||||
/** height of the image in pixels */
|
/** height of the image in pixels */
|
||||||
|
@ -232,13 +269,29 @@ struct MYNTEYE_API ImuIntrinsics {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup calibration
|
* @ingroup calibration
|
||||||
* Cross-stream extrinsics, represent how the different devices are connected.
|
* Extrinsics, represent how the different datas are connected.
|
||||||
*/
|
*/
|
||||||
struct MYNTEYE_API Extrinsics {
|
struct MYNTEYE_API Extrinsics {
|
||||||
double rotation[3][3]; /**< rotation matrix */
|
double rotation[3][3]; /**< rotation matrix */
|
||||||
double translation[3]; /**< translation vector */
|
double translation[3]; /**< translation vector */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup calibration
|
||||||
|
* Image extrinsics.
|
||||||
|
*/
|
||||||
|
struct MYNTEYE_API ImgExtrinsics {
|
||||||
|
Extrinsics left_to_right;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup calibration
|
||||||
|
* IMU extrinsics.
|
||||||
|
*/
|
||||||
|
struct MYNTEYE_API ImuExtrinsics {
|
||||||
|
Extrinsics left_to_imu;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup datatypes Datatypes
|
* @defgroup datatypes Datatypes
|
||||||
* @brief Public data types.
|
* @brief Public data types.
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "mynteye/mynteye.h"
|
#include "mynteye/mynteye.h"
|
||||||
|
#include "mynteye/types.h"
|
||||||
#include "internal/types.h"
|
|
||||||
#include "uvc/uvc.h"
|
#include "uvc/uvc.h"
|
||||||
|
|
||||||
#include "glog_init.h" // NOLINT
|
#include "glog_init.h" // NOLINT
|
||||||
|
|
|
@ -13,6 +13,7 @@ MYNTEYE_BEGIN_NAMESPACE
|
||||||
Device::Device(const Model &model, std::shared_ptr<uvc::device> device)
|
Device::Device(const Model &model, std::shared_ptr<uvc::device> device)
|
||||||
: model_(model), device_(device) {
|
: model_(model), device_(device) {
|
||||||
VLOG(2) << __func__;
|
VLOG(2) << __func__;
|
||||||
|
ReadDeviceInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::~Device() {
|
Device::~Device() {
|
||||||
|
@ -79,4 +80,61 @@ std::string Device::GetInfo(const Info &info) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImgIntrinsics Device::GetImgIntrinsics() const {
|
||||||
|
return img_intrinsics_;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImgExtrinsics Device::GetImgExtrinsics() const {
|
||||||
|
return img_extrinsics_;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImuIntrinsics Device::GetImuIntrinsics() const {
|
||||||
|
return imu_intrinsics_;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImuExtrinsics Device::GetImuExtrinsics() const {
|
||||||
|
return imu_extrinsics_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::SetStreamCallback(
|
||||||
|
const Stream &stream, stream_callback_t callback) {
|
||||||
|
if (!Supports(stream)) {
|
||||||
|
LOG(WARNING) << "Unsupported stream: " << to_string(stream);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (callback) {
|
||||||
|
stream_callbacks_[stream] = callback;
|
||||||
|
} else {
|
||||||
|
stream_callbacks_.erase(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::SetMotionCallback(motion_callback_t callback) {
|
||||||
|
motion_callback_ = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::ReadDeviceInfo() {
|
||||||
|
// TODO(JohnZhao): Read device info
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::WriteImgIntrinsics(const ImgIntrinsics &intrinsics) {
|
||||||
|
// TODO(JohnZhao): Write img intrinsics
|
||||||
|
UNUSED(intrinsics);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::WriteImgExtrinsics(const ImgExtrinsics &extrinsics) {
|
||||||
|
// TODO(JohnZhao): Write img extrinsics
|
||||||
|
UNUSED(extrinsics);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::WriteImuIntrinsics(const ImuIntrinsics &intrinsics) {
|
||||||
|
// TODO(JohnZhao): Write imu intrinsics
|
||||||
|
UNUSED(intrinsics);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::WriteImuExtrinsics(const ImuExtrinsics &extrinsics) {
|
||||||
|
// TODO(JohnZhao): Write imu extrinsics
|
||||||
|
UNUSED(extrinsics);
|
||||||
|
}
|
||||||
|
|
||||||
MYNTEYE_END_NAMESPACE
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
|
@ -2,12 +2,15 @@
|
||||||
#define MYNTEYE_DEVICE_H_
|
#define MYNTEYE_DEVICE_H_
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "mynteye/mynteye.h"
|
#include "mynteye/mynteye.h"
|
||||||
#include "mynteye/types.h"
|
#include "mynteye/types.h"
|
||||||
|
|
||||||
|
#include "internal/callbacks.h"
|
||||||
|
|
||||||
MYNTEYE_BEGIN_NAMESPACE
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
namespace uvc {
|
namespace uvc {
|
||||||
|
@ -20,12 +23,21 @@ struct DeviceInfo;
|
||||||
|
|
||||||
class Device {
|
class Device {
|
||||||
public:
|
public:
|
||||||
|
using stream_callback_t = device::StreamCallback;
|
||||||
|
using motion_callback_t = device::MotionCallback;
|
||||||
|
|
||||||
|
using stream_callbacks_t = std::map<Stream, stream_callback_t>;
|
||||||
|
|
||||||
Device(const Model &model, std::shared_ptr<uvc::device> device);
|
Device(const Model &model, std::shared_ptr<uvc::device> device);
|
||||||
virtual ~Device();
|
virtual ~Device();
|
||||||
|
|
||||||
static std::shared_ptr<Device> Create(
|
static std::shared_ptr<Device> Create(
|
||||||
const std::string &name, std::shared_ptr<uvc::device> device);
|
const std::string &name, std::shared_ptr<uvc::device> device);
|
||||||
|
|
||||||
|
Model GetModel() const {
|
||||||
|
return model_;
|
||||||
|
}
|
||||||
|
|
||||||
bool Supports(const Stream &stream) const;
|
bool Supports(const Stream &stream) const;
|
||||||
bool Supports(const Capabilities &capability) const;
|
bool Supports(const Capabilities &capability) const;
|
||||||
bool Supports(const Option &option) const;
|
bool Supports(const Option &option) const;
|
||||||
|
@ -33,19 +45,46 @@ class Device {
|
||||||
std::shared_ptr<DeviceInfo> GetInfo() const;
|
std::shared_ptr<DeviceInfo> GetInfo() const;
|
||||||
std::string GetInfo(const Info &info) const;
|
std::string GetInfo(const Info &info) const;
|
||||||
|
|
||||||
Model model() const {
|
ImgIntrinsics GetImgIntrinsics() const;
|
||||||
return model_;
|
ImgExtrinsics GetImgExtrinsics() const;
|
||||||
}
|
|
||||||
|
ImuIntrinsics GetImuIntrinsics() const;
|
||||||
|
ImuExtrinsics GetImuExtrinsics() const;
|
||||||
|
|
||||||
|
void SetStreamCallback(const Stream &stream, stream_callback_t callback);
|
||||||
|
void SetMotionCallback(motion_callback_t callback);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<uvc::device> device() const {
|
std::shared_ptr<uvc::device> device() const {
|
||||||
return device_;
|
return device_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<DeviceInfo> device_info() const {
|
||||||
|
return device_info_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Model model_;
|
Model model_;
|
||||||
std::shared_ptr<uvc::device> device_;
|
std::shared_ptr<uvc::device> device_;
|
||||||
std::shared_ptr<DeviceInfo> device_info_;
|
std::shared_ptr<DeviceInfo> device_info_;
|
||||||
|
|
||||||
|
ImgIntrinsics img_intrinsics_;
|
||||||
|
ImgExtrinsics img_extrinsics_;
|
||||||
|
ImuIntrinsics imu_intrinsics_;
|
||||||
|
ImuExtrinsics imu_extrinsics_;
|
||||||
|
|
||||||
|
stream_callbacks_t stream_callbacks_;
|
||||||
|
motion_callback_t motion_callback_;
|
||||||
|
|
||||||
|
void ReadDeviceInfo();
|
||||||
|
|
||||||
|
void WriteImgIntrinsics(const ImgIntrinsics &intrinsics);
|
||||||
|
void WriteImgExtrinsics(const ImgExtrinsics &extrinsics);
|
||||||
|
|
||||||
|
void WriteImuIntrinsics(const ImuIntrinsics &intrinsics);
|
||||||
|
void WriteImuExtrinsics(const ImuExtrinsics &extrinsics);
|
||||||
|
|
||||||
|
// friend DeviceWriter;
|
||||||
};
|
};
|
||||||
|
|
||||||
MYNTEYE_END_NAMESPACE
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
29
src/internal/callbacks.h
Normal file
29
src/internal/callbacks.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef MYNTEYE_INTERNAL_CALLBACKS_H_ // NOLINT
|
||||||
|
#define MYNTEYE_INTERNAL_CALLBACKS_H_
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include "mynteye/mynteye.h"
|
||||||
|
#include "mynteye/types.h"
|
||||||
|
|
||||||
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
namespace device {
|
||||||
|
|
||||||
|
struct MYNTEYE_API StreamData {
|
||||||
|
ImgData img;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MYNTEYE_API MotionData {
|
||||||
|
ImuData imu;
|
||||||
|
};
|
||||||
|
|
||||||
|
using StreamCallback = std::function<void(const StreamData &data)>;
|
||||||
|
using MotionCallback = std::function<void(const MotionData &data)>;
|
||||||
|
|
||||||
|
} // namespace device
|
||||||
|
|
||||||
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // MYNTEYE_INTERNAL_CALLBACKS_H_ NOLINT
|
|
@ -12,20 +12,6 @@
|
||||||
|
|
||||||
MYNTEYE_BEGIN_NAMESPACE
|
MYNTEYE_BEGIN_NAMESPACE
|
||||||
|
|
||||||
#define MYNTEYE_FOURCC(a, b, c, d) \
|
|
||||||
((std::uint32_t)(a) | ((std::uint32_t)(b) << 8) | \
|
|
||||||
((std::uint32_t)(c) << 16) | ((std::uint32_t)(d) << 24)) // NOLINT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup enumerations
|
|
||||||
* @brief Formats define how each stream can be encoded.
|
|
||||||
*/
|
|
||||||
enum class Format : std::uint32_t {
|
|
||||||
YUYV = MYNTEYE_FOURCC('Y', 'U', 'Y', 'V'),
|
|
||||||
};
|
|
||||||
|
|
||||||
#undef MYNTEYE_FOURCC
|
|
||||||
|
|
||||||
#define MYNTEYE_PROPERTY(TYPE, NAME) \
|
#define MYNTEYE_PROPERTY(TYPE, NAME) \
|
||||||
public: \
|
public: \
|
||||||
void set_##NAME(TYPE NAME) { \
|
void set_##NAME(TYPE NAME) { \
|
||||||
|
|
|
@ -102,4 +102,16 @@ const char *to_string(const Option &value) {
|
||||||
#undef CASE
|
#undef CASE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *to_string(const Format &value) {
|
||||||
|
#define CASE(X) \
|
||||||
|
case Format::X: \
|
||||||
|
return "Format::" #X;
|
||||||
|
switch (value) {
|
||||||
|
CASE(YUYV)
|
||||||
|
default:
|
||||||
|
return "Format::UNKNOWN";
|
||||||
|
}
|
||||||
|
#undef CASE
|
||||||
|
}
|
||||||
|
|
||||||
MYNTEYE_END_NAMESPACE
|
MYNTEYE_END_NAMESPACE
|
||||||
|
|
|
@ -61,3 +61,7 @@ TEST(Option, VerifyToString) {
|
||||||
to_string(Option::ZERO_DRIFT_CALIBRATION));
|
to_string(Option::ZERO_DRIFT_CALIBRATION));
|
||||||
EXPECT_STREQ("Option::ERASE_CHIP", to_string(Option::ERASE_CHIP));
|
EXPECT_STREQ("Option::ERASE_CHIP", to_string(Option::ERASE_CHIP));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Format, VerifyToString) {
|
||||||
|
EXPECT_STREQ("Format::YUYV", to_string(Format::YUYV));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user