1 #ifndef ANDROIDTVREMOTE_SERVICE_JNI_GAMEPAD_KEYS_H_ 2 #define ANDROIDTVREMOTE_SERVICE_JNI_GAMEPAD_KEYS_H_ 3 4 #include <android/input.h> 5 #include <android/keycodes.h> 6 #include <linux/input.h> 7 8 namespace android { 9 10 // The constant array below defines a mapping between "Android" IDs (key code 11 // within events) and what is being sent through /dev/uinput. 12 // 13 // The translation back from uinput key codes into android key codes is done through 14 // the corresponding key layout files. This file and 15 // 16 // data/keyboards/Vendor_18d1_Product_0200.kl 17 // 18 // MUST be kept in sync. 19 // 20 // see https://source.android.com/devices/input/key-layout-files for documentation. 21 22 // Defines axis mapping information between android and 23 // uinput axis. 24 struct GamepadKey { 25 int32_t androidKeyCode; 26 int linuxUinputKeyCode; 27 }; 28 29 static const GamepadKey GAMEPAD_KEYS[] = { 30 // Right-side buttons. A/B/X/Y or circle/triangle/square/X or similar 31 {AKEYCODE_BUTTON_A, BTN_A}, 32 {AKEYCODE_BUTTON_B, BTN_B}, 33 {AKEYCODE_BUTTON_X, BTN_X}, 34 {AKEYCODE_BUTTON_Y, BTN_Y}, 35 36 // Bumper buttons and digital triggers. Triggers generally have 37 // both analog versions (GAS and BRAKE output) and digital ones 38 {AKEYCODE_BUTTON_L1, BTN_TL2}, 39 {AKEYCODE_BUTTON_L2, BTN_TL}, 40 {AKEYCODE_BUTTON_R1, BTN_TR2}, 41 {AKEYCODE_BUTTON_R2, BTN_TR}, 42 43 // general actions for controllers 44 {AKEYCODE_BUTTON_SELECT, BTN_SELECT}, // Options or "..." 45 {AKEYCODE_BUTTON_START, BTN_START}, // Menu/Hamburger menu 46 {AKEYCODE_BUTTON_MODE, BTN_MODE}, // "main" button 47 48 // Pressing on the joyticks themselves 49 {AKEYCODE_BUTTON_THUMBL, BTN_THUMBL}, 50 {AKEYCODE_BUTTON_THUMBR, BTN_THUMBR}, 51 52 // DPAD digital keys. HAT axis events are generally also sent. 53 {AKEYCODE_DPAD_UP, KEY_UP}, 54 {AKEYCODE_DPAD_DOWN, KEY_DOWN}, 55 {AKEYCODE_DPAD_LEFT, KEY_LEFT}, 56 {AKEYCODE_DPAD_RIGHT, KEY_RIGHT}, 57 58 // "Extra" controller buttons: some devices have "share" and "assistant" 59 {AKEYCODE_BUTTON_1, BTN_TRIGGER_HAPPY1}, 60 {AKEYCODE_BUTTON_2, BTN_TRIGGER_HAPPY2}, 61 {AKEYCODE_BUTTON_3, BTN_TRIGGER_HAPPY3}, 62 {AKEYCODE_BUTTON_4, BTN_TRIGGER_HAPPY4}, 63 {AKEYCODE_BUTTON_5, BTN_TRIGGER_HAPPY5}, 64 {AKEYCODE_BUTTON_6, BTN_TRIGGER_HAPPY6}, 65 {AKEYCODE_BUTTON_7, BTN_TRIGGER_HAPPY7}, 66 {AKEYCODE_BUTTON_8, BTN_TRIGGER_HAPPY8}, 67 {AKEYCODE_BUTTON_9, BTN_TRIGGER_HAPPY9}, 68 {AKEYCODE_BUTTON_10, BTN_TRIGGER_HAPPY10}, 69 {AKEYCODE_BUTTON_11, BTN_TRIGGER_HAPPY11}, 70 {AKEYCODE_BUTTON_12, BTN_TRIGGER_HAPPY12}, 71 {AKEYCODE_BUTTON_13, BTN_TRIGGER_HAPPY13}, 72 {AKEYCODE_BUTTON_14, BTN_TRIGGER_HAPPY14}, 73 {AKEYCODE_BUTTON_15, BTN_TRIGGER_HAPPY15}, 74 {AKEYCODE_BUTTON_16, BTN_TRIGGER_HAPPY16}, 75 76 // Assignment to support global assistant for devices that support it. 77 {AKEYCODE_ASSIST, KEY_ASSISTANT}, 78 {AKEYCODE_VOICE_ASSIST, KEY_VOICECOMMAND}, 79 }; 80 81 // Defines axis mapping information between android and 82 // uinput axis. 83 struct GamepadAxis { 84 int32_t androidAxis; 85 float androidRangeMin; 86 float androidRangeMax; 87 int linuxUinputAxis; 88 int linuxUinputRangeMin; 89 int linuxUinputRangeMax; 90 }; 91 92 // List of all axes supported by a gamepad 93 static const GamepadAxis GAMEPAD_AXES[] = { 94 {AMOTION_EVENT_AXIS_X, -1, 1, ABS_X, 0, 254}, // Left joystick X 95 {AMOTION_EVENT_AXIS_Y, -1, 1, ABS_Y, 0, 254}, // Left joystick Y 96 {AMOTION_EVENT_AXIS_Z, -1, 1, ABS_Z, 0, 254}, // Right joystick X 97 {AMOTION_EVENT_AXIS_RZ, -1, 1, ABS_RZ, 0, 254}, // Right joystick Y 98 {AMOTION_EVENT_AXIS_LTRIGGER, 0, 1, ABS_GAS, 0, 254}, // Left trigger 99 {AMOTION_EVENT_AXIS_RTRIGGER, 0, 1, ABS_BRAKE, 0, 254}, // Right trigger 100 {AMOTION_EVENT_AXIS_HAT_X, -1, 1, ABS_HAT0X, -1, 1}, // DPad X 101 {AMOTION_EVENT_AXIS_HAT_Y, -1, 1, ABS_HAT0Y, -1, 1}, // DPad Y 102 }; 103 104 } // namespace android 105 106 #endif // ANDROIDTVREMOTE_SERVICE_JNI_GAMEPAD_KEYS_H_ 107