Hardware/LPC/F718XX.cs
changeset 130 80065ab20b84
parent 122 3ef997c53b50
child 132 680ed54e05ca
     1.1 --- a/Hardware/LPC/F718XX.cs	Sat May 29 13:49:20 2010 +0000
     1.2 +++ b/Hardware/LPC/F718XX.cs	Thu Jun 03 22:40:18 2010 +0000
     1.3 @@ -37,18 +37,18 @@
     1.4  
     1.5  using System;
     1.6  using System.Collections.Generic;
     1.7 -using System.Drawing;
     1.8  using System.Text;
     1.9 +using OpenHardwareMonitor.Utilities;
    1.10  
    1.11  namespace OpenHardwareMonitor.Hardware.LPC {
    1.12 -  public class F718XX : LPCHardware, IHardware {
    1.13 +  public class F718XX : ISuperIO {
    1.14  
    1.15      private ushort address;
    1.16 +    private Chip chip;
    1.17  
    1.18 -    private Sensor[] temperatures;
    1.19 -    private Sensor[] fans;
    1.20 -    private Sensor[] voltages;
    1.21 -    private float[] voltageGains;
    1.22 +    private float?[] voltages;
    1.23 +    private float?[] temperatures;
    1.24 +    private float?[] fans;
    1.25  
    1.26      // Hardware Monitor
    1.27      private const byte ADDRESS_REGISTER_OFFSET = 0x05;
    1.28 @@ -66,40 +66,21 @@
    1.29        return WinRing0.ReadIoPortByte((ushort)(address + DATA_REGISTER_OFFSET));
    1.30      } 
    1.31  
    1.32 -    public F718XX(Chip chip, ushort address) : base(chip) {
    1.33 +    public F718XX(Chip chip, ushort address) {
    1.34        this.address = address;
    1.35 +      this.chip = chip;
    1.36  
    1.37 -      temperatures = new Sensor[3];
    1.38 -      for (int i = 0; i < temperatures.Length; i++)
    1.39 -        temperatures[i] = new Sensor("Temperature #" + (i + 1), i, null,
    1.40 -          SensorType.Temperature, this, new ParameterDescription[] {
    1.41 -            new ParameterDescription("Offset [°C]", "Temperature offset.", 0)
    1.42 -          });
    1.43 -
    1.44 -      fans = new Sensor[chip == Chip.F71882 ? 4 : 3];
    1.45 -      for (int i = 0; i < fans.Length; i++)
    1.46 -        fans[i] = new Sensor("Fan #" + (i + 1), i, SensorType.Fan, this);
    1.47 -
    1.48 -      switch (chip) {
    1.49 -        case Chip.F71858:
    1.50 -          voltageGains = new float[] { 1, 1, 1 };
    1.51 -          voltages = new Sensor[3];
    1.52 -          voltages[0] = new Sensor("VCC3V", 0, SensorType.Voltage, this);
    1.53 -          voltages[1] = new Sensor("VSB3V", 1, SensorType.Voltage, this);
    1.54 -          voltages[2] = new Sensor("Battery", 2, SensorType.Voltage, this);
    1.55 -          break;
    1.56 -        default:
    1.57 -          voltageGains = new float[] { 1, 0.5f, 1, 1, 1, 1, 1, 1, 1 };
    1.58 -          voltages = new Sensor[4];
    1.59 -          voltages[0] = new Sensor("VCC3V", 0, SensorType.Voltage, this);
    1.60 -          voltages[1] = new Sensor("CPU VCore", 1, SensorType.Voltage, this);
    1.61 -          voltages[2] = new Sensor("VSB3V", 7, SensorType.Voltage, this);
    1.62 -          voltages[3] = new Sensor("Battery", 8, SensorType.Voltage, this);
    1.63 -          break;
    1.64 -      }
    1.65 +      voltages = new float?[chip == Chip.F71858 ? 3 : 9];
    1.66 +      temperatures = new float?[3];
    1.67 +      fans = new float?[chip == Chip.F71882 || chip == Chip.F71858? 4 : 3];
    1.68      }
    1.69  
    1.70 -    public override string GetReport() {
    1.71 +    public Chip Chip { get { return chip; } }
    1.72 +    public float?[] Voltages { get { return voltages; } }
    1.73 +    public float?[] Temperatures { get { return temperatures; } }
    1.74 +    public float?[] Fans { get { return fans; } }
    1.75 +
    1.76 +    public string GetReport() {
    1.77        StringBuilder r = new StringBuilder();
    1.78  
    1.79        r.AppendLine("LPC " + this.GetType().Name);
    1.80 @@ -123,23 +104,21 @@
    1.81        return r.ToString();
    1.82      }
    1.83  
    1.84 -    public override void Update() {
    1.85 +    public void Update() {
    1.86  
    1.87 -      foreach (Sensor sensor in voltages) {
    1.88 -        int value = ReadByte((byte)(VOLTAGE_BASE_REG + sensor.Index));
    1.89 -        sensor.Value = voltageGains[sensor.Index] * 0.001f * (value << 4);
    1.90 -        if (sensor.Value > 0)
    1.91 -          ActivateSensor(sensor);
    1.92 +      for (int i = 0; i < voltages.Length; i++) {
    1.93 +        int value = ReadByte((byte)(VOLTAGE_BASE_REG + i));
    1.94 +        voltages[i] = 0.001f * (value << 4);
    1.95        }
    1.96       
    1.97 -      foreach (Sensor sensor in temperatures) {
    1.98 +      for (int i = 0; i < temperatures.Length; i++) {
    1.99          switch (chip) {
   1.100            case Chip.F71858: {
   1.101                int tableMode = 0x3 & ReadByte((byte)(TEMPERATURE_CONFIG_REG));
   1.102                int high = 
   1.103 -                ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * sensor.Index));
   1.104 +                ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * i));
   1.105                int low =
   1.106 -                ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * sensor.Index + 1));              
   1.107 +                ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * i + 1));              
   1.108                if (high != 0xbb && high != 0xcc) {
   1.109                  int bits = 0;
   1.110                  switch (tableMode) {
   1.111 @@ -151,33 +130,30 @@
   1.112                  bits |= high << 7;
   1.113                  bits |= (low & 0xe0) >> 1;
   1.114                  short value = (short)(bits & 0xfff0);
   1.115 -                sensor.Value = value / 128.0f;
   1.116 -                ActivateSensor(sensor);
   1.117 +                temperatures[i] = value / 128.0f;
   1.118                } else {
   1.119 -                sensor.Value = null;
   1.120 +                temperatures[i] = null;
   1.121                }
   1.122            } break;
   1.123            default: {
   1.124              sbyte value = (sbyte)ReadByte((byte)(
   1.125 -              TEMPERATURE_BASE_REG + 2 * (sensor.Index + 1)));
   1.126 -            sensor.Value = value + sensor.Parameters[0].Value;
   1.127 +              TEMPERATURE_BASE_REG + 2 * (i + 1)));            
   1.128              if (value < sbyte.MaxValue && value > 0)
   1.129 -              ActivateSensor(sensor);
   1.130 +              temperatures[i] = value;
   1.131 +            else
   1.132 +              temperatures[i] = null;
   1.133            } break;
   1.134          }
   1.135        }
   1.136  
   1.137 -      foreach (Sensor sensor in fans) {
   1.138 -        int value = ReadByte(FAN_TACHOMETER_REG[sensor.Index]) << 8;
   1.139 -        value |= ReadByte((byte)(FAN_TACHOMETER_REG[sensor.Index] + 1));
   1.140 +      for (int i = 0; i < fans.Length; i++) {
   1.141 +        int value = ReadByte(FAN_TACHOMETER_REG[i]) << 8;
   1.142 +        value |= ReadByte((byte)(FAN_TACHOMETER_REG[i] + 1));
   1.143  
   1.144 -        if (value > 0) {
   1.145 -          sensor.Value = (value < 0x0fff) ? 1.5e6f / value : 0;
   1.146 -          if (sensor.Value > 0)
   1.147 -            ActivateSensor(sensor);
   1.148 -        } else {
   1.149 -          sensor.Value = null;
   1.150 -        }
   1.151 +        if (value > 0) 
   1.152 +          fans[i] = (value < 0x0fff) ? 1.5e6f / value : 0;
   1.153 +        else 
   1.154 +          fans[i] = null;        
   1.155        }      
   1.156      }
   1.157    }