haimgel / display-switch

Turn a $30 USB switch into a full-featured multi-monitor KVM switch
https://haim.dev/posts/2020-07-28-dual-monitor-kvm/
MIT License
2.85k stars 112 forks source link

Failed to get current input #21

Closed davertron closed 3 years ago

davertron commented 3 years ago

Monitor: Dell U2415 connected to my Macbook Pro 15 2017 via a mini display port -> usb-c adapter

When I launch display-switch, it immediately prints the following lines:

18:02:42 [ERROR] Failed to get current input for display '0'
18:02:42 [ERROR] Failed to get current input for display '1'

See Update Below It's also not clear to me which monitor_input value I should use for mini display port (I've tried them all, but none of them work, I get 18:02:46 [ERROR] Failed to set display '1' to 0xf), but I don't think it currently matters since it can't seem to talk to my monitor. I know this monitor supports DDC/CI because I created some shortcuts in windows using dell display manager and can switch the inputs from there, so maybe it's the dongle getting in the way?

I have a mini-dp to display port adapter coming soon that I'm going to plug into the dock I have connected to the mbp, so I'll give it a shot once that gets here and see how I fare, but if you have any advice I'd appreciate it! Love the idea!

Update: I was able to use ddcctl to verify that that works (and I will use DisplayPort2 to switch to mini display port). So not sure why display-switch can't read the current monitor input, maybe because of the dongle?

Update 2: Removing the dongle and going from my dock to the monitor via DisplayPort didn't solve the problem either :(

haimgel commented 3 years ago

I acknowledge the issue: for me, ddcctl sometimes can read the input, sometimes cannot, but display-switch can never read it on MacOS. It does switch inputs successfully though. My MacBook is connected via USB-C directly to the display, so I don't think dongle is to blame here.

davertron commented 3 years ago

Interesting, display-switch doesn't successfully switch inputs for me, this is what I see:

21:36:40 [INFO] Detected device we're looking for "1532:005c"
21:36:40 [INFO] Display '0' set to 0xf
21:36:40 [ERROR] Failed to set display '1' to 0xf
GazzaHazza commented 3 years ago

Sorry to chime in on someone else' issue but i am having the same issue. I use this app, and it shows my 3 monitors. See attached Screenshot 2020-09-14 at 08 46 40

jbolter commented 3 years ago

I seem to be having the same issue.

Configuration { usb_device: "0bda:0411", monitor_input: Symbolic(DisplayPort1) } 22:44:10 [ERROR] Failed to get current input for display '0' 22:44:10 [ERROR] Failed to get current input for display '1' 22:44:13 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0bda:0411" 22:44:13 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:085c" 22:44:13 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:c52b" 22:44:13 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0bda:5411" 22:44:17 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0bda:5411" 22:44:17 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0bda:0411" 22:44:17 [INFO] Detected device we're looking for "0bda:0411" 22:44:17 [ERROR] Failed to set display '0' to 0xf 22:44:17 [INFO] Display '1' set to 0xf 22:44:19 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:085c" 22:44:19 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:c52b"

It thinks that it worked but the input does not change.

haimgel commented 3 years ago

Thanks for the logs. I'm working on rewriting the DDC/CI code on macOS specifically, the library I used does not work reliably enough. I'll post a link to a branch here for testing, once I have something working.

haimgel commented 3 years ago

I've updated the current master with the improvements mentioned above. I'd appreciate a test whether there are any changes for you guys: does the app read the current inputs now? Can it change them?

GazzaHazza commented 3 years ago

Ill give it ago now!

GazzaHazza commented 3 years ago

Just tried latest master and now my logs look like this

12:57:58 [INFO] Configuration loaded ("/Users/{username}/Library/Preferences/display-switch.ini"): Configuration { usb_device: "0066:0d8c", monitor_input: Symbolic(Hdmi1) }
12:57:59 [ERROR] Failed to get current input for display 'XB271HU S/N 1938823913' #0: Io(-536870212)
12:57:59 [INFO] Display 'Acer BE270U A S/N 1918346280' #1 is currently set to 0x11
12:57:59 [INFO] Display 'PL3493WQ' #2 is currently set to 0x2212

So i think its working now but looks like one of my displays doesnt support DDC

EDIT: the monitors that haven't error'd are switching correctly though

davertron commented 3 years ago

It's working for me now :) When it starts up, it logs that it can't get the current input for my monitor, but when I use my USB switch it correctly changes inputs, which is awesome! I've included the beginning of the log just in case it's useful:

12:58:15 [INFO] Configuration loaded ("/Users/ddcddavis/Library/Preferences/display-switch.ini"): Configuration { usb_device: "1532:005c", monitor_input: Symbolic(DisplayPort2) }
12:58:15 [ERROR] Failed to get current input for display 'DELL U2415 S/N 826816076' #0: Ddc(InvalidChecksum)
davertron commented 3 years ago

So if it can detect the current input on the monitor, will it prevent it from trying to switch inputs if it's already on the correct input? It's a very minor annoyance, but right now I only have display-switch running on my Mac so when I switch back to my PC the monitor doesn't switch inputs. Then when I switch back to my Mac it "switches" the input, but I was already on the correct one. I'm guessing this is because it can't correctly determine that it's already on the right one (due to the error mentioned in my previous comment above).

Not a big deal, it would be nice if that were an easy thing to fix but it's definitely something I can live with.

haimgel commented 3 years ago

Ideally, it should do something like this, when input switch if required:

  1. Get the current inputs (with several retries).
  2. If already on the desired input, do nothing.
  3. If not on the desired input, or if the current state cannot be determined, do the input change.
  4. Try to read the current input, and re-try #3 if we are still not on the right input.

Unfortunately, the DDC implementation varies between different monitors, and is often buggy. The write command also does not have meaningful feedback (we don't know if it succeeded or not), and for some monitors we do need to retry to reliably switch the inputs. So it's quite challenging, not an easy fix, but I agree this is frustrating that the monitors flicker on switch when they should not be, or not switch at all on the first try. So I'll look into this.

haimgel commented 3 years ago

@GazzaHazza seems like XB271HU supports DDC/CI in general, but not switching the inputs (at least from my quick Google search).

GazzaHazza commented 3 years ago

@haimgel - any reason why it wouldnt work? I have used this to try and change brightness in command line but nothing happens šŸ‘ŽšŸ»

haimgel commented 3 years ago

Monitor vendors implement a subset of a DDC/CI standard that they feel like to... Monitor firmware is often buggy šŸ¤· This is a rarely-used feature and not something you can brag about in the marketing literature.

About your monitor specifically, I saw this and this, which tells me this monitor's DDC/CI support is not 100% there.

GazzaHazza commented 3 years ago

Thanks for looking into this! i guess im stuck with manually switching one monitor!

Thanks again. šŸ‘šŸ»