Transforming a ~30 USD USB switch into something else

Posted on Feb 6, 2023
The device used, ATEN US424

First off, lets pretend I only paid ~30 USD for this USB switch thingy. :)

This is old news, but there’s a project called display-switch that allows you to change which input your monitor is using, only based on USB events on your computer.

This is really handy if you have multiple computers hooked up to the same monitor, like a work laptop, a raspberry pi and a desktop PC, but you are too lazy to move cables between machines when going between computers. With display-switch, you just install and configure the software on all computers you need, and then your monitor will switch inputs when the USB switch goes between machines.

Setup involving multiple devices and multiple computers

Setup

Configuration

The configuration needed is this, save it to ~/.config/display-switch/display-switch.ini on Linux:

usb_device: "1A40:0101"
on_usb_connect = "Hdmi2"

I’m just listening for my USB switch, which has an ID of 1A40:0101 (lsusb to find out). For my work laptop I’m using DisplayPort2 but the same USB device ID.

The only caveat I’ve had is that my Debian machine wouldn’t work without adding a group & some udev rules, and loading a kernel module at boot.

Also, on Windows the file should be saved in %APPDATA%/display-switch/display-switch.ini.

Groups, udev rules, and kernel modules

The group & udev rules, taken from the project README:

groupadd i2c
echo 'KERNEL=="i2c-[0-9]*", GROUP="i2c"' >> /etc/udev/rules.d/10-local_i2c_group.rules
udevadm control --reload-rules && udevadm trigger

The kernel module is i2c-dev:

modprobe i2c-dev
echo "i2c-dev" > /etc/modules-load.d/ddcutils.conf

And add my user to the new i2c group:

sudo usermod -aG i2c $(whoami)

systemd service

Custom system unit file, saved to ~/.config/systemd/user/display-switch.service:

[Unit]
Description=Display switch via USB switch

[Service]
# Or where you keep your binary
ExecStart=/usr/local/bin/display_switch
Type=simple
StandardOutput=journal
Restart=always

[Install]
WantedBy=default.target

Load, enable and start the user service:

systemctl --user daemon-reload
systemctl --user enable display-switch.service
systemctl --user start display-switch.service

Conclusion

The only things I wish I could improve is:

  • To write a system service, so it will work after boot instead of after logging in as my user,
  • To make it work on my M1 Macbook, and
  • cable management on and under my desk…