Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions il2_missing_axis.lua
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions installService.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Binary file added wejoy
Binary file not shown.
13 changes: 13 additions & 0 deletions wejoy-run.sh
Original file line number Diff line number Diff line change
@@ -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
"$@"
12 changes: 12 additions & 0 deletions wejoy.service
Original file line number Diff line number Diff line change
@@ -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