From b903ee85e158470148cb2e32fadbec2471f344e3 Mon Sep 17 00:00:00 2001 From: Attila Greguss Date: Tue, 18 Feb 2025 14:31:13 +0100 Subject: [PATCH 1/3] Add timeout if at least one monitor loaded but not all --- src/monitor.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/monitor.rs b/src/monitor.rs index 69f1a3e..a6053b0 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -38,6 +38,7 @@ enum State { pub fn sub() -> impl Stream { stream::channel(100, |mut output| async move { let mut state = State::Waiting; + let mut failed_attempts = 0; let mut duration = Duration::from_millis(50); @@ -55,16 +56,23 @@ pub fn sub() -> impl Stream { debug!("start enumerate"); + let mut some_loaded = false; + let mut some_failed = false; for mut display in Display::enumerate() { let brightness = match display.handle.get_vcp_feature(BRIGHTNESS_CODE) { - Ok(v) => v.value(), + Ok(v) => { + some_loaded = true; + v.value() + }, + // on my machine, i get this error when starting the session + // can't get_vcp_feature: DDC/CI error: Expected DDC/CI length bit + // This go away after the third attempt + // On some monitors this error is permanent + // So we mark the app as read if at least one monitor is loaded above after 5 attempts Err(e) => { - // on my machine, i get this error when starting the session - // can't get_vcp_feature: DDC/CI error: Expected DDC/CI length bit - // This go away after the third attempt error!("can't get_vcp_feature: {e}"); - state = State::Waiting; - break; + some_failed = true; + continue; } }; @@ -77,7 +85,14 @@ pub fn sub() -> impl Stream { displays.insert(display.info.id.clone(), Arc::new(Mutex::new(display))); } - if let State::Waiting = state { + if some_failed { + failed_attempts += 1; + } else { + failed_attempts = 0; + } + + if (some_failed && failed_attempts < 5) || !some_loaded { + state = State::Waiting; continue; } From 03ae95dc2e9575f6408c44617727fd3dd52df8f7 Mon Sep 17 00:00:00 2001 From: Attila Greguss Date: Tue, 18 Feb 2025 18:20:38 +0100 Subject: [PATCH 2/3] amend comment --- src/monitor.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/monitor.rs b/src/monitor.rs index a6053b0..6ee00c1 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -67,8 +67,6 @@ pub fn sub() -> impl Stream { // on my machine, i get this error when starting the session // can't get_vcp_feature: DDC/CI error: Expected DDC/CI length bit // This go away after the third attempt - // On some monitors this error is permanent - // So we mark the app as read if at least one monitor is loaded above after 5 attempts Err(e) => { error!("can't get_vcp_feature: {e}"); some_failed = true; @@ -91,6 +89,8 @@ pub fn sub() -> impl Stream { failed_attempts = 0; } + // On some monitors this error is permanent + // So we mark the app as ready if at least one monitor is loaded after 5 attempts if (some_failed && failed_attempts < 5) || !some_loaded { state = State::Waiting; continue; From 8458c872c153b048d64d19841b1f28717f5db458 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Wed, 19 Feb 2025 05:30:51 +0100 Subject: [PATCH 3/3] Update monitor.rs --- src/monitor.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/monitor.rs b/src/monitor.rs index 6ee00c1..104fed0 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -56,12 +56,10 @@ pub fn sub() -> impl Stream { debug!("start enumerate"); - let mut some_loaded = false; let mut some_failed = false; for mut display in Display::enumerate() { let brightness = match display.handle.get_vcp_feature(BRIGHTNESS_CODE) { Ok(v) => { - some_loaded = true; v.value() }, // on my machine, i get this error when starting the session @@ -85,13 +83,11 @@ pub fn sub() -> impl Stream { if some_failed { failed_attempts += 1; - } else { - failed_attempts = 0; } // On some monitors this error is permanent // So we mark the app as ready if at least one monitor is loaded after 5 attempts - if (some_failed && failed_attempts < 5) || !some_loaded { + if some_failed && failed_attempts < 5 { state = State::Waiting; continue; }