hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * imu_service.h - interfaces for EIS algorithm to access imu sensor
 *
 *  Copyright (c) 2021 Rockchip Electronics Co., Ltd.
 *
 * 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.
 *
 * Author: Cody Xie <cody.xie@rock-chips.com>
 */
#ifndef ALGOS_AEIS_IMU_SERVICE_H
#define ALGOS_AEIS_IMU_SERVICE_H
 
#include <memory>
#include <utility>
#include <vector>
 
#include "rk_aiq_mems_sensor.h"
#include "task_service.h"
#include "xcam_common.h"
 
using namespace XCam;
 
namespace RkCam {
 
class EisImuAdaptor;
 
class EisImuData {
 public:
    EisImuData() = delete;
    explicit EisImuData(std::shared_ptr<EisImuAdaptor> imu, mems_sensor_type_t type,
                        mems_sensor_event_t* data, size_t count);
    EisImuData(const EisImuData&) = delete;
    const EisImuData& operator=(const EisImuData&) = delete;
    ~EisImuData();
 
    const mems_sensor_type_t GetType();
    const mems_sensor_event_t* GetData();
    const size_t GetCount();
 
 private:
    const std::shared_ptr<EisImuAdaptor> imu_;
    const mems_sensor_type_t type_;
    mems_sensor_event_t* data_;
    const size_t count_;
};
 
class EisImuAdaptor : std::enable_shared_from_this<EisImuAdaptor> {
 public:
    EisImuAdaptor() = delete;
    explicit EisImuAdaptor(const rk_aiq_mems_sensor_intf_t intf,
                           const mems_sensor_type_t type = SENSOR_ALL_TYPE);
    EisImuAdaptor(const EisImuAdaptor&) = delete;
    const EisImuAdaptor& operator=(const EisImuAdaptor&) = delete;
    ~EisImuAdaptor();
 
    constexpr const mems_sensor_type_t GetType() { return type_; };
    std::shared_ptr<EisImuAdaptor> GetPtr() { return shared_from_this(); }
 
    mems_sensor_event_t* GetData(size_t* num_sample);
    void FreeData(mems_sensor_event_t* data);
 
    XCamReturn Init(float sample_rate);
 
 private:
    XCamReturn DeInit();
 
    const rk_aiq_mems_sensor_intf_t intf_;
    const mems_sensor_type_t type_;
    std::string key_;
    mems_sensor_ctx_t ctx_;
    mems_sensor_handle_t handle_;
    std::vector<std::pair<size_t, mems_sensor_event_t*>> datas_;
};
 
struct imu_param {
    int frame_id;
    TaskTimePoint time_point;
    std::unique_ptr<EisImuData> data;
};
 
class ImuTask final : public ServiceTask<imu_param> {
 public:
    ImuTask() = delete;
    explicit ImuTask(std::shared_ptr<EisImuAdaptor> imu) : imu_(imu) {}
    ImuTask(const ImuTask&) = delete;
    const ImuTask& operator=(const ImuTask&) = delete;
    ~ImuTask()                               = default;
 
    TaskResult operator()(ServiceParam<imu_param>& p);
 
 private:
    std::shared_ptr<EisImuAdaptor> imu_;
};
 
using ImuService = TaskService<imu_param>;
 
};  // namespace RkCam
 
#endif  // ALGOS_AEIS_IMU_SERVICE_H