summaryrefslogtreecommitdiff
path: root/modules/sensors/dynamic_sensor/HidUtils/HidReport.h
blob: 9b01b68af44164e09924126adb605387fd59b4e8 (plain)
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
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * 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.
 */
#ifndef HIDUTIL_HIDREPORT_H_
#define HIDUTIL_HIDREPORT_H_

#include "HidGlobal.h"
#include "HidLocal.h"
#include "TriState.h"
#include <cstdint>
#include <memory>
#include <iostream>
#include <utility>

namespace HidUtil {

class HidParser;
class HidTreeNode;

// HidReport represent an input, output or feature report
class HidReport {
    friend std::ostream& operator<<(std::ostream& os, const HidReport& h);
public:
    HidReport(uint32_t type_, uint32_t data, const HidGlobal &global, const HidLocal &local);

    // This is called during parsing process when the parser regroups multi-valued report into one
    void setCollapsed(uint32_t fullUsage);

    // get report id
    unsigned int getReportId() const;
    // get type of report, return constant of HidDef::MainTag
    unsigned int getType() const;
    // Full sensor usage
    unsigned int getFullUsage() const;

    // binary properties
    bool isArray() const;
    bool isData() const;
    bool isVariable() const;

    // logical and physical value range
    std::pair<int64_t, int64_t> getLogicalRange() const;
    std::pair<int64_t, int64_t> getPhysicalRange() const;
    double getExponentValue() const;

    // return HID unit nibbles in an unsigned int
    unsigned int getUnit() const;

    // size in bits
    size_t getSize() const;
    // dimension (if it is vector/matrix) or number of concurrent input values
    // it is also used to calculate memory foot print
    size_t getCount() const;

    // for output to stream
    static std::string reportTypeToString(int type);
    std::string getStringType() const;
    std::string getExponentString() const;
    std::string getUnitString() const;
    std::string getFlagString() const;
    const std::vector<unsigned int>& getUsageVector() const;
private:
    bool mIsCollapsed;

    // mandatary fields
    unsigned int mReportType;
    unsigned int mFlag;
    unsigned int mUsagePage;
    unsigned int mUsage;
    std::vector<unsigned int> mUsageVector;

    int mLogicalMin;        // 32 bit is enough
    int mLogicalMax;
    unsigned int mReportSize;
    unsigned int mReportCount;

    // these below are optional
    tri_int mPhysicalMin;
    tri_int mPhysicalMax;

    tri_uint mExponent;
    tri_uint mUnit;
    tri_uint mReportId;
};

std::ostream& operator<<(std::ostream& os, const HidReport& h);
} // namespace HidUtil
#endif // HIDUTIL_HIDREPORT_H_