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_gamepad.h"
17
18 namespace OHOS {
19 namespace MMI {
20 namespace {
21 constexpr int32_t ABS_MAX_RXYZ = 255;
22 constexpr int32_t ABS_FLAT = 15;
23 constexpr int32_t ABS_MIN_HAT = -1;
24 constexpr int32_t ABS_MIN_VALUE = -32768;
25 constexpr int32_t ABS_MAX_VALUE = 32767;
26 constexpr int32_t ABS_FUZZ_VALUE = 16;
27 constexpr int32_t ABS_FLAT_VALUE = 128;
28
29 AbsInfo absInfos[] = {
30 { ABS_X, 0, ABS_MAX_RXYZ, 0, ABS_FLAT },
31 { ABS_Y, 0, ABS_MAX_RXYZ, 0, ABS_FLAT },
32 { ABS_Z, 0, ABS_MAX_RXYZ, 0, ABS_FLAT },
33 { ABS_RX, ABS_MIN_VALUE, ABS_MAX_RXYZ, ABS_FUZZ_VALUE, ABS_FLAT_VALUE },
34 { ABS_RY, ABS_MIN_VALUE, ABS_MAX_VALUE, ABS_FUZZ_VALUE, ABS_FLAT_VALUE },
35 { ABS_RZ, 0, ABS_MAX_RXYZ, 0, ABS_FLAT },
36 { ABS_GAS, 0, ABS_MAX_RXYZ, 0, ABS_FLAT },
37 { ABS_BRAKE, 0, ABS_MAX_RXYZ, 0, ABS_FLAT },
38 { ABS_HAT0X, ABS_MIN_HAT, 1, 0, 0 },
39 { ABS_HAT0Y, ABS_MIN_HAT, 1, 0, 0 }
40 };
41 } // namespace
42
VirtualGamePad()43 VirtualGamePad::VirtualGamePad() : VirtualDevice("Virtual GamePad", BUS_USB, 0x79, 0x181c)
44 {
45 eventTypes_ = { EV_KEY, EV_ABS, EV_MSC };
46 abs_ = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y };
47 keys_ = {
48 KEY_HOMEPAGE, BTN_SOUTH, BTN_EAST, BTN_C, BTN_NORTH, BTN_WEST, BTN_Z, BTN_TL, BTN_TR,
49 BTN_TL2, BTN_TR2, BTN_SELECT, BTN_START, BTN_MODE, BTN_THUMBL, BTN_THUMBR
50 };
51 miscellaneous_ = { MSC_SCAN };
52
53 for (const auto &item : absInfos) {
54 SetAbsValue(item);
55 }
56 }
57 } // namespace MMI
58 } // namespace OHOS