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 <vector>
21
22 #include "nocopyable.h"
23
24 namespace OHOS {
25 namespace MMI {
26 enum InputDeviceCapability {
27 INPUT_DEV_CAP_KEYBOARD,
28 INPUT_DEV_CAP_POINTER,
29 INPUT_DEV_CAP_TOUCH,
30 INPUT_DEV_CAP_TABLET_TOOL,
31 INPUT_DEV_CAP_TABLET_PAD,
32 INPUT_DEV_CAP_GESTURE,
33 INPUT_DEV_CAP_SWITCH,
34 INPUT_DEV_CAP_JOYSTICK,
35 INPUT_DEV_CAP_MAX
36 };
37
38 enum FunctionKey {
39 FUNCTION_KEY_CAPSLOCK = 1,
40 };
41
CapabilityToTags(InputDeviceCapability capability)42 inline constexpr uint32_t CapabilityToTags(InputDeviceCapability capability)
43 {
44 return static_cast<uint32_t>((1 << capability) - (capability / INPUT_DEV_CAP_MAX));
45 }
46
47 enum KeyboardType {
48 KEYBOARD_TYPE_NONE,
49 KEYBOARD_TYPE_UNKNOWN,
50 KEYBOARD_TYPE_ALPHABETICKEYBOARD,
51 KEYBOARD_TYPE_DIGITALKEYBOARD,
52 KEYBOARD_TYPE_HANDWRITINGPEN,
53 KEYBOARD_TYPE_REMOTECONTROL,
54 KEYBOARD_TYPE_MAX
55 };
56
57 class InputDevice {
58 public:
59 InputDevice() = default;
60 DISALLOW_COPY_AND_MOVE(InputDevice);
61 ~InputDevice() = default;
62
63 void SetId(int32_t deviceId);
64 int32_t GetId() const;
65 void SetName(std::string name);
66 std::string GetName() const;
67 void SetType(int32_t deviceType);
68 int32_t GetType() const;
69 void SetBus(int32_t bus);
70 int32_t GetBus() const;
71 void SetVersion(int32_t version);
72 int32_t GetVersion() const;
73 void SetProduct(int32_t product);
74 int32_t GetProduct() const;
75 void SetVendor(int32_t vendor);
76 int32_t GetVendor() const;
77 void SetPhys(std::string phys);
78 std::string GetPhys() const;
79 void SetUniq(std::string uniq);
80 std::string GetUniq() const;
81 void AddCapability(InputDeviceCapability cap);
82 bool HasCapability(InputDeviceCapability cap) const;
83 bool HasCapability(uint32_t deviceTags) const;
84
85 unsigned long GetCapabilities() const;
86 void SetCapabilities(unsigned long caps);
87
88 class AxisInfo {
89 public:
90 AxisInfo() = default;
91 AxisInfo(int32_t type, int32_t min, int32_t max, int32_t fuzz, int32_t flat, int32_t resolution);
92 ~AxisInfo() = default;
93 void SetAxisType(int32_t type);
94 int32_t GetAxisType() const;
95 void SetMinimum(int32_t min);
96 int32_t GetMinimum() const;
97 void SetMaximum(int32_t max);
98 int32_t GetMaximum() const;
99 void SetFuzz(int32_t fuzz);
100 int32_t GetFuzz() const;
101 void SetFlat(int32_t flat);
102 int32_t GetFlat() const;
103 void SetResolution(int32_t resolution);
104 int32_t GetResolution() const;
105
106 private:
107 int32_t axisType_ { 0 };
108 int32_t minimum_ { 0 };
109 int32_t maximum_ { 0 };
110 int32_t fuzz_ { 0 };
111 int32_t flat_ { 0 };
112 int32_t resolution_ { 0 };
113 };
114
115 void AddAxisInfo(AxisInfo axis);
116 std::vector<AxisInfo> GetAxisInfo();
117 void SetAxisInfo(std::vector<AxisInfo> axis);
118 InputDevice(int32_t id, std::string name, int32_t deviceType, int32_t bus, int32_t version, int32_t product,
119 int32_t vendor, std::string phys, std::string uniq, const std::vector<AxisInfo>& axis);
120
121 private:
122 int32_t id_ { -1 };
123 std::string name_ { "null" };
124 int32_t type_ { 0 };
125 int32_t bus_ { -1 };
126 int32_t version_ { -1 };
127 int32_t product_ { -1 };
128 int32_t vendor_ { -1 };
129 std::string phys_ { "null" };
130 std::string uniq_ { "null" };
131 std::vector<AxisInfo> axis_;
132 std::bitset<INPUT_DEV_CAP_MAX> capabilities_;
133 };
134
GetCapabilities()135 inline unsigned long InputDevice::GetCapabilities() const
136 {
137 return capabilities_.to_ulong();
138 }
139
SetCapabilities(unsigned long caps)140 inline void InputDevice::SetCapabilities(unsigned long caps)
141 {
142 capabilities_ = std::bitset<INPUT_DEV_CAP_MAX>(caps % (1 << INPUT_DEV_CAP_MAX));
143 }
144 } // namespace MMI
145 } // namespace OHOS
146 #endif // INPUT_DEVICE_H