1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef INPUT_DEVICE_H
17 #define INPUT_DEVICE_H
18
19 #include <bitset>
20 #include <string>
21 #include <vector>
22
23 #include "nocopyable.h"
24
25 namespace OHOS {
26 namespace MMI {
27 enum InputDeviceCapability {
28 INPUT_DEV_CAP_KEYBOARD,
29 INPUT_DEV_CAP_POINTER,
30 INPUT_DEV_CAP_TOUCH,
31 INPUT_DEV_CAP_TABLET_TOOL,
32 INPUT_DEV_CAP_TABLET_PAD,
33 INPUT_DEV_CAP_GESTURE,
34 INPUT_DEV_CAP_SWITCH,
35 INPUT_DEV_CAP_JOYSTICK,
36 INPUT_DEV_CAP_MAX
37 };
38
39 enum FunctionKey {
40 FUNCTION_KEY_CAPSLOCK = 1,
41 };
42
CapabilityToTags(InputDeviceCapability capability)43 inline constexpr uint32_t CapabilityToTags(InputDeviceCapability capability)
44 {
45 return static_cast<uint32_t>((1 << capability) - (capability / INPUT_DEV_CAP_MAX));
46 }
47
48 enum KeyboardType {
49 KEYBOARD_TYPE_NONE,
50 KEYBOARD_TYPE_UNKNOWN,
51 KEYBOARD_TYPE_ALPHABETICKEYBOARD,
52 KEYBOARD_TYPE_DIGITALKEYBOARD,
53 KEYBOARD_TYPE_HANDWRITINGPEN,
54 KEYBOARD_TYPE_REMOTECONTROL,
55 KEYBOARD_TYPE_MAX
56 };
57
58 class InputDevice {
59 public:
60 InputDevice() = default;
61 DISALLOW_COPY_AND_MOVE(InputDevice);
62 ~InputDevice() = default;
63
64 void SetId(int32_t deviceId);
65 int32_t GetId() const;
66 void SetName(std::string name);
67 std::string GetName() const;
68 void SetType(int32_t deviceType);
69 int32_t GetType() const;
70 void SetBus(int32_t bus);
71 int32_t GetBus() const;
72 void SetVersion(int32_t version);
73 int32_t GetVersion() const;
74 void SetProduct(int32_t product);
75 int32_t GetProduct() const;
76 void SetVendor(int32_t vendor);
77 int32_t GetVendor() const;
78 void SetPhys(std::string phys);
79 std::string GetPhys() const;
80 void SetUniq(std::string uniq);
81 std::string GetUniq() const;
82 void AddCapability(InputDeviceCapability cap);
83 bool HasCapability(InputDeviceCapability cap) const;
84 bool HasCapability(uint32_t deviceTags) const;
85
86 unsigned long GetCapabilities() const;
87 void SetCapabilities(unsigned long caps);
88
89 class AxisInfo {
90 public:
91 AxisInfo() = default;
92 AxisInfo(int32_t type, int32_t min, int32_t max, int32_t fuzz, int32_t flat, int32_t resolution);
93 ~AxisInfo() = default;
94 void SetAxisType(int32_t type);
95 int32_t GetAxisType() const;
96 void SetMinimum(int32_t min);
97 int32_t GetMinimum() const;
98 void SetMaximum(int32_t max);
99 int32_t GetMaximum() const;
100 void SetFuzz(int32_t fuzz);
101 int32_t GetFuzz() const;
102 void SetFlat(int32_t flat);
103 int32_t GetFlat() const;
104 void SetResolution(int32_t resolution);
105 int32_t GetResolution() const;
106
107 private:
108 int32_t axisType_ { 0 };
109 int32_t minimum_ { 0 };
110 int32_t maximum_ { 0 };
111 int32_t fuzz_ { 0 };
112 int32_t flat_ { 0 };
113 int32_t resolution_ { 0 };
114 };
115
116 void AddAxisInfo(AxisInfo axis);
117 std::vector<AxisInfo> GetAxisInfo();
118 void SetAxisInfo(std::vector<AxisInfo> axis);
119 InputDevice(int32_t id, std::string name, int32_t deviceType, int32_t bus, int32_t version, int32_t product,
120 int32_t vendor, std::string phys, std::string uniq, const std::vector<AxisInfo>& axis);
121
122 private:
123 int32_t id_ { -1 };
124 std::string name_ { "null" };
125 int32_t type_ { 0 };
126 int32_t bus_ { -1 };
127 int32_t version_ { -1 };
128 int32_t product_ { -1 };
129 int32_t vendor_ { -1 };
130 std::string phys_ { "null" };
131 std::string uniq_ { "null" };
132 std::vector<AxisInfo> axis_;
133 std::bitset<INPUT_DEV_CAP_MAX> capabilities_;
134 };
135
GetCapabilities()136 inline unsigned long InputDevice::GetCapabilities() const
137 {
138 return capabilities_.to_ulong();
139 }
140
SetCapabilities(unsigned long caps)141 inline void InputDevice::SetCapabilities(unsigned long caps)
142 {
143 capabilities_ = std::bitset<INPUT_DEV_CAP_MAX>(caps % (1 << INPUT_DEV_CAP_MAX));
144 }
145 } // namespace MMI
146 } // namespace OHOS
147 #endif // INPUT_DEVICE_H