Add device layer
This commit is contained in:
30
src/device/context.cc
Normal file
30
src/device/context.cc
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "device/context.h"
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "device/device.h"
|
||||
#include "uvc/uvc.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
Context::Context() : context_(uvc::create_context()) {
|
||||
VLOG(2) << __func__;
|
||||
|
||||
for (auto &&device : uvc::query_devices(context_)) {
|
||||
auto name = uvc::get_name(*device);
|
||||
auto vid = uvc::get_vendor_id(*device);
|
||||
auto pid = uvc::get_product_id(*device);
|
||||
// auto video_name = uvc::get_video_name(*device);
|
||||
LOG(INFO) << "name: " << name << ", vid: 0x" << std::hex << vid
|
||||
<< ", pid: 0x" << std::hex << pid;
|
||||
if (vid == MYNTEYE_VID) {
|
||||
devices_.push_back(Device::Create(name, device));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context::~Context() {
|
||||
VLOG(2) << __func__;
|
||||
}
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
36
src/device/context.h
Normal file
36
src/device/context.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef MYNTEYE_CONTEXT_H_ // NOLINT
|
||||
#define MYNTEYE_CONTEXT_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
namespace uvc {
|
||||
|
||||
struct context;
|
||||
|
||||
} // namespace uvc
|
||||
|
||||
class Device;
|
||||
|
||||
class Context {
|
||||
public:
|
||||
Context();
|
||||
~Context();
|
||||
|
||||
std::vector<std::shared_ptr<Device>> devices() const {
|
||||
return devices_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<uvc::context> context_;
|
||||
std::vector<std::shared_ptr<Device>> devices_;
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_CONTEXT_H_ NOLINT
|
||||
22
src/device/device.cc
Normal file
22
src/device/device.cc
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "device/device.h"
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "uvc/uvc.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
Device::Device() {
|
||||
VLOG(2) << __func__;
|
||||
}
|
||||
|
||||
Device::~Device() {
|
||||
VLOG(2) << __func__;
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> Device::Create(
|
||||
const std::string &name, std::shared_ptr<uvc::device> device) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
31
src/device/device.h
Normal file
31
src/device/device.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef MYNTEYE_DEVICE_H_ // NOLINT
|
||||
#define MYNTEYE_DEVICE_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "mynteye/mynteye.h"
|
||||
|
||||
MYNTEYE_BEGIN_NAMESPACE
|
||||
|
||||
namespace uvc {
|
||||
|
||||
struct device;
|
||||
|
||||
} // namespace uvc
|
||||
|
||||
class Device {
|
||||
public:
|
||||
Device();
|
||||
virtual ~Device();
|
||||
|
||||
static std::shared_ptr<Device> Create(
|
||||
const std::string &name, std::shared_ptr<uvc::device> device);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
MYNTEYE_END_NAMESPACE
|
||||
|
||||
#endif // MYNTEYE_DEVICE_H_ NOLINT
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "uvc.h" // NOLINT
|
||||
#include "uvc/uvc.h" // NOLINT
|
||||
|
||||
#include <glog/logging.h>
|
||||
#include <libuvc/libuvc.h>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "uvc.h" // NOLINT
|
||||
#include "uvc/uvc.h" // NOLINT
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
@@ -79,6 +79,7 @@ struct device {
|
||||
std::string dev_name; // Device name (typically of the form /dev/video*)
|
||||
int busnum, devnum, parent_devnum; // USB device bus number and device number
|
||||
|
||||
std::string name; // Device description name
|
||||
int vid, pid, mi; // Vendor ID, product ID, and multiple interface index
|
||||
int fd = -1; // File descriptor for this device
|
||||
|
||||
@@ -125,6 +126,10 @@ struct device {
|
||||
if (!good)
|
||||
LOG(FATAL) << "Failed to read busnum/devnum";
|
||||
|
||||
if (!(std::ifstream("/sys/class/video4linux/" + name + "/name") >>
|
||||
this->name))
|
||||
LOG(FATAL) << "Failed to read name";
|
||||
|
||||
std::string modalias;
|
||||
if (!(std::ifstream(
|
||||
"/sys/class/video4linux/" + name + "/device/modalias") >>
|
||||
@@ -423,6 +428,10 @@ std::vector<std::shared_ptr<device>> query_devices(
|
||||
return devices;
|
||||
}
|
||||
|
||||
std::string get_name(const device &device) {
|
||||
return device.name;
|
||||
}
|
||||
|
||||
int get_vendor_id(const device &device) {
|
||||
return device.vid;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ std::vector<std::shared_ptr<device>> query_devices(
|
||||
std::shared_ptr<context> context);
|
||||
|
||||
// Static device properties
|
||||
std::string get_name(const device &device);
|
||||
int get_vendor_id(const device &device);
|
||||
int get_product_id(const device &device);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user