55using System ;
66using System . Collections . Generic ;
77using System . Runtime . InteropServices ;
8+ using ManagedCommon ;
89using Windows . Win32 . Foundation ;
910using static PowerDisplay . Common . Drivers . NativeConstants ;
1011using static PowerDisplay . Common . Drivers . PInvoke ;
@@ -27,32 +28,55 @@ public static DdcCiValidationResult FetchCapabilities(IntPtr hPhysicalMonitor)
2728 {
2829 if ( hPhysicalMonitor == IntPtr . Zero )
2930 {
31+ Logger . LogWarning ( "DDC: Monitor ignored - null physical monitor handle" ) ;
3032 return DdcCiValidationResult . Invalid ;
3133 }
3234
35+ var handleHex = $ "0x{ hPhysicalMonitor : X} ";
36+
3337 try
3438 {
3539 // Try to get capabilities string (slow I2C operation)
3640 var capsString = TryGetCapabilitiesString ( hPhysicalMonitor ) ;
3741 if ( string . IsNullOrEmpty ( capsString ) )
3842 {
43+ Logger . LogWarning ( $ "DDC: Monitor ignored (handle={ handleHex } ) - empty capabilities string from DDC/CI") ;
3944 return DdcCiValidationResult . Invalid ;
4045 }
4146
47+ Logger . LogInfo ( $ "DDC: Capabilities raw (handle={ handleHex } , length={ capsString . Length } ): { capsString } ") ;
48+
4249 // Parse the capabilities string
4350 var parseResult = Utils . MccsCapabilitiesParser . Parse ( capsString ) ;
4451 var capabilities = parseResult . Capabilities ;
52+
4553 if ( capabilities == null || capabilities . SupportedVcpCodes . Count == 0 )
4654 {
55+ Logger . LogWarning ( $ "DDC: Monitor ignored (handle={ handleHex } ) - parsed capabilities have no VCP codes (parseErrors={ parseResult . Errors . Count } )") ;
4756 return DdcCiValidationResult . Invalid ;
4857 }
4958
5059 // Check if brightness (VCP 0x10) is supported - determines DDC/CI validity
5160 bool supportsBrightness = capabilities . SupportsVcpCode ( NativeConstants . VcpCodeBrightness ) ;
61+ bool supportsContrast = capabilities . SupportsVcpCode ( NativeConstants . VcpCodeContrast ) ;
62+ bool supportsColorTemperature = capabilities . SupportsVcpCode ( NativeConstants . VcpCodeSelectColorPreset ) ;
63+ bool supportsVolume = capabilities . SupportsVcpCode ( NativeConstants . VcpCodeVolume ) ;
64+
65+ Logger . LogInfo (
66+ $ "DDC: Capabilities parsed (handle={ handleHex } ) - " +
67+ $ "Brightness={ supportsBrightness } Contrast={ supportsContrast } " +
68+ $ "ColorTemperature={ supportsColorTemperature } Volume={ supportsVolume } ") ;
69+
70+ if ( ! supportsBrightness )
71+ {
72+ Logger . LogWarning ( $ "DDC: Monitor ignored (handle={ handleHex } ) - brightness (VCP 0x10) not advertised in capabilities") ;
73+ }
74+
5275 return new DdcCiValidationResult ( supportsBrightness , capsString , capabilities ) ;
5376 }
5477 catch ( Exception ex ) when ( ex is not OutOfMemoryException )
5578 {
79+ Logger . LogError ( $ "DDC: Monitor ignored (handle={ handleHex } ) - exception during FetchCapabilities: { ex . Message } ") ;
5680 return DdcCiValidationResult . Invalid ;
5781 }
5882 }
@@ -74,6 +98,7 @@ public static DdcCiValidationResult FetchCapabilities(IntPtr hPhysicalMonitor)
7498 // Get capabilities string length
7599 if ( ! GetCapabilitiesStringLength ( hPhysicalMonitor , out uint length ) || length == 0 )
76100 {
101+ Logger . LogWarning ( $ "DDC: GetCapabilitiesStringLength failed (handle=0x{ hPhysicalMonitor : X} , length={ length } )") ;
77102 return null ;
78103 }
79104
@@ -83,6 +108,7 @@ public static DdcCiValidationResult FetchCapabilities(IntPtr hPhysicalMonitor)
83108 {
84109 if ( ! CapabilitiesRequestAndCapabilitiesReply ( hPhysicalMonitor , buffer , length ) )
85110 {
111+ Logger . LogWarning ( $ "DDC: CapabilitiesRequestAndCapabilitiesReply failed (handle=0x{ hPhysicalMonitor : X} )") ;
86112 return null ;
87113 }
88114
@@ -95,6 +121,7 @@ public static DdcCiValidationResult FetchCapabilities(IntPtr hPhysicalMonitor)
95121 }
96122 catch ( Exception ex ) when ( ex is not OutOfMemoryException )
97123 {
124+ Logger . LogError ( $ "DDC: TryGetCapabilitiesString exception (handle=0x{ hPhysicalMonitor : X} ): { ex . Message } ") ;
98125 return null ;
99126 }
100127 }
0 commit comments