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