jacob-pro / solar-screen-brightness

Automatically adjust monitor / screen brightness at night using sunrise/sunset times
GNU Lesser General Public License v3.0
54 stars 4 forks source link

Setting brightness failed for device - IoctlSetBrightnessFailed (Windows) #17

Closed stijnthurkow closed 2 years ago

stijnthurkow commented 2 years ago

The following error occurs:

image

I tried googling '0x80070006 The handle is invalid' but unfortunately this did not make me wiser. Any thoughts on what this could be? If you need more information, please let me know!

Maybe good to mention that DDC on my monitors works fine with the Dell Display Manager and Monitorian.

Console log:

_[2021-12-20T10:27:44Z INFO solar_screen_brightness::lock::lock_impl] Acquired lock: solar-screen-brightness-04e3ed [2021-12-20T10:27:44Z INFO solar_screen_brightness::config] Successfully loaded config file [2021-12-20T10:27:44Z INFO solar_screen_brightness::controller] Starting BrightnessController [2021-12-20T10:27:44Z INFO solar_screen_brightness::tray] Launching tray application [2021-12-20T10:27:44Z INFO solar_screen_brightness::controller::apply] Computed base brightness of 100% [2021-12-20T10:27:44Z ERROR solar_screen_brightness::controller::apply] An error occurred setting monitor brightness: SettingBrightnessFailed { device: "\\.\DISPLAY1\Monitor0", source: IoctlSetBrightnessFailed { device_name: "\\.\DISPLAY1\Monitor0", source: Error { code: 0x80070006, message: "The handle is invalid.", win32_code: 6 } } } - IoctlSetBrightnessFailed { device_name: "\\.\DISPLAY1\Monitor0", source: Error { code: 0x80070006, message: "The handle is invalid.", win32_code: 6 } } - Error { code: 0x80070006, message: "The handle is invalid.", win32_code: 6 } [2021-12-20T10:27:44Z ERROR solar_screen_brightness::controller::apply] An error occurred setting monitor brightness: SettingBrightnessFailed { device: "\\.\DISPLAY2\Monitor0", source: IoctlSetBrightnessFailed { device_name: "\\.\DISPLAY2\Monitor0", source: Error { code: 0x80070006, message: "The handle is invalid.", win32_code: 6 } } } - IoctlSetBrightnessFailed { device_name: "\\.\DISPLAY2\Monitor0", source: Error { code: 0x80070006, message: "The handle is invalid.", win32_code: 6 } } - Error { code: 0x80070006, message: "The handle is invalid.", win32_code: 6 } [2021-12-20T10:27:44Z INFO solar_screen_brightness::controller::worker] Brightness Worker sleeping for 4:39:41 [2021-12-20T10:27:44Z INFO solar_screen_brightness::console] Showing console [2021-12-20T10:27:44Z INFO solar_screen_brightness::tui] Cursive thread starting [2021-12-20T10:27:44Z INFO solar_screen_brightness::console::console_impl] Found valid PDChWnd in 6.03 ms

Details:

OS: Windows 11 Pro OS Build: 22000.376 SSB build: 0.1.4

jacob-pro commented 2 years ago

Hi, sorry it is not working, it looks like an issue with an upstream dependency - https://github.com/stephaneyfx/brightness - I will look into fixing it in the next few days.

stijnthurkow commented 2 years ago

Thanks! Appreciate it 👍

jacob-pro commented 2 years ago

@stijnthurkow Just to confirm both of your displays are external monitors and not laptop screens right?

What I think is happening here is that Windows has two sets of APIs, one for laptop screens (Ioctl/WMI), the other for external monitors (DDC/CI), and it would appear is attempting to use the wrong one:

https://github.com/stephaneyfx/brightness/blob/a74a8222b2c68b3a1ea3ec2aaf4186725c5e3e5a/src/windows.rs#L105

stijnthurkow commented 2 years ago

I'm using two external Dell UltraSharp U2715H monitors on my desktop (so no laptop screen exists). They are daisy-chained and connected through one DisplayPort. Perhaps that would be relevant?

jacob-pro commented 2 years ago

Hi @stijnthurkow Hopefully I have fixed this in the latest release: https://github.com/jacob-pro/solar-screen-brightness/releases/tag/0.1.5

Would you please test it and let me know if it is now working on 0.1.5?

(If it is not working - I noticed that you said you were able to use Monitorian without issue - would you please be able to paste the monitorian probe.log here?)

stijnthurkow commented 2 years ago

It's working now! Thank you!