Giter VIP home page Giter VIP logo

thrifty-kvm's Introduction

Thrifty-KVM

Scripts to switch monitor source based on USB keyboard plug/unplug events.

Overview

My home office for work and personal computing and I need to be able to switch back-and-forth between my work and personal computers.

3-Monitor KVM switches can be really pricey!

So I settled on just a basic USB-only KVM switch.

Monitors have multiple source inputs anyways, so why not just switch the source when I switch the KVM?

To do that, we either need to manually change the monitor source (ugh.) or, we need to get one of the computers to change the source for the monitors.

I have three Dell U2415s which support MCCS (Monitor Control Command Set) which video drivers (on Linux) will expose as an I2C bus at /dev/i2c-N.

ddcutil can be used to read/write and explore the settings exposed by the monitors.

Note: If you are using this repo to jury-rig your own KVM, your settings will likely be different. The first step to installing this is figuring out what your settings should be and editing the scripts.

Now, to run the monitor switching scripts, we need to know when the usb KVM switch is toggled. To do that, udev to listen for the events fired when our usb keyboard is plugged in or unplugged.

Configuration

  1. Install ddcutil. On Ubuntu 20.04:

    sudo apt install ddcutil
    
  2. Find your monitor(s) serial numbers:

    sudo ddcutil detect
    

    Your output will look something like:

    Display 1
       I2C bus:             /dev/i2c-1
       EDID synopsis:
          Mfg id:           DEL
          Model:            DELL U2415
          Serial number:    CFV9N6B8058L
          Manufacture year: 2016
          EDID version:     1.3
       VCP version:         2.1
    
    Display 2
       I2C bus:             /dev/i2c-3
       EDID synopsis:
          Mfg id:           DEL
          Model:            DELL U2415
          Serial number:    CFV9N6B80KEL
          Manufacture year: 2016
          EDID version:     1.3
       VCP version:         2.1
    
    Display 3
       I2C bus:             /dev/i2c-5
       EDID synopsis:
          Mfg id:           DEL
          Model:            DELL U2415
          Serial number:    CFV9N7BO103L
          Manufacture year: 2017
          EDID version:     1.3
       VCP version:         2.1
    

    Save the Serial number: CFV9N6B8058L for later.

  3. Find the capabilities of your monitors

    sudo ddcutil capabilities --sn=[YOUR SERIAL NUMBER]
    

    Look for Input Source in the output e.g.

       Feature: 60 (Input Source)
          Values:
             0f: DisplayPort-1
             10: DisplayPort-2
             11: HDMI-1
             12: HDMI-2
    
  4. Edit src/on-keyboard-plug.sh and src/on-keyboard-unplug.sh to set the [SERIAL], [FEATURE] and [VALUE] you want the monitor to be in when the keyboard is plugged in or unplugged.

    Note #1: ddcutil lists the values as hexidecimal, but requires a leading x to interpret command line arguments as hex. So, changing to HDMI-2 on my monitors, I edit the script to use x12 as the value.

    Note #2: Remove the square brackets on [FEATURE] and [VALUE]

    Note #3: Add / remove commands depending on how many monitors / serial numbers you have.

  5. Figure out your keyboard's vendor ID:

    sudo udevadm monitor
    

    Now unplug your keyboard and plug it back in. You should see a bunch of events logged to the console like.

    UDEV  [2520806.444432] add      /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1.2/3-1.2:1.0/0003:045E:00DB.0034 (hid)
    

    Stop the monitoring with ctrl-C. The part that matches 045E in the output above is likely the vendor ID. To confirm, take the 3-1.2 equivalent from the device path in the output above and find the device in your sys filesystem.

    For example my keyboard's sys path is /sys/bus/usb/devices/3-1.2

    sudo udevadm info  /sys/bus/usb/devices/3-1.2 | grep -e "DEVPATH" -e "ID_VENDOR_ID"
    

    Outputs:

    E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1.2
    E: ID_VENDOR_ID=045e
    
  6. Edit src/80-thrifty-kvm.rules to set your [VENDOR_ID].

    Note #1: Remove the square brackets replacing all of [VENDOR_ID].

    Note #2: [VENDOR_ID] is in src/80-thrifty-kvm.rules twice.

Installation

make PREFIX=/usr/local
sudo make install PREFIX=/usr/local

Removal

sudo make uninstall PREFIX=/usr/local

thrifty-kvm's People

Contributors

prsutherland avatar

Stargazers

Matt Kelly avatar Devin Auclair avatar Noah Pendleton avatar

Watchers

 avatar

Forkers

pspglb

thrifty-kvm's Issues

Automate configuration workflow

The six step configuration in the README.md is error prone. It should be automated and give the user clear choices. The config probing and file editing can be done with a script.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.