Hardware/ATI/ATIGPU.cs
changeset 15 0e812fe67bac
parent 3 1a0928afac6b
child 24 09ab31bee6bd
     1.1 --- a/Hardware/ATI/ATIGPU.cs	Sun Jan 31 20:57:18 2010 +0000
     1.2 +++ b/Hardware/ATI/ATIGPU.cs	Sun Jan 31 22:00:31 2010 +0000
     1.3 @@ -54,6 +54,8 @@
     1.4      private Sensor memoryClock;
     1.5      private Sensor coreVoltage;
     1.6  
     1.7 +    private List<ISensor> active = new List<ISensor>();
     1.8 +
     1.9      public ATIGPU(string name, int adapterIndex, int busNumber, 
    1.10        int deviceNumber) 
    1.11      {
    1.12 @@ -92,10 +94,7 @@
    1.13      }
    1.14  
    1.15      public ISensor[] Sensors {
    1.16 -      get {
    1.17 -        return new ISensor[] { coreVoltage, coreClock, memoryClock, temperature, 
    1.18 -          fan };
    1.19 -      }
    1.20 +      get { return active.ToArray(); }
    1.21      }
    1.22  
    1.23      public string GetReport() {
    1.24 @@ -104,24 +103,60 @@
    1.25  
    1.26      public void Update() {
    1.27        ADLTemperature adlt = new ADLTemperature();
    1.28 -      ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt);
    1.29 -      temperature.Value = 0.001f * adlt.Temperature;
    1.30 +      if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
    1.31 +        == ADL.ADL_OK) 
    1.32 +      {
    1.33 +        temperature.Value = 0.001f * adlt.Temperature;
    1.34 +        ActivateSensor(temperature);
    1.35 +      } else {
    1.36 +        DeactivateSensor(temperature);
    1.37 +      }
    1.38  
    1.39        ADLFanSpeedValue adlf = new ADLFanSpeedValue();
    1.40        adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_RPM;
    1.41 -      ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf);
    1.42 -      fan.Value = adlf.FanSpeed;
    1.43 +      if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
    1.44 +        == ADL.ADL_OK) 
    1.45 +      {
    1.46 +        fan.Value = adlf.FanSpeed;
    1.47 +        ActivateSensor(fan);
    1.48 +      } else {
    1.49 +        DeactivateSensor(fan);
    1.50 +      }
    1.51  
    1.52        ADLPMActivity adlp = new ADLPMActivity();
    1.53 -      ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp);
    1.54 -      coreClock.Value = 0.01f * adlp.EngineClock;
    1.55 -      memoryClock.Value = 0.01f * adlp.MemoryClock;
    1.56 -      coreVoltage.Value = 0.001f * adlp.Vddc;
    1.57 +      if (ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp)
    1.58 +        == ADL.ADL_OK) 
    1.59 +      {
    1.60 +        coreClock.Value = 0.01f * adlp.EngineClock;
    1.61 +        memoryClock.Value = 0.01f * adlp.MemoryClock;
    1.62 +        coreVoltage.Value = 0.001f * adlp.Vddc;
    1.63 +        ActivateSensor(coreClock);
    1.64 +        ActivateSensor(memoryClock);
    1.65 +        ActivateSensor(coreVoltage);
    1.66 +      } else {
    1.67 +        DeactivateSensor(coreClock);
    1.68 +        DeactivateSensor(memoryClock);
    1.69 +        DeactivateSensor(coreVoltage);
    1.70 +      }
    1.71      }
    1.72  
    1.73 -    #pragma warning disable 67
    1.74 +    private void ActivateSensor(Sensor sensor) {
    1.75 +      if (!active.Contains(sensor)) {
    1.76 +        active.Add(sensor);
    1.77 +        if (SensorAdded != null) 
    1.78 +          SensorAdded(sensor);
    1.79 +      }
    1.80 +    }
    1.81 +
    1.82 +    private void DeactivateSensor(Sensor sensor) {
    1.83 +      if (active.Contains(sensor)) {
    1.84 +        active.Remove(sensor);
    1.85 +        if (SensorRemoved != null)
    1.86 +          SensorRemoved(sensor);
    1.87 +      }
    1.88 +    }
    1.89 +
    1.90      public event SensorEventHandler SensorAdded;
    1.91      public event SensorEventHandler SensorRemoved;
    1.92 -    #pragma warning restore 67
    1.93    }
    1.94  }