1 /*
2  * Copyright (c) 2021-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_touch_screen.h"
17 
18 #include "linux/input-event-codes.h"
19 #include "linux/uinput.h"
20 
21 namespace OHOS {
22 namespace MMI {
23 namespace {
24 constexpr int32_t ABS_MAX_PRESSURE = 100;
25 constexpr int32_t ABS_MT_MIN_ORIENTATION = -90;
26 constexpr int32_t ABS_MT_MAX_ORIENTATION = 90;
27 constexpr int32_t ABS_MT_BLOB_MAX_ID = 10;
28 constexpr int32_t ABS_MT_TRACKING_MAX_ID = 9;
29 constexpr int32_t ABS_MT_MAX_PRESSURE = 100;
30 } // namespace
31 
GetEventTypes() const32 const std::vector<uint32_t> &VirtualTouchScreen::GetEventTypes() const
33 {
34     static const std::vector<uint32_t> evtTypes {EV_ABS, EV_KEY, EV_SYN};
35     return evtTypes;
36 }
37 
GetKeys() const38 const std::vector<uint32_t> &VirtualTouchScreen::GetKeys() const
39 {
40     static const std::vector<uint32_t> keys {BTN_TOUCH};
41     return keys;
42 }
43 
GetProperties() const44 const std::vector<uint32_t> &VirtualTouchScreen::GetProperties() const
45 {
46     static const std::vector<uint32_t> properties {INPUT_PROP_DIRECT};
47     return properties;
48 }
49 
GetAbs() const50 const std::vector<uint32_t> &VirtualTouchScreen::GetAbs() const
51 {
52     static const std::vector<uint32_t> abs {
53         ABS_X,
54         ABS_Y,
55         ABS_PRESSURE,
56         ABS_MT_TOUCH_MAJOR,
57         ABS_MT_TOUCH_MINOR,
58         ABS_MT_ORIENTATION,
59         ABS_MT_POSITION_X,
60         ABS_MT_POSITION_Y,
61         ABS_MT_BLOB_ID,
62         ABS_MT_TRACKING_ID,
63         ABS_MT_PRESSURE
64         };
65     return abs;
66 }
67 
VirtualTouchScreen(const uint32_t maxX,const uint32_t maxY)68 VirtualTouchScreen::VirtualTouchScreen(const uint32_t maxX, const uint32_t maxY)
69     : VirtualDevice("VSoC touchscreen", 0x6006)
70 {
71     dev_.absmin[ABS_X] = 0;
72     dev_.absmax[ABS_X] = maxX;
73     dev_.absmin[ABS_Y] = 0;
74     dev_.absmax[ABS_Y] = maxY;
75 
76     dev_.absmin[ABS_PRESSURE] = 0;
77     dev_.absmax[ABS_PRESSURE] = ABS_MAX_PRESSURE;
78 
79     dev_.absmin[ABS_MT_TOUCH_MAJOR] = 0;
80     dev_.absmax[ABS_MT_TOUCH_MAJOR] = 1;
81     dev_.absmin[ABS_MT_TOUCH_MINOR] = 0;
82     dev_.absmax[ABS_MT_TOUCH_MINOR] = 1;
83 
84     dev_.absmin[ABS_MT_ORIENTATION] = ABS_MT_MIN_ORIENTATION;
85     dev_.absmax[ABS_MT_ORIENTATION] = ABS_MT_MAX_ORIENTATION;
86 
87     dev_.absmin[ABS_MT_POSITION_X] = 0;
88     dev_.absmax[ABS_MT_POSITION_X] = maxX;
89     dev_.absmin[ABS_MT_POSITION_Y] = 0;
90     dev_.absmax[ABS_MT_POSITION_Y] = maxY;
91 
92     dev_.absmin[ABS_MT_BLOB_ID] = 0;
93     dev_.absmax[ABS_MT_BLOB_ID] = ABS_MT_BLOB_MAX_ID;
94     dev_.absmin[ABS_MT_TRACKING_ID] = 0;
95     dev_.absmax[ABS_MT_TRACKING_ID] = ABS_MT_TRACKING_MAX_ID;
96     dev_.absmin[ABS_MT_PRESSURE] = 0;
97     dev_.absmax[ABS_MT_PRESSURE] = ABS_MT_MAX_PRESSURE;
98 }
99 } // namespace MMI
100 } // namespace OHOS
101