GUI/SensorNode.cs
author moel.mich
Sun, 23 Sep 2012 18:37:43 +0000
changeset 380 573f1fff48b2
parent 340 600962f8a298
permissions -rw-r--r--
Fixed Issue 387. The new implementation does not try to start a ring 0 driver that already exists, but could not be opened. It tries to delete the driver and install it new. The driver is now stored temporarily in the application folder. The driver is not correctly removed on system shutdown.
     1 /*
     2  
     3   This Source Code Form is subject to the terms of the Mozilla Public
     4   License, v. 2.0. If a copy of the MPL was not distributed with this
     5   file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  
     7   Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	
     9 */
    10 
    11 using System;
    12 using System.Collections.Generic;
    13 using OpenHardwareMonitor.Hardware;
    14 using OpenHardwareMonitor.Utilities;
    15 
    16 namespace OpenHardwareMonitor.GUI {
    17   public class SensorNode : Node {
    18     
    19     private ISensor sensor;
    20     private PersistentSettings settings;
    21     private UnitManager unitManager;
    22     private string format;
    23     private bool plot = false;       
    24 
    25     public string ValueToString(float? value) {
    26       if (value.HasValue) {
    27         if (sensor.SensorType == SensorType.Temperature && 
    28           unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) {
    29           return string.Format("{0:F1} °F", value * 1.8 + 32);
    30         } else {
    31           return string.Format(format, value);
    32         }                
    33       } else
    34         return "-";
    35     }
    36 
    37     public SensorNode(ISensor sensor, PersistentSettings settings, 
    38       UnitManager unitManager) : base() {      
    39       this.sensor = sensor;
    40       this.settings = settings;
    41       this.unitManager = unitManager;
    42       switch (sensor.SensorType) {
    43         case SensorType.Voltage: format = "{0:F3} V"; break;
    44         case SensorType.Clock: format = "{0:F0} MHz"; break;
    45         case SensorType.Load: format = "{0:F1} %"; break;
    46         case SensorType.Temperature: format = "{0:F1} °C"; break;
    47         case SensorType.Fan: format = "{0:F0} RPM"; break;
    48         case SensorType.Flow: format = "{0:F0} L/h"; break;
    49         case SensorType.Control: format = "{0:F1} %"; break;
    50         case SensorType.Level: format = "{0:F1} %"; break;
    51         case SensorType.Power: format = "{0:F1} W"; break;
    52         case SensorType.Data: format = "{0:F1} GB"; break;
    53         case SensorType.Factor: format = "{0:F3}"; break;
    54       }
    55 
    56       bool hidden = settings.GetValue(new Identifier(sensor.Identifier, 
    57         "hidden").ToString(), sensor.IsDefaultHidden);
    58       base.IsVisible = !hidden;
    59 
    60       this.Plot = settings.GetValue(new Identifier(sensor.Identifier, 
    61         "plot").ToString(), false);
    62     }
    63 
    64     public override string Text {
    65       get { return sensor.Name; }
    66       set { sensor.Name = value; }
    67     }
    68 
    69     public override bool IsVisible {
    70       get { return base.IsVisible; }
    71       set { 
    72         base.IsVisible = value;
    73         settings.SetValue(new Identifier(sensor.Identifier,
    74           "hidden").ToString(), !value);
    75       }
    76     }
    77 
    78     public bool Plot {
    79       get { return plot; }
    80       set { 
    81         plot = value;
    82         settings.SetValue(new Identifier(sensor.Identifier, "plot").ToString(), 
    83           value);
    84         if (PlotSelectionChanged != null)
    85           PlotSelectionChanged(this, null);
    86       }
    87     }
    88 
    89     public event EventHandler PlotSelectionChanged;
    90 
    91     public ISensor Sensor {
    92       get { return sensor; }
    93     }
    94 
    95     public string Value {
    96       get { return ValueToString(sensor.Value); }
    97     }
    98 
    99     public string Min {
   100       get { return ValueToString(sensor.Min); }
   101     }
   102 
   103     public string Max {
   104       get { return ValueToString(sensor.Max); }
   105     }
   106 
   107     public override bool Equals(System.Object obj) {
   108       if (obj == null) 
   109         return false;
   110 
   111       SensorNode s = obj as SensorNode;
   112       if (s == null) 
   113         return false;
   114 
   115       return (sensor == s.sensor);
   116     }
   117 
   118     public override int GetHashCode() {
   119       return sensor.GetHashCode();
   120     }
   121 
   122   }
   123 }