Hardware/ATI/ADL.cs
changeset 333 c34cbcc7df66
parent 247 6dc755f1970e
child 344 3145aadca3d2
     1.1 --- a/Hardware/ATI/ADL.cs	Sun Jan 15 14:05:52 2012 +0000
     1.2 +++ b/Hardware/ATI/ADL.cs	Sun Jan 15 15:07:23 2012 +0000
     1.3 @@ -16,7 +16,7 @@
     1.4  
     1.5    The Initial Developer of the Original Code is 
     1.6    Michael Möller <m.moeller@gmx.ch>.
     1.7 -  Portions created by the Initial Developer are Copyright (C) 2009-2010
     1.8 +  Portions created by the Initial Developer are Copyright (C) 2009-2012
     1.9    the Initial Developer. All Rights Reserved.
    1.10  
    1.11    Contributor(s):
    1.12 @@ -37,6 +37,7 @@
    1.13  
    1.14  using System;
    1.15  using System.Runtime.InteropServices;
    1.16 +using System.Text.RegularExpressions;
    1.17  
    1.18  namespace OpenHardwareMonitor.Hardware.ATI {
    1.19    
    1.20 @@ -124,8 +125,7 @@
    1.21      public const int ADL_DL_FANCTRL_SUPPORTS_RPM_WRITE = 8;
    1.22      public const int ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED = 1;
    1.23  
    1.24 -    public const int ATI_VENDOR_ID1 = 1002;
    1.25 -    public const int ATI_VENDOR_ID2 = 0x1002;
    1.26 +    public const int ATI_VENDOR_ID = 0x1002;
    1.27  
    1.28      private delegate int ADL_Main_Control_CreateDelegate(
    1.29        ADL_Main_Memory_AllocDelegate callback, int enumConnectedAdapters);
    1.30 @@ -261,6 +261,23 @@
    1.31            Marshal.PtrToStructure((IntPtr)((long)ptr + i * elementSize),
    1.32            typeof(ADLAdapterInfo));
    1.33        Marshal.FreeHGlobal(ptr);
    1.34 +
    1.35 +      // the ADLAdapterInfo.VendorID field reported by ADL is wrong on 
    1.36 +      // Windows systems (parse error), so we fix this here
    1.37 +      for (int i = 0; i < info.Length; i++) {
    1.38 +        // try Windows UDID format
    1.39 +        Match m = Regex.Match(info[i].UDID, "PCI_VEN_([A-Fa-f0-9]{1,4})&.*");
    1.40 +        if (m.Success && m.Groups.Count == 2) {
    1.41 +          info[i].VendorID = Convert.ToInt32(m.Groups[1].Value, 16);
    1.42 +          continue;
    1.43 +        }
    1.44 +        // if above failed, try Unix UDID format
    1.45 +        m = Regex.Match(info[i].UDID, "[0-9]+:[0-9]+:([0-9]+):[0-9]+:[0-9]+");
    1.46 +        if (m.Success && m.Groups.Count == 2) {
    1.47 +          info[i].VendorID = Convert.ToInt32(m.Groups[1].Value, 10);
    1.48 +        }
    1.49 +      }
    1.50 +
    1.51        return result;
    1.52      }
    1.53