MYNT-EYE-S-SDK/src/internal/channels.h

158 lines
4.4 KiB
C
Raw Normal View History

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-09 10:54:14 +03:00
#ifndef MYNTEYE_INTERNAL_CHANNELS_H_ // NOLINT
#define MYNTEYE_INTERNAL_CHANNELS_H_
#pragma once
2018-04-09 17:24:34 +03:00
#include <map>
2018-04-09 10:54:14 +03:00
#include <memory>
2018-04-10 15:20:42 +03:00
#include <thread>
2018-04-09 10:54:14 +03:00
#include "mynteye/mynteye.h"
2018-04-13 11:08:47 +03:00
#include "mynteye/types.h"
2018-04-10 12:48:27 +03:00
#include "internal/types.h"
2018-04-09 17:24:34 +03:00
#include "uvc/uvc.h"
2018-04-09 10:54:14 +03:00
MYNTEYE_BEGIN_NAMESPACE
namespace uvc {
struct device;
struct xu;
} // namespace uvc
2018-04-23 18:11:11 +03:00
class MYNTEYE_API Channels {
2018-04-09 10:54:14 +03:00
public:
2018-04-09 17:24:34 +03:00
typedef enum Channel {
2018-05-29 07:21:30 +03:00
CHANNEL_CAM_CTRL = 1,
CHANNEL_HALF_DUPLEX = 2,
CHANNEL_IMU_WRITE = 3,
CHANNEL_IMU_READ = 4,
CHANNEL_FILE = 5,
2018-04-09 17:24:34 +03:00
CHANNEL_LAST
} channel_t;
typedef struct ControlInfo {
std::int32_t min;
std::int32_t max;
std::int32_t def;
} control_info_t;
2018-04-09 10:54:14 +03:00
2018-04-10 11:00:38 +03:00
typedef enum XuCmd {
XU_CMD_ZDC = 0xE6, // zero drift calibration
XU_CMD_ERASE = 0xDE, // erase chip
XU_CMD_LAST
} xu_cmd_t;
2018-04-13 11:08:47 +03:00
typedef enum FileId {
2018-04-19 12:23:02 +03:00
FID_DEVICE_INFO = 1, // device info
FID_IMG_PARAMS = 2, // image intrinsics & extrinsics
FID_IMU_PARAMS = 4, // imu intrinsics & extrinsics
2018-04-13 11:08:47 +03:00
FID_LAST,
} file_id_t;
2018-04-10 15:20:42 +03:00
using imu_callback_t = std::function<void(const ImuPacket &packet)>;
2018-04-13 11:08:47 +03:00
using device_info_t = DeviceInfo;
typedef struct ImgParams {
2018-04-19 12:23:02 +03:00
bool ok;
2018-09-14 15:00:28 +03:00
std::map<Resolution, Intrinsics> in_left_map;
std::map<Resolution, Intrinsics> in_right_map;
Extrinsics ex_left_to_right;
2018-04-13 11:08:47 +03:00
} img_params_t;
typedef struct ImuParams {
2018-04-19 12:23:02 +03:00
bool ok;
ImuIntrinsics in_accel;
ImuIntrinsics in_gyro;
Extrinsics ex_left_to_imu;
2018-04-13 11:08:47 +03:00
} imu_params_t;
2018-04-09 10:54:14 +03:00
explicit Channels(std::shared_ptr<uvc::device> device);
~Channels();
2018-04-09 19:26:22 +03:00
void LogControlInfos() const;
2018-04-10 08:58:37 +03:00
void UpdateControlInfos();
2018-04-09 19:26:22 +03:00
control_info_t GetControlInfo(const Option &option) const;
2018-04-10 11:00:38 +03:00
2018-04-09 19:26:22 +03:00
std::int32_t GetControlValue(const Option &option) const;
void SetControlValue(const Option &option, std::int32_t value);
2018-04-10 11:00:38 +03:00
bool RunControlAction(const Option &option) const;
2018-04-10 15:20:42 +03:00
void SetImuCallback(imu_callback_t callback);
void DoImuTrack();
2018-04-10 15:20:42 +03:00
void StartImuTracking(imu_callback_t callback = nullptr);
void StopImuTracking();
2018-04-13 11:08:47 +03:00
bool GetFiles(
2018-04-19 12:23:02 +03:00
device_info_t *info, img_params_t *img_params, imu_params_t *imu_params,
Version *spec_version = nullptr) const;
2018-04-13 11:08:47 +03:00
bool SetFiles(
2018-04-19 12:23:02 +03:00
device_info_t *info, img_params_t *img_params, imu_params_t *imu_params,
Version *spec_version = nullptr);
2018-04-13 11:08:47 +03:00
2018-04-09 10:54:14 +03:00
private:
2018-04-09 19:26:22 +03:00
bool PuControlRange(
Option option, int32_t *min, int32_t *max, int32_t *def) const;
bool PuControlQuery(Option option, uvc::pu_query query, int32_t *value) const;
bool XuControlRange(
channel_t channel, uint8_t id, int32_t *min, int32_t *max,
int32_t *def) const;
bool XuControlRange(
const uvc::xu &xu, uint8_t selector, uint8_t id, int32_t *min,
int32_t *max, int32_t *def) const;
2018-04-09 17:24:34 +03:00
bool XuControlQuery(
2018-04-10 11:00:38 +03:00
channel_t channel, uvc::xu_query query, uint16_t size,
2018-04-09 19:26:22 +03:00
uint8_t *data) const;
2018-04-09 17:24:34 +03:00
bool XuControlQuery(
const uvc::xu &xu, uint8_t selector, uvc::xu_query query, uint16_t size,
2018-04-09 19:26:22 +03:00
uint8_t *data) const;
bool XuCamCtrlQuery(uvc::xu_query query, uint16_t size, uint8_t *data) const;
std::int32_t XuCamCtrlGet(Option option) const;
2018-04-10 08:58:37 +03:00
void XuCamCtrlSet(Option option, std::int32_t value) const;
2018-04-09 19:26:22 +03:00
2018-04-10 11:00:38 +03:00
bool XuHalfDuplexSet(Option option, xu_cmd_t cmd) const;
2018-04-10 12:48:27 +03:00
bool XuImuWrite(const ImuReqPacket &req) const;
bool XuImuRead(ImuResPacket *res) const;
2018-04-13 11:08:47 +03:00
bool XuFileQuery(uvc::xu_query query, uint16_t size, uint8_t *data) const;
2018-04-09 19:26:22 +03:00
control_info_t PuControlInfo(Option option) const;
control_info_t XuControlInfo(Option option) const;
2018-04-09 10:54:14 +03:00
std::shared_ptr<uvc::device> device_;
2018-04-09 17:24:34 +03:00
2018-04-09 19:26:22 +03:00
std::map<Option, control_info_t> control_infos_;
2018-04-10 15:20:42 +03:00
bool is_imu_tracking_;
std::thread imu_track_thread_;
volatile bool imu_track_stop_;
std::uint32_t imu_sn_;
imu_callback_t imu_callback_;
2018-04-09 10:54:14 +03:00
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_INTERNAL_CHANNELS_H_ NOLINT