From d80189512d8ce13ca4d5ef0c1e3b29cc29e7b043 Mon Sep 17 00:00:00 2001 From: John Zhao Date: Sat, 7 Apr 2018 09:36:41 +0800 Subject: [PATCH] Add start/stop source --- include/mynteye/types.h | 16 +++++++++++++++ src/device/device.cc | 41 +++++++++++++++++++++++++++++++++++++++ src/device/device.h | 9 +++++++++ src/public/types.cc | 14 +++++++++++++ test/public/types_test.cc | 6 ++++++ 5 files changed, 86 insertions(+) diff --git a/include/mynteye/types.h b/include/mynteye/types.h index b0961e7..f518f9d 100644 --- a/include/mynteye/types.h +++ b/include/mynteye/types.h @@ -149,6 +149,21 @@ enum class Option : std::uint8_t { LAST }; +/** + * @ingroup enumerations + * @brief Source allows the user to choose which data to be captured. + */ +enum class Source : std::uint8_t { + /** Video streaming of stereo, color, depth, etc. */ + VIDEO_STREAMING, + /** Motion tracking of IMU (accelerometer, gyroscope) */ + MOTION_TRACKING, + /** Enable everything together */ + ALL, + /** Last guard */ + LAST +}; + #define MYNTEYE_ENUM_HELPERS(TYPE) \ const char *to_string(const TYPE &value); \ inline bool is_valid(const TYPE &value) { \ @@ -170,6 +185,7 @@ MYNTEYE_ENUM_HELPERS(Stream) MYNTEYE_ENUM_HELPERS(Capabilities) MYNTEYE_ENUM_HELPERS(Info) MYNTEYE_ENUM_HELPERS(Option) +MYNTEYE_ENUM_HELPERS(Source) #undef MYNTEYE_ENUM_HELPERS diff --git a/src/device/device.cc b/src/device/device.cc index cad1aa1..637806a 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -113,6 +113,32 @@ void Device::SetMotionCallback(motion_callback_t callback) { motion_callback_ = callback; } +void Device::Start(const Source &source) { + if (source == Source::VIDEO_STREAMING) { + StartVideoStreaming(); + } else if (source == Source::MOTION_TRACKING) { + StartMotionTracking(); + } else if (source == Source::ALL) { + Start(Source::VIDEO_STREAMING); + Start(Source::MOTION_TRACKING); + } else { + LOG(FATAL) << "Unsupported source :("; + } +} + +void Device::Stop(const Source &source) { + if (source == Source::VIDEO_STREAMING) { + StopVideoStreaming(); + } else if (source == Source::MOTION_TRACKING) { + StopMotionTracking(); + } else if (source == Source::ALL) { + Stop(Source::VIDEO_STREAMING); + Stop(Source::MOTION_TRACKING); + } else { + LOG(FATAL) << "Unsupported source :("; + } +} + StreamRequest Device::GetStreamRequest(const Capabilities &capability) const { if (!Supports(capability)) { LOG(FATAL) << "Unsupported capability: " << to_string(capability); @@ -121,6 +147,21 @@ StreamRequest Device::GetStreamRequest(const Capabilities &capability) const { return requests.at(capability); } +void Device::StartVideoStreaming() {} + +void Device::StopVideoStreaming() {} + +void Device::StartMotionTracking() { + if (!Supports(Capabilities::IMU)) { + LOG(FATAL) << "IMU is not supported by this device"; + } + // TODO(JohnZhao) +} + +void Device::StopMotionTracking() { + // TODO(JohnZhao) +} + void Device::ReadDeviceInfo() { // TODO(JohnZhao): Read device info } diff --git a/src/device/device.h b/src/device/device.h index 2b2f325..e0391cc 100644 --- a/src/device/device.h +++ b/src/device/device.h @@ -54,6 +54,9 @@ class Device { void SetStreamCallback(const Stream &stream, stream_callback_t callback); void SetMotionCallback(motion_callback_t callback); + virtual void Start(const Source &source); + virtual void Stop(const Source &source); + protected: std::shared_ptr device() const { return device_; @@ -65,6 +68,12 @@ class Device { StreamRequest GetStreamRequest(const Capabilities &capability) const; + virtual void StartVideoStreaming(); + virtual void StopVideoStreaming(); + + virtual void StartMotionTracking(); + virtual void StopMotionTracking(); + private: Model model_; std::shared_ptr device_; diff --git a/src/public/types.cc b/src/public/types.cc index 9dbc97a..ef10981 100644 --- a/src/public/types.cc +++ b/src/public/types.cc @@ -102,6 +102,20 @@ const char *to_string(const Option &value) { #undef CASE } +const char *to_string(const Source &value) { +#define CASE(X) \ + case Source::X: \ + return "Source::" #X; + switch (value) { + CASE(VIDEO_STREAMING) + CASE(MOTION_TRACKING) + CASE(ALL) + default: + return "Source::UNKNOWN"; + } +#undef CASE +} + const char *to_string(const Format &value) { #define CASE(X) \ case Format::X: \ diff --git a/test/public/types_test.cc b/test/public/types_test.cc index 5369fa2..d5eab36 100644 --- a/test/public/types_test.cc +++ b/test/public/types_test.cc @@ -62,6 +62,12 @@ TEST(Option, VerifyToString) { EXPECT_STREQ("Option::ERASE_CHIP", to_string(Option::ERASE_CHIP)); } +TEST(Source, VerifyToString) { + EXPECT_STREQ("Source::VIDEO_STREAMING", to_string(Source::VIDEO_STREAMING)); + EXPECT_STREQ("Source::MOTION_TRACKING", to_string(Source::MOTION_TRACKING)); + EXPECT_STREQ("Source::ALL", to_string(Source::ALL)); +} + TEST(Format, VerifyToString) { EXPECT_STREQ("Format::YUYV", to_string(Format::YUYV)); }