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 #include "virtual_stylus.h"
17 
18 namespace OHOS {
19 namespace MMI {
20 namespace {
21 constexpr int32_t ABS_MAX_X = 31920;
22 constexpr int32_t ABS_MAX_Y = 19950;
23 constexpr int32_t ABS_MIN_Z = -900;
24 constexpr int32_t ABS_MAX_Z = 899;
25 constexpr int32_t ABS_MAX_WHEEL = 2047;
26 constexpr int32_t ABS_MAX_PRESSURE = 8191;
27 constexpr int32_t ABS_MIN_TILT_XY = -64;
28 constexpr int32_t ABS_MAX_TILT_XY_DISTANCE = 63;
29 constexpr int32_t ABS_MIN_MISC = -2147483648;
30 constexpr int32_t ABS_MAX_MISC = 2147483647;
31 constexpr int32_t ABS_FUZZ_XY = 4;
32 constexpr int32_t STYLUS_ABS_RANGE = 200;
33 
34 AbsInfo absInfos[] = {
35     { ABS_X, 0, ABS_MAX_X, ABS_FUZZ_XY, 0 },
36     { ABS_Y, 0, ABS_MAX_Y, ABS_FUZZ_XY, 0 },
37     { ABS_Z, ABS_MIN_Z, ABS_MAX_Z, 0, 0 },
38     { ABS_WHEEL, 0, ABS_MAX_WHEEL, 0, 0 },
39     { ABS_PRESSURE, 0, ABS_MAX_PRESSURE, 0, 0 },
40     { ABS_DISTANCE, 0, ABS_MAX_TILT_XY_DISTANCE, 0, 0 },
41     { ABS_TILT_X, ABS_MIN_TILT_XY, ABS_MAX_TILT_XY_DISTANCE, 0, 0 },
42     { ABS_TILT_Y, ABS_MIN_TILT_XY, ABS_MAX_TILT_XY_DISTANCE, 0, 0 },
43     { ABS_MISC, ABS_MIN_MISC, ABS_MAX_MISC, 0, 0 }
44 };
45 
46 ResolutionInfo resolutionInfos[] = {
47     { ABS_X, STYLUS_ABS_RANGE },
48     { ABS_Y, STYLUS_ABS_RANGE }
49 };
50 } // namespace
51 
VirtualStylus()52 VirtualStylus::VirtualStylus() : VirtualDevice("Virtual Stylus", BUS_USB, 0x56a, 0x392)
53 {
54     eventTypes_ = { EV_KEY, EV_ABS, EV_MSC };
55     miscellaneous_ = { MSC_SERIAL };
56     properties_ = { INPUT_PROP_POINTER };
57     abs_ = { ABS_X, ABS_Y, ABS_Z, ABS_WHEEL, ABS_PRESSURE, ABS_DISTANCE, ABS_TILT_X, ABS_TILT_Y, ABS_MISC };
58     keys_ = {
59         BTN_TOOL_PEN, BTN_TOOL_RUBBER, BTN_TOOL_BRUSH, BTN_TOOL_PENCIL, BTN_TOOL_AIRBRUSH, BTN_TOOL_MOUSE,
60         BTN_TOOL_LENS, BTN_STYLUS3, BTN_TOUCH, BTN_STYLUS, BTN_STYLUS2
61     };
62 
63     for (const auto &item : absInfos) {
64         SetAbsValue(item);
65     }
66 
67     for (const auto &item : resolutionInfos) {
68         SetResolution(item);
69     }
70 }
71 } // namespace MMI
72 } // namespace OHOS