1 /*
2 * Copyright (c) 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_pen.h"
17 namespace OHOS {
18 namespace MMI {
19 namespace {
20 constexpr int32_t ABS_MAX_X = 20479;
21 constexpr int32_t ABS_MAX_Y = 12799;
22 constexpr int32_t ABS_MAX_PRESSURE = 4096;
23 constexpr int32_t ABS_MIN_TILT_X = -90;
24 constexpr int32_t ABS_MAX_TILT_X = 90;
25 constexpr int32_t ABS_MIN_TILT_Y = -90;
26 constexpr int32_t ABS_MAX_TILT_Y = 90;
27 constexpr int32_t ABS_MAX_TYPE = 15;
28 constexpr int32_t PEN_ABS_RANGE = 200;
29
30 ResolutionInfo resolutionInfos[] = {
31 { ABS_X, PEN_ABS_RANGE },
32 { ABS_Y, PEN_ABS_RANGE }
33 };
34
35 AbsInfo absInfos[] = {
36 { ABS_X, 0, ABS_MAX_X, 0, 0 },
37 { ABS_Y, 0, ABS_MAX_Y, 0, 0 },
38 { ABS_PRESSURE, 0, ABS_MAX_PRESSURE, 0, 0 },
39 { ABS_TILT_X, ABS_MIN_TILT_X, ABS_MAX_TILT_X, 0, 0 },
40 { ABS_TILT_Y, ABS_MIN_TILT_Y, ABS_MAX_TILT_Y, 0, 0 },
41 { ABS_MT_TOOL_TYPE, 0, ABS_MAX_TYPE, 0, 0 }
42 };
43 } // namespace
44
VirtualPen()45 VirtualPen::VirtualPen() : VirtualDevice("V-Pencil", BUS_USB, 0, 0)
46 {
47 eventTypes_ = { EV_KEY, EV_ABS };
48 keys_ = { 0xc5, 0xc6, BTN_TOOL_PEN, BTN_TOUCH, BTN_STYLUS };
49 properties_ = { INPUT_PROP_DIRECT };
50 abs_ = { ABS_X, ABS_Y, ABS_PRESSURE, ABS_TILT_X, ABS_TILT_Y, ABS_MT_TOOL_TYPE };
51
52 for (const auto &item : absInfos) {
53 SetAbsValue(item);
54 }
55
56 for (const auto &item : resolutionInfos) {
57 SetResolution(item);
58 }
59 }
60 } // namespace MMI
61 } // namespace OHOS