1 /*
2  * Copyright (c) 2024 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 #include "virtual_pc_touchpad.h"
17 
18 namespace OHOS {
19 namespace MMI {
20 namespace {
21 constexpr int32_t ABS_MAX_X = 1919;
22 constexpr int32_t ABS_MAX_Y = 1079;
23 constexpr int32_t ABS_SLOT_MAX = 4;
24 constexpr int32_t ABS_POSITION_X_MAX = 1919;
25 constexpr int32_t ABS_POSITION_Y_MAX = 1079;
26 constexpr int32_t ABS_MT_TOOL_TYPE_MAX = 2;
27 constexpr int32_t ABS_MT_TRACKING_ID_MAX = 65535;
28 constexpr int32_t ABS_X_RANGE = 16;
29 constexpr int32_t ABS_Y_RANGE = 15;
30 constexpr int32_t ABS_MT_X_RANGE = 16;
31 constexpr int32_t ABS_MT_Y_RANGE = 15;
32 
33 AbsInfo absInfos[] = {
34     { ABS_X, 0, ABS_MAX_X, 0, 0 },
35     { ABS_Y, 0, ABS_MAX_Y, 0, 0 },
36     { ABS_MT_SLOT, 0, ABS_SLOT_MAX, 0, 0 },
37     { ABS_MT_POSITION_X, 0, ABS_POSITION_X_MAX, 0, 0 },
38     { ABS_MT_POSITION_Y, 0, ABS_POSITION_Y_MAX, 0, 0 },
39     { ABS_MT_TOOL_TYPE, 0, ABS_MT_TOOL_TYPE_MAX, 0, 0 },
40     { ABS_MT_TRACKING_ID, 0, ABS_MT_TRACKING_ID_MAX, 0, 0 }
41 };
42 
43 ResolutionInfo resolutionInfos[] = {
44     { ABS_X, ABS_X_RANGE },
45     { ABS_Y, ABS_Y_RANGE },
46     { ABS_MT_POSITION_X, ABS_MT_X_RANGE },
47     { ABS_MT_POSITION_Y, ABS_MT_Y_RANGE }
48 };
49 } // namespace
50 
VirtualPcTouchpad()51 VirtualPcTouchpad::VirtualPcTouchpad() : VirtualDevice("Virtual PcTouchPad", BUS_USB, 0x27c6, 0x100)
52 {
53     eventTypes_ = { EV_KEY, EV_ABS, EV_MSC };
54     keys_ = { BTN_LEFT, BTN_TOOL_FINGER, BTN_TOOL_QUINTTAP, BTN_TOUCH, BTN_TOOL_DOUBLETAP, BTN_TOOL_TRIPLETAP,
55         BTN_TOOL_QUADTAP };
56     abs_ = { ABS_X, ABS_Y, ABS_MT_SLOT, ABS_MT_POSITION_X, ABS_MT_POSITION_Y, ABS_MT_TOOL_TYPE, ABS_MT_TRACKING_ID };
57     miscellaneous_ = { MSC_SCAN };
58     properties_ = { INPUT_PROP_POINTER, INPUT_PROP_BUTTONPAD };
59     for (const auto &item : absInfos) {
60         SetAbsValue(item);
61     }
62 
63     for (const auto &item : resolutionInfos) {
64         SetResolution(item);
65     }
66 }
67 } // namespace MMI
68 } // namespace OHOS