Make EDID detection robust

Modified EDID detection to make it more
robust and to report what went wrong in
the logs in more detail. Aids in #16
This commit is contained in:
Terry MacDonald 2021-05-19 21:32:49 +12:00
parent a4db4b39b7
commit 2096322cf0
3 changed files with 96 additions and 20 deletions

View File

@ -52,19 +52,63 @@ namespace DisplayMagicianShared.NVIDIA
public static SurroundTopology FromPathTargetInfo(PathTargetInfo pathTargetInfo) public static SurroundTopology FromPathTargetInfo(PathTargetInfo pathTargetInfo)
{ {
// We go through the code if only the path belongs to a NVIDIA virtual surround display // We go through the code if only the path belongs to a NVIDIA virtual surround display
// TODO: Should we try to resolve every target info to be sure? // and is not null
if (!string.Equals( if (pathTargetInfo == null)
pathTargetInfo.DisplayTarget.EDIDManufactureCode,
"NVS",
StringComparison.InvariantCultureIgnoreCase
) &&
!string.Equals(
pathTargetInfo.DisplayTarget.FriendlyName,
"NV Surround",
StringComparison.InvariantCultureIgnoreCase
) &&
!pathTargetInfo.DisplayTarget.DevicePath.ToLower().Contains("&UID5120".ToLower()))
{ {
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: The PathTargetInfo object supplied was null, so we have to return null back.");
return null;
}
string EDIDManufactureCode = "";
string friendlyName = "";
bool devicePathContainsUID5120 = false;
bool isNvidiaSurround = false;
try
{
EDIDManufactureCode = pathTargetInfo.DisplayTarget.EDIDManufactureCode;
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Grabbed EDIDManufactureCode of {EDIDManufactureCode}.");
if (string.Equals(EDIDManufactureCode, "NVS", StringComparison.InvariantCultureIgnoreCase))
{
isNvidiaSurround = true;
}
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"SurroundTopology/FromPathTargetInfo: Exception trying to access EDIDManufactureCode.");
}
try
{
friendlyName = pathTargetInfo.DisplayTarget.FriendlyName;
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Grabbed Display FriendlyName of {friendlyName}.");
if (string.Equals(friendlyName, "NV Surround", StringComparison.InvariantCultureIgnoreCase))
{
isNvidiaSurround = true;
}
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"SurroundTopology/FromPathTargetInfo: Exception trying to access friendlyName.");
}
try
{
devicePathContainsUID5120 = pathTargetInfo.DisplayTarget.DevicePath.ToLower().Contains("&UID5120".ToLower());
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Testing if the Display DevicePath contains UID5120 = {devicePathContainsUID5120}.");
if (devicePathContainsUID5120)
{
isNvidiaSurround = true;
}
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"SurroundTopology/FromPathTargetInfo: Exception trying to access friendlyName.");
}
// If the checks haven't passed, then we return null
if (!isNvidiaSurround)
{
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: As far as we can tell, this isn't an NVIDIA Surround window, so we're returning null.");
return null; return null;
} }
@ -116,11 +160,12 @@ namespace DisplayMagicianShared.NVIDIA
} }
} }
} }
catch catch (Exception ex)
{ {
// ignored SharedLogger.logger.Warn(ex, $"SurroundTopology/FromPathTargetInfo: Exception trying to get the Grid Topology from the NVIDIA driver.");
} }
// if we get here, then we've failed to get the NVIDIA Grid Topology
SharedLogger.logger.Warn($"SurroundTopology/FromPathTargetInfo: We've tried to get the Grid Topology from the NVIDIA driver but we can't!");
return null; return null;
} }

View File

@ -515,11 +515,17 @@ namespace DisplayMagicianShared
foreach (string profileDisplayIdentifier in ProfileDisplayIdentifiers) foreach (string profileDisplayIdentifier in ProfileDisplayIdentifiers)
{ {
// If this profile has a display that isn't currently available then we need to say it's a no! // If this profile has a display that isn't currently available then we need to say it's a no!
//if (ProfileRepository.ConnectedDisplayIdentifiers.Contains(profileDisplayIdentifier))
//validDisplayCount = (from connectedDisplay in ProfileRepository.ConnectedDisplayIdentifiers select connectedDisplay == profileDisplayIdentifier).Count();
if (ProfileRepository.ConnectedDisplayIdentifiers.Any(s => profileDisplayIdentifier.Equals(s))) if (ProfileRepository.ConnectedDisplayIdentifiers.Any(s => profileDisplayIdentifier.Equals(s)))
{
SharedLogger.logger.Trace($"ProfileItem/RefreshPossbility: We found the display in the profile {Name} with profileDisplayIdentifier {profileDisplayIdentifier} is connected now.");
validDisplayCount++; validDisplayCount++;
} }
else
{
SharedLogger.logger.Warn($"ProfileItem/RefreshPossbility: We found the display in the profile {Name} with profileDisplayIdentifier {profileDisplayIdentifier} is NOT currently connected, so this profile cannot be used.");
}
}
if (validDisplayCount == ProfileDisplayIdentifiers.Count) if (validDisplayCount == ProfileDisplayIdentifiers.Count)
{ {

View File

@ -18,23 +18,48 @@ namespace DisplayMagicianShared.Topology
if (index > 0) if (index > 0)
{ {
DevicePath = DevicePath.Substring(0, index).TrimEnd('#'); DevicePath = DevicePath.Substring(0, index).TrimEnd('#');
SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the DevicePath of {DevicePath}.");
} }
FrequencyInMillihertz = targetInfo.FrequencyInMillihertz; FrequencyInMillihertz = targetInfo.FrequencyInMillihertz;
SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the FrequencyInMillihertz of {FrequencyInMillihertz}.");
Rotation = targetInfo.Rotation.ToRotation(); Rotation = targetInfo.Rotation.ToRotation();
SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the Rotation of {Rotation}.");
Scaling = targetInfo.Scaling.ToScaling(); Scaling = targetInfo.Scaling.ToScaling();
SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the Scaling of {Scaling}.");
ScanLineOrdering = targetInfo.ScanLineOrdering.ToScanLineOrdering(); ScanLineOrdering = targetInfo.ScanLineOrdering.ToScanLineOrdering();
SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the ScanLineOrdering of {ScanLineOrdering}.");
try try
{ {
DisplayName = targetInfo.DisplayTarget.FriendlyName; DisplayName = targetInfo.DisplayTarget.FriendlyName;
SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the DisplayName of {DisplayName}.");
} }
catch catch (Exception ex)
{ {
SharedLogger.logger.Warn(ex, $"PathTarget/PathTarget: Exception grabbing the DisplayName of {DisplayName} from the TargetInfo DisplayTarget.");
DisplayName = null; DisplayName = null;
} }
SurroundTopology = surround ?? SurroundTopology.FromPathTargetInfo(targetInfo); if (surround != null)
{
try
{
SurroundTopology = SurroundTopology.FromPathTargetInfo(targetInfo);
SharedLogger.logger.Trace($"PathTarget/PathTarget: The SurroundTopology object supplied was not null, and we found {SurroundTopology.Displays.Count()} displays involved in it {SurroundTopology.Columns}x{SurroundTopology.Rows}");
}
catch (Exception ex)
{
SharedLogger.logger.Error(ex, $"PathTarget/PathTarget: A SurroundTopology object was supplied, but we had an exception getting the SurroundTopology from the PathTargetInfo object.");
}
}
else
{
SharedLogger.logger.Trace($"PathTarget/PathTarget: This PathTarget doesn't use NVIDIA surround technology, so leaving the SurroundTopology null.");
}
} }