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_joystick.h"
17
18 namespace OHOS {
19 namespace MMI {
20 namespace {
21 constexpr int32_t ABS_MAX_XY = 16383;
22 constexpr int32_t ABS_FUZZ = 63;
23 constexpr int32_t ABS_FLAT = 1023;
24 constexpr int32_t ABS_MAX_RZ = 255;
25 constexpr int32_t ABS_FLAT_RZ = 15;
26 constexpr int32_t ABS_MIN_HAT = -1;
27
28 AbsInfo absInfos[] = {
29 { ABS_X, 0, ABS_MAX_XY, ABS_FUZZ, ABS_FLAT },
30 { ABS_Y, 0, ABS_MAX_XY, ABS_FUZZ, ABS_FLAT },
31 { ABS_RZ, 0, ABS_MAX_RZ, 0, ABS_FLAT_RZ },
32 { ABS_THROTTLE, 0, ABS_MAX_RZ, 0, ABS_FLAT_RZ },
33 { ABS_HAT0X, ABS_MIN_HAT, 1, 0, 0 },
34 { ABS_HAT0Y, ABS_MIN_HAT, 1, 0, 0 }
35 };
36 } // namespace
37
VirtualJoystick()38 VirtualJoystick::VirtualJoystick() : VirtualDevice("Virtual Joystick", BUS_USB, 0x44f, 0xb10a)
39 {
40 eventTypes_ = { EV_KEY, EV_ABS };
41 abs_ = { ABS_X, ABS_Y, ABS_RZ, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y };
42 keys_ = {
43 BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2,
44 BTN_PINKIE, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4,
45 BTN_BASE5, BTN_BASE6, BTN_DEAD
46 };
47
48 for (const auto &item : absInfos) {
49 SetAbsValue(item);
50 }
51 }
52 } // namespace MMI
53 } // namespace OHOS