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_touchscreen.h"
17
18namespace OHOS {
19namespace MMI {
20namespace {
21constexpr int32_t ABS_MAX_X = 480;
22constexpr int32_t ABS_MAX_Y = 960;
23constexpr int32_t ABS_PRESSURE_MAX = 100;
24constexpr int32_t ABS_MT_ORIENTATION_MIN = -90;
25constexpr int32_t ABS_MT_ORIENTATION_MAX = 90;
26constexpr int32_t ABS_MT_BLOB_ID_MAX = 10;
27constexpr int32_t ABS_MT_TRACKING_ID_MAX = 9;
28constexpr int32_t ABS_TOOL_TYPE_MAX = 15;
29
30AbsInfo absInfos[] = {
31    { ABS_X, 0, ABS_MAX_X, 0, 0 },
32    { ABS_Y, 0, ABS_MAX_Y, 0, 0 },
33    { ABS_PRESSURE, 0, ABS_PRESSURE_MAX, 0, 0 },
34    { ABS_MT_TOUCH_MAJOR, 0, 1, 0, 0 },
35    { ABS_MT_TOUCH_MINOR, 0, 1, 0, 0 },
36    { ABS_MT_ORIENTATION, ABS_MT_ORIENTATION_MIN, ABS_MT_ORIENTATION_MAX, 0, 0 },
37    { ABS_MT_POSITION_X, 0, ABS_MAX_X, 0, 0 },
38    { ABS_MT_POSITION_Y, 0, ABS_MAX_Y, 0, 0 },
39    { ABS_MT_BLOB_ID, 0, ABS_MT_BLOB_ID_MAX, 0, 0 },
40    { ABS_MT_TRACKING_ID, 0, ABS_MT_TRACKING_ID_MAX, 0, 0 },
41    { ABS_MT_PRESSURE, 0, ABS_PRESSURE_MAX, 0, 0 },
42    { ABS_MT_TOOL_TYPE, 0, ABS_TOOL_TYPE_MAX, 0, 0 },
43    { ABS_MT_WIDTH_MAJOR, 0, 1, 0, 0 },
44    { ABS_MT_WIDTH_MINOR, 0, 1, 0, 0 },
45    { ABS_MT_TOOL_X, 0, ABS_MAX_X, 0, 0 },
46    { ABS_MT_TOOL_Y, 0, 1, 0, 0 }
47};
48} // namespace
49
50VirtualTouchScreen::VirtualTouchScreen() : VirtualDevice("Virtual TouchScreen", BUS_USB, 0x6006, 0x6006)
51{
52    eventTypes_ = { EV_ABS, EV_KEY };
53    properties_ = { INPUT_PROP_DIRECT };
54    keys_ = {
55        BTN_TOUCH, BTN_TOOL_RUBBER, BTN_TOOL_BRUSH, BTN_TOOL_PENCIL, BTN_TOOL_AIRBRUSH, BTN_TOOL_FINGER,
56        BTN_TOOL_MOUSE, BTN_TOOL_LENS
57    };
58    abs_ = {
59        ABS_X, ABS_Y, ABS_PRESSURE, ABS_MT_TOUCH_MAJOR, ABS_MT_TOUCH_MINOR, ABS_MT_ORIENTATION, ABS_MT_POSITION_X,
60        ABS_MT_POSITION_Y, ABS_MT_BLOB_ID, ABS_MT_TRACKING_ID, ABS_MT_PRESSURE, ABS_MT_WIDTH_MAJOR, ABS_MT_WIDTH_MINOR,
61        ABS_MT_TOOL_X, ABS_MT_TOOL_Y, ABS_MT_TOOL_TYPE
62    };
63
64    for (const auto &item : absInfos) {
65        SetAbsValue(item);
66    }
67}
68} // namespace MMI
69} // namespace OHOS