• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef HIDUTIL_HIDREPORT_H_
17 #define HIDUTIL_HIDREPORT_H_
18 
19 #include "HidGlobal.h"
20 #include "HidLocal.h"
21 #include "TriState.h"
22 #include <cstdint>
23 #include <memory>
24 #include <iostream>
25 #include <utility>
26 
27 namespace HidUtil {
28 
29 class HidParser;
30 class HidTreeNode;
31 
32 // HidReport represent an input, output or feature report
33 class HidReport {
34     friend std::ostream& operator<<(std::ostream& os, const HidReport& h);
35 public:
36     HidReport(uint32_t type_, uint32_t data, const HidGlobal &global, const HidLocal &local);
37 
38     // This is called during parsing process when the parser regroups multi-valued report into one
39     void setCollapsed(uint32_t fullUsage);
40 
41     // get report id
42     unsigned int getReportId() const;
43     // get type of report, return constant of HidDef::MainTag
44     unsigned int getType() const;
45     // Full sensor usage
46     unsigned int getFullUsage() const;
47 
48     // binary properties
49     bool isArray() const;
50     bool isData() const;
51     bool isVariable() const;
52 
53     // logical and physical value range
54     std::pair<int64_t, int64_t> getLogicalRange() const;
55     std::pair<int64_t, int64_t> getPhysicalRange() const;
56     double getExponentValue() const;
57 
58     // return HID unit nibbles in an unsigned int
59     unsigned int getUnit() const;
60 
61     // size in bits
62     size_t getSize() const;
63     // dimension (if it is vector/matrix) or number of concurrent input values
64     // it is also used to calculate memory foot print
65     size_t getCount() const;
66 
67     // for output to stream
68     static std::string reportTypeToString(int type);
69     std::string getStringType() const;
70     std::string getExponentString() const;
71     std::string getUnitString() const;
72     std::string getFlagString() const;
73     const std::vector<unsigned int>& getUsageVector() const;
74 private:
75     bool mIsCollapsed;
76 
77     // mandatary fields
78     unsigned int mReportType;
79     unsigned int mFlag;
80     unsigned int mUsagePage;
81     unsigned int mUsage;
82     std::vector<unsigned int> mUsageVector;
83 
84     int mLogicalMin;        // 32 bit is enough
85     int mLogicalMax;
86     unsigned int mReportSize;
87     unsigned int mReportCount;
88 
89     // these below are optional
90     tri_int mPhysicalMin;
91     tri_int mPhysicalMax;
92 
93     tri_uint mExponent;
94     tri_uint mUnit;
95     tri_uint mReportId;
96 };
97 
98 std::ostream& operator<<(std::ostream& os, const HidReport& h);
99 } // namespace HidUtil
100 #endif // HIDUTIL_HIDREPORT_H_
101