diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..e70de8b --- /dev/null +++ b/config.lua @@ -0,0 +1,57 @@ +-- ########## +-- IL2 Sturmovik Battle of Stalingrad does not recognize the sliders axis of the throtle and pedals. +-- This config creates a virtual joystick with those 2 axis. +-- It also makes the button 2(1) of the throtle a modifier, to use it as the LEFT ALT key. +-- ########## + +--Physical devices to use (type lsusb in terminal to list your connected devices) +devices = + { + d0 = --Thrustmaster Throttle + { + vendorid = 0x044f, + productid = 0xb687, + } + } + +--Virtual devices to create, current limit is maximum 53 (0 to 52) buttons and 19 (0 to 18) axes. Note that not every button or axis is fully tested to work. +--Creating more than one virtual devices is possible, making room for more buttons and axes. +v_devices = + { + v0 = + { + buttons = 1, + axes = 2 + } + } + +-- Send method for keyboard. Key is given, i.e. KEY_G (check reference document for more supported key-codes), and state is given, i.e. 0 for release or 1 for press. +-- send_keyboard_event(key, state) + +-- Send methods for virtual devices. Index of virtual device is given, i.e. 0 for v0, 1 for v1 and so on. Button/axis is given, i.e. 0 for button 0, 1 for button 1 and so on. +-- send_button_event(vjoy, button, state) +-- send_axis_event(vjoy, axis, pos) //pos is the axis position (-32767 >= pos <= 32767) + +-- Get methods for physical devices. Arguments applies in the same way as for above methods. +-- get_button_status(joy, button) //Returns 0 or 1 if button is pressed or not. +-- get_axis_status(joy, axis) //Returns the axis position value + +-- Get methods for virtual devices, applies in the same way as for physical devices. +-- get_vjoy_button_status(vjoy, button) +-- get_vjoy_axis_status(vjoy, axis) + +-- When axis 1 on device 0 is changed, set the axis 1 on virtual device 0, inverted or not depending on button 1 on device 0. +function d0_a6_event(value) + send_axis_event(0, 0, value) +end +function d0_a7_event(value) + send_axis_event(0, 1, value) +end +-- Send a button 0 event to virtual device 0 when button 0 on physical device 0 is pressed and released. +function d0_b1_event(value) + if value == 1 then + send_keyboard_event(KEY_LEFTALT, 1) + else + send_keyboard_event(KEY_LEFTALT, 0) + end +end \ No newline at end of file diff --git a/il2_missing_axis.lua b/il2_missing_axis.lua new file mode 100644 index 0000000..e70de8b --- /dev/null +++ b/il2_missing_axis.lua @@ -0,0 +1,57 @@ +-- ########## +-- IL2 Sturmovik Battle of Stalingrad does not recognize the sliders axis of the throtle and pedals. +-- This config creates a virtual joystick with those 2 axis. +-- It also makes the button 2(1) of the throtle a modifier, to use it as the LEFT ALT key. +-- ########## + +--Physical devices to use (type lsusb in terminal to list your connected devices) +devices = + { + d0 = --Thrustmaster Throttle + { + vendorid = 0x044f, + productid = 0xb687, + } + } + +--Virtual devices to create, current limit is maximum 53 (0 to 52) buttons and 19 (0 to 18) axes. Note that not every button or axis is fully tested to work. +--Creating more than one virtual devices is possible, making room for more buttons and axes. +v_devices = + { + v0 = + { + buttons = 1, + axes = 2 + } + } + +-- Send method for keyboard. Key is given, i.e. KEY_G (check reference document for more supported key-codes), and state is given, i.e. 0 for release or 1 for press. +-- send_keyboard_event(key, state) + +-- Send methods for virtual devices. Index of virtual device is given, i.e. 0 for v0, 1 for v1 and so on. Button/axis is given, i.e. 0 for button 0, 1 for button 1 and so on. +-- send_button_event(vjoy, button, state) +-- send_axis_event(vjoy, axis, pos) //pos is the axis position (-32767 >= pos <= 32767) + +-- Get methods for physical devices. Arguments applies in the same way as for above methods. +-- get_button_status(joy, button) //Returns 0 or 1 if button is pressed or not. +-- get_axis_status(joy, axis) //Returns the axis position value + +-- Get methods for virtual devices, applies in the same way as for physical devices. +-- get_vjoy_button_status(vjoy, button) +-- get_vjoy_axis_status(vjoy, axis) + +-- When axis 1 on device 0 is changed, set the axis 1 on virtual device 0, inverted or not depending on button 1 on device 0. +function d0_a6_event(value) + send_axis_event(0, 0, value) +end +function d0_a7_event(value) + send_axis_event(0, 1, value) +end +-- Send a button 0 event to virtual device 0 when button 0 on physical device 0 is pressed and released. +function d0_b1_event(value) + if value == 1 then + send_keyboard_event(KEY_LEFTALT, 1) + else + send_keyboard_event(KEY_LEFTALT, 0) + end +end \ No newline at end of file diff --git a/installService.sh b/installService.sh new file mode 100755 index 0000000..b7225fb --- /dev/null +++ b/installService.sh @@ -0,0 +1,19 @@ +if [[ $UID != 0 ]]; then + echo "Please run this script with sudo:" + echo "sudo $0 $*" + exit 1 +fi +if [ "$#" -ne 1 ] +then + echo "Please provide the lua script that will be installed as a service in /etc/wejoy/config.lua" + echo "Usage: ./installService.sh CONFIG_SCRIPT.lua" + exit 1 +fi + +mkdir -p /etc/wejoy +cp $1 /etc/wejoy/config.lua +cp wejoy.service /etc/systemd/system/ +systemctl daemon-reload +systemctl start wejoy +systemctl enable wejoy +echo "Wejoy was installed and started. You can test it on your gamepad settings or with evtest" \ No newline at end of file diff --git a/main.cc b/main.cc index 0ffa67a..0ee3e76 100644 --- a/main.cc +++ b/main.cc @@ -289,7 +289,7 @@ int main(int argc, char** argv) std::thread threadUpdateJoysticks(updateThreadJoysticks, std::ref(lScript)); std::thread threadUpdateKeyboard(updateThreadKeyboard, std::ref(lScript)); - while(getchar()!='q'); + while(getchar()!='q') { sleep(10);}; bPoll = false, threadUpdateJoysticks.join(); threadUpdateKeyboard.join(); diff --git a/readme.md b/readme.md index 78b0206..e49d7ad 100644 --- a/readme.md +++ b/readme.md @@ -51,6 +51,16 @@ If the module uinput is not loaded on your system, you need to manually load it: * * You can quit 'wejoy' by pressing 'q' end then 'ENTER'. +# Install it as a service ---- + +If you want to have a permanent config script running, you may also install wejoy as a service by running the `installService.sh` script +This script will create a systemd service that starts on boot and copy the script config you want to `/etc/wejoy/config.lua`. +Example: `sudo ./installService.sh il2_missing_axis.lua` + +# Run it with a steam game + +If you only want to run it with a steam game, you can set the game's launch options as: `/route/to/wejoy-run.sh %command%`. This way wejoy will launch automatically when you launch that game. You can also clone the SH file and customize a lua config script for each game. + # LUA scripting ---- * Please read the example.lua and warthog_throttle.lua to learn how to customize your script. * Also read the keycodes_ref.txt for keyboard reference. These variables are globally accessable in your LUA script. diff --git a/wejoy b/wejoy new file mode 100755 index 0000000..f91e18c Binary files /dev/null and b/wejoy differ diff --git a/wejoy-run.sh b/wejoy-run.sh new file mode 100755 index 0000000..dbfc3c4 --- /dev/null +++ b/wejoy-run.sh @@ -0,0 +1,13 @@ +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +# Game launch script for STEAM +# set launch options to "/route/to/wejoy-run.sh %command%" +cleanup() { + # kill all processes whose parent is this process + kill $WEJOY_PID + pkill -P $$ +} +# Customize the LUA config script you want to use. +wejoy $SCRIPT_DIR/config.lua & +WEJOY_PID=$! +trap cleanup EXIT +"$@" diff --git a/wejoy.service b/wejoy.service new file mode 100644 index 0000000..32dad9b --- /dev/null +++ b/wejoy.service @@ -0,0 +1,12 @@ +[Unit] +Description=wejoy + +[Service] +Type=idle +ExecStart=/usr/bin/wejoy /etc/wejoy/config.lua +Restart=always +Environment=PATH=/usr/bin:/usr/local/bin +WorkingDirectory=/etc/wejoy + +[Install] +WantedBy=multi-user.target \ No newline at end of file