├── src └── handycon │ ├── __init__.py │ ├── handhelds │ ├── __init__.py │ ├── gpd_gen4.py │ ├── gpd_gen3.py │ ├── gpd_gen2.py │ ├── gpd_gen1.py │ ├── go_gen1.py │ ├── ayn_gen1.py │ ├── ayn_gen2.py │ ├── ayn_gen3.py │ ├── aya_gen2.py │ ├── aya_gen1.py │ ├── aya_gen10.py │ ├── aya_gen4.py │ ├── aya_gen6.py │ ├── aya_gen7.py │ ├── aya_gen3.py │ ├── aya_gen5.py │ ├── aya_gen9.py │ ├── oxp_gen1.py │ ├── oxp_gen5.py │ ├── oxp_gen6.py │ ├── aya_gen8.py │ ├── oxp_gen2.py │ ├── anb_gen1.py │ ├── oxp_gen7.py │ ├── oxp_gen4.py │ ├── aok_gen1.py │ ├── aok_gen2.py │ ├── oxp_gen3.py │ └── ally_gen1.py │ ├── main.py │ ├── handycon.py │ ├── constants.py │ ├── utilities.py │ └── devices.py ├── .gitignore ├── makefile ├── usr ├── lib │ ├── udev │ │ ├── hwdb.d │ │ │ └── 59-handygccs-ayaneo.hwdb │ │ └── rules.d │ │ │ └── 60-handycon.rules │ └── systemd │ │ └── system │ │ └── handycon.service └── share │ └── handygccs │ └── scripts │ └── capture-system.py ├── remove.sh ├── pyproject.toml ├── README.md └── LICENSE /src/handycon/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/handycon/handhelds/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | capture_file.txt 3 | build 4 | dist 5 | handycon.egg-info 6 | 7 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | .PHONY: install 2 | install: 3 | ./install.sh 4 | 5 | .PHONY: clean 6 | clean: 7 | ./remove.sh 8 | -------------------------------------------------------------------------------- /usr/lib/udev/hwdb.d/59-handygccs-ayaneo.hwdb: -------------------------------------------------------------------------------- 1 | ## AYANEO DEVICES 2 | evdev:name:AT Translated Set 2 keyboard:dmi:*:svnAYANEO:* 3 | KEYBOARD_KEY_66=f15 4 | KEYBOARD_KEY_67=f16 5 | KEYBOARD_KEY_68=f17 6 | KEYBOARD_KEY_69=f18 7 | -------------------------------------------------------------------------------- /src/handycon/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from . import handycon 6 | 7 | if __name__ == "__main__": 8 | handycon.main() 9 | -------------------------------------------------------------------------------- /usr/lib/systemd/system/handycon.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Handheld Game Console Controller Service 3 | After=graphical-session.target 4 | StartLimitIntervalSec=500 5 | StartLimitBurst=5 6 | 7 | [Service] 8 | Restart=on-failure 9 | RestartSec=5s 10 | ExecStart=/usr/bin/nice --15 /usr/bin/handycon 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | -------------------------------------------------------------------------------- /remove.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf build dist src/handycon.egg-info 3 | sudo rm -rf /usr/lib/python3*/site-packages/handycon* 4 | sudo rm /usr/bin/handycon 5 | sudo rm -rf /usr/share/handygccs 6 | sudo rm -rf /etc/handygccs 7 | sudo rm /usr/lib/systemd/system/handycon.service 8 | sudo rm /usr/lib/udev/hwdb.d/59-handygccs-ayaneo.hwdb 9 | sudo rm /usr/lib/udev/rules.d/60-handycon.rules 10 | sudo systemd-hwdb update 11 | sudo udevadm control -R 12 | 13 | -------------------------------------------------------------------------------- /usr/lib/udev/rules.d/60-handycon.rules: -------------------------------------------------------------------------------- 1 | # Adds uaccess to Handheld Controller and makes it act like a joystick. 2 | ACTION=="add|change", KERNEL=="event[0-9]*", SUBSYSTEM=="input", ATTRS{name}=="Handheld Controller", MODE="0660", TAG+="uaccess", ENV{ID_INPUT_JOYSTICK}="1" 3 | 4 | # Adds necessary keycodes to GPD devices for the back buttons. 5 | ACTION=="add|change", KERNEL=="event[0-9]*", ATTRS{idVendor}=="2f24", ATTRS{idProduct}=="0135", ENV{ID_INPUT_KEYBOARD}="1" 6 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "handycon" 7 | version = "2.0.0" 8 | authors = [ 9 | { name="Derek J. Clark", email="derekjohn.clark@gmail.com" }, 10 | ] 11 | description = " Python module that provides full controller support for handheld consoles. " 12 | readme = "README.md" 13 | requires-python = ">=3.10" 14 | classifiers = [ 15 | "Programming Language :: Python :: 3", 16 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", 17 | "Operating System :: POSIX :: Linux", 18 | ] 19 | dependencies = [] 20 | 21 | [project.urls] 22 | "Homepage" = "https://github.com/ShadowBlip/HandyGCCS" 23 | "Bug Tracker" = "https://github.com/ShadowBlip/HandyGCCS/issues" 24 | 25 | [project.scripts] 26 | handycon = "handycon.handycon:main" 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HandyGCCS 2 | This project is archived and will no longer receive updates. All functionality has moved over to [InputPlumber](https://github.com/ShadowBlip/InputPlumber). 3 | 4 | Handheld Game Console Controller Support (Handy Geeks) for Linux 5 | 6 | Designed to bring the full controller functionality to handheld game consoles including: 7 | - Programmable extra buttons 8 | - Rumble effects 9 | 10 | ## Background 11 | Many of the handheld game consoles designed for windows have buttons on then in addition to the normal "X-Box" style controls. These controls are typically keyboard macros for built in windows functions (such as CTRL+ALT+DEL). This software captures all input from these devices, as well as the built in controller, hides them from the system, and creates a new virtual controller that acts as a single input device. This ensures that input isn't duplicated, and all buttons appear to come from the same controller. 12 | 13 | ## Supported Devices 14 | 15 | ### Anbernic 16 | - Win600 17 | 18 | ### AOKZOE 19 | - AOKZOE A1/Pro 20 | 21 | ### ASUS 22 | - ROG Ally 23 | 24 | ### Aya Neo 25 | - Founders Edition and 2021 Series 26 | - Next Series 27 | - Air/Pro/Plus 28 | - 2/2S 29 | - GEEK/1S 30 | 31 | ### Ayn 32 | - Loki Max 33 | - Loki Zero 34 | - Loki MiniPro 35 | 36 | ### GPD 37 | - GPD Win3 38 | - GPD WinMax2 39 | - GPD Win4 40 | 41 | ### Lenovo 42 | - Legion Go 43 | 44 | ### OneNetBook 45 | - OneXPlayer 1S 46 | - OneXPlayer Mini/Pro 47 | - OneXPlayer 2/Pro 48 | - OneXFly 49 | 50 | ## Installation 51 | 52 | ### From the AUR 53 | ``` 54 | pikaur -Sy handygccs-git 55 | sudo systemctl enable --now handycon 56 | ``` 57 | 58 | ### From Source 59 | 60 | ``` 61 | git clone https://github.com/ShadowBlip/HandyGCCS.git 62 | cd HandyGCCS 63 | sudo ./build.sh 64 | sudo systemctl enable --now handycon 65 | ``` 66 | 67 | ## Removal 68 | 69 | ### From the AUR 70 | `pikaur -U handygccs-git` 71 | -------------------------------------------------------------------------------- /src/handycon/handhelds/gpd_gen4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:63:00.3-5/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "usb-0000:63:00.3-3/input1" 20 | handycon.KEYBOARD_NAME = " Mouse for Windows" 21 | 22 | 23 | async def process_event(seed_event, active_keys): 24 | global handycon 25 | 26 | # Button map shortcuts for easy reference. 27 | button1 = handycon.button_map["button1"] 28 | button2 = handycon.button_map["button2"] 29 | 30 | # Loop variables 31 | button_on = seed_event.value 32 | 33 | # Automatically pass default keycodes we dont intend to replace. 34 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 35 | handycon.emit_event(seed_event) 36 | 37 | # BUTTON 1 (Default: Screenshot) 38 | if active_keys == [119] and button_on == 1 and button1 not in handycon.event_queue: 39 | await handycon.handle_key_down(seed_event, button1) 40 | elif ( 41 | active_keys == [] 42 | and seed_event.code in [119] 43 | and button_on == 0 44 | and button1 in handycon.event_queue 45 | ): 46 | await handycon.handle_key_up(seed_event, button1) 47 | 48 | # BUTTON 2 (Default: QAM) 49 | if active_keys == [99] and button_on == 1 and button2 not in handycon.event_queue: 50 | await handycon.handle_key_down(seed_event, button2) 51 | elif ( 52 | active_keys == [] 53 | and seed_event.code in [99] 54 | and button_on == 0 55 | and button2 in handycon.event_queue 56 | ): 57 | await handycon.handle_key_up(seed_event, button2) 58 | 59 | if handycon.last_button: 60 | await handycon.handle_key_up(seed_event, handycon.last_button) 61 | -------------------------------------------------------------------------------- /src/handycon/handhelds/gpd_gen3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:73:00.3-4.1/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "usb-0000:73:00.3-4.2/input1" 20 | handycon.KEYBOARD_NAME = " Mouse for Windows" 21 | 22 | 23 | async def process_event(seed_event, active_keys): 24 | global handycon 25 | 26 | # Button map shortcuts for easy reference. 27 | button1 = handycon.button_map["button1"] 28 | button2 = handycon.button_map["button2"] 29 | 30 | # Loop variables 31 | button_on = seed_event.value 32 | 33 | # Automatically pass default keycodes we dont intend to replace. 34 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 35 | handycon.emit_event(seed_event) 36 | 37 | # BUTTON 1 (Default: Screenshot) 38 | if active_keys == [119] and button_on == 1 and button1 not in handycon.event_queue: 39 | await handycon.handle_key_down(seed_event, button1) 40 | elif ( 41 | active_keys == [] 42 | and seed_event.code in [119] 43 | and button_on == 0 44 | and button1 in handycon.event_queue 45 | ): 46 | await handycon.handle_key_up(seed_event, button1) 47 | 48 | # BUTTON 2 (Default: QAM) 49 | if active_keys == [99] and button_on == 1 and button2 not in handycon.event_queue: 50 | await handycon.handle_key_down(seed_event, button2) 51 | elif ( 52 | active_keys == [] 53 | and seed_event.code in [99] 54 | and button_on == 0 55 | and button2 in handycon.event_queue 56 | ): 57 | await handycon.handle_key_up(seed_event, button2) 58 | 59 | if handycon.last_button: 60 | await handycon.handle_key_up(seed_event, handycon.last_button) 61 | -------------------------------------------------------------------------------- /src/handycon/handhelds/gpd_gen2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:74:00.3-3/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "usb-0000:74:00.3-4/input0" 20 | handycon.KEYBOARD_NAME = " Mouse for Windows" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | 31 | # Loop variables 32 | button_on = seed_event.value 33 | 34 | # Automatically pass default keycodes we dont intend to replace. 35 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 36 | handycon.emit_event(seed_event) 37 | 38 | # BUTTON 1 (Default: Screenshot) 39 | if active_keys == [11] and button_on == 1 and button1 not in handycon.event_queue: 40 | await handycon.handle_key_down(seed_event, button1) 41 | elif ( 42 | active_keys == [] 43 | and seed_event.code in [11] 44 | and button_on == 0 45 | and button1 in handycon.event_queue 46 | ): 47 | await handycon.handle_key_up(seed_event, button1) 48 | 49 | # BUTTON 2 (Default: QAM) 50 | if active_keys == [10] and button_on == 1 and button2 not in handycon.event_queue: 51 | await handycon.handle_key_down(seed_event, button2) 52 | elif ( 53 | active_keys == [] 54 | and seed_event.code in [10] 55 | and button_on == 0 56 | and button2 in handycon.event_queue 57 | ): 58 | await handycon.handle_key_up(seed_event, button2) 59 | 60 | if handycon.last_button: 61 | await handycon.handle_key_up(seed_event, handycon.last_button) 62 | -------------------------------------------------------------------------------- /src/handycon/handhelds/gpd_gen1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:00:14.0-7/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "usb-0000:00:14.0-5/input0" 20 | handycon.KEYBOARD_NAME = " Mouse for Windows" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | 31 | # Loop variables 32 | button_on = seed_event.value 33 | 34 | # Automatically pass default keycodes we dont intend to replace. 35 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 36 | handycon.emit_event(seed_event) 37 | 38 | # BUTTON 1 (Default: Screenshot) 39 | if ( 40 | active_keys == [29, 56, 111] 41 | and button_on == 1 42 | and button1 not in handycon.event_queue 43 | ): 44 | await handycon.handle_key_down(seed_event, button1) 45 | elif ( 46 | active_keys == [] 47 | and seed_event.code in [29, 56, 111] 48 | and button_on == 0 49 | and button1 in handycon.event_queue 50 | ): 51 | await handycon.handle_key_up(seed_event, button1) 52 | 53 | # BUTTON 2 (Default: QAM) 54 | if active_keys == [1] and button_on == 1 and button2 not in handycon.event_queue: 55 | await handycon.handle_key_down(seed_event, button2) 56 | elif ( 57 | active_keys == [] 58 | and seed_event.code in [1] 59 | and button_on == 0 60 | and button2 in handycon.event_queue 61 | ): 62 | await handycon.handle_key_up(seed_event, button2) 63 | 64 | if handycon.last_button: 65 | await handycon.handle_key_up(seed_event, handycon.last_button) 66 | -------------------------------------------------------------------------------- /src/handycon/handhelds/go_gen1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | handycon = None 6 | 7 | 8 | def init_handheld(handheld_controller): 9 | global handycon 10 | handycon = handheld_controller 11 | handycon.BUTTON_DELAY = 0.2 12 | handycon.CAPTURE_CONTROLLER = True 13 | handycon.CAPTURE_KEYBOARD = True 14 | handycon.CAPTURE_POWER = True 15 | handycon.GAMEPAD_ADDRESS = "usb-0000:c2:00.3-3/input0" 16 | handycon.GAMEPAD_NAME = "Generic X-Box pad" 17 | handycon.KEYBOARD_ADDRESS = "usb-0000:c2:00.3-3/input3" 18 | handycon.KEYBOARD_NAME = " Legion Controller for Windows Keyboard" 19 | 20 | 21 | # Captures keyboard events and translates them to virtual device events. 22 | async def process_event(seed_event, active_keys): 23 | global handycon 24 | 25 | # Button map shortcuts for easy reference. 26 | button2 = handycon.button_map["button2"] 27 | button4 = handycon.button_map["button4"] 28 | button5 = handycon.button_map["button5"] 29 | 30 | # Loop variables 31 | button_on = seed_event.value 32 | 33 | # Legion + a = QAM 34 | if ( 35 | active_keys == [29, 56, 111] 36 | and button_on == 1 37 | and button2 not in handycon.event_queue 38 | ): 39 | await handycon.handle_key_down(seed_event, button2) 40 | elif ( 41 | active_keys == [] 42 | and seed_event.code in [29, 56, 111] 43 | and button_on == 0 44 | and button2 in handycon.event_queue 45 | ): 46 | await handycon.handle_key_up(seed_event, button2) 47 | 48 | # Legion + B = OSK 49 | if ( 50 | active_keys == [24, 29, 125] 51 | and button_on == 1 52 | and button4 not in handycon.event_queue 53 | ): 54 | await handycon.handle_key_down(seed_event, button4) 55 | elif ( 56 | active_keys == [] 57 | and seed_event.code in [24, 29, 125] 58 | and button_on == 0 59 | and button4 in handycon.event_queue 60 | ): 61 | await handycon.handle_key_up(seed_event, button4) 62 | 63 | # Legion + x = MODE 64 | if active_keys == [99] and button_on == 1 and button5 not in handycon.event_queue: 65 | await handycon.handle_key_down(seed_event, button5) 66 | elif ( 67 | active_keys == [] 68 | and seed_event.code in [99] 69 | and button_on == 0 70 | and button5 in handycon.event_queue 71 | ): 72 | await handycon.handle_key_up(seed_event, button5) 73 | 74 | if handycon.last_button: 75 | await handycon.handle_key_up(seed_event, handycon.last_button) 76 | -------------------------------------------------------------------------------- /src/handycon/handhelds/ayn_gen1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # HandyGCCS HandyCon 3 | # Copyright 2022 Derek J. Clark 4 | # This will create a virtual UInput device and pull data from the built-in 5 | # controller and "keyboard". Right side buttons are keyboard buttons that 6 | # send macros (i.e. CTRL/ALT/DEL). We capture those events and send button 7 | # presses that Steam understands. 8 | 9 | import sys 10 | from evdev import InputDevice, InputEvent, UInput, ecodes as e, list_devices, ff 11 | 12 | handycon = None 13 | 14 | 15 | def init_handheld(handheld_controller): 16 | global handycon 17 | handycon = handheld_controller 18 | handycon.BUTTON_DELAY = 0.11 19 | handycon.CAPTURE_CONTROLLER = True 20 | handycon.CAPTURE_KEYBOARD = True 21 | handycon.CAPTURE_POWER = True 22 | handycon.GAMEPAD_ADDRESS = "usb-0000:74:00.0-1/input0" 23 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 24 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 25 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 26 | 27 | 28 | # Captures keyboard events and translates them to virtual device events. 29 | async def process_event(seed_event, active_keys): 30 | global handycon 31 | 32 | # Button map shortcuts for easy reference. 33 | button2 = handycon.button_map["button2"] # Default QAM 34 | 35 | # Loop variables 36 | button_on = seed_event.value 37 | 38 | # Automatically pass default keycodes we dont intend to replace. 39 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 40 | handycon.emit_event(seed_event) 41 | 42 | # BUTTON 1 (Default: Screenshot) Front lower-left + front lower-right 43 | if active_keys == [111] and button_on == 1 and button1 not in handycon.event_queue: 44 | await handycon.handle_key_down(seed_event, button1) 45 | elif ( 46 | active_keys == [] 47 | and seed_event.code in [111] 48 | and button_on == 0 49 | and button1 in handycon.event_queue 50 | ): 51 | await handycon.handle_key_up(seed_event, button1) 52 | 53 | # BUTTON 2 (Default: QAM) Front lower-right 54 | if ( 55 | active_keys == [20, 29, 42, 56] 56 | and button_on == 1 57 | and button2 not in handycon.event_queue 58 | ): 59 | await handycon.handle_key_down(seed_event, button2) 60 | elif ( 61 | active_keys == [] 62 | and seed_event.code in [20, 29, 42, 56] 63 | and button_on == 0 64 | and button2 in handycon.event_queue 65 | ): 66 | await handycon.handle_key_up(seed_event, button2) 67 | 68 | if handycon.last_button: 69 | await handycon.handle_key_up(seed_event, handycon.last_button) 70 | -------------------------------------------------------------------------------- /src/handycon/handhelds/ayn_gen2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # HandyGCCS HandyCon 3 | # Copyright 2022 Derek J. Clark 4 | # This will create a virtual UInput device and pull data from the built-in 5 | # controller and "keyboard". Right side buttons are keyboard buttons that 6 | # send macros (i.e. CTRL/ALT/DEL). We capture those events and send button 7 | # presses that Steam understands. 8 | 9 | import sys 10 | from evdev import InputDevice, InputEvent, UInput, ecodes as e, list_devices, ff 11 | 12 | handycon = None 13 | 14 | 15 | def init_handheld(handheld_controller): 16 | global handycon 17 | handycon = handheld_controller 18 | handycon.BUTTON_DELAY = 0.11 19 | handycon.CAPTURE_CONTROLLER = True 20 | handycon.CAPTURE_KEYBOARD = True 21 | handycon.CAPTURE_POWER = True 22 | handycon.GAMEPAD_ADDRESS = "usb-0000:04:00.3-4/input0" 23 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 24 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 25 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 26 | 27 | 28 | # Captures keyboard events and translates them to virtual device events. 29 | async def process_event(seed_event, active_keys): 30 | global handycon 31 | 32 | # Button map shortcuts for easy reference. 33 | button2 = handycon.button_map["button2"] # Default QAM 34 | 35 | # Loop variables 36 | button_on = seed_event.value 37 | 38 | # Automatically pass default keycodes we dont intend to replace. 39 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 40 | handycon.emit_event(seed_event) 41 | 42 | # BUTTON 1 (Default: Screenshot) Front lower-left + front lower-right 43 | if active_keys == [111] and button_on == 1 and button1 not in handycon.event_queue: 44 | await handycon.handle_key_down(seed_event, button1) 45 | elif ( 46 | active_keys == [] 47 | and seed_event.code in [111] 48 | and button_on == 0 49 | and button1 in handycon.event_queue 50 | ): 51 | await handycon.handle_key_up(seed_event, button1) 52 | 53 | # BUTTON 2 (Default: QAM) Front lower-right 54 | if ( 55 | active_keys == [20, 29, 42, 56] 56 | and button_on == 1 57 | and button2 not in handycon.event_queue 58 | ): 59 | await handycon.handle_key_down(seed_event, button2) 60 | elif ( 61 | active_keys == [] 62 | and seed_event.code in [20, 29, 42, 56] 63 | and button_on == 0 64 | and button2 in handycon.event_queue 65 | ): 66 | await handycon.handle_key_up(seed_event, button2) 67 | 68 | if handycon.last_button: 69 | await handycon.handle_key_up(seed_event, handycon.last_button) 70 | -------------------------------------------------------------------------------- /src/handycon/handhelds/ayn_gen3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # HandyGCCS HandyCon 3 | # Copyright 2022 Derek J. Clark 4 | # This will create a virtual UInput device and pull data from the built-in 5 | # controller and "keyboard". Right side buttons are keyboard buttons that 6 | # send macros (i.e. CTRL/ALT/DEL). We capture those events and send button 7 | # presses that Steam understands. 8 | 9 | import sys 10 | from evdev import InputDevice, InputEvent, UInput, ecodes as e, list_devices, ff 11 | 12 | handycon = None 13 | 14 | 15 | def init_handheld(handheld_controller): 16 | global handycon 17 | handycon = handheld_controller 18 | handycon.BUTTON_DELAY = 0.11 19 | handycon.CAPTURE_CONTROLLER = True 20 | handycon.CAPTURE_KEYBOARD = True 21 | handycon.CAPTURE_POWER = True 22 | handycon.GAMEPAD_ADDRESS = "usb-0000:04:00.4-2/input0" 23 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 24 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 25 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 26 | 27 | 28 | # Captures keyboard events and translates them to virtual device events. 29 | async def process_event(seed_event, active_keys): 30 | global handycon 31 | 32 | # Button map shortcuts for easy reference. 33 | button2 = handycon.button_map["button2"] # Default QAM 34 | 35 | # Loop variables 36 | button_on = seed_event.value 37 | 38 | # Automatically pass default keycodes we dont intend to replace. 39 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 40 | handycon.emit_event(seed_event) 41 | 42 | # BUTTON 1 (Default: Screenshot) Front lower-left + front lower-right 43 | if active_keys == [111] and button_on == 1 and button1 not in handycon.event_queue: 44 | await handycon.handle_key_down(seed_event, button1) 45 | elif ( 46 | active_keys == [] 47 | and seed_event.code in [111] 48 | and button_on == 0 49 | and button1 in handycon.event_queue 50 | ): 51 | await handycon.handle_key_up(seed_event, button1) 52 | 53 | # BUTTON 2 (Default: QAM) Front lower-right 54 | if ( 55 | active_keys == [20, 29, 42, 56] 56 | and button_on == 1 57 | and button2 not in handycon.event_queue 58 | ): 59 | await handycon.handle_key_down(seed_event, button2) 60 | elif ( 61 | active_keys == [] 62 | and seed_event.code in [20, 29, 42, 56] 63 | and button_on == 0 64 | and button2 in handycon.event_queue 65 | ): 66 | await handycon.handle_key_up(seed_event, button2) 67 | 68 | if handycon.last_button: 69 | await handycon.handle_key_up(seed_event, handycon.last_button) 70 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.10 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:03:00.3-4/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button2 = handycon.button_map["button2"] # Default QAM 29 | button5 = handycon.button_map["button5"] # Default MODE 30 | 31 | # Loop variables 32 | button_on = seed_event.value 33 | 34 | # Automatically pass default keycodes we dont intend to replace. 35 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 36 | handycon.emit_event(seed_event) 37 | 38 | # BUTTON 2 (Default: QAM) Small Button Short Press 39 | if ( 40 | active_keys in [[40, 133], [32, 125]] 41 | and button_on == 1 42 | and button2 not in handycon.event_queue 43 | ): 44 | await handycon.handle_key_down(seed_event, button2) 45 | elif ( 46 | active_keys == [] 47 | and seed_event.code in [32, 40, 125, 133] 48 | and button_on == 0 49 | and button2 in handycon.event_queue 50 | ): 51 | await handycon.handle_key_up(seed_event, button2) 52 | 53 | # BUTTON 4 (Default: OSK) Small button Long Press 54 | # This button spams up/down events, useless for now. 55 | # active_keys == [97, 100, 111] 56 | 57 | # BUTTON 5 (Default: MODE) Big button 58 | if ( 59 | active_keys in [[96, 105, 133], [88, 97, 125]] 60 | and button_on == 1 61 | and button5 not in handycon.event_queue 62 | ): 63 | await handycon.handle_key_down(seed_event, button5) 64 | elif ( 65 | active_keys == [] 66 | and seed_event.code in [88, 96, 97, 105, 125, 133] 67 | and button_on == 0 68 | and button5 in handycon.event_queue 69 | ): 70 | await handycon.handle_key_up(seed_event, button5) 71 | 72 | # Clean up old button presses. 73 | if handycon.last_button: 74 | await handycon.handle_key_up(seed_event, handycon.last_button) 75 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:03:00.3-4/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | button3 = handycon.button_map["button3"] 31 | button4 = handycon.button_map["button4"] 32 | 33 | # Loop variables 34 | button_on = seed_event.value 35 | 36 | # Automatically pass default keycodes we dont intend to replace. 37 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 38 | handycon.emit_event(seed_event) 39 | 40 | # BUTTON 1 (Default: Screenshot) WIN button 41 | if active_keys == [125] and button_on == 1 and button1 not in handycon.event_queue: 42 | await handycon.handle_key_down(seed_event, button1) 43 | elif ( 44 | active_keys == [] 45 | and seed_event.code == 125 46 | and button_on == 0 47 | and button1 in handycon.event_queue 48 | ): 49 | await handycon.handle_key_up(seed_event, button1) 50 | 51 | # BUTTON 2 (Default: QAM) TM Button 52 | if ( 53 | active_keys == [97, 100, 111] 54 | and button_on == 1 55 | and button2 not in handycon.event_queue 56 | ): 57 | await handycon.handle_key_down(seed_event, button2) 58 | elif ( 59 | active_keys == [] 60 | and seed_event.code in [97, 100, 111] 61 | and button_on == 0 62 | and button2 in handycon.event_queue 63 | ): 64 | await handycon.handle_key_up(seed_event, button2) 65 | 66 | # BUTTON 3 (Default: ESC) ESC Button 67 | if ( 68 | active_keys == [1] 69 | and seed_event.code == 1 70 | and button_on == 1 71 | and button3 not in handycon.event_queue 72 | ): 73 | await handycon.handle_key_down(seed_event, button3) 74 | elif ( 75 | active_keys == [] 76 | and seed_event.code == 1 77 | and button_on == 0 78 | and button3 in handycon.event_queue 79 | ): 80 | await handycon.handle_key_up(seed_event, button3) 81 | 82 | # BUTTON 4 (Default: OSK) KB Button 83 | if ( 84 | active_keys == [24, 97, 125] 85 | and button_on == 1 86 | and button4 not in handycon.event_queue 87 | ): 88 | await handycon.handle_key_down(seed_event, button4) 89 | elif ( 90 | active_keys == [] 91 | and seed_event.code in [24, 97, 125] 92 | and button_on == 0 93 | and button4 in handycon.event_queue 94 | ): 95 | await handycon.handle_key_up(seed_event, button4) 96 | 97 | if handycon.last_button: 98 | await handycon.handle_key_up(seed_event, handycon.last_button) 99 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen10.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:05:00.0-1/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | button4 = handycon.button_map["button4"] 31 | button5 = handycon.button_map["button5"] 32 | 33 | # Loop variables 34 | button_on = seed_event.value 35 | 36 | # Automatically pass default keycodes we dont intend to replace. 37 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 38 | handycon.emit_event(seed_event) 39 | 40 | # BUTTON 1 (Default: Screenshot/Launch Chiumera) LC Button 41 | if ( 42 | active_keys == [97, 125, 185] 43 | and button_on == 1 44 | and button1 not in handycon.event_queue 45 | ): 46 | await handycon.handle_key_down(seed_event, button1) 47 | elif ( 48 | active_keys == [] 49 | and seed_event.code in [97, 125, 185] 50 | and button_on == 0 51 | and button1 in handycon.event_queue 52 | ): 53 | await handycon.handle_key_up(seed_event, button1) 54 | 55 | # BUTTON 2 (Default: QAM) Small Button 56 | if ( 57 | active_keys == [32, 125] 58 | and button_on == 1 59 | and button2 not in handycon.event_queue 60 | ): 61 | await handycon.handle_key_down(seed_event, button2) 62 | elif ( 63 | active_keys == [] 64 | and seed_event.code in [32, 125] 65 | and button_on == 0 66 | and button2 in handycon.event_queue 67 | ): 68 | await handycon.handle_key_up(seed_event, button2) 69 | 70 | # BUTTON 4 (Default: OSK) RC Button 71 | if ( 72 | active_keys == [97, 125, 186] 73 | and button_on == 1 74 | and button4 not in handycon.event_queue 75 | ): 76 | await handycon.handle_key_down(seed_event, button4) 77 | elif ( 78 | active_keys == [] 79 | and seed_event.code in [97, 125, 186] 80 | and button_on == 0 81 | and button4 in handycon.event_queue 82 | ): 83 | await handycon.handle_key_up(seed_event, button4) 84 | 85 | # BUTTON 5 (Default: MODE) Big button 86 | if ( 87 | active_keys == [97, 125, 187] 88 | and button_on == 1 89 | and button5 not in handycon.event_queue 90 | ): 91 | await handycon.handle_key_down(seed_event, button5) 92 | elif ( 93 | active_keys == [] 94 | and seed_event.code in [97, 125, 187] 95 | and button_on == 0 96 | and button5 in handycon.event_queue 97 | ): 98 | await handycon.handle_key_up(seed_event, button5) 99 | 100 | if handycon.last_button: 101 | await handycon.handle_key_up(seed_event, handycon.last_button) 102 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:e4:00.3-4/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | button4 = handycon.button_map["button4"] 31 | button5 = handycon.button_map["button5"] 32 | 33 | # Loop variables 34 | button_on = seed_event.value 35 | 36 | # Automatically pass default keycodes we dont intend to replace. 37 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 38 | handycon.emit_event(seed_event) 39 | 40 | # BUTTON 1 (Default: Screenshot/Launch Chiumera) LC Button 41 | if ( 42 | active_keys == [97, 125, 185] 43 | and button_on == 1 44 | and button1 not in handycon.event_queue 45 | ): 46 | await handycon.handle_key_down(seed_event, button1) 47 | elif ( 48 | active_keys == [] 49 | and seed_event.code in [97, 125, 185] 50 | and button_on == 0 51 | and button1 in handycon.event_queue 52 | ): 53 | await handycon.handle_key_up(seed_event, button1) 54 | 55 | # BUTTON 2 (Default: QAM) Small Button 56 | if ( 57 | active_keys == [32, 125] 58 | and button_on == 1 59 | and button2 not in handycon.event_queue 60 | ): 61 | await handycon.handle_key_down(seed_event, button2) 62 | elif ( 63 | active_keys == [] 64 | and seed_event.code in [32, 125] 65 | and button_on == 0 66 | and button2 in handycon.event_queue 67 | ): 68 | await handycon.handle_key_up(seed_event, button2) 69 | 70 | # BUTTON 4 (Default: OSK) RC Button 71 | if ( 72 | active_keys == [97, 125, 186] 73 | and button_on == 1 74 | and button4 not in handycon.event_queue 75 | ): 76 | await handycon.handle_key_down(seed_event, button4) 77 | elif ( 78 | active_keys == [] 79 | and seed_event.code in [97, 125, 186] 80 | and button_on == 0 81 | and button4 in handycon.event_queue 82 | ): 83 | await handycon.handle_key_up(seed_event, button4) 84 | 85 | # BUTTON 5 (Default: MODE) Big button 86 | if ( 87 | active_keys == [97, 125, 187] 88 | and button_on == 1 89 | and button5 not in handycon.event_queue 90 | ): 91 | await handycon.handle_key_down(seed_event, button5) 92 | elif ( 93 | active_keys == [] 94 | and seed_event.code in [97, 125, 187] 95 | and button_on == 0 96 | and button5 in handycon.event_queue 97 | ): 98 | await handycon.handle_key_up(seed_event, button5) 99 | 100 | if handycon.last_button: 101 | await handycon.handle_key_up(seed_event, handycon.last_button) 102 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen6.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:c4:00.3-4/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | button4 = handycon.button_map["button4"] 31 | button5 = handycon.button_map["button5"] 32 | 33 | # Loop variables 34 | button_on = seed_event.value 35 | 36 | # Automatically pass default keycodes we dont intend to replace. 37 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 38 | handycon.emit_event(seed_event) 39 | 40 | # BUTTON 1 (Default: Screenshot/Launch Chiumera) LC Button 41 | if ( 42 | active_keys == [97, 125, 185] 43 | and button_on == 1 44 | and button1 not in handycon.event_queue 45 | ): 46 | await handycon.handle_key_down(seed_event, button1) 47 | elif ( 48 | active_keys == [] 49 | and seed_event.code in [97, 125, 185] 50 | and button_on == 0 51 | and button1 in handycon.event_queue 52 | ): 53 | await handycon.handle_key_up(seed_event, button1) 54 | 55 | # BUTTON 2 (Default: QAM) Small Button 56 | if ( 57 | active_keys == [32, 125] 58 | and button_on == 1 59 | and button2 not in handycon.event_queue 60 | ): 61 | await handycon.handle_key_down(seed_event, button2) 62 | elif ( 63 | active_keys == [] 64 | and seed_event.code in [32, 125] 65 | and button_on == 0 66 | and button2 in handycon.event_queue 67 | ): 68 | await handycon.handle_key_up(seed_event, button2) 69 | 70 | # BUTTON 4 (Default: OSK) RC Button 71 | if ( 72 | active_keys == [97, 125, 186] 73 | and button_on == 1 74 | and button4 not in handycon.event_queue 75 | ): 76 | await handycon.handle_key_down(seed_event, button4) 77 | elif ( 78 | active_keys == [] 79 | and seed_event.code in [97, 125, 186] 80 | and button_on == 0 81 | and button4 in handycon.event_queue 82 | ): 83 | await handycon.handle_key_up(seed_event, button4) 84 | 85 | # BUTTON 5 (Default: MODE) Big button 86 | if ( 87 | active_keys == [97, 125, 187] 88 | and button_on == 1 89 | and button5 not in handycon.event_queue 90 | ): 91 | await handycon.handle_key_down(seed_event, button5) 92 | elif ( 93 | active_keys == [] 94 | and seed_event.code in [97, 125, 187] 95 | and button_on == 0 96 | and button5 in handycon.event_queue 97 | ): 98 | await handycon.handle_key_up(seed_event, button5) 99 | 100 | if handycon.last_button: 101 | await handycon.handle_key_up(seed_event, handycon.last_button) 102 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen7.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:00:14.0-6/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | button4 = handycon.button_map["button4"] 31 | button5 = handycon.button_map["button5"] 32 | 33 | # Loop variables 34 | button_on = seed_event.value 35 | 36 | # Automatically pass default keycodes we dont intend to replace. 37 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 38 | handycon.emit_event(seed_event) 39 | 40 | # BUTTON 1 (Default: Screenshot/Launch Chiumera) LC Button 41 | if ( 42 | active_keys == [29, 125, 185] 43 | and button_on == 1 44 | and button1 not in handycon.event_queue 45 | ): 46 | await handycon.handle_key_down(seed_event, button1) 47 | elif ( 48 | active_keys == [] 49 | and seed_event.code in [29, 125, 185] 50 | and button_on == 0 51 | and button1 in handycon.event_queue 52 | ): 53 | await handycon.handle_key_up(seed_event, button1) 54 | 55 | # BUTTON 2 (Default: QAM) Small Button 56 | if ( 57 | active_keys == [32, 125] 58 | and button_on == 1 59 | and button2 not in handycon.event_queue 60 | ): 61 | await handycon.handle_key_down(seed_event, button2) 62 | elif ( 63 | active_keys == [] 64 | and seed_event.code in [32, 125] 65 | and button_on == 0 66 | and button2 in handycon.event_queue 67 | ): 68 | await handycon.handle_key_up(seed_event, button2) 69 | 70 | # BUTTON 4 (Default: OSK) RC Button 71 | if ( 72 | active_keys == [29, 125, 186] 73 | and button_on == 1 74 | and button4 not in handycon.event_queue 75 | ): 76 | await handycon.handle_key_down(seed_event, button4) 77 | elif ( 78 | active_keys == [] 79 | and seed_event.code in [29, 125, 186] 80 | and button_on == 0 81 | and button4 in handycon.event_queue 82 | ): 83 | await handycon.handle_key_up(seed_event, button4) 84 | 85 | # BUTTON 5 (Default: MODE) Big button 86 | if ( 87 | active_keys == [29, 125, 187] 88 | and button_on == 1 89 | and button5 not in handycon.event_queue 90 | ): 91 | await handycon.handle_key_down(seed_event, button5) 92 | elif ( 93 | active_keys == [] 94 | and seed_event.code in [29, 125, 187] 95 | and button_on == 0 96 | and button5 in handycon.event_queue 97 | ): 98 | await handycon.handle_key_up(seed_event, button5) 99 | 100 | if handycon.last_button: 101 | await handycon.handle_key_up(seed_event, handycon.last_button) 102 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.10 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:04:00.3-4/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | button4 = handycon.button_map["button4"] 31 | button5 = handycon.button_map["button5"] 32 | 33 | # Loop variables 34 | button_on = seed_event.value 35 | 36 | # Automatically pass default keycodes we dont intend to replace. 37 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 38 | handycon.emit_event(seed_event) 39 | 40 | # BUTTON 1 (Default: Screenshot/Launch Chiumera) LC Button 41 | if ( 42 | active_keys == [87, 97, 125] 43 | and button_on == 1 44 | and button1 not in handycon.event_queue 45 | ): 46 | await handycon.handle_key_down(seed_event, button1) 47 | elif ( 48 | active_keys == [] 49 | and seed_event.code in [87, 97, 125] 50 | and button_on == 0 51 | and button1 in handycon.event_queue 52 | ): 53 | await handycon.handle_key_up(seed_event, button1) 54 | 55 | # BUTTON 2 (Default: QAM) Small Button 56 | if ( 57 | active_keys == [32, 125] 58 | and button_on == 1 59 | and button2 not in handycon.event_queue 60 | ): 61 | await handycon.handle_key_down(seed_event, button2) 62 | elif ( 63 | active_keys == [] 64 | and seed_event.code in [32, 40, 125, 133] 65 | and button_on == 0 66 | and button2 in handycon.event_queue 67 | ): 68 | await handycon.handle_key_up(seed_event, button2) 69 | 70 | # BUTTON 4 (Default: OSK) RC Button 71 | if ( 72 | active_keys == [68, 97, 125] 73 | and button_on == 1 74 | and button4 not in handycon.event_queue 75 | ): 76 | await handycon.handle_key_down(seed_event, button4) 77 | elif ( 78 | active_keys == [] 79 | and seed_event.code in [68, 97, 125] 80 | and button_on == 0 81 | and button4 in handycon.event_queue 82 | ): 83 | await handycon.handle_key_up(seed_event, button4) 84 | 85 | # BUTTON 5 (Default: MODE) Big button 86 | if ( 87 | active_keys == [88, 97, 125] 88 | and button_on == 1 89 | and button5 not in handycon.event_queue 90 | ): 91 | await handycon.handle_key_down(seed_event, button5) 92 | elif ( 93 | active_keys == [] 94 | and seed_event.code in [88, 97, 125] 95 | and button_on == 0 96 | and button5 in handycon.event_queue 97 | ): 98 | await handycon.handle_key_up(seed_event, button5) 99 | 100 | if handycon.last_button: 101 | await handycon.handle_key_up(seed_event, handycon.last_button) 102 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | 13 | devices = [] 14 | proc_dev_fd = open("/proc/bus/input/devices", "r") 15 | for line in proc_dev_fd: 16 | devices.append(line) 17 | proc_dev_fd.close() 18 | 19 | handycon = handheld_controller 20 | handycon.BUTTON_DELAY = 0.11 21 | handycon.CAPTURE_CONTROLLER = True 22 | handycon.CAPTURE_KEYBOARD = True 23 | handycon.CAPTURE_POWER = True 24 | handycon.GAMEPAD_ADDRESS = "usb-0000:64:00.3-3/input0" 25 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 26 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 27 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 28 | 29 | 30 | # Captures keyboard events and translates them to virtual device events. 31 | async def process_event(seed_event, active_keys): 32 | global handycon 33 | 34 | # Button map shortcuts for easy reference. 35 | button1 = handycon.button_map["button1"] 36 | button2 = handycon.button_map["button2"] 37 | button4 = handycon.button_map["button4"] 38 | button5 = handycon.button_map["button5"] 39 | 40 | # Loop variables 41 | button_on = seed_event.value 42 | 43 | # Automatically pass default keycodes we dont intend to replace. 44 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 45 | handycon.emit_event(seed_event) 46 | 47 | # BUTTON 1 (Default: Screenshot/Launch Chiumera) LC Button 48 | if ( 49 | active_keys == [29, 125, 185] 50 | and button_on == 1 51 | and button1 not in handycon.event_queue 52 | ): 53 | await handycon.handle_key_down(seed_event, button1) 54 | elif ( 55 | active_keys == [] 56 | and seed_event.code in [29, 125, 185] 57 | and button_on == 0 58 | and button1 in handycon.event_queue 59 | ): 60 | await handycon.handle_key_up(seed_event, button1) 61 | 62 | # BUTTON 2 (Default: QAM) Small Button 63 | if ( 64 | active_keys == [32, 125] 65 | and button_on == 1 66 | and button2 not in handycon.event_queue 67 | ): 68 | await handycon.handle_key_down(seed_event, button2) 69 | elif ( 70 | active_keys == [] 71 | and seed_event.code in [32, 125] 72 | and button_on == 0 73 | and button2 in handycon.event_queue 74 | ): 75 | await handycon.handle_key_up(seed_event, button2) 76 | 77 | # BUTTON 4 (Default: OSK) RC Button 78 | if ( 79 | active_keys == [29, 125, 186] 80 | and button_on == 1 81 | and button4 not in handycon.event_queue 82 | ): 83 | await handycon.handle_key_down(seed_event, button4) 84 | elif ( 85 | active_keys == [] 86 | and seed_event.code in [29, 125, 186] 87 | and button_on == 0 88 | and button4 in handycon.event_queue 89 | ): 90 | await handycon.handle_key_up(seed_event, button4) 91 | 92 | # BUTTON 5 (Default: MODE) Big button 93 | if ( 94 | active_keys == [29, 125, 187] 95 | and button_on == 1 96 | and button5 not in handycon.event_queue 97 | ): 98 | await handycon.handle_key_down(seed_event, button5) 99 | elif ( 100 | active_keys == [] 101 | and seed_event.code in [29, 125, 187] 102 | and button_on == 0 103 | and button5 in handycon.event_queue 104 | ): 105 | await handycon.handle_key_up(seed_event, button5) 106 | 107 | if handycon.last_button: 108 | await handycon.handle_key_up(seed_event, handycon.last_button) 109 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen9.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | 13 | devices = [] 14 | proc_dev_fd = open("/proc/bus/input/devices", "r") 15 | for line in proc_dev_fd: 16 | devices.append(line) 17 | proc_dev_fd.close() 18 | 19 | handycon = handheld_controller 20 | handycon.BUTTON_DELAY = 0.11 21 | handycon.CAPTURE_CONTROLLER = True 22 | handycon.CAPTURE_KEYBOARD = True 23 | handycon.CAPTURE_POWER = True 24 | handycon.GAMEPAD_ADDRESS = "usb-0000:c4:00.3-3/input0" 25 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 26 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 27 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 28 | 29 | 30 | # Captures keyboard events and translates them to virtual device events. 31 | async def process_event(seed_event, active_keys): 32 | global handycon 33 | 34 | # Button map shortcuts for easy reference. 35 | button1 = handycon.button_map["button1"] 36 | button2 = handycon.button_map["button2"] 37 | button4 = handycon.button_map["button4"] 38 | button5 = handycon.button_map["button5"] 39 | 40 | # Loop variables 41 | button_on = seed_event.value 42 | 43 | # Automatically pass default keycodes we dont intend to replace. 44 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 45 | handycon.emit_event(seed_event) 46 | 47 | # BUTTON 1 (Default: Screenshot/Launch Chiumera) LC Button 48 | if ( 49 | active_keys == [29, 125, 185] 50 | and button_on == 1 51 | and button1 not in handycon.event_queue 52 | ): 53 | await handycon.handle_key_down(seed_event, button1) 54 | elif ( 55 | active_keys == [] 56 | and seed_event.code in [29, 125, 185] 57 | and button_on == 0 58 | and button1 in handycon.event_queue 59 | ): 60 | await handycon.handle_key_up(seed_event, button1) 61 | 62 | # BUTTON 2 (Default: QAM) Small Button 63 | if ( 64 | active_keys == [32, 125] 65 | and button_on == 1 66 | and button2 not in handycon.event_queue 67 | ): 68 | await handycon.handle_key_down(seed_event, button2) 69 | elif ( 70 | active_keys == [] 71 | and seed_event.code in [32, 125] 72 | and button_on == 0 73 | and button2 in handycon.event_queue 74 | ): 75 | await handycon.handle_key_up(seed_event, button2) 76 | 77 | # BUTTON 4 (Default: OSK) RC Button 78 | if ( 79 | active_keys == [29, 125, 186] 80 | and button_on == 1 81 | and button4 not in handycon.event_queue 82 | ): 83 | await handycon.handle_key_down(seed_event, button4) 84 | elif ( 85 | active_keys == [] 86 | and seed_event.code in [29, 125, 186] 87 | and button_on == 0 88 | and button4 in handycon.event_queue 89 | ): 90 | await handycon.handle_key_up(seed_event, button4) 91 | 92 | # BUTTON 5 (Default: MODE) Big button 93 | if ( 94 | active_keys == [29, 125, 187] 95 | and button_on == 1 96 | and button5 not in handycon.event_queue 97 | ): 98 | await handycon.handle_key_down(seed_event, button5) 99 | elif ( 100 | active_keys == [] 101 | and seed_event.code in [29, 125, 187] 102 | and button_on == 0 103 | and button5 in handycon.event_queue 104 | ): 105 | await handycon.handle_key_up(seed_event, button5) 106 | 107 | if handycon.last_button: 108 | await handycon.handle_key_up(seed_event, handycon.last_button) 109 | -------------------------------------------------------------------------------- /src/handycon/handhelds/oxp_gen1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:00:14.0-9/input0" 18 | handycon.GAMEPAD_NAME = "OneXPlayer Gamepad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | async def process_event(seed_event, active_keys): 24 | global handycon 25 | 26 | # Button map shortcuts for easy reference. 27 | button1 = handycon.button_map["button1"] 28 | button2 = handycon.button_map["button2"] 29 | button3 = handycon.button_map["button3"] 30 | button4 = handycon.button_map["button4"] 31 | 32 | # Loop variables 33 | this_button = None 34 | button_on = seed_event.value 35 | 36 | # Automatically pass default keycodes we dont intend to replace. 37 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP, e.KEY_MUTE]: 38 | handycon.emit_event(seed_event) 39 | 40 | # Handle missed keys. 41 | if active_keys == [] and handycon.event_queue != []: 42 | this_button = handycon.event_queue[0] 43 | 44 | # BUTTON 1 (Possible dangerous fan activity!) Short press orange + ||||| 45 | if ( 46 | active_keys == [99, 125] 47 | and button_on == 1 48 | and button1 not in handycon.event_queue 49 | ): 50 | handycon.event_queue.append(button1) 51 | elif ( 52 | active_keys == [] 53 | and seed_event.code in [99] 54 | and button_on == 0 55 | and button1 in handycon.event_queue 56 | ): 57 | this_button - button1 58 | 59 | # BUTTON 2 (Default: QAM) Short press orange 60 | if ( 61 | active_keys == [32, 125] 62 | and button_on == 1 63 | and button2 not in handycon.event_queue 64 | ): 65 | handycon.event_queue.append(button2) 66 | elif ( 67 | active_keys == [] 68 | and seed_event.code in [34] 69 | and button_on == 0 70 | and button2 in handycon.event_queue 71 | ): 72 | this_button = button2 73 | 74 | # BUTTON 3 (Default: ESC) Short press orange + KB 75 | if ( 76 | active_keys == [97, 100, 111] 77 | and button_on == 1 78 | and button3 not in handycon.event_queue 79 | ): 80 | handycon.event_queue.append(button3) 81 | elif ( 82 | active_keys == [] 83 | and seed_event.code in [100, 111] 84 | and button_on == 0 85 | and button3 in handycon.event_queue 86 | ): 87 | this_button = button3 88 | 89 | # BUTTON 4 (Default: OSK) Short press KB 90 | if ( 91 | active_keys == [24, 97, 125] 92 | and button_on == 1 93 | and button4 not in handycon.event_queue 94 | ): 95 | handycon.event_queue.append(button4) 96 | elif ( 97 | active_keys == [] 98 | and seed_event.code in [24] 99 | and button_on == 0 100 | and button4 in handycon.event_queue 101 | ): 102 | this_button = button4 103 | 104 | # Create list of events to fire. 105 | # Handle new button presses. 106 | if this_button and not handycon.last_button: 107 | handycon.event_queue.remove(this_button) 108 | handycon.last_button = this_button 109 | await handycon.emit_now(seed_event, this_button, 1) 110 | 111 | # Clean up old button presses. 112 | elif handycon.last_button and not this_button: 113 | await handycon.emit_now(seed_event, handycon.last_button, 0) 114 | handycon.last_button = None 115 | -------------------------------------------------------------------------------- /src/handycon/handhelds/oxp_gen5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | import os 6 | from evdev import ecodes as e 7 | 8 | from .. import constants as cons 9 | 10 | handycon = None 11 | 12 | 13 | def init_handheld(handheld_controller): 14 | global handycon 15 | handycon = handheld_controller 16 | handycon.BUTTON_DELAY = 0.09 17 | handycon.CAPTURE_CONTROLLER = True 18 | handycon.CAPTURE_KEYBOARD = True 19 | handycon.CAPTURE_POWER = True 20 | handycon.GAMEPAD_ADDRESS = "usb-0000:74:00.3-4/input0" 21 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 22 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 23 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 24 | 25 | if os.path.exists("/sys/devices/platform/oxp-platform/tt_toggle"): 26 | command = f"echo 1 > /sys/devices/platform/oxp-platform/tt_toggle" 27 | os.popen(command, "r", 1).read().strip() 28 | handycon.logger.info(f"Turbo button takeover enabled") 29 | else: 30 | handycon.logger.warn( 31 | f"Turbo takeover failed. Ensure you have the latest oxp-sensors driver installed." 32 | ) 33 | 34 | 35 | # Captures keyboard events and translates them to virtual device events. 36 | async def process_event(seed_event, active_keys): 37 | global handycon 38 | 39 | # Button map shortcuts for easy reference. 40 | # Volume keys can either be volume or macro mode, map both to volume. 41 | button0 = cons.EVENT_MAP["VOLUP"] 42 | button00 = cons.EVENT_MAP["VOLDOWN"] 43 | button2 = handycon.button_map["button2"] 44 | 45 | # Loop variables 46 | this_button = None 47 | button_on = seed_event.value 48 | 49 | # Automatically pass default keycodes we dont intend to replace. 50 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 51 | handycon.emit_event(seed_event) 52 | 53 | # Handle missed keys. 54 | if active_keys == [] and handycon.event_queue != []: 55 | this_button = handycon.event_queue[0] 56 | 57 | # Push volume keys for X1/X2 if they are not in volume mode. 58 | # BUTTON 0 (VOLUP): X1 59 | if ( 60 | active_keys == [32, 125] 61 | and button_on == 1 62 | and button0 not in handycon.event_queue 63 | ): 64 | handycon.event_queue.append(button0) 65 | elif ( 66 | active_keys == [] 67 | and seed_event.code in [32] 68 | and button_on == 0 69 | and button0 in handycon.event_queue 70 | ): 71 | this_button = button0 72 | 73 | # BUTTON 00 (VOLDOWN): X2 74 | if ( 75 | active_keys == [24, 29, 125] 76 | and button_on == 1 77 | and button00 not in handycon.event_queue 78 | ): 79 | handycon.event_queue.append(button00) 80 | elif ( 81 | active_keys == [] 82 | and seed_event.code in [24, 29] 83 | and button_on == 0 84 | and button00 in handycon.event_queue 85 | ): 86 | this_button = button00 87 | 88 | # BUTTON 2 (Default: QAM) Turbo Button 89 | if ( 90 | active_keys == [29, 56, 125] 91 | and button_on == 1 92 | and button2 not in handycon.event_queue 93 | ): 94 | handycon.event_queue.append(button2) 95 | elif ( 96 | active_keys == [] 97 | and seed_event.code in [29, 56] 98 | and button_on == 0 99 | and button2 in handycon.event_queue 100 | ): 101 | this_button = button2 102 | 103 | # Create list of events to fire. 104 | # Handle new button presses. 105 | if this_button and not handycon.last_button: 106 | handycon.event_queue.remove(this_button) 107 | handycon.last_button = this_button 108 | await handycon.emit_now(seed_event, this_button, 1) 109 | 110 | # Clean up old button presses. 111 | elif handycon.last_button and not this_button: 112 | await handycon.emit_now(seed_event, handycon.last_button, 0) 113 | handycon.last_button = None 114 | -------------------------------------------------------------------------------- /src/handycon/handhelds/oxp_gen6.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | import os 6 | from evdev import ecodes as e 7 | 8 | from .. import constants as cons 9 | 10 | handycon = None 11 | 12 | 13 | def init_handheld(handheld_controller): 14 | global handycon 15 | handycon = handheld_controller 16 | handycon.BUTTON_DELAY = 0.09 17 | handycon.CAPTURE_CONTROLLER = True 18 | handycon.CAPTURE_KEYBOARD = True 19 | handycon.CAPTURE_POWER = True 20 | handycon.GAMEPAD_ADDRESS = "usb-0000:64:00.3-4/input0" 21 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 22 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 23 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 24 | 25 | if os.path.exists("/sys/devices/platform/oxp-platform/tt_toggle"): 26 | command = f"echo 1 > /sys/devices/platform/oxp-platform/tt_toggle" 27 | os.popen(command, "r", 1).read().strip() 28 | handycon.logger.info(f"Turbo button takeover enabled") 29 | else: 30 | handycon.logger.warn( 31 | f"Turbo takeover failed. Ensure you have the latest oxp-sensors driver installed." 32 | ) 33 | 34 | 35 | # Captures keyboard events and translates them to virtual device events. 36 | async def process_event(seed_event, active_keys): 37 | global handycon 38 | 39 | # Button map shortcuts for easy reference. 40 | # Volume keys can either be volume or macro mode, map both to volume. 41 | button0 = cons.EVENT_MAP["VOLUP"] 42 | button00 = cons.EVENT_MAP["VOLDOWN"] 43 | button2 = handycon.button_map["button2"] 44 | 45 | # Loop variables 46 | this_button = None 47 | button_on = seed_event.value 48 | 49 | # Automatically pass default keycodes we dont intend to replace. 50 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 51 | handycon.emit_event(seed_event) 52 | 53 | # Handle missed keys. 54 | if active_keys == [] and handycon.event_queue != []: 55 | this_button = handycon.event_queue[0] 56 | 57 | # Push volume keys for X1/X2 if they are not in volume mode. 58 | # BUTTON 0 (VOLUP): X1 59 | if ( 60 | active_keys == [32, 125] 61 | and button_on == 1 62 | and button0 not in handycon.event_queue 63 | ): 64 | handycon.event_queue.append(button0) 65 | elif ( 66 | active_keys == [] 67 | and seed_event.code in [32] 68 | and button_on == 0 69 | and button0 in handycon.event_queue 70 | ): 71 | this_button = button0 72 | 73 | # BUTTON 00 (VOLDOWN): X2 74 | if ( 75 | active_keys == [24, 29, 125] 76 | and button_on == 1 77 | and button00 not in handycon.event_queue 78 | ): 79 | handycon.event_queue.append(button00) 80 | elif ( 81 | active_keys == [] 82 | and seed_event.code in [24, 29] 83 | and button_on == 0 84 | and button00 in handycon.event_queue 85 | ): 86 | this_button = button00 87 | 88 | # BUTTON 2 (Default: QAM) Turbo Button 89 | if ( 90 | active_keys == [29, 56, 125] 91 | and button_on == 1 92 | and button2 not in handycon.event_queue 93 | ): 94 | handycon.event_queue.append(button2) 95 | elif ( 96 | active_keys == [] 97 | and seed_event.code in [29, 56] 98 | and button_on == 0 99 | and button2 in handycon.event_queue 100 | ): 101 | this_button = button2 102 | 103 | # Create list of events to fire. 104 | # Handle new button presses. 105 | if this_button and not handycon.last_button: 106 | handycon.event_queue.remove(this_button) 107 | handycon.last_button = this_button 108 | await handycon.emit_now(seed_event, this_button, 1) 109 | 110 | # Clean up old button presses. 111 | elif handycon.last_button and not this_button: 112 | await handycon.emit_now(seed_event, handycon.last_button, 0) 113 | handycon.last_button = None 114 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aya_gen8.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:c4:00.3-4.1/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | button4 = handycon.button_map["button4"] 31 | button5 = handycon.button_map["button5"] 32 | button6 = handycon.button_map["button6"] 33 | 34 | # Loop variables 35 | button_on = seed_event.value 36 | 37 | # Automatically pass default keycodes we dont intend to replace. 38 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 39 | handycon.emit_event(seed_event) 40 | 41 | # BUTTON 1: LC Button 42 | if ( 43 | active_keys == [97, 125, 185] 44 | and button_on == 1 45 | and button1 not in handycon.event_queue 46 | ): 47 | await handycon.handle_key_down(seed_event, button1) 48 | elif ( 49 | active_keys == [] 50 | and seed_event.code in [97, 125, 185] 51 | and button_on == 0 52 | and button1 in handycon.event_queue 53 | ): 54 | await handycon.handle_key_up(seed_event, button1) 55 | 56 | # BUTTON 2: AYA small Button 57 | if ( 58 | active_keys == [32, 125] 59 | and button_on == 1 60 | and button2 not in handycon.event_queue 61 | ): 62 | await handycon.handle_key_down(seed_event, button2) 63 | elif ( 64 | active_keys == [] 65 | and seed_event.code in [32, 125] 66 | and button_on == 0 67 | and button2 in handycon.event_queue 68 | ): 69 | await handycon.handle_key_up(seed_event, button2) 70 | 71 | # BUTTON 4: RC Button 72 | if ( 73 | active_keys == [97, 125, 186] 74 | and button_on == 1 75 | and button4 not in handycon.event_queue 76 | ): 77 | await handycon.handle_key_down(seed_event, button4) 78 | elif ( 79 | active_keys == [] 80 | and seed_event.code in [97, 125, 186] 81 | and button_on == 0 82 | and button4 in handycon.event_queue 83 | ): 84 | await handycon.handle_key_up(seed_event, button4) 85 | 86 | # BUTTON 5: AYAspace 87 | if ( 88 | active_keys == [97, 125, 187] 89 | and button_on == 1 90 | and button5 not in handycon.event_queue 91 | ): 92 | await handycon.handle_key_down(seed_event, button5) 93 | elif ( 94 | active_keys == [] 95 | and seed_event.code in [97, 125, 187] 96 | and button_on == 0 97 | and button5 in handycon.event_queue 98 | ): 99 | await handycon.handle_key_up(seed_event, button5) 100 | 101 | # BUTTON 6: T Button 102 | if ( 103 | active_keys == [97, 125, 188] 104 | and button_on == 1 105 | and button6 not in handycon.event_queue 106 | ): 107 | await handycon.handle_key_down(seed_event, button6) 108 | elif ( 109 | active_keys == [] 110 | and seed_event.code in [97, 125, 188] 111 | and button_on == 0 112 | and button6 in handycon.event_queue 113 | ): 114 | await handycon.handle_key_up(seed_event, button6) 115 | 116 | if handycon.last_button: 117 | await handycon.handle_key_up(seed_event, handycon.last_button) 118 | -------------------------------------------------------------------------------- /src/handycon/handhelds/oxp_gen2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.11 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:03:00.3-4/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | # Button map shortcuts for easy reference. 27 | button1 = handycon.button_map["button1"] 28 | button2 = handycon.button_map["button2"] 29 | button3 = handycon.button_map["button3"] 30 | button4 = handycon.button_map["button4"] 31 | button5 = handycon.button_map["button5"] 32 | 33 | # Loop variables 34 | this_button = None 35 | button_on = seed_event.value 36 | 37 | # Automatically pass default keycodes we dont intend to replace. 38 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 39 | handycon.emit_event(seed_event) 40 | 41 | # Handle missed keys. 42 | if active_keys == [] and handycon.event_queue != []: 43 | this_button = handycon.event_queue[0] 44 | 45 | # BUTTON 1 (Possible dangerous fan activity!) Short press orange + ||||| 46 | if ( 47 | active_keys == [99, 125] 48 | and button_on == 1 49 | and button1 not in handycon.event_queue 50 | ): 51 | handycon.event_queue.append(button1) 52 | elif ( 53 | active_keys == [] 54 | and seed_event.code in [99] 55 | and button_on == 0 56 | and button1 in handycon.event_queue 57 | ): 58 | this_button = button1 59 | 60 | # BUTTON 2 (Default: QAM) Long press orange 61 | if ( 62 | active_keys == [34, 125] 63 | and button_on == 1 64 | and button2 not in handycon.event_queue 65 | ): 66 | handycon.event_queue.append(button2) 67 | elif ( 68 | active_keys == [] 69 | and seed_event.code in [34] 70 | and button_on == 0 71 | and button2 in handycon.event_queue 72 | ): 73 | this_button = button2 74 | 75 | # BUTTON 3 (Default: ESC) Short press orange + KB 76 | if ( 77 | active_keys == [97, 100, 111] 78 | and button_on == 1 79 | and button3 not in handycon.event_queue 80 | ): 81 | handycon.event_queue.append(button3) 82 | elif ( 83 | active_keys == [] 84 | and seed_event.code in [100, 111] 85 | and button_on == 0 86 | and button3 in handycon.event_queue 87 | ): 88 | this_button = button3 89 | 90 | # BUTTON 4 (Default: OSK) Short press KB 91 | if ( 92 | active_keys == [24, 97, 125] 93 | and button_on == 1 94 | and button4 not in handycon.event_queue 95 | ): 96 | handycon.event_queue.append(button4) 97 | elif ( 98 | active_keys == [] 99 | and seed_event.code in [24] 100 | and button_on == 0 101 | and button4 in handycon.event_queue 102 | ): 103 | this_button = button4 104 | 105 | # BUTTON 5 (Default: MODE) Short press orange 106 | if ( 107 | active_keys == [32, 125] 108 | and button_on == 1 109 | and button5 not in handycon.event_queue 110 | ): 111 | handycon.event_queue.append(button5) 112 | elif ( 113 | active_keys == [] 114 | and seed_event.code in [32] 115 | and button_on == 0 116 | and button5 in handycon.event_queue 117 | ): 118 | this_button = button5 119 | 120 | # Create list of events to fire. 121 | # Handle new button presses. 122 | if this_button and not handycon.last_button: 123 | handycon.event_queue.remove(this_button) 124 | handycon.last_button = this_button 125 | await handycon.emit_now(seed_event, this_button, 1) 126 | 127 | # Clean up old button presses. 128 | elif handycon.last_button and not this_button: 129 | await handycon.emit_now(seed_event, handycon.last_button, 0) 130 | handycon.last_button = None 131 | -------------------------------------------------------------------------------- /src/handycon/handhelds/anb_gen1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | handycon = handheld_controller 13 | handycon.BUTTON_DELAY = 0.04 14 | handycon.CAPTURE_CONTROLLER = True 15 | handycon.CAPTURE_KEYBOARD = True 16 | handycon.CAPTURE_POWER = True 17 | handycon.GAMEPAD_ADDRESS = "usb-0000:02:00.3-5/input0" 18 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 19 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 20 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 21 | 22 | 23 | # Captures keyboard events and translates them to virtual device events. 24 | async def process_event(seed_event, active_keys): 25 | global handycon 26 | 27 | # Button map shortcuts for easy reference. 28 | button1 = handycon.button_map["button1"] 29 | button2 = handycon.button_map["button2"] 30 | button3 = handycon.button_map["button3"] 31 | button4 = handycon.button_map["button4"] 32 | button5 = handycon.button_map["button5"] 33 | 34 | # Loop variables 35 | events = [] 36 | this_button = None 37 | button_on = seed_event.value 38 | 39 | # Automatically pass default keycodes we dont intend to replace. 40 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 41 | events.append(seed_event) 42 | 43 | # Handle missed keys. 44 | if active_keys == [] and handycon.event_queue != []: 45 | this_button = handycon.event_queue[0] 46 | 47 | # BUTTON 1 (BUTTON 4 ALT Mode) (Default: Screenshot) Long press KB 48 | if ( 49 | active_keys == [24, 29, 125] 50 | and button_on == 2 51 | and button1 not in handycon.event_queue 52 | ): 53 | if button4 in handycon.event_queue: 54 | handycon.event_queue.remove(button4) 55 | if button5 in handycon.event_queue: 56 | handycon.event_queue.remove(button5) 57 | handycon.event_queue.append(button1) 58 | elif ( 59 | active_keys == [] 60 | and seed_event.code in [24, 29, 125] 61 | and button_on == 0 62 | and button1 in handycon.event_queue 63 | ): 64 | this_button = button1 65 | 66 | # BUTTON 2 (Default: QAM) Home key. 67 | if active_keys == [125] and button_on == 1 and button2 not in handycon.event_queue: 68 | if button5 in handycon.event_queue: 69 | handycon.event_queue.remove(button5) 70 | handycon.event_queue.append(button2) 71 | elif ( 72 | active_keys == [] 73 | and seed_event.code in [125] 74 | and button_on == 0 75 | and button2 in handycon.event_queue 76 | ): 77 | this_button = button2 78 | 79 | # BUTTON 3, BUTTON 2 ALt mode (Defalt ESC) 80 | elif active_keys == [1] and button_on == 1 and button3 not in handycon.event_queue: 81 | if button2 in handycon.event_queue: 82 | handycon.event_queue.remove(button2) 83 | handycon.event_queue.append(button3) 84 | await handycon.do_rumble(0, 75, 1000, 0) 85 | elif ( 86 | active_keys == [] 87 | and seed_event.code == 1 88 | and button_on == 0 89 | and button3 in handycon.event_queue 90 | ): 91 | this_button = button3 92 | 93 | # BUTTON 4 (Default: OSK) Short press KB 94 | if ( 95 | active_keys == [24, 29, 125] 96 | and button_on == 1 97 | and button4 not in handycon.event_queue 98 | ): 99 | if button5 in handycon.event_queue: 100 | handycon.event_queue.remove(button5) 101 | handycon.event_queue.append(button4) 102 | elif ( 103 | active_keys == [] 104 | and seed_event.code in [24, 29, 125] 105 | and button_on == 0 106 | and button4 in handycon.event_queue 107 | ): 108 | this_button = button4 109 | 110 | # BUTTON 5 (Default: GUIDE) Meta/Windows key. 111 | if ( 112 | active_keys == [34, 125] 113 | and button_on == 1 114 | and button5 not in handycon.event_queue 115 | ): 116 | handycon.event_queue.append(button5) 117 | elif ( 118 | active_keys == [] 119 | and seed_event.code in [34, 125] 120 | and button_on == 0 121 | and button5 in handycon.event_queue 122 | ): 123 | this_button = button5 124 | 125 | # Create list of events to fire. 126 | # Handle new button presses. 127 | if this_button and not handycon.last_button: 128 | handycon.event_queue.remove(this_button) 129 | handycon.last_button = this_button 130 | await handycon.emit_now(seed_event, this_button, 1) 131 | 132 | # Clean up old button presses. 133 | elif handycon.last_button and not this_button: 134 | await handycon.emit_now(seed_event, handycon.last_button, 0) 135 | handycon.last_button = None 136 | -------------------------------------------------------------------------------- /src/handycon/handhelds/oxp_gen7.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | import os 6 | from evdev import ecodes as e 7 | 8 | handycon = None 9 | 10 | 11 | def init_handheld(handheld_controller): 12 | global handycon 13 | handycon = handheld_controller 14 | handycon.BUTTON_DELAY = 0.09 15 | handycon.CAPTURE_CONTROLLER = True 16 | handycon.CAPTURE_KEYBOARD = True 17 | handycon.CAPTURE_POWER = True 18 | handycon.GAMEPAD_ADDRESS = "usb-0000:c4:00.3-4/input0" 19 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 20 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 21 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 22 | if os.path.exists("/sys/devices/platform/oxp-platform/tt_toggle"): 23 | command = f"echo 1 > /sys/devices/platform/oxp-platform/tt_toggle" 24 | os.popen(command, "r", 1).read().strip() 25 | handycon.logger.info(f"Turbo button takeover enabled") 26 | else: 27 | handycon.logger.warn( 28 | f"Turbo takeover failed. Ensure you have the latest oxp-sensors driver installed." 29 | ) 30 | 31 | 32 | # Captures keyboard events and translates them to virtual device events. 33 | async def process_event(seed_event, active_keys): 34 | global handycon 35 | 36 | # Button map shortcuts for easy reference. 37 | button1 = handycon.button_map["button1"] 38 | button2 = handycon.button_map["button2"] 39 | button3 = handycon.button_map["button3"] 40 | button4 = handycon.button_map["button4"] 41 | button5 = handycon.button_map["button5"] 42 | button6 = handycon.button_map["button6"] 43 | 44 | # Loop variables 45 | this_button = None 46 | button_on = seed_event.value 47 | 48 | # Automatically pass default keycodes we dont intend to replace. 49 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 50 | handycon.emit_event(seed_event) 51 | 52 | # Handle missed keys. 53 | if active_keys == [] and handycon.event_queue != []: 54 | this_button = handycon.event_queue[0] 55 | 56 | # BUTTON 1 Short press orange + turbo 57 | if ( 58 | active_keys == [99, 125] 59 | and button_on == 1 60 | and button1 not in handycon.event_queue 61 | ): 62 | handycon.event_queue.append(button1) 63 | elif ( 64 | active_keys == [] 65 | and seed_event.code in [99] 66 | and button_on == 0 67 | and button1 in handycon.event_queue 68 | ): 69 | this_button = button1 70 | 71 | # BUTTON 2 (Default: QAM) Turbo Button 72 | if ( 73 | active_keys == [29, 56, 125] 74 | and button_on == 1 75 | and button2 not in handycon.event_queue 76 | ): 77 | handycon.event_queue.append(button2) 78 | elif ( 79 | active_keys == [] 80 | and seed_event.code in [29, 56] 81 | and button_on == 0 82 | and button2 in handycon.event_queue 83 | ): 84 | this_button = button2 85 | 86 | # BUTTON 3 (Default: ESC) Short press orange + KB 87 | if ( 88 | active_keys == [97, 100, 111] 89 | and button_on == 1 90 | and button3 not in handycon.event_queue 91 | ): 92 | handycon.event_queue.append(button3) 93 | elif ( 94 | active_keys == [] 95 | and seed_event.code in [97, 100, 111] 96 | and button_on == 0 97 | and button3 in handycon.event_queue 98 | ): 99 | this_button = button3 100 | 101 | # BUTTON 4 (Default: OSK) Short press KB 102 | if ( 103 | active_keys == [24, 97, 125] 104 | and button_on == 1 105 | and button4 not in handycon.event_queue 106 | ): 107 | handycon.event_queue.append(button4) 108 | elif ( 109 | active_keys == [] 110 | and seed_event.code in [24, 97] 111 | and button_on == 0 112 | and button4 in handycon.event_queue 113 | ): 114 | this_button = button4 115 | 116 | # BUTTON 5 (Default: MODE) Short press orange 117 | if ( 118 | active_keys == [32, 125] 119 | and button_on == 1 120 | and button5 not in handycon.event_queue 121 | ): 122 | handycon.event_queue.append(button5) 123 | elif ( 124 | active_keys == [] 125 | and seed_event.code in [32] 126 | and button_on == 0 127 | and button5 in handycon.event_queue 128 | ): 129 | this_button = button5 130 | 131 | # BUTTON 6 (Default: Launch Chimera) Long press orange 132 | if ( 133 | active_keys == [34, 125] 134 | and button_on == 1 135 | and button6 not in handycon.event_queue 136 | ): 137 | handycon.event_queue.append(button6) 138 | elif ( 139 | active_keys == [] 140 | and seed_event.code in [34] 141 | and button_on == 0 142 | and button6 in handycon.event_queue 143 | ): 144 | this_button = button6 145 | 146 | # Create list of events to fire. 147 | # Handle new button presses. 148 | if this_button and not handycon.last_button: 149 | handycon.event_queue.remove(this_button) 150 | handycon.last_button = this_button 151 | await handycon.emit_now(seed_event, this_button, 1) 152 | 153 | # Clean up old button presses. 154 | elif handycon.last_button and not this_button: 155 | await handycon.emit_now(seed_event, handycon.last_button, 0) 156 | handycon.last_button = None 157 | -------------------------------------------------------------------------------- /src/handycon/handhelds/oxp_gen4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | import os 6 | from evdev import ecodes as e 7 | 8 | handycon = None 9 | 10 | 11 | def init_handheld(handheld_controller): 12 | global handycon 13 | handycon = handheld_controller 14 | handycon.BUTTON_DELAY = 0.09 15 | handycon.CAPTURE_CONTROLLER = True 16 | handycon.CAPTURE_KEYBOARD = True 17 | handycon.CAPTURE_POWER = True 18 | handycon.GAMEPAD_ADDRESS = "usb-0000:e3:00.3-4/input0" 19 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 20 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 21 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 22 | if os.path.exists("/sys/devices/platform/oxp-platform/tt_toggle"): 23 | command = f"echo 1 > /sys/devices/platform/oxp-platform/tt_toggle" 24 | os.popen(command, "r", 1).read().strip() 25 | handycon.logger.info(f"Turbo button takeover enabled") 26 | else: 27 | handycon.logger.warn( 28 | f"Turbo takeover failed. Ensure you have the latest oxp-sensors driver installed." 29 | ) 30 | 31 | 32 | # Captures keyboard events and translates them to virtual device events. 33 | async def process_event(seed_event, active_keys): 34 | global handycon 35 | 36 | # Button map shortcuts for easy reference. 37 | button1 = handycon.button_map["button1"] 38 | button2 = handycon.button_map["button2"] 39 | button3 = handycon.button_map["button3"] 40 | button4 = handycon.button_map["button4"] 41 | button5 = handycon.button_map["button5"] 42 | button6 = handycon.button_map["button6"] 43 | 44 | # Loop variables 45 | this_button = None 46 | button_on = seed_event.value 47 | 48 | # Automatically pass default keycodes we dont intend to replace. 49 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 50 | handycon.emit_event(seed_event) 51 | 52 | # Handle missed keys. 53 | if active_keys == [] and handycon.event_queue != []: 54 | this_button = handycon.event_queue[0] 55 | 56 | # BUTTON 1 (Possible dangerous fan activity!) Short press orange + ||||| 57 | if ( 58 | active_keys == [99, 125] 59 | and button_on == 1 60 | and button1 not in handycon.event_queue 61 | ): 62 | handycon.event_queue.append(button1) 63 | elif ( 64 | active_keys == [] 65 | and seed_event.code in [99] 66 | and button_on == 0 67 | and button1 in handycon.event_queue 68 | ): 69 | this_button = button1 70 | 71 | # BUTTON 2 (Default: QAM) Turbo Button 72 | if ( 73 | active_keys == [29, 56, 125] 74 | and button_on == 1 75 | and button2 not in handycon.event_queue 76 | ): 77 | handycon.event_queue.append(button2) 78 | elif ( 79 | active_keys == [] 80 | and seed_event.code in [29, 56] 81 | and button_on == 0 82 | and button2 in handycon.event_queue 83 | ): 84 | this_button = button2 85 | 86 | # BUTTON 3 (Default: ESC) Short press orange + KB 87 | if ( 88 | active_keys == [97, 100, 111] 89 | and button_on == 1 90 | and button3 not in handycon.event_queue 91 | ): 92 | handycon.event_queue.append(button3) 93 | elif ( 94 | active_keys == [] 95 | and seed_event.code in [100, 111] 96 | and button_on == 0 97 | and button3 in handycon.event_queue 98 | ): 99 | this_button = button3 100 | 101 | # BUTTON 4 (Default: OSK) Short press KB 102 | if ( 103 | active_keys == [24, 97, 125] 104 | and button_on == 1 105 | and button4 not in handycon.event_queue 106 | ): 107 | handycon.event_queue.append(button4) 108 | elif ( 109 | active_keys == [] 110 | and seed_event.code in [24] 111 | and button_on == 0 112 | and button4 in handycon.event_queue 113 | ): 114 | this_button = button4 115 | 116 | # BUTTON 5 (Default: MODE) Short press orange 117 | if ( 118 | active_keys == [32, 125] 119 | and button_on == 1 120 | and button5 not in handycon.event_queue 121 | ): 122 | handycon.event_queue.append(button5) 123 | elif ( 124 | active_keys == [] 125 | and seed_event.code in [32] 126 | and button_on == 0 127 | and button5 in handycon.event_queue 128 | ): 129 | this_button = button5 130 | 131 | # BUTTON 6 (Default: Launch Chimera) Long press orange 132 | if ( 133 | active_keys == [34, 125] 134 | and button_on == 1 135 | and button6 not in handycon.event_queue 136 | ): 137 | handycon.event_queue.append(button6) 138 | elif ( 139 | active_keys == [] 140 | and seed_event.code in [34] 141 | and button_on == 0 142 | and button6 in handycon.event_queue 143 | ): 144 | this_button = button6 145 | 146 | # Create list of events to fire. 147 | # Handle new button presses. 148 | if this_button and not handycon.last_button: 149 | handycon.event_queue.remove(this_button) 150 | handycon.last_button = this_button 151 | await handycon.emit_now(seed_event, this_button, 1) 152 | 153 | # Clean up old button presses. 154 | elif handycon.last_button and not this_button: 155 | await handycon.emit_now(seed_event, handycon.last_button, 0) 156 | handycon.last_button = None 157 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aok_gen1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | import os 6 | from evdev import ecodes as e 7 | 8 | handycon = None 9 | 10 | 11 | def init_handheld(handheld_controller): 12 | global handycon 13 | handycon = handheld_controller 14 | handycon.BUTTON_DELAY = 0.09 15 | handycon.CAPTURE_CONTROLLER = True 16 | handycon.CAPTURE_KEYBOARD = True 17 | handycon.CAPTURE_POWER = True 18 | handycon.GAMEPAD_ADDRESS = "usb-0000:e4:00.3-4/input0" 19 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 20 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 21 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 22 | if os.path.exists("/sys/devices/platform/oxp-platform/tt_toggle"): 23 | command = f"echo 1 > /sys/devices/platform/oxp-platform/tt_toggle" 24 | os.popen(command, "r", 1).read().strip() 25 | handycon.logger.info(f"Turbo button takeover enabled") 26 | 27 | 28 | # Captures keyboard events and translates them to virtual device events. 29 | async def process_event(seed_event, active_keys): 30 | global handycon 31 | 32 | # Button map shortcuts for easy reference. 33 | button1 = handycon.button_map["button1"] 34 | button2 = handycon.button_map["button2"] 35 | button3 = handycon.button_map["button3"] 36 | button4 = handycon.button_map["button4"] 37 | button5 = handycon.button_map["button5"] 38 | button6 = handycon.button_map["button6"] 39 | 40 | # Loop variables 41 | this_button = None 42 | button_on = seed_event.value 43 | 44 | # Automatically pass default keycodes we dont intend to replace. 45 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 46 | handycon.emit_event(seed_event) 47 | 48 | # Handle missed keys. 49 | if active_keys == [] and handycon.event_queue != []: 50 | this_button = handycon.event_queue[0] 51 | 52 | # BUTTON 1 (Possible dangerous fan activity!) Short press orange + ||||| 53 | if ( 54 | active_keys == [99, 125] 55 | and button_on == 1 56 | and button1 not in handycon.event_queue 57 | ): 58 | handycon.event_queue.append(button1) 59 | elif ( 60 | active_keys == [] 61 | and seed_event.code in [99, 125] 62 | and button_on == 0 63 | and button1 in handycon.event_queue 64 | ): 65 | this_button = button1 66 | 67 | # BUTTON 2 (Default: QAM) Turbo Button 68 | # if active_keys == [34, 125] and button_on == 1 and button2 not in handycon.event_queue: 69 | if ( 70 | active_keys == [29, 56, 125] 71 | and button_on == 1 72 | and button2 not in handycon.event_queue 73 | ): 74 | handycon.event_queue.append(button2) 75 | elif ( 76 | active_keys == [] 77 | and seed_event.code in [29, 56, 125] 78 | and button_on == 0 79 | and button2 in handycon.event_queue 80 | ): 81 | this_button = button2 82 | await handycon.do_rumble(0, 150, 1000, 0) 83 | 84 | # BUTTON 3 (Default: ESC) Short press orange + KB 85 | if ( 86 | active_keys == [97, 100, 111] 87 | and button_on == 1 88 | and button3 not in handycon.event_queue 89 | ): 90 | handycon.event_queue.append(button3) 91 | elif ( 92 | active_keys == [] 93 | and seed_event.code in [100, 111] 94 | and button_on == 0 95 | and button3 in handycon.event_queue 96 | ): 97 | this_button = button3 98 | 99 | # BUTTON 4 (Default: OSK) Short press KB 100 | if ( 101 | active_keys == [24, 97, 125] 102 | and button_on == 1 103 | and button4 not in handycon.event_queue 104 | ): 105 | handycon.event_queue.append(button4) 106 | elif ( 107 | active_keys == [] 108 | and seed_event.code in [24, 97, 125] 109 | and button_on == 0 110 | and button4 in handycon.event_queue 111 | ): 112 | this_button = button4 113 | 114 | # BUTTON 5 (Default: MODE) Short press orange 115 | if ( 116 | active_keys == [32, 125] 117 | and button_on == 1 118 | and button5 not in handycon.event_queue 119 | ): 120 | handycon.event_queue.append(button5) 121 | elif ( 122 | active_keys == [] 123 | and seed_event.code in [32, 125] 124 | and button_on == 0 125 | and button5 in handycon.event_queue 126 | ): 127 | this_button = button5 128 | 129 | # BUTTON 6 (Default: Launch Chimera) Long press orange 130 | if ( 131 | active_keys == [34, 125] 132 | and button_on == 1 133 | and button6 not in handycon.event_queue 134 | ): 135 | handycon.event_queue.append(button6) 136 | elif ( 137 | active_keys == [] 138 | and seed_event.code in [34, 125] 139 | and button_on == 0 140 | and button6 in handycon.event_queue 141 | ): 142 | this_button = button6 143 | 144 | # Create list of events to fire. 145 | # Handle new button presses. 146 | if this_button and not handycon.last_button: 147 | handycon.event_queue.remove(this_button) 148 | handycon.last_button = this_button 149 | await handycon.emit_now(seed_event, this_button, 1) 150 | 151 | # Clean up old button presses. 152 | elif handycon.last_button and not this_button: 153 | await handycon.emit_now(seed_event, handycon.last_button, 0) 154 | handycon.last_button = None 155 | -------------------------------------------------------------------------------- /src/handycon/handhelds/aok_gen2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | import os 6 | from evdev import ecodes as e 7 | 8 | handycon = None 9 | 10 | 11 | def init_handheld(handheld_controller): 12 | global handycon 13 | handycon = handheld_controller 14 | handycon.BUTTON_DELAY = 0.09 15 | handycon.CAPTURE_CONTROLLER = True 16 | handycon.CAPTURE_KEYBOARD = True 17 | handycon.CAPTURE_POWER = True 18 | handycon.GAMEPAD_ADDRESS = "usb-0000:c4:00.3-4/input0" 19 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 20 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 21 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 22 | if os.path.exists("/sys/devices/platform/oxp-platform/tt_toggle"): 23 | command = f"echo 1 > /sys/devices/platform/oxp-platform/tt_toggle" 24 | os.popen(command, "r", 1).read().strip() 25 | handycon.logger.info(f"Turbo button takeover enabled") 26 | 27 | 28 | # Captures keyboard events and translates them to virtual device events. 29 | async def process_event(seed_event, active_keys): 30 | global handycon 31 | 32 | # Button map shortcuts for easy reference. 33 | button1 = handycon.button_map["button1"] 34 | button2 = handycon.button_map["button2"] 35 | button3 = handycon.button_map["button3"] 36 | button4 = handycon.button_map["button4"] 37 | button5 = handycon.button_map["button5"] 38 | button6 = handycon.button_map["button6"] 39 | 40 | # Loop variables 41 | this_button = None 42 | button_on = seed_event.value 43 | 44 | # Automatically pass default keycodes we dont intend to replace. 45 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 46 | handycon.emit_event(seed_event) 47 | 48 | # Handle missed keys. 49 | if active_keys == [] and handycon.event_queue != []: 50 | this_button = handycon.event_queue[0] 51 | 52 | # BUTTON 1 (Possible dangerous fan activity!) Short press orange + ||||| 53 | if ( 54 | active_keys == [99, 125] 55 | and button_on == 1 56 | and button1 not in handycon.event_queue 57 | ): 58 | handycon.event_queue.append(button1) 59 | elif ( 60 | active_keys == [] 61 | and seed_event.code in [99, 125] 62 | and button_on == 0 63 | and button1 in handycon.event_queue 64 | ): 65 | this_button = button1 66 | 67 | # BUTTON 2 (Default: QAM) Turbo Button 68 | # if active_keys == [34, 125] and button_on == 1 and button2 not in handycon.event_queue: 69 | if ( 70 | active_keys == [29, 56, 125] 71 | and button_on == 1 72 | and button2 not in handycon.event_queue 73 | ): 74 | handycon.event_queue.append(button2) 75 | elif ( 76 | active_keys == [] 77 | and seed_event.code in [29, 56, 125] 78 | and button_on == 0 79 | and button2 in handycon.event_queue 80 | ): 81 | this_button = button2 82 | await handycon.do_rumble(0, 150, 1000, 0) 83 | 84 | # BUTTON 3 (Default: ESC) Short press orange + KB 85 | if ( 86 | active_keys == [97, 100, 111] 87 | and button_on == 1 88 | and button3 not in handycon.event_queue 89 | ): 90 | handycon.event_queue.append(button3) 91 | elif ( 92 | active_keys == [] 93 | and seed_event.code in [100, 111] 94 | and button_on == 0 95 | and button3 in handycon.event_queue 96 | ): 97 | this_button = button3 98 | 99 | # BUTTON 4 (Default: OSK) Short press KB 100 | if ( 101 | active_keys == [24, 97, 125] 102 | and button_on == 1 103 | and button4 not in handycon.event_queue 104 | ): 105 | handycon.event_queue.append(button4) 106 | elif ( 107 | active_keys == [] 108 | and seed_event.code in [24, 97, 125] 109 | and button_on == 0 110 | and button4 in handycon.event_queue 111 | ): 112 | this_button = button4 113 | 114 | # BUTTON 5 (Default: MODE) Short press orange 115 | if ( 116 | active_keys == [32, 125] 117 | and button_on == 1 118 | and button5 not in handycon.event_queue 119 | ): 120 | handycon.event_queue.append(button5) 121 | elif ( 122 | active_keys == [] 123 | and seed_event.code in [32, 125] 124 | and button_on == 0 125 | and button5 in handycon.event_queue 126 | ): 127 | this_button = button5 128 | 129 | # BUTTON 6 (Default: Launch Chimera) Long press orange 130 | if ( 131 | active_keys == [34, 125] 132 | and button_on == 1 133 | and button6 not in handycon.event_queue 134 | ): 135 | handycon.event_queue.append(button6) 136 | elif ( 137 | active_keys == [] 138 | and seed_event.code in [34, 125] 139 | and button_on == 0 140 | and button6 in handycon.event_queue 141 | ): 142 | this_button = button6 143 | 144 | # Create list of events to fire. 145 | # Handle new button presses. 146 | if this_button and not handycon.last_button: 147 | handycon.event_queue.remove(this_button) 148 | handycon.last_button = this_button 149 | await handycon.emit_now(seed_event, this_button, 1) 150 | 151 | # Clean up old button presses. 152 | elif handycon.last_button and not this_button: 153 | await handycon.emit_now(seed_event, handycon.last_button, 0) 154 | handycon.last_button = None 155 | -------------------------------------------------------------------------------- /src/handycon/handhelds/oxp_gen3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import ecodes as e 6 | 7 | import os 8 | 9 | handycon = None 10 | 11 | 12 | def init_handheld(handheld_controller): 13 | global handycon 14 | handycon = handheld_controller 15 | handycon.BUTTON_DELAY = 0.11 16 | handycon.CAPTURE_CONTROLLER = True 17 | handycon.CAPTURE_KEYBOARD = True 18 | handycon.CAPTURE_POWER = True 19 | handycon.GAMEPAD_ADDRESS = "usb-0000:03:00.3-4/input0" 20 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 21 | handycon.KEYBOARD_ADDRESS = "isa0060/serio0/input0" 22 | handycon.KEYBOARD_NAME = "AT Translated Set 2 keyboard" 23 | if os.path.exists("/sys/devices/platform/oxp-platform/tt_toggle"): 24 | command = f"echo 1 > /sys/devices/platform/oxp-platform/tt_toggle" 25 | os.popen(command, "r", 1).read().strip() 26 | handycon.logger.info(f"Turbo button takeover enabled") 27 | else: 28 | handycon.logger.warn( 29 | f"Turbo takeover failed. Ensure you have the latest oxp-sensors driver installed." 30 | ) 31 | 32 | 33 | # Captures keyboard events and translates them to virtual device events. 34 | async def process_event(seed_event, active_keys): 35 | global handycon 36 | # Button map shortcuts for easy reference. 37 | button1 = handycon.button_map["button1"] 38 | button2 = handycon.button_map["button2"] 39 | button3 = handycon.button_map["button3"] 40 | button4 = handycon.button_map["button4"] 41 | button5 = handycon.button_map["button5"] 42 | button6 = handycon.button_map["button6"] 43 | 44 | # Loop variables 45 | this_button = None 46 | button_on = seed_event.value 47 | 48 | # Automatically pass default keycodes we dont intend to replace. 49 | if seed_event.code in [e.KEY_VOLUMEDOWN, e.KEY_VOLUMEUP]: 50 | handycon.emit_event(seed_event) 51 | 52 | # Handle missed keys. 53 | if active_keys == [] and handycon.event_queue != []: 54 | this_button = handycon.event_queue[0] 55 | 56 | # BUTTON 1 (Possible dangerous fan activity!) Short press orange + ||||| 57 | if ( 58 | active_keys == [99, 125] 59 | and button_on == 1 60 | and button1 not in handycon.event_queue 61 | ): 62 | handycon.event_queue.append(button1) 63 | elif ( 64 | active_keys == [] 65 | and seed_event.code in [99] 66 | and button_on == 0 67 | and button1 in handycon.event_queue 68 | ): 69 | this_button = button1 70 | 71 | # BUTTON 2 (Default: QAM) Turbo Button 72 | if ( 73 | active_keys == [29, 56, 125] 74 | and button_on == 1 75 | and button2 not in handycon.event_queue 76 | ): 77 | handycon.event_queue.append(button2) 78 | elif ( 79 | active_keys == [] 80 | and seed_event.code in [29, 56] 81 | and button_on == 0 82 | and button2 in handycon.event_queue 83 | ): 84 | this_button = button2 85 | await handycon.do_rumble(0, 150, 1000, 0) 86 | 87 | # BUTTON 3 (Default: ESC) Short press orange + KB 88 | if ( 89 | active_keys == [97, 100, 111] 90 | and button_on == 1 91 | and button3 not in handycon.event_queue 92 | ): 93 | handycon.event_queue.append(button3) 94 | elif ( 95 | active_keys == [] 96 | and seed_event.code in [100, 111] 97 | and button_on == 0 98 | and button3 in handycon.event_queued 99 | ): 100 | this_button = button3 101 | 102 | # BUTTON 4 (Default: OSK) Short press KB 103 | if ( 104 | active_keys == [24, 97, 125] 105 | and button_on == 1 106 | and button4 not in handycon.event_queue 107 | ): 108 | handycon.event_queue.append(button4) 109 | elif ( 110 | active_keys == [] 111 | and seed_event.code in [24] 112 | and button_on == 0 113 | and button4 in handycon.event_queue 114 | ): 115 | this_button = button4 116 | 117 | # BUTTON 5 (Default: MODE) Short press orange 118 | if ( 119 | active_keys == [32, 125] 120 | and button_on == 1 121 | and button5 not in handycon.event_queue 122 | ): 123 | handycon.event_queue.append(button5) 124 | elif ( 125 | active_keys == [] 126 | and seed_event.code in [32] 127 | and button_on == 0 128 | and button5 in handycon.event_queue 129 | ): 130 | this_button = button5 131 | 132 | # BUTTON 6 (Default: Launch Chimera) Long press orange 133 | if ( 134 | active_keys == [34, 125] 135 | and button_on == 1 136 | and button6 not in handycon.event_queue 137 | ): 138 | handycon.event_queue.append(button6) 139 | elif ( 140 | active_keys == [] 141 | and seed_event.code in [34] 142 | and button_on == 0 143 | and button6 in handycon.event_queue 144 | ): 145 | this_button = button6 146 | 147 | # Create list of events to fire. 148 | # Handle new button presses. 149 | if this_button and not handycon.last_button: 150 | handycon.event_queue.remove(this_button) 151 | handycon.last_button = this_button 152 | await handycon.emit_now(seed_event, this_button, 1) 153 | 154 | # Clean up old button presses. 155 | elif handycon.last_button and not this_button: 156 | await handycon.emit_now(seed_event, handycon.last_button, 0) 157 | handycon.last_button = None 158 | -------------------------------------------------------------------------------- /usr/share/handygccs/scripts/capture-system.py: -------------------------------------------------------------------------------- 1 | #!/sbin/python3 2 | # Capture System 3 | # Copyright 2022 Derek J. Clark 4 | # Produces an output file that caputres relevant system data that can be uploaded 5 | # to github when reporting a new device. 6 | 7 | import asyncio 8 | import signal 9 | 10 | from evdev import InputDevice, list_devices 11 | 12 | # Declare global variables 13 | all_devices = None 14 | captured_keys = [] 15 | keybd = None 16 | sys_id = None 17 | xb360 = None 18 | 19 | 20 | def capture_system(): 21 | 22 | global all_devices 23 | global keybd 24 | global sys_id 25 | global xb360 26 | 27 | kb_path = None 28 | xb_path = None 29 | 30 | # Identify the current device type. Kill script if not compatible. 31 | sys_id = open("/sys/devices/virtual/dmi/id/product_name", "r").read().strip() 32 | 33 | 34 | # Identify system input event devices. 35 | devices = [InputDevice(path) for path in list_devices()] 36 | for device in devices: 37 | 38 | # Xbox 360 Controller 39 | if device.name in ['Microsoft X-Box 360 pad', 'Generic X-Box pad', 'OneXPlayer Gamepad',]: 40 | xb_path = device.path 41 | 42 | # Keyboard Device 43 | elif device.name == 'AT Translated Set 2 keyboard': 44 | kb_path = device.path 45 | 46 | # Catch if devices weren't found. 47 | if not xb_path or kb_path: 48 | all_devices = devices 49 | 50 | # Grab the built-in devices. 51 | if kb_path: 52 | keybd = InputDevice(kb_path) 53 | if xb_path: 54 | xb360 = InputDevice(xb_path) 55 | 56 | async def capture_events(device): 57 | 58 | global captured_keys 59 | current = [] 60 | 61 | # Capture events for the given device. 62 | async for event in device.async_read_loop(): 63 | 64 | # We use active keys instead of ev1.code as we will override ev1 and 65 | # we don't want to trigger additional/different events when doing that 66 | active = device.active_keys() 67 | if active != []: 68 | print(current, active, event) 69 | if event.value == 1 and current != active: 70 | current = active 71 | elif event.value == 0 and current not in captured_keys and current != []: 72 | print("Identified new keymap: ", current) 73 | captured_keys.append(current) 74 | current = [] 75 | 76 | 77 | def save_capture(): 78 | 79 | global all_devices 80 | global captured_keys 81 | global keybd 82 | global sys_id 83 | global xb360 84 | 85 | with open('capture_file.txt', 'w') as f: 86 | 87 | # System ID 88 | f.write('System ID:\n') 89 | f.write(sys_id) 90 | f.write('\n\n') 91 | 92 | # Controller 93 | f.write('X-Box 360 Device:\n') 94 | if xb360: 95 | f.write(xb360.name) 96 | f.write(' | ') 97 | f.write(xb360.phys) 98 | f.write(' | ') 99 | f.write('bustype: ') 100 | f.write(str(xb360.info.bustype)) 101 | f.write(' vendor: ') 102 | f.write(str(xb360.info.vendor)) 103 | f.write(' product: ') 104 | f.write(str(xb360.info.product)) 105 | f.write(' version: ') 106 | f.write(str(xb360.info.version)) 107 | f.write('\n\n') 108 | 109 | # Keyboard 110 | f.write('keyboard Device:\n') 111 | if keybd: 112 | f.write(keybd.name) 113 | f.write(' | ') 114 | f.write(keybd.phys) 115 | f.write(' | ') 116 | f.write('bustype: ') 117 | f.write(str(keybd.info.bustype)) 118 | f.write(' vendor: ') 119 | f.write(str(keybd.info.vendor)) 120 | f.write(' product: ') 121 | f.write(str(keybd.info.product)) 122 | f.write(' version: ') 123 | f.write(str(keybd.info.version)) 124 | f.write('\n\n') 125 | 126 | # All Devices: 127 | f.write('All Devices:') 128 | if all_devices: 129 | for d in all_devices: 130 | f.write('\n') 131 | f.write(d.name) 132 | f.write(' | ') 133 | f.write(d.phys) 134 | f.write(' | ') 135 | f.write('bustype: ') 136 | f.write(str(d.info.bustype)) 137 | f.write(' vendor: ') 138 | f.write(str(d.info.vendor)) 139 | f.write(' product: ') 140 | f.write(str(d.info.product)) 141 | f.write(' version: ') 142 | f.write(str(d.info.version)) 143 | f.write('\n\n') 144 | 145 | # Captured Keys 146 | f.write('Captured Keymaps:\n') 147 | for keymap in captured_keys: 148 | f.write(str(keymap)) 149 | f.write('\n') 150 | print('Capture complete. Please upload the file titled "capture_file.txt" in \ 151 | a new GitHub issue to https://github.com/ShadowBlip/HandyGCCS/issues and any \ 152 | additional information you have.') 153 | 154 | 155 | def main(killer): 156 | print('Gathering system info...') 157 | capture_system() 158 | 159 | if xb360 and keybd: 160 | print('Successfully identified compatible controllers. Press each \ 161 | non-functioning button in succession. When complete press ctrl+c to end capture.') 162 | else: 163 | print('Unable to identify compatible controller. Additional steps may be \ 164 | required after uploading your capture file to fully integrate your device.') 165 | killer.alive = False 166 | return 167 | 168 | # Run asyncio loop to capture all events 169 | asyncio.ensure_future(capture_events(xb360)) 170 | asyncio.ensure_future(capture_events(keybd)) 171 | 172 | loop = asyncio.get_event_loop() 173 | loop.run_forever() 174 | 175 | 176 | class GracefulKiller: 177 | alive = True 178 | 179 | def __init__(self): 180 | signal.signal(signal.SIGINT, self.exit_gracefully) 181 | signal.signal(signal.SIGTERM, self.exit_gracefully) 182 | 183 | def exit_gracefully(self, *args): 184 | self.alive = False 185 | save_capture() 186 | exit(0) 187 | 188 | if __name__ == "__main__": 189 | print('Scanning system and creating device profile.') 190 | killer = GracefulKiller() 191 | while killer.alive: 192 | main(killer) 193 | save_capture() 194 | exit(0) 195 | -------------------------------------------------------------------------------- /src/handycon/handhelds/ally_gen1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from time import sleep 6 | 7 | handycon = None 8 | 9 | 10 | def init_handheld(handheld_controller): 11 | global handycon 12 | devices = [] 13 | proc_dev_fd = open("/proc/bus/input/devices", "r") 14 | for line in proc_dev_fd: 15 | devices.append(line) 16 | proc_dev_fd.close() 17 | 18 | handycon = handheld_controller 19 | handycon.BUTTON_DELAY = 0.2 20 | handycon.CAPTURE_CONTROLLER = True 21 | handycon.CAPTURE_KEYBOARD = True 22 | handycon.CAPTURE_POWER = True 23 | handycon.GAMEPAD_NAME = "Microsoft X-Box 360 pad" 24 | handycon.KEYBOARD_NAME = "Asus Keyboard" 25 | handycon.KEYBOARD_2_NAME = "Asus Keyboard" 26 | GAMEPAD_ADDRESS_LIST = [ 27 | "usb-0000:08:00.3-2/input0", 28 | "usb-0000:09:00.3-2/input0", 29 | "usb-0000:0a:00.3-2/input0", 30 | ] 31 | KEYBOARD_ADDRESS_LIST = [ 32 | "usb-0000:08:00.3-3/input0", 33 | "usb-0000:09:00.3-3/input0", 34 | "usb-0000:0a:00.3-3/input0", 35 | ] 36 | KEYBOARD_2_ADDRESS_LIST = [ 37 | "usb-0000:08:00.3-3/input2", 38 | "usb-0000:09:00.3-3/input2", 39 | "usb-0000:0a:00.3-3/input2", 40 | ] 41 | for line in devices: 42 | for address in GAMEPAD_ADDRESS_LIST: 43 | if address in line: 44 | handycon.GAMEPAD_ADDRESS = address 45 | for address in KEYBOARD_ADDRESS_LIST: 46 | if address in line: 47 | handycon.KEYBOARD_ADDRESS = address 48 | for address in KEYBOARD_2_ADDRESS_LIST: 49 | if address in line: 50 | handycon.KEYBOARD_2_ADDRESS = address 51 | 52 | if ( 53 | not handycon.GAMEPAD_ADDRESS 54 | or not handycon.KEYBOARD_ADDRESS 55 | or not handycon.KEYBOARD_2_ADDRESS 56 | ): 57 | handycon.logger.warn( 58 | "Unable to identify one or more input devices by address. Please submit a bug report with a copy of '/proc/bus/input/devices'" 59 | ) 60 | exit() 61 | 62 | # asus_hid needs tiem to initialize and set the gamepad mode or everything breaks. Wait for 10s to let that happen. 63 | sleep(10) 64 | 65 | 66 | # Captures keyboard events and translates them to virtual device events. 67 | 68 | 69 | async def process_event(seed_event, active_keys): 70 | global handycon 71 | 72 | # Button map shortcuts for easy reference. 73 | button2 = handycon.button_map["button2"] # Default: QAM 74 | button4 = handycon.button_map["button4"] # Default: OSK 75 | button5 = handycon.button_map["button5"] # Default: BTN_MODE 76 | button7 = handycon.button_map["button7"] # Default: Toggle Performance 77 | button8 = handycon.button_map["button8"] # Default: BTN_THUMBL 78 | button9 = handycon.button_map["button9"] # Default: BTN_THUMBR 79 | 80 | # Loop variables 81 | button_on = seed_event.value 82 | this_button = None 83 | 84 | # Handle missed keys. 85 | if active_keys == [] and handycon.event_queue != []: 86 | this_button = handycon.event_queue[0] 87 | 88 | # BUTTON 2 (Default: QAM) Armory Crate Button Short Press 89 | if active_keys == [148] and button_on == 1 and button2 not in handycon.event_queue: 90 | handycon.event_queue.append(button2) 91 | elif ( 92 | active_keys == [] 93 | and seed_event.code in [148] 94 | and button_on == 0 95 | and button2 in handycon.event_queue 96 | ): 97 | this_button = button2 98 | 99 | # BUTTON 4 (Default: OSK) Control Center Long Press. 100 | if ( 101 | active_keys == [29, 56, 111] 102 | and button_on == 1 103 | and button4 not in handycon.event_queue 104 | ): 105 | handycon.event_queue.append(button4) 106 | await handycon.do_rumble(0, 150, 1000, 0) 107 | elif ( 108 | active_keys == [] 109 | and seed_event.code in [29, 56, 111] 110 | and button_on == 0 111 | and button4 in handycon.event_queue 112 | ): 113 | this_button = button4 114 | 115 | # BUTTON 5 (Default: Mode) Control Center Short Press. 116 | if active_keys == [186] and button_on == 1 and button5 not in handycon.event_queue: 117 | handycon.event_queue.append(button5) 118 | elif ( 119 | active_keys == [] 120 | and seed_event.code in [186] 121 | and button_on == 0 122 | and button5 in handycon.event_queue 123 | ): 124 | this_button = button5 125 | 126 | # BUTTON 7 (Default: Toggle Performance) Armory Crate Button Long Press 127 | # This button triggers immediate down/up after holding for ~1s an F17 and then 128 | # released another down/up for F18 on release. We use the F18 "KEY_UP" for release. 129 | if active_keys == [187] and button_on == 1 and button7 not in handycon.event_queue: 130 | await handycon.do_rumble(0, 150, 1000, 0) 131 | await handycon.handle_key_down(seed_event, button7) 132 | elif ( 133 | active_keys == [] 134 | and seed_event.code in [188] 135 | and button_on == 0 136 | and button7 in handycon.event_queue 137 | ): 138 | await handycon.handle_key_up(seed_event, button7) 139 | 140 | # BUTTON 11 (Default: Happy Trigger 1) Left Paddle 141 | if active_keys == [184] and button_on == 1 and button8 not in handycon.event_queue: 142 | await handycon.handle_key_down(seed_event, button8) 143 | elif ( 144 | active_keys == [] 145 | and seed_event.code in [184] 146 | and button_on == 0 147 | and button8 in handycon.event_queue 148 | ): 149 | await handycon.handle_key_up(seed_event, button8) 150 | 151 | # BUTTON 4 (Default: Happy Trigger 2) Right Paddle 152 | if active_keys == [185] and button_on == 1 and button9 not in handycon.event_queue: 153 | await handycon.handle_key_down(seed_event, button9) 154 | elif ( 155 | active_keys == [] 156 | and seed_event.code in [185] 157 | and button_on == 0 158 | and button9 in handycon.event_queue 159 | ): 160 | await handycon.handle_key_up(seed_event, button9) 161 | 162 | # Create list of events to fire. 163 | # Handle new button presses. 164 | if this_button and not handycon.last_button: 165 | handycon.event_queue.remove(this_button) 166 | handycon.last_button = this_button 167 | await handycon.emit_now(seed_event, this_button, 1) 168 | 169 | # Clean up old button presses. 170 | elif handycon.last_button and not this_button: 171 | await handycon.emit_now(seed_event, handycon.last_button, 0) 172 | handycon.last_button = None 173 | -------------------------------------------------------------------------------- /src/handycon/handycon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | # Python Modules 6 | import asyncio 7 | import logging 8 | import os 9 | import signal 10 | import sys 11 | import traceback 12 | import warnings 13 | 14 | # Local modules 15 | from .constants import * 16 | from . import devices 17 | from . import utilities 18 | 19 | # Partial imports 20 | from pathlib import Path 21 | 22 | 23 | warnings.filterwarnings("ignore", category=DeprecationWarning) 24 | 25 | 26 | class HandheldController: 27 | # Logging 28 | logging.basicConfig( 29 | format="[%(asctime)s | %(filename)s:%(lineno)s:%(funcName)s] %(message)s", 30 | datefmt="%y%m%d_%H:%M:%S", 31 | level=logging.INFO, 32 | ) 33 | logger = logging.getLogger(__name__) 34 | 35 | # Session Variables 36 | config = None 37 | button_map = {} 38 | event_queue = [] # Stores inng button presses to block spam 39 | last_button = None 40 | last_x_val = 0 41 | last_y_val = 0 42 | power_action = "Suspend" 43 | running = False 44 | 45 | # Handheld Config 46 | BUTTON_DELAY = 0.00 47 | CAPTURE_CONTROLLER = False 48 | CAPTURE_KEYBOARD = False 49 | CAPTURE_POWER = False 50 | GAMEPAD_ADDRESS = "" 51 | GAMEPAD_NAME = "" 52 | KEYBOARD_ADDRESS = "" 53 | KEYBOARD_NAME = "" 54 | KEYBOARD_2_ADDRESS = "" 55 | KEYBOARD_2_NAME = "" 56 | POWER_BUTTON_PRIMARY = "LNXPWRBN/button/input0" 57 | POWER_BUTTON_SECONDARY = "PNP0C0C/button/input0" 58 | 59 | # Enviroment Variables 60 | HAS_CHIMERA_LAUNCHER = False 61 | USER = None 62 | HOME_PATH = None 63 | 64 | # UInput Devices 65 | controller_device = None 66 | keyboard_device = None 67 | keyboard_2_device = None 68 | power_device = None 69 | power_device_2 = None 70 | 71 | # Paths 72 | controller_event = None 73 | controller_path = None 74 | keyboard_event = None 75 | keyboard_path = None 76 | keyboard_2_event = None 77 | keyboard_2_path = None 78 | 79 | # Performance settings 80 | performance_mode = "--power-saving" 81 | thermal_mode = "0" 82 | 83 | def __init__(self): 84 | self.running = True 85 | devices.set_handycon(self) 86 | utilities.set_handycon(self) 87 | self.logger.info("Starting Handheld Game Console Controller Service...") 88 | if utilities.is_process_running("opengamepadui"): 89 | self.logger.warn( 90 | "Detected an OpenGamepadUI Process. Input management not possible. Exiting." 91 | ) 92 | exit() 93 | Path(HIDE_PATH).mkdir(parents=True, exist_ok=True) 94 | devices.restore_hidden() 95 | utilities.get_user() 96 | self.HAS_CHIMERA_LAUNCHER = os.path.isfile(CHIMERA_LAUNCHER_PATH) 97 | utilities.id_system() 98 | utilities.get_config() 99 | devices.make_controller() 100 | 101 | # Run asyncio loop to capture all events. 102 | self.loop = asyncio.get_event_loop() 103 | 104 | # Attach the event loop of each device to the asyncio loop. 105 | asyncio.ensure_future(devices.capture_controller_events()) 106 | asyncio.ensure_future(devices.capture_ff_events()) 107 | asyncio.ensure_future(devices.capture_keyboard_events()) 108 | if self.KEYBOARD_2_NAME != "" and self.KEYBOARD_2_ADDRESS != "": 109 | asyncio.ensure_future(devices.capture_keyboard_2_events()) 110 | 111 | asyncio.ensure_future(devices.capture_power_events()) 112 | self.logger.info("Handheld Game Console Controller Service started.") 113 | 114 | # Establish signaling to handle gracefull shutdown. 115 | for s in (signal.SIGHUP, signal.SIGTERM, signal.SIGINT, signal.SIGQUIT): 116 | self.loop.add_signal_handler( 117 | s, lambda s=s: asyncio.create_task(self.exit()) 118 | ) 119 | 120 | try: 121 | self.loop.run_forever() 122 | exit_code = 0 123 | except KeyboardInterrupt: 124 | self.logger.info("Keyboard interrupt.") 125 | exit_code = 1 126 | except Exception as err: 127 | self.logger.error(f"{err} | Hit exception condition.") 128 | self.logger.error(traceback.format_exc()) 129 | exit_code = 2 130 | finally: 131 | self.loop.stop() 132 | sys.exit(exit_code) 133 | 134 | # These functions avoid recursive imports. 135 | def steam_ifrunning_deckui(self, cmd): 136 | return utilities.steam_ifrunning_deckui(cmd) 137 | 138 | def launch_chimera(self): 139 | utilities.launch_chimera() 140 | 141 | def emit_event(self, event): 142 | devices.emit_event(event) 143 | 144 | async def emit_events(self, events): 145 | await devices.emit_events(events) 146 | 147 | async def emit_now(self, seed_event, event_list, value): 148 | await devices.emit_now(seed_event, event_list, value) 149 | 150 | async def do_rumble(self, button=0, interval=10, length=1000, delay=0): 151 | await devices.do_rumble(button, interval, length, delay) 152 | 153 | async def handle_key_up(self, seed_event, queued_event): 154 | await devices.handle_key_up(seed_event, queued_event) 155 | 156 | async def handle_key_down(self, seed_event, queued_event): 157 | await devices.handle_key_down(seed_event, queued_event) 158 | 159 | # Gracefull shutdown. 160 | async def exit(self): 161 | self.logger.info("Receved exit signal. Restoring devices.") 162 | self.running = False 163 | 164 | if self.controller_device: 165 | try: 166 | self.controller_device.ungrab() 167 | except IOError as err: 168 | pass 169 | devices.restore_device(self.controller_event, self.controller_path) 170 | if self.keyboard_device: 171 | try: 172 | self.keyboard_device.ungrab() 173 | except IOError as err: 174 | pass 175 | devices.restore_device(self.keyboard_event, self.keyboard_path) 176 | if self.keyboard_2_device: 177 | try: 178 | self.keyboard_2_device.ungrab() 179 | except IOError as err: 180 | pass 181 | devices.restore_device(self.keyboard_2_event, self.keyboard_2_path) 182 | if self.power_device and self.CAPTURE_POWER: 183 | try: 184 | self.power_device.ungrab() 185 | except IOError as err: 186 | pass 187 | if self.power_device_2 and self.CAPTURE_POWER: 188 | try: 189 | self.power_device_2.ungrab() 190 | except IOError as err: 191 | pass 192 | self.logger.info("Devices restored.") 193 | 194 | # Kill all tasks. They are infinite loops so we will wait forver. 195 | for task in [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]: 196 | task.cancel() 197 | try: 198 | await task 199 | except asyncio.CancelledError: 200 | self.logger.error(traceback.format_exc()) 201 | self.loop.stop() 202 | self.logger.info("Handheld Game Console Controller Service stopped.") 203 | 204 | 205 | def main(): 206 | handycon = HandheldController() 207 | -------------------------------------------------------------------------------- /src/handycon/constants.py: -------------------------------------------------------------------------------- 1 | #!/sbin/python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | from evdev import AbsInfo, ecodes as e 6 | from pathlib import Path 7 | 8 | CHIMERA_LAUNCHER_PATH = Path("/usr/share/chimera/bin/chimera-web-launcher") 9 | CONFIG_DIR = "/etc/handygccs/" 10 | CONFIG_PATH = "/etc/handygccs/handygccs.conf" 11 | CONTROLLER_EVENTS = { 12 | e.EV_KEY: [ 13 | e.KEY_ESC, 14 | e.KEY_1, 15 | e.KEY_2, 16 | e.KEY_3, 17 | e.KEY_4, 18 | e.KEY_5, 19 | e.KEY_6, 20 | e.KEY_7, 21 | e.KEY_8, 22 | e.KEY_9, 23 | e.KEY_0, 24 | e.KEY_MINUS, 25 | e.KEY_EQUAL, 26 | e.KEY_BACKSPACE, 27 | e.KEY_TAB, 28 | e.KEY_Q, 29 | e.KEY_W, 30 | e.KEY_E, 31 | e.KEY_R, 32 | e.KEY_T, 33 | e.KEY_Y, 34 | e.KEY_U, 35 | e.KEY_I, 36 | e.KEY_O, 37 | e.KEY_P, 38 | e.KEY_LEFTBRACE, 39 | e.KEY_RIGHTBRACE, 40 | e.KEY_ENTER, 41 | e.KEY_LEFTCTRL, 42 | e.KEY_A, 43 | e.KEY_S, 44 | e.KEY_D, 45 | e.KEY_F, 46 | e.KEY_G, 47 | e.KEY_H, 48 | e.KEY_J, 49 | e.KEY_K, 50 | e.KEY_L, 51 | e.KEY_SEMICOLON, 52 | e.KEY_APOSTROPHE, 53 | e.KEY_GRAVE, 54 | e.KEY_LEFTSHIFT, 55 | e.KEY_BACKSLASH, 56 | e.KEY_Z, 57 | e.KEY_X, 58 | e.KEY_C, 59 | e.KEY_V, 60 | e.KEY_B, 61 | e.KEY_N, 62 | e.KEY_M, 63 | e.KEY_COMMA, 64 | e.KEY_DOT, 65 | e.KEY_SLASH, 66 | e.KEY_RIGHTSHIFT, 67 | e.KEY_KPASTERISK, 68 | e.KEY_LEFTALT, 69 | e.KEY_SPACE, 70 | e.KEY_CAPSLOCK, 71 | e.KEY_F1, 72 | e.KEY_F2, 73 | e.KEY_F3, 74 | e.KEY_F4, 75 | e.KEY_F5, 76 | e.KEY_F6, 77 | e.KEY_F7, 78 | e.KEY_F8, 79 | e.KEY_F9, 80 | e.KEY_F10, 81 | e.KEY_NUMLOCK, 82 | e.KEY_SCROLLLOCK, 83 | e.KEY_KP7, 84 | e.KEY_KP8, 85 | e.KEY_KP9, 86 | e.KEY_KPMINUS, 87 | e.KEY_KP4, 88 | e.KEY_KP5, 89 | e.KEY_KP6, 90 | e.KEY_KPPLUS, 91 | e.KEY_KP1, 92 | e.KEY_KP2, 93 | e.KEY_KP3, 94 | e.KEY_KP0, 95 | e.KEY_KPDOT, 96 | e.KEY_ZENKAKUHANKAKU, 97 | e.KEY_102ND, 98 | e.KEY_F11, 99 | e.KEY_F12, 100 | e.KEY_RO, 101 | e.KEY_KATAKANA, 102 | e.KEY_HIRAGANA, 103 | e.KEY_HENKAN, 104 | e.KEY_KATAKANAHIRAGANA, 105 | e.KEY_MUHENKAN, 106 | e.KEY_KPJPCOMMA, 107 | e.KEY_KPENTER, 108 | e.KEY_RIGHTCTRL, 109 | e.KEY_KPSLASH, 110 | e.KEY_SYSRQ, 111 | e.KEY_RIGHTALT, 112 | e.KEY_HOME, 113 | e.KEY_UP, 114 | e.KEY_PAGEUP, 115 | e.KEY_LEFT, 116 | e.KEY_RIGHT, 117 | e.KEY_END, 118 | e.KEY_DOWN, 119 | e.KEY_PAGEDOWN, 120 | e.KEY_INSERT, 121 | e.KEY_DELETE, 122 | e.KEY_MACRO, 123 | e.KEY_MUTE, 124 | e.KEY_VOLUMEDOWN, 125 | e.KEY_VOLUMEUP, 126 | e.KEY_POWER, 127 | e.KEY_KPEQUAL, 128 | e.KEY_KPPLUSMINUS, 129 | e.KEY_PAUSE, 130 | e.KEY_KPCOMMA, 131 | e.KEY_HANGUEL, 132 | e.KEY_HANJA, 133 | e.KEY_YEN, 134 | e.KEY_LEFTMETA, 135 | e.KEY_RIGHTMETA, 136 | e.KEY_COMPOSE, 137 | e.KEY_STOP, 138 | e.KEY_CALC, 139 | e.KEY_SLEEP, 140 | e.KEY_WAKEUP, 141 | e.KEY_MAIL, 142 | e.KEY_BOOKMARKS, 143 | e.KEY_COMPUTER, 144 | e.KEY_BACK, 145 | e.KEY_FORWARD, 146 | e.KEY_NEXTSONG, 147 | e.KEY_PLAYPAUSE, 148 | e.KEY_PREVIOUSSONG, 149 | e.KEY_STOPCD, 150 | e.KEY_HOMEPAGE, 151 | e.KEY_REFRESH, 152 | e.KEY_F13, 153 | e.KEY_F14, 154 | e.KEY_F15, 155 | e.KEY_SEARCH, 156 | e.KEY_MEDIA, 157 | e.BTN_SOUTH, 158 | e.BTN_EAST, 159 | e.BTN_NORTH, 160 | e.BTN_WEST, 161 | e.BTN_TL, 162 | e.BTN_TR, 163 | e.BTN_SELECT, 164 | e.BTN_START, 165 | e.BTN_MODE, 166 | e.BTN_THUMBL, 167 | e.BTN_THUMBR, 168 | e.BTN_TRIGGER_HAPPY1, 169 | e.BTN_TRIGGER_HAPPY2, 170 | ], 171 | e.EV_ABS: [ 172 | (e.ABS_X, AbsInfo(0, -32768, 32767, 16, 128, 0)), 173 | (e.ABS_Y, AbsInfo(0, -32768, 32767, 16, 128, 0)), 174 | (e.ABS_Z, AbsInfo(0, 0, 255, 0, 0, 0)), 175 | (e.ABS_RX, AbsInfo(0, -32768, 32767, 16, 128, 0)), 176 | (e.ABS_RY, AbsInfo(0, -32768, 32767, 16, 128, 0)), 177 | (e.ABS_RZ, AbsInfo(0, 0, 255, 0, 0, 0)), 178 | (e.ABS_HAT0X, AbsInfo(0, -1, 1, 0, 0, 0)), 179 | (e.ABS_HAT0Y, AbsInfo(0, -1, 1, 0, 0, 0)), 180 | ], 181 | e.EV_MSC: [ 182 | e.MSC_SCAN, 183 | ], 184 | e.EV_LED: [ 185 | e.LED_NUML, 186 | e.LED_CAPSL, 187 | e.LED_SCROLLL, 188 | ], 189 | e.EV_FF: [ 190 | e.FF_RUMBLE, 191 | e.FF_PERIODIC, 192 | e.FF_SQUARE, 193 | e.FF_TRIANGLE, 194 | e.FF_SINE, 195 | e.FF_GAIN, 196 | ], 197 | } 198 | DETECT_DELAY = 0.5 199 | EVENT_ALT_TAB = [[e.EV_KEY, e.KEY_LEFTALT], [e.EV_KEY, e.KEY_TAB]] 200 | EVENT_ESC = [[e.EV_MSC, e.MSC_SCAN], [e.EV_KEY, e.KEY_ESC]] 201 | EVENT_KILL = [ 202 | [e.EV_KEY, e.KEY_LEFTMETA], 203 | [e.EV_KEY, e.KEY_LEFTCTRL], 204 | [e.EV_KEY, e.KEY_ESC], 205 | ] 206 | EVENT_MODE = [[e.EV_KEY, e.BTN_MODE]] 207 | EVENT_OPEN_CHIM = ["Open Chimera"] 208 | EVENT_OSK = [[e.EV_KEY, e.BTN_MODE], [e.EV_KEY, e.BTN_NORTH]] 209 | EVENT_OSK_DE = [ 210 | [e.EV_KEY, e.KEY_LEFTMETA], 211 | [e.EV_KEY, e.KEY_LEFTCTRL], 212 | [e.EV_KEY, e.KEY_O], 213 | ] 214 | EVENT_OSK_NES = [[e.EV_KEY, e.BTN_MODE], [e.EV_KEY, e.BTN_WEST]] 215 | EVENT_QAM = [[e.EV_KEY, e.BTN_MODE], [e.EV_KEY, e.BTN_SOUTH]] 216 | EVENT_QAM_NES = [[e.EV_KEY, e.BTN_MODE], [e.EV_KEY, e.BTN_EAST]] 217 | EVENT_SCR = [[e.EV_KEY, e.BTN_MODE], [e.EV_KEY, e.BTN_TR]] 218 | EVENT_THUMBL = [[e.EV_KEY, e.BTN_THUMBL]] 219 | EVENT_THUMBR = [[e.EV_KEY, e.BTN_THUMBR]] 220 | EVENT_TOGGLE_GYRO = ["Toggle Gyro"] 221 | EVENT_TOGGLE_MOUSE = ["Toggle Mouse Mode"] 222 | EVENT_TOGGLE_PERF = ["Toggle Performance"] 223 | EVENT_VOLUP = [[e.EV_KEY, e.KEY_VOLUMEUP]] 224 | EVENT_VOLDOWN = [[e.EV_KEY, e.KEY_VOLUMEDOWN]] 225 | EVENT_MAP = { 226 | "ALT_TAB": EVENT_ALT_TAB, 227 | "ESC": EVENT_ESC, 228 | "KILL": EVENT_KILL, 229 | "MODE": EVENT_MODE, 230 | "OPEN_CHIMERA": EVENT_OPEN_CHIM, 231 | "OSK": EVENT_OSK, 232 | "OSK_DE": EVENT_OSK_DE, 233 | "OSK_NES": EVENT_OSK_NES, 234 | "QAM": EVENT_QAM, 235 | "QAM_NES": EVENT_QAM_NES, 236 | "SCR": EVENT_SCR, 237 | "THUMBL": EVENT_THUMBL, 238 | "THUMBR": EVENT_THUMBR, 239 | "TOGGLE_GYRO": EVENT_TOGGLE_GYRO, 240 | "TOGGLE_MOUSE": EVENT_TOGGLE_MOUSE, 241 | "TOGGLE_PERFORMANCE": EVENT_TOGGLE_PERF, 242 | "VOLUP": EVENT_VOLUP, 243 | "VOLDOWN": EVENT_VOLDOWN, 244 | } 245 | POWER_ACTION_HIBERNATE = ["Hibernate"] 246 | POWER_ACTION_SHUTDOWN = ["Shutdown"] 247 | POWER_ACTION_SUSPEND = ["Suspend"] 248 | POWER_ACTION_SUSPEND_THEN_HIBERNATE = ["Suspend then hibernate"] 249 | POWER_ACTION_MAP = { 250 | "HIBERNATE": POWER_ACTION_HIBERNATE, 251 | "SHUTDOWN": POWER_ACTION_SHUTDOWN, 252 | "SUSPEND": POWER_ACTION_SUSPEND, 253 | "SUSPEND_THEN_HIBERNATE": POWER_ACTION_SUSPEND_THEN_HIBERNATE, 254 | } 255 | INSTANT_EVENTS = [ 256 | EVENT_MODE, 257 | EVENT_OPEN_CHIM, 258 | EVENT_TOGGLE_GYRO, 259 | EVENT_THUMBL, 260 | EVENT_THUMBR, 261 | EVENT_TOGGLE_MOUSE, 262 | EVENT_TOGGLE_PERF, 263 | EVENT_VOLUP, 264 | EVENT_VOLDOWN, 265 | ] 266 | QUEUED_EVENTS = [ 267 | EVENT_ALT_TAB, 268 | EVENT_ESC, 269 | EVENT_KILL, 270 | EVENT_OSK, 271 | EVENT_OSK_DE, 272 | EVENT_OSK_NES, 273 | EVENT_QAM, 274 | EVENT_QAM_NES, 275 | EVENT_SCR, 276 | ] 277 | FF_DELAY = 0.2 278 | HIDE_PATH = Path("/dev/input/.hidden/") 279 | HOME_PATH = Path("/home") 280 | JOY_MAX = 32767 281 | JOY_MIN = -32767 282 | -------------------------------------------------------------------------------- /src/handycon/utilities.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | # Python Modules 6 | import configparser 7 | import os 8 | import re 9 | import subprocess 10 | import sys 11 | import traceback 12 | 13 | # Local modules 14 | import handycon.handhelds.ally_gen1 as ally_gen1 15 | import handycon.handhelds.anb_gen1 as anb_gen1 16 | import handycon.handhelds.aok_gen1 as aok_gen1 17 | import handycon.handhelds.aok_gen2 as aok_gen2 18 | import handycon.handhelds.aya_gen1 as aya_gen1 19 | import handycon.handhelds.aya_gen2 as aya_gen2 20 | import handycon.handhelds.aya_gen3 as aya_gen3 21 | import handycon.handhelds.aya_gen4 as aya_gen4 22 | import handycon.handhelds.aya_gen5 as aya_gen5 23 | import handycon.handhelds.aya_gen6 as aya_gen6 24 | import handycon.handhelds.aya_gen7 as aya_gen7 25 | import handycon.handhelds.aya_gen8 as aya_gen8 26 | import handycon.handhelds.aya_gen9 as aya_gen9 27 | import handycon.handhelds.aya_gen10 as aya_gen10 28 | import handycon.handhelds.ayn_gen1 as ayn_gen1 29 | import handycon.handhelds.ayn_gen2 as ayn_gen2 30 | import handycon.handhelds.ayn_gen3 as ayn_gen3 31 | import handycon.handhelds.go_gen1 as go_gen1 32 | import handycon.handhelds.gpd_gen1 as gpd_gen1 33 | import handycon.handhelds.gpd_gen2 as gpd_gen2 34 | import handycon.handhelds.gpd_gen3 as gpd_gen3 35 | import handycon.handhelds.gpd_gen4 as gpd_gen4 36 | import handycon.handhelds.oxp_gen1 as oxp_gen1 37 | import handycon.handhelds.oxp_gen2 as oxp_gen2 38 | import handycon.handhelds.oxp_gen3 as oxp_gen3 39 | import handycon.handhelds.oxp_gen4 as oxp_gen4 40 | import handycon.handhelds.oxp_gen5 as oxp_gen5 41 | import handycon.handhelds.oxp_gen6 as oxp_gen6 42 | import handycon.handhelds.oxp_gen7 as oxp_gen7 43 | from .constants import * 44 | 45 | # Partial imports 46 | from time import sleep 47 | 48 | handycon = None 49 | 50 | 51 | def set_handycon(handheld_controller): 52 | global handycon 53 | handycon = handheld_controller 54 | 55 | 56 | # Capture the username and home path of the user who has been logged in the longest. 57 | def get_user(): 58 | global handycon 59 | 60 | handycon.logger.debug("Identifying user.") 61 | cmd = "who | awk '{print $1}' | sort | head -1" 62 | while handycon.USER is None: 63 | USER_LIST = subprocess.Popen( 64 | cmd, 65 | stdin=subprocess.PIPE, 66 | stdout=subprocess.PIPE, 67 | stderr=subprocess.PIPE, 68 | shell=True, 69 | ) 70 | for get_first in USER_LIST.stdout: 71 | name = get_first.decode().strip() 72 | if name is not None: 73 | handycon.USER = name 74 | break 75 | sleep(1) 76 | 77 | handycon.logger.debug(f"USER: {handycon.USER}") 78 | handycon.HOME_PATH = "/home/" + handycon.USER 79 | handycon.logger.debug(f"HOME_PATH: {handycon.HOME_PATH}") 80 | 81 | 82 | # Identify the current device type. Kill script if not atible. 83 | def id_system(): 84 | global handycon 85 | 86 | system_id = open( 87 | "/sys/devices/virtual/dmi/id/product_name", "r").read().strip() 88 | handycon.logger.info(f"Found System ID: {system_id}") 89 | 90 | cpu_vendor = get_cpu_vendor() 91 | handycon.logger.info(f"Found CPU Vendor: {cpu_vendor}") 92 | 93 | board_name = open( 94 | "/sys/devices/virtual/dmi/id/board_name", "r").read().strip() 95 | handycon.logger.info(f"Found Board Name: {board_name}") 96 | 97 | # Verify all system hardweare has initialized. 98 | handycon.logger.info("Identifying system hardware.") 99 | timeout = 0 100 | while not os.path.exists("/proc/bus/input/devices"): 101 | sleep(1) 102 | timeout += 1 103 | if timeout == 30: 104 | handycon.logger.error( 105 | "Unable to read input devices after 30 seconds. Exiting." 106 | ) 107 | sys.exit(0) 108 | 109 | # ANBERNIC Devices 110 | if system_id in ("Win600",): 111 | handycon.system_type = "ANB_GEN1" 112 | anb_gen1.init_handheld(handycon) 113 | 114 | # AOKZOE Devices 115 | elif system_id in ("AOKZOE A1 AR07",): 116 | handycon.system_type = "AOK_GEN1" 117 | aok_gen1.init_handheld(handycon) 118 | 119 | elif system_id in ("AOKZOE A1 Pro",): 120 | handycon.system_type = "AOK_GEN2" 121 | aok_gen2.init_handheld(handycon) 122 | 123 | # ASUS Devices 124 | elif system_id in ( 125 | "ROG Ally RC71L", 126 | "ROG Ally RC71L_RC71L", 127 | ): 128 | handycon.system_type = "ALY_GEN1" 129 | ally_gen1.init_handheld(handycon) 130 | 131 | # Aya Neo Devices 132 | elif system_id in ( 133 | "AYA NEO 2021", 134 | "AYA NEO FOUNDER", 135 | "AYANEO 2021 Pro Retro Power", 136 | "AYANEO 2021 Pro", 137 | "AYANEO 2021", 138 | ): 139 | handycon.system_type = "AYA_GEN1" 140 | aya_gen1.init_handheld(handycon) 141 | 142 | elif system_id in ( 143 | "AYANEO NEXT Advance", 144 | "AYANEO NEXT Pro", 145 | "AYANEO NEXT", 146 | "NEXT Advance", 147 | "NEXT Lite", 148 | "NEXT Pro", 149 | "NEXT", 150 | ): 151 | handycon.system_type = "AYA_GEN2" 152 | aya_gen2.init_handheld(handycon) 153 | 154 | elif system_id in ( 155 | "AIR", 156 | "AIR Pro", 157 | ): 158 | handycon.system_type = "AYA_GEN3" 159 | aya_gen3.init_handheld(handycon) 160 | 161 | elif system_id in ( 162 | "AYANEO 2", 163 | "GEEK", 164 | ): 165 | handycon.system_type = "AYA_GEN4" 166 | aya_gen4.init_handheld(handycon) 167 | 168 | elif system_id in ("AIR Plus",): 169 | if cpu_vendor == "GenuineIntel": 170 | handycon.system_type = "AYA_GEN7" 171 | aya_gen7.init_handheld(handycon) 172 | else: 173 | if board_name == "AB05-Mendocino": 174 | handycon.system_type = "AYA_GEN10" 175 | aya_gen10.init_handheld(handycon) 176 | else: 177 | handycon.system_type = "AYA_GEN5" 178 | aya_gen5.init_handheld(handycon) 179 | 180 | elif system_id in ( 181 | "AYANEO 2S", 182 | "FLIP KB", 183 | "FLIP DS", 184 | "GEEK 1S", 185 | "AIR 1S", 186 | "AIR 1S Limited", 187 | ): 188 | handycon.system_type = "AYA_GEN6" 189 | aya_gen6.init_handheld(handycon) 190 | 191 | elif system_id in ("KUN",): 192 | handycon.system_type = "AYA_GEN8" 193 | aya_gen8.init_handheld(handycon) 194 | 195 | elif system_id in ("SLIDE",): 196 | handycon.system_type = "AYA_GEN9" 197 | aya_gen9.init_handheld(handycon) 198 | 199 | # Ayn Devices 200 | elif system_id in ("Loki Max",): 201 | handycon.system_type = "AYN_GEN1" 202 | ayn_gen1.init_handheld(handycon) 203 | 204 | elif system_id in ("Loki Zero",): 205 | handycon.system_type = "AYN_GEN2" 206 | ayn_gen2.init_handheld(handycon) 207 | 208 | elif system_id in ("Loki MiniPro",): 209 | handycon.system_type = "AYN_GEN3" 210 | ayn_gen3.init_handheld(handycon) 211 | 212 | # Lenovo Devices 213 | elif system_id in ( 214 | "83E1", # Legion Go 215 | ): 216 | handycon.system_type = "GO_GEN1" 217 | go_gen1.init_handheld(handycon) 218 | 219 | # GPD Devices 220 | # Have 2 buttons with 3 modes (left, right, both) 221 | elif system_id in ( 222 | "G1618-03", # Win3 223 | ): 224 | handycon.system_type = "GPD_GEN1" 225 | gpd_gen1.init_handheld(handycon) 226 | 227 | elif system_id in ( 228 | "G1619-04", # WinMax2 229 | ): 230 | handycon.system_type = "GPD_GEN2" 231 | gpd_gen2.init_handheld(handycon) 232 | 233 | elif system_id in ( 234 | "G1618-04", # Win4 235 | ): 236 | handycon.system_type = "GPD_GEN3" 237 | gpd_gen3.init_handheld(handycon) 238 | 239 | elif system_id in ( 240 | "G1617-01", # WinMini 241 | ): 242 | handycon.system_type = "GPD_GEN4" 243 | gpd_gen4.init_handheld(handycon) 244 | 245 | # ONEXPLAYER Devices 246 | # Older BIOS have incomlete DMI data and most models report as "ONE XPLAYER" or "ONEXPLAYER". 247 | elif system_id in ( 248 | "ONE XPLAYER", 249 | "ONEXPLAYER", 250 | ): 251 | # GEN 1 252 | if cpu_vendor == "GenuineIntel": 253 | handycon.system_type = "OXP_GEN1" 254 | oxp_gen1.init_handheld(handycon) 255 | 256 | # GEN 2 257 | else: 258 | handycon.system_type = "OXP_GEN2" 259 | oxp_gen2.init_handheld(handycon) 260 | 261 | # GEN 3 262 | elif system_id in ("ONEXPLAYER mini A07",): 263 | handycon.system_type = "OXP_GEN3" 264 | oxp_gen3.init_handheld(handycon) 265 | 266 | # GEN 4 267 | elif system_id in ("ONEXPLAYER Mini Pro",): 268 | handycon.system_type = "OXP_GEN4" 269 | oxp_gen4.init_handheld(handycon) 270 | 271 | # GEN 5 272 | elif system_id in ("ONEXPLAYER 2 ARP23",): 273 | handycon.system_type = "OXP_GEN5" 274 | oxp_gen5.init_handheld(handycon) 275 | 276 | # GEN 6 277 | elif system_id in ( 278 | "ONEXPLAYER 2 PRO ARP23P", 279 | "ONEXPLAYER 2 PRO ARP23P EVA-01", 280 | ): 281 | handycon.system_type = "OXP_GEN6" 282 | oxp_gen6.init_handheld(handycon) 283 | 284 | # GEN 7 285 | elif system_id in ("ONEXPLAYER F1",): 286 | handycon.system_type = "OXP_GEN7" 287 | oxp_gen7.init_handheld(handycon) 288 | 289 | # Devices that aren't supported could cause issues, exit. 290 | else: 291 | handycon.logger.error(f"{system_id} is not currently supported by this tool. Open an issue on \ 292 | ub at https://github.ShadowBlip/HandyGCCS if this is a bug. If possible, \ 293 | se run the capture-system.py utility found on the GitHub repository and upload \ 294 | the file with your issue.") 295 | sys.exit(0) 296 | handycon.logger.info( 297 | f"Identified host system as {system_id} and configured defaults for {handycon.system_type}." 298 | ) 299 | 300 | 301 | def get_cpu_vendor(): 302 | global handycon 303 | 304 | cmd = "cat /proc/cpuinfo" 305 | all_info = subprocess.check_output(cmd, shell=True).decode().strip() 306 | for line in all_info.split("\n"): 307 | if "vendor_id" in line: 308 | return re.sub(".*vendor_id.*:", "", line, 1).strip() 309 | 310 | 311 | def get_config(): 312 | global handycon 313 | # Check for an existing config file and load it. 314 | handycon.config = configparser.ConfigParser() 315 | if os.path.exists(CONFIG_PATH): 316 | handycon.logger.info(f"Loading existing config: {CONFIG_PATH}") 317 | handycon.config.read(CONFIG_PATH) 318 | if "version" not in handycon.config or float(handycon.config["version"]) < 1.2: 319 | handycon.logger.info( 320 | "Config file out of date. Generating new config.") 321 | set_default_config() 322 | write_config() 323 | else: 324 | set_default_config() 325 | write_config() 326 | map_config() 327 | 328 | 329 | # Match runtime variables to the config 330 | def map_config(): 331 | # Assign config file values 332 | handycon.button_map = { 333 | "button1": EVENT_MAP[handycon.config["Button Map"]["button1"]], 334 | "button2": EVENT_MAP[handycon.config["Button Map"]["button2"]], 335 | "button3": EVENT_MAP[handycon.config["Button Map"]["button3"]], 336 | "button4": EVENT_MAP[handycon.config["Button Map"]["button4"]], 337 | "button5": EVENT_MAP[handycon.config["Button Map"]["button5"]], 338 | "button6": EVENT_MAP[handycon.config["Button Map"]["button6"]], 339 | "button7": EVENT_MAP[handycon.config["Button Map"]["button7"]], 340 | "button8": EVENT_MAP[handycon.config["Button Map"]["button8"]], 341 | "button9": EVENT_MAP[handycon.config["Button Map"]["button9"]], 342 | } 343 | handycon.power_action = POWER_ACTION_MAP[ 344 | handycon.config["Button Map"]["power_button"] 345 | ][0] 346 | 347 | 348 | # Sets the default configuration. 349 | def set_default_config(): 350 | global handycon 351 | handycon.config["Button Map"] = { 352 | "version": "1.2", 353 | "button1": "SCR", 354 | "button2": "QAM", 355 | "button3": "ESC", 356 | "button4": "OSK", 357 | "button5": "MODE", 358 | "button6": "OPEN_CHIMERA", 359 | "button7": "TOGGLE_PERFORMANCE", 360 | "button8": "THUMBL", 361 | "button9": "THUMBR", 362 | "power_button": "SUSPEND", 363 | } 364 | 365 | 366 | # Writes current config to disk. 367 | def write_config(): 368 | global handycon 369 | # Make the HandyGCCS directory if it doesn't exist. 370 | if not os.path.exists(CONFIG_DIR): 371 | os.mkdir(CONFIG_DIR) 372 | 373 | with open(CONFIG_PATH, "w") as config_file: 374 | handycon.config.write(config_file) 375 | handycon.logger.info(f"Created new config: {CONFIG_PATH}") 376 | 377 | 378 | def steam_ifrunning_deckui(cmd): 379 | global handycon 380 | 381 | # Get the currently running Steam PID. 382 | steampid_path = handycon.HOME_PATH + "/.steam/steam.pid" 383 | try: 384 | with open(steampid_path) as f: 385 | pid = f.read().strip() 386 | except Exception as err: 387 | handycon.logger.error(f"{err} | Error getting steam PID.") 388 | handycon.logger.error(traceback.format_exc()) 389 | return False 390 | 391 | # Get the andline for the Steam process by checking /proc. 392 | steam_cmd_path = f"/proc/{pid}/cmdline" 393 | if not os.path.exists(steam_cmd_path): 394 | # Steam not running. 395 | return False 396 | 397 | try: 398 | with open(steam_cmd_path, "rb") as f: 399 | steam_cmd = f.read() 400 | except Exception as err: 401 | handycon.logger.error(f"{err} | Error getting steam cmdline.") 402 | handycon.logger.error(traceback.format_exc()) 403 | return False 404 | 405 | # Use this andline to determine if Steam is running in DeckUI mode. 406 | # e.g. "steam://shortpowerpress" only works in DeckUI. 407 | is_deckui = b"-gamepadui" in steam_cmd 408 | if not is_deckui: 409 | return False 410 | 411 | steam_path = handycon.HOME_PATH + "/.steam/root/ubuntu12_32/steam" 412 | try: 413 | result = subprocess.run( 414 | ["su", handycon.USER, "-c", f"{steam_path} -ifrunning {cmd}"] 415 | ) 416 | return result.returncode == 0 417 | except Exception as err: 418 | handycon.logger.error(f"{err} | Error sending and to Steam.") 419 | handycon.logger.error(traceback.format_exc()) 420 | return False 421 | 422 | 423 | def launch_chimera(): 424 | global handycon 425 | 426 | if not handycon.HAS_CHIMERA_LAUNCHER: 427 | return 428 | subprocess.run(["su", handycon.USER, "-c", CHIMERA_LAUNCHER_PATH]) 429 | 430 | 431 | def is_process_running(name) -> bool: 432 | read_proc = os.popen("ps -Af").read() 433 | proc_count = read_proc.count(name) 434 | if proc_count > 0: 435 | handycon.logger.debug(f"Process {name} is running.") 436 | return True 437 | handycon.logger.debug(f"Process {name} is NOT running.") 438 | return False 439 | -------------------------------------------------------------------------------- /src/handycon/devices.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # This file is part of Handheld Game Console Controller System (HandyGCCS) 3 | # Copyright 2022-2023 Derek J. Clark 4 | 5 | # Python Modules 6 | import asyncio 7 | import os 8 | import traceback 9 | 10 | # Local modules 11 | import handycon.handhelds.ally_gen1 as ally_gen1 12 | import handycon.handhelds.anb_gen1 as anb_gen1 13 | import handycon.handhelds.aok_gen1 as aok_gen1 14 | import handycon.handhelds.aok_gen2 as aok_gen2 15 | import handycon.handhelds.aya_gen1 as aya_gen1 16 | import handycon.handhelds.aya_gen2 as aya_gen2 17 | import handycon.handhelds.aya_gen3 as aya_gen3 18 | import handycon.handhelds.aya_gen4 as aya_gen4 19 | import handycon.handhelds.aya_gen5 as aya_gen5 20 | import handycon.handhelds.aya_gen6 as aya_gen6 21 | import handycon.handhelds.aya_gen7 as aya_gen7 22 | import handycon.handhelds.aya_gen8 as aya_gen8 23 | import handycon.handhelds.aya_gen9 as aya_gen9 24 | import handycon.handhelds.aya_gen10 as aya_gen10 25 | import handycon.handhelds.ayn_gen1 as ayn_gen1 26 | import handycon.handhelds.ayn_gen2 as ayn_gen2 27 | import handycon.handhelds.ayn_gen3 as ayn_gen3 28 | import handycon.handhelds.go_gen1 as go_gen1 29 | import handycon.handhelds.gpd_gen1 as gpd_gen1 30 | import handycon.handhelds.gpd_gen2 as gpd_gen2 31 | import handycon.handhelds.gpd_gen3 as gpd_gen3 32 | import handycon.handhelds.gpd_gen4 as gpd_gen4 33 | import handycon.handhelds.oxp_gen1 as oxp_gen1 34 | import handycon.handhelds.oxp_gen2 as oxp_gen2 35 | import handycon.handhelds.oxp_gen3 as oxp_gen3 36 | import handycon.handhelds.oxp_gen4 as oxp_gen4 37 | import handycon.handhelds.oxp_gen5 as oxp_gen5 38 | import handycon.handhelds.oxp_gen6 as oxp_gen6 39 | import handycon.handhelds.oxp_gen7 as oxp_gen7 40 | from .constants import * 41 | 42 | # Partial imports 43 | from evdev import ecodes as e, ff, InputDevice, InputEvent, list_devices, UInput 44 | from pathlib import Path 45 | from shutil import move 46 | from time import sleep 47 | 48 | handycon = None 49 | 50 | 51 | def set_handycon(handheld_controller): 52 | global handycon 53 | handycon = handheld_controller 54 | 55 | 56 | def get_controller(): 57 | global handycon 58 | 59 | # Identify system input event devices. 60 | handycon.logger.debug(f"Attempting to grab {handycon.GAMEPAD_NAME}.") 61 | try: 62 | devices_original = [InputDevice(path) for path in list_devices()] 63 | 64 | except Exception as err: 65 | handycon.logger.error("Error when scanning event devices. Restarting scan.") 66 | handycon.logger.error(traceback.format_exc()) 67 | sleep(DETECT_DELAY) 68 | return False 69 | 70 | # Grab the built-in devices. This will give us exclusive acces to the devices and their capabilities. 71 | for device in devices_original: 72 | if ( 73 | device.name == handycon.GAMEPAD_NAME 74 | and device.phys == handycon.GAMEPAD_ADDRESS 75 | ): 76 | handycon.controller_path = device.path 77 | handycon.controller_device = InputDevice(handycon.controller_path) 78 | if handycon.CAPTURE_CONTROLLER: 79 | handycon.controller_device.grab() 80 | handycon.controller_event = Path(handycon.controller_path).name 81 | move( 82 | handycon.controller_path, str(HIDE_PATH / handycon.controller_event) 83 | ) 84 | break 85 | 86 | # Sometimes the service loads before all input devices have full initialized. Try a few times. 87 | if not handycon.controller_device: 88 | handycon.logger.warn("Controller device not yet found. Restarting scan.") 89 | sleep(DETECT_DELAY) 90 | return False 91 | else: 92 | handycon.logger.info( 93 | f"Found {handycon.controller_device.name}. Capturing input data." 94 | ) 95 | return True 96 | 97 | 98 | def get_keyboard(): 99 | global handycon 100 | 101 | # Identify system input event devices. 102 | handycon.logger.debug(f"Attempting to grab {handycon.KEYBOARD_NAME}.") 103 | try: 104 | devices_original = [InputDevice(path) for path in list_devices()] 105 | except Exception as err: 106 | handycon.logger.error("Error when scanning event devices. Restarting scan.") 107 | handycon.logger.error(traceback.format_exc()) 108 | sleep(DETECT_DELAY) 109 | return False 110 | # Grab the built-in devices. This will give us exclusive acces to the devices and their capabilities. 111 | for device in devices_original: 112 | handycon.logger.debug(f"{device.name}, {device.phys}") 113 | if ( 114 | device.name == handycon.KEYBOARD_NAME 115 | and device.phys == handycon.KEYBOARD_ADDRESS 116 | ): 117 | handycon.keyboard_path = device.path 118 | handycon.keyboard_device = InputDevice(handycon.keyboard_path) 119 | if handycon.CAPTURE_KEYBOARD: 120 | handycon.keyboard_device.grab() 121 | handycon.keyboard_event = Path(handycon.keyboard_path).name 122 | move(handycon.keyboard_path, str(HIDE_PATH / handycon.keyboard_event)) 123 | break 124 | 125 | # Sometimes the service loads before all input devices have full initialized. Try a few times. 126 | if not handycon.keyboard_device: 127 | handycon.logger.warn("Keyboard device not yet found. Restarting scan.") 128 | sleep(DETECT_DELAY) 129 | return False 130 | else: 131 | handycon.logger.info( 132 | f"Found {handycon.keyboard_device.name}. Capturing input data." 133 | ) 134 | return True 135 | 136 | 137 | def get_keyboard_2(): 138 | global handycon 139 | 140 | handycon.logger.debug(f"Attempting to grab {handycon.KEYBOARD_2_NAME}.") 141 | try: 142 | devices_original = [InputDevice(path) for path in list_devices()] 143 | except Exception as err: 144 | handycon.logger.error("Error when scanning event devices. Restarting scan.") 145 | handycon.logger.error(traceback.format_exc()) 146 | sleep(DETECT_DELAY) 147 | return False 148 | 149 | # Grab the built-in devices. This will give us exclusive acces to the devices and their capabilities. 150 | for device in devices_original: 151 | handycon.logger.debug(f"{device.name}, {device.phys}") 152 | if ( 153 | device.name == handycon.KEYBOARD_2_NAME 154 | and device.phys == handycon.KEYBOARD_2_ADDRESS 155 | ): 156 | handycon.keyboard_2_path = device.path 157 | handycon.keyboard_2_device = InputDevice(handycon.keyboard_2_path) 158 | if handycon.CAPTURE_KEYBOARD: 159 | handycon.keyboard_2_device.grab() 160 | handycon.keyboard_2_event = Path(handycon.keyboard_2_path).name 161 | move( 162 | handycon.keyboard_2_path, str(HIDE_PATH / handycon.keyboard_2_event) 163 | ) 164 | break 165 | 166 | # Sometimes the service loads before all input devices have full initialized. Try a few times. 167 | if not handycon.keyboard_2_device: 168 | handycon.logger.warn("Keyboard device 2 not yet found. Restarting scan.") 169 | sleep(DETECT_DELAY) 170 | return False 171 | else: 172 | handycon.logger.info( 173 | f"Found {handycon.keyboard_2_device.name}. Capturing input data." 174 | ) 175 | return True 176 | 177 | 178 | def get_powerkey(): 179 | global handycon 180 | 181 | handycon.logger.debug(f"Attempting to grab power buttons.") 182 | # Identify system input event devices. 183 | try: 184 | devices_original = [InputDevice(path) for path in list_devices()] 185 | # Some funky stuff happens sometimes when booting. Give it another shot. 186 | except Exception as err: 187 | handycon.logger.error("Error when scanning event devices. Restarting scan.") 188 | handycon.logger.error(traceback.format_exc()) 189 | sleep(DETECT_DELAY) 190 | return False 191 | 192 | # Grab the built-in devices. This will give us exclusive acces to the devices and their capabilities. 193 | for device in devices_original: 194 | # Power Button 195 | if ( 196 | device.name == "Power Button" 197 | and device.phys == handycon.POWER_BUTTON_PRIMARY 198 | and not handycon.power_device 199 | ): 200 | handycon.power_device = device 201 | handycon.logger.debug(f"found power device {handycon.power_device.phys}") 202 | if handycon.CAPTURE_POWER: 203 | handycon.power_device.grab() 204 | 205 | # Some devices have an extra power input device corresponding to the same 206 | # physical button that needs to be grabbed. 207 | if ( 208 | device.name == "Power Button" 209 | and device.phys == handycon.POWER_BUTTON_SECONDARY 210 | and not handycon.power_device_2 211 | ): 212 | handycon.power_device_2 = device 213 | handycon.logger.debug( 214 | f"found alternate power device {handycon.power_device_2.phys}" 215 | ) 216 | if handycon.CAPTURE_POWER: 217 | handycon.power_device_2.grab() 218 | 219 | if not handycon.power_device and not handycon.power_device_2: 220 | handycon.logger.warn("No Power Button found. Restarting scan.") 221 | sleep(DETECT_DELAY) 222 | return False 223 | else: 224 | if handycon.power_device: 225 | handycon.logger.info( 226 | f"Found {handycon.power_device.name}. Capturing input data." 227 | ) 228 | if handycon.power_device_2: 229 | handycon.logger.info( 230 | f"Found {handycon.power_device_2.name}. Capturing input data." 231 | ) 232 | return True 233 | 234 | 235 | async def do_rumble(button=0, interval=10, length=1000, delay=0): 236 | global handycon 237 | 238 | # Prevent look crash if controller_device was taken. 239 | if not handycon.controller_device: 240 | return 241 | 242 | # Create the rumble effect. 243 | rumble = ff.Rumble(strong_magnitude=0x0000, weak_magnitude=0xFFFF) 244 | effect = ff.Effect( 245 | e.FF_RUMBLE, 246 | -1, 247 | 0, 248 | ff.Trigger(button, interval), 249 | ff.Replay(length, delay), 250 | ff.EffectType(ff_rumble_effect=rumble), 251 | ) 252 | 253 | # Upload and transmit the effect. 254 | effect_id = handycon.controller_device.upload_effect(effect) 255 | handycon.controller_device.write(e.EV_FF, effect_id, 1) 256 | await asyncio.sleep(interval / 1000) 257 | handycon.controller_device.erase_effect(effect_id) 258 | 259 | 260 | # Captures keyboard events and translates them to virtual device events. 261 | async def capture_keyboard_events(): 262 | global handycon 263 | 264 | # Capture keyboard events and translate them to mapped events. 265 | while handycon.running: 266 | if handycon.keyboard_device: 267 | try: 268 | async for seed_event in handycon.keyboard_device.async_read_loop(): 269 | # Loop variables 270 | active_keys = handycon.keyboard_device.active_keys() 271 | 272 | # Debugging variables 273 | handycon.logger.debug( 274 | f"Seed Value: {seed_event.value}, Seed Code: {seed_event.code}, Seed Type: {seed_event.type}." 275 | ) 276 | if active_keys != []: 277 | handycon.logger.debug(f"Active Keys: {active_keys}") 278 | else: 279 | handycon.logger.debug("No active keys") 280 | if handycon.event_queue != []: 281 | handycon.logger.debug(f"Queued events: {handycon.event_queue}") 282 | else: 283 | handycon.logger.debug("No active events.") 284 | 285 | # Capture keyboard events and translate them to mapped events. 286 | match handycon.system_type: 287 | case "ALY_GEN1": 288 | await ally_gen1.process_event(seed_event, active_keys) 289 | case "ANB_GEN1": 290 | await anb_gen1.process_event(seed_event, active_keys) 291 | case "AOK_GEN1": 292 | await aok_gen1.process_event(seed_event, active_keys) 293 | case "AOK_GEN2": 294 | await aok_gen2.process_event(seed_event, active_keys) 295 | case "AYA_GEN1": 296 | await aya_gen1.process_event(seed_event, active_keys) 297 | case "AYA_GEN2": 298 | await aya_gen2.process_event(seed_event, active_keys) 299 | case "AYA_GEN3": 300 | await aya_gen3.process_event(seed_event, active_keys) 301 | case "AYA_GEN4": 302 | await aya_gen4.process_event(seed_event, active_keys) 303 | case "AYA_GEN5": 304 | await aya_gen5.process_event(seed_event, active_keys) 305 | case "AYA_GEN6": 306 | await aya_gen6.process_event(seed_event, active_keys) 307 | case "AYA_GEN7": 308 | await aya_gen7.process_event(seed_event, active_keys) 309 | case "AYA_GEN8": 310 | await aya_gen8.process_event(seed_event, active_keys) 311 | case "AYA_GEN9": 312 | await aya_gen9.process_event(seed_event, active_keys) 313 | case "AYA_GEN10": 314 | await aya_gen10.process_event(seed_event, active_keys) 315 | case "AYN_GEN1": 316 | await ayn_gen1.process_event(seed_event, active_keys) 317 | case "AYN_GEN2": 318 | await ayn_gen2.process_event(seed_event, active_keys) 319 | case "AYN_GEN3": 320 | await ayn_gen3.process_event(seed_event, active_keys) 321 | case "GO_GEN1": 322 | await go_gen1.process_event(seed_event, active_keys) 323 | case "GPD_GEN1": 324 | await gpd_gen1.process_event(seed_event, active_keys) 325 | case "GPD_GEN2": 326 | await gpd_gen2.process_event(seed_event, active_keys) 327 | case "GPD_GEN3": 328 | await gpd_gen3.process_event(seed_event, active_keys) 329 | case "GPD_GEN4": 330 | await gpd_gen4.process_event(seed_event, active_keys) 331 | case "OXP_GEN1": 332 | await oxp_gen1.process_event(seed_event, active_keys) 333 | case "OXP_GEN2": 334 | await oxp_gen2.process_event(seed_event, active_keys) 335 | case "OXP_GEN3": 336 | await oxp_gen3.process_event(seed_event, active_keys) 337 | case "OXP_GEN4": 338 | await oxp_gen4.process_event(seed_event, active_keys) 339 | case "OXP_GEN5": 340 | await oxp_gen5.process_event(seed_event, active_keys) 341 | case "OXP_GEN6": 342 | await oxp_gen6.process_event(seed_event, active_keys) 343 | case "OXP_GEN7": 344 | await oxp_gen7.process_event(seed_event, active_keys) 345 | 346 | except Exception as err: 347 | handycon.logger.error( 348 | f"{err} | Error reading events from {handycon.keyboard_device.name}" 349 | ) 350 | handycon.logger.error(traceback.format_exc()) 351 | remove_device(HIDE_PATH, handycon.keyboard_event) 352 | handycon.keyboard_device = None 353 | handycon.keyboard_event = None 354 | handycon.keyboard_path = None 355 | else: 356 | handycon.logger.info("Attempting to grab keyboard device...") 357 | get_keyboard() 358 | await asyncio.sleep(DETECT_DELAY) 359 | 360 | 361 | # Captures keyboard events and translates them to virtual device events. 362 | async def capture_keyboard_2_events(): 363 | global handycon 364 | 365 | # Capture keyboard events and translate them to mapped events. 366 | while handycon.running: 367 | if handycon.keyboard_2_device: 368 | try: 369 | async for seed_event_2 in handycon.keyboard_2_device.async_read_loop(): 370 | # Loop variables 371 | active_keys_2 = handycon.keyboard_2_device.active_keys() 372 | 373 | # Debugging variables 374 | handycon.logger.debug( 375 | f"Seed Value: {seed_event_2.value}, Seed Code: {seed_event_2.code}, Seed Type: {seed_event_2.type}." 376 | ) 377 | if active_keys_2 != []: 378 | handycon.logger.debug(f"Active Keys: {active_keys_2}") 379 | else: 380 | handycon.logger.debug("No active keys") 381 | if handycon.event_queue != []: 382 | handycon.logger.debug(f"Queued events: {handycon.event_queue}") 383 | else: 384 | handycon.logger.debug("No active events.") 385 | 386 | # Capture keyboard events and translate them to mapped events. 387 | match handycon.system_type: 388 | case "ALY_GEN1": 389 | await ally_gen1.process_event(seed_event_2, active_keys_2) 390 | 391 | except Exception as err: 392 | handycon.logger.error( 393 | f"{err} | Error reading events from {handycon.keyboard_2_device.name}" 394 | ) 395 | handycon.logger.error(traceback.format_exc()) 396 | remove_device(HIDE_PATH, handycon.keyboard_2_event) 397 | handycon.keyboard_2_device = None 398 | handycon.keyboard_2_event = None 399 | handycon.keyboard_2_path = None 400 | else: 401 | handycon.logger.info("Attempting to grab keyboard device 2...") 402 | get_keyboard_2() 403 | await asyncio.sleep(DETECT_DELAY) 404 | 405 | 406 | async def capture_controller_events(): 407 | global handycon 408 | 409 | handycon.logger.debug(f"capture_controller_events, {handycon.running}") 410 | while handycon.running: 411 | if handycon.controller_device: 412 | try: 413 | async for event in handycon.controller_device.async_read_loop(): 414 | # Block FF events, or get infinite recursion. Up to you I guess... 415 | if event.type in [e.EV_FF, e.EV_UINPUT]: 416 | continue 417 | 418 | # Output the event. 419 | emit_event(event) 420 | except Exception as err: 421 | handycon.logger.error( 422 | f"{err} | Error reading events from {handycon.controller_device.name}." 423 | ) 424 | handycon.logger.error(traceback.format_exc()) 425 | remove_device(HIDE_PATH, handycon.controller_event) 426 | handycon.controller_device = None 427 | handycon.controller_event = None 428 | handycon.controller_path = None 429 | else: 430 | handycon.logger.info("Attempting to grab controller device...") 431 | get_controller() 432 | await asyncio.sleep(DETECT_DELAY) 433 | 434 | 435 | # Captures power events and handles long or short press events. 436 | async def capture_power_events(): 437 | global handycon 438 | 439 | while handycon.running: 440 | if handycon.power_device: 441 | try: 442 | async for event in handycon.power_device.async_read_loop(): 443 | handycon.logger.debug( 444 | f"Got event: {event.type} | {event.code} | {event.value}" 445 | ) 446 | if event.type == e.EV_KEY and event.code == 116: # KEY_POWER 447 | if event.value == 0: 448 | handle_power_action() 449 | 450 | except Exception as err: 451 | handycon.logger.error( 452 | f"{err} | Error reading events from power device." 453 | ) 454 | handycon.logger.error(traceback.format_exc()) 455 | handycon.power_device = None 456 | 457 | elif handycon.power_device_2 and not handycon.power_device: 458 | try: 459 | async for event in handycon.power_device_2.async_read_loop(): 460 | handycon.logger.debug( 461 | f"Got event: {event.type} | {event.code} | {event.value}" 462 | ) 463 | if event.type == e.EV_KEY and event.code == 116: # KEY_POWER 464 | if event.value == 0: 465 | handle_power_action() 466 | 467 | except Exception as err: 468 | handycon.logger.error( 469 | f"{err} | Error reading events from power device." 470 | ) 471 | handycon.logger.error(traceback.format_exc()) 472 | handycon.power_device_2 = None 473 | 474 | else: 475 | handycon.logger.info("Attempting to grab controller device...") 476 | get_powerkey() 477 | await asyncio.sleep(DETECT_DELAY) 478 | 479 | 480 | # Performs specific power actions based on user config. 481 | def handle_power_action(): 482 | handycon.logger.debug(f"Power Action: {handycon.power_action}") 483 | match handycon.power_action: 484 | case "Suspend": 485 | # For DeckUI Sessions 486 | is_deckui = handycon.steam_ifrunning_deckui("steam://shortpowerpress") 487 | 488 | # For BPM and Desktop sessions 489 | if not is_deckui: 490 | os.system("systemctl suspend") 491 | 492 | case "Hibernate": 493 | os.system("systemctl hibernate") 494 | 495 | case "Shutdown": 496 | is_deckui = handycon.steam_ifrunning_deckui("steam://longpowerpress") 497 | 498 | if not is_deckui: 499 | os.system("systemctl poweroff") 500 | 501 | case "Suspend then hibernate": 502 | os.system("systemctl suspend-then-hibernate") 503 | 504 | 505 | # Handle FF event uploads 506 | 507 | 508 | async def capture_ff_events(): 509 | global handycon 510 | 511 | ff_effect_id_set = set() 512 | 513 | async for event in handycon.ui_device.async_read_loop(): 514 | if handycon.controller_device is None: 515 | # Slow down the loop so we don't waste millions of cycles and overheat our controller. 516 | await asyncio.sleep(DETECT_DELAY) 517 | continue 518 | 519 | if event.type == e.EV_FF: 520 | # Forward FF event to controller. 521 | handycon.controller_device.write(e.EV_FF, event.code, event.value) 522 | continue 523 | 524 | # Programs will submit these EV_UINPUT events to ensure the device is capable. 525 | # Doing this forever doesn't seem to pose a problem, and attempting to ignore 526 | # any of them causes the program to halt. 527 | if event.type != e.EV_UINPUT: 528 | continue 529 | 530 | if event.code == e.UI_FF_UPLOAD: 531 | # Upload to the virtual device to prevent threadlocking. This does nothing else 532 | upload = handycon.ui_device.begin_upload(event.value) 533 | effect = upload.effect 534 | 535 | if effect.id not in ff_effect_id_set: 536 | # set to -1 for kernel to allocate a new id. all other values throw an error for invalid input. 537 | effect.id = -1 538 | 539 | try: 540 | # Upload to the actual controller. 541 | effect_id = handycon.controller_device.upload_effect(effect) 542 | effect.id = effect_id 543 | 544 | ff_effect_id_set.add(effect_id) 545 | 546 | upload.retval = 0 547 | except IOError as err: 548 | handycon.logger.error(f"{err} | Error uploading effect {effect.id}.") 549 | handycon.logger.error(traceback.format_exc()) 550 | upload.retval = -1 551 | 552 | handycon.ui_device.end_upload(upload) 553 | 554 | elif event.code == e.UI_FF_ERASE: 555 | erase = handycon.ui_device.begin_erase(event.value) 556 | 557 | try: 558 | handycon.controller_device.erase_effect(erase.effect_id) 559 | ff_effect_id_set.remove(erase.effect_id) 560 | erase.retval = 0 561 | except IOError as err: 562 | handycon.logger.error( 563 | f"{err} | Error erasing effect {erase.effect_id}." 564 | ) 565 | handycon.logger.error(traceback.format_exc()) 566 | erase.retval = -1 567 | 568 | handycon.ui_device.end_erase(erase) 569 | 570 | 571 | def restore_device(event, path): 572 | # Both devices threads will attempt this, so ignore if they have been moved. 573 | try: 574 | move(str(HIDE_PATH / event), path) 575 | except FileNotFoundError: 576 | pass 577 | 578 | 579 | def restore_hidden(): 580 | hidden_events = os.listdir(HIDE_PATH) 581 | if len(hidden_events) == 0: 582 | return 583 | for hidden_event in hidden_events: 584 | handycon.logger.debug(f"Restoring {hidden_event}") 585 | move(str(HIDE_PATH / hidden_event), "/dev/input/" + hidden_event) 586 | 587 | 588 | def remove_device(path, event): 589 | try: 590 | os.remove(str(path / event)) 591 | except FileNotFoundError: 592 | pass 593 | 594 | 595 | # Emits passed or generated events to the virtual controller. 596 | # This shouldn't be called directly for custom events, only to pass realtime events. 597 | # Use emit_now and the device's event_queue. 598 | 599 | 600 | async def emit_events(events: list): 601 | for event in events: 602 | emit_event(event) 603 | # Pause between multiple events, but not after the last one in the list. 604 | if event != events[len(events) - 1]: 605 | await asyncio.sleep(handycon.BUTTON_DELAY) 606 | 607 | 608 | # Emit a single event. Skips some logic checks for optimization. 609 | def emit_event(event): 610 | global handycon 611 | handycon.logger.debug(f"Emitting event: {event}") 612 | handycon.ui_device.write_event(event) 613 | handycon.ui_device.syn() 614 | 615 | 616 | # Generates events from an event list. Can be called directly or when looping through 617 | # the event queue. 618 | async def emit_now(seed_event, event_list, value): 619 | global handycon 620 | 621 | # Ignore malformed requests 622 | if not event_list: 623 | handycon.logger.error("emit_now received malfirmed event_list. No action") 624 | return 625 | 626 | # Handle string events 627 | if type(event_list[0]) is str: 628 | if value == 0: 629 | handycon.logger.debug( 630 | "Received string event with value 0. KEY_UP event not required. Skipping" 631 | ) 632 | return 633 | match event_list[0]: 634 | case "Open Chimera": 635 | handycon.logger.debug("Open Chimera") 636 | handycon.launch_chimera() 637 | case "Toggle Gyro": 638 | handycon.logger.debug("Toggle Gyro is not currently enabled") 639 | case "Toggle Mouse Mode": 640 | handycon.logger.debug("Toggle Mouse Mode is not currently enabled") 641 | case "Toggle Performance": 642 | handycon.logger.debug("Toggle Performance") 643 | await toggle_performance() 644 | case "Hibernate", "Suspend", "Shutdown", "Suspend then hibernate": 645 | handycon.logger.error( 646 | f"Power mode {event_list[0]} set to button action. Check your configuration file." 647 | ) 648 | case _: 649 | handycon.logger.warn(f"{event_list[0]} not defined.") 650 | return 651 | 652 | handycon.logger.debug(f"Event list: {event_list}") 653 | events = [] 654 | 655 | if value == 0: 656 | for button_event in reversed(event_list): 657 | new_event = InputEvent( 658 | seed_event.sec, seed_event.usec, button_event[0], button_event[1], value 659 | ) 660 | events.append(new_event) 661 | else: 662 | for button_event in event_list: 663 | new_event = InputEvent( 664 | seed_event.sec, seed_event.usec, button_event[0], button_event[1], value 665 | ) 666 | events.append(new_event) 667 | 668 | size = len(events) 669 | if size > 1: 670 | await emit_events(events) 671 | elif size == 1: 672 | emit_event(events[0]) 673 | 674 | 675 | async def handle_key_down(seed_event, queued_event): 676 | handycon.event_queue.append(queued_event) 677 | if queued_event in INSTANT_EVENTS: 678 | await handycon.emit_now(seed_event, queued_event, 1) 679 | 680 | 681 | async def handle_key_up(seed_event, queued_event): 682 | if queued_event in INSTANT_EVENTS: 683 | handycon.event_queue.remove(queued_event) 684 | await handycon.emit_now(seed_event, queued_event, 0) 685 | elif queued_event in QUEUED_EVENTS: 686 | # Create list of events to fire. 687 | # Handle new button presses. 688 | if not handycon.last_button: 689 | handycon.event_queue.remove(queued_event) 690 | handycon.last_button = queued_event 691 | await handycon.emit_now(seed_event, queued_event, 1) 692 | return 693 | 694 | # Clean up old button presses. 695 | if handycon.last_button: 696 | await handycon.emit_now(seed_event, handycon.last_button, 0) 697 | handycon.last_button = None 698 | 699 | 700 | async def toggle_performance(): 701 | global handycon 702 | 703 | if handycon.performance_mode == "--max-performance": 704 | handycon.performance_mode = "--power-saving" 705 | await do_rumble(0, 100, 1000, 0) 706 | await asyncio.sleep(FF_DELAY) 707 | await do_rumble(0, 100, 1000, 0) 708 | else: 709 | handycon.performance_mode = "--max-performance" 710 | await do_rumble(0, 500, 1000, 0) 711 | await asyncio.sleep(FF_DELAY) 712 | await do_rumble(0, 75, 1000, 0) 713 | await asyncio.sleep(FF_DELAY) 714 | await do_rumble(0, 75, 1000, 0) 715 | 716 | ryzenadj_command = f"ryzenadj {handycon.performance_mode}" 717 | run = os.popen(ryzenadj_command, "r", 1).read().strip() 718 | handycon.logger.debug(run) 719 | 720 | if handycon.system_type in ["ALY_GEN1"]: 721 | if handycon.thermal_mode == "1": 722 | handycon.thermal_mode = "0" 723 | else: 724 | handycon.thermal_mode = "1" 725 | 726 | command = f"echo {handycon.thermal_mode} > /sys/devices/platform/asus-nb-wmi/throttle_thermal_policy" 727 | run = os.popen(command, "r", 1).read().strip() 728 | handycon.logger.debug(f"Thermal mode set to {handycon.thermal_mode}.") 729 | 730 | 731 | def make_controller(): 732 | global handycon 733 | 734 | # Create the virtual controller. 735 | handycon.ui_device = UInput( 736 | CONTROLLER_EVENTS, 737 | name="Handheld Controller", 738 | bustype=0x3, 739 | vendor=0x045E, 740 | product=0x028E, 741 | version=0x110, 742 | ) 743 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------