GUI/SensorNode.cs
author StephaneLenclud
Thu, 18 Apr 2013 23:25:10 +0200
branchMiniDisplay
changeset 444 9b09e2ee0968
parent 340 600962f8a298
permissions -rw-r--r--
Front View plug-in does not init if no sensor added.
Fixing some format to make strings shorter.
Now trying to start SoundGraphAccess.exe process from same directory.
Packed mode now can display three sensors along with the current time.
moel@1
     1
/*
moel@1
     2
 
moel@344
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@344
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@1
     6
 
moel@344
     7
  Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
	
moel@1
     9
*/
moel@1
    10
moel@1
    11
using System;
moel@1
    12
using System.Collections.Generic;
moel@1
    13
using OpenHardwareMonitor.Hardware;
moel@111
    14
using OpenHardwareMonitor.Utilities;
moel@1
    15
moel@1
    16
namespace OpenHardwareMonitor.GUI {
moel@1
    17
  public class SensorNode : Node {
moel@1
    18
    
moel@1
    19
    private ISensor sensor;
moel@165
    20
    private PersistentSettings settings;
moel@165
    21
    private UnitManager unitManager;
moel@1
    22
    private string format;
moel@165
    23
    private bool plot = false;       
moel@1
    24
moel@1
    25
    public string ValueToString(float? value) {
moel@122
    26
      if (value.HasValue) {
moel@122
    27
        if (sensor.SensorType == SensorType.Temperature && 
moel@165
    28
          unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) {
moel@122
    29
          return string.Format("{0:F1} °F", value * 1.8 + 32);
moel@122
    30
        } else {
moel@122
    31
          return string.Format(format, value);
moel@122
    32
        }                
moel@122
    33
      } else
moel@1
    34
        return "-";
moel@1
    35
    }
moel@1
    36
moel@165
    37
    public SensorNode(ISensor sensor, PersistentSettings settings, 
moel@165
    38
      UnitManager unitManager) : base() {      
moel@1
    39
      this.sensor = sensor;
moel@165
    40
      this.settings = settings;
moel@165
    41
      this.unitManager = unitManager;
moel@1
    42
      switch (sensor.SensorType) {
moel@287
    43
        case SensorType.Voltage: format = "{0:F3} V"; break;
moel@1
    44
        case SensorType.Clock: format = "{0:F0} MHz"; break;
moel@24
    45
        case SensorType.Load: format = "{0:F1} %"; break;
moel@1
    46
        case SensorType.Temperature: format = "{0:F1} °C"; break;
moel@1
    47
        case SensorType.Fan: format = "{0:F0} RPM"; break;
moel@57
    48
        case SensorType.Flow: format = "{0:F0} L/h"; break;
moel@118
    49
        case SensorType.Control: format = "{0:F1} %"; break;
moel@217
    50
        case SensorType.Level: format = "{0:F1} %"; break;
moel@317
    51
        case SensorType.Power: format = "{0:F1} W"; break;
moel@324
    52
        case SensorType.Data: format = "{0:F1} GB"; break;
moel@340
    53
        case SensorType.Factor: format = "{0:F3}"; break;
moel@111
    54
      }
moel@111
    55
moel@166
    56
      bool hidden = settings.GetValue(new Identifier(sensor.Identifier, 
moel@111
    57
        "hidden").ToString(), sensor.IsDefaultHidden);
moel@126
    58
      base.IsVisible = !hidden;
moel@327
    59
moel@327
    60
      this.Plot = settings.GetValue(new Identifier(sensor.Identifier, 
moel@327
    61
        "plot").ToString(), false);
moel@1
    62
    }
moel@1
    63
moel@1
    64
    public override string Text {
moel@1
    65
      get { return sensor.Name; }
moel@1
    66
      set { sensor.Name = value; }
moel@111
    67
    }
moel@111
    68
moel@111
    69
    public override bool IsVisible {
moel@111
    70
      get { return base.IsVisible; }
moel@111
    71
      set { 
moel@111
    72
        base.IsVisible = value;
moel@166
    73
        settings.SetValue(new Identifier(sensor.Identifier,
moel@111
    74
          "hidden").ToString(), !value);
moel@111
    75
      }
moel@111
    76
    }
moel@1
    77
moel@1
    78
    public bool Plot {
moel@1
    79
      get { return plot; }
moel@327
    80
      set { 
moel@327
    81
        plot = value;
moel@327
    82
        settings.SetValue(new Identifier(sensor.Identifier, "plot").ToString(), 
moel@327
    83
          value);
moel@327
    84
        if (PlotSelectionChanged != null)
moel@327
    85
          PlotSelectionChanged(this, null);
moel@327
    86
      }
moel@1
    87
    }
moel@1
    88
moel@327
    89
    public event EventHandler PlotSelectionChanged;
moel@327
    90
moel@1
    91
    public ISensor Sensor {
moel@1
    92
      get { return sensor; }
moel@1
    93
    }
moel@1
    94
moel@1
    95
    public string Value {
moel@1
    96
      get { return ValueToString(sensor.Value); }
moel@1
    97
    }
moel@1
    98
moel@1
    99
    public string Min {
moel@1
   100
      get { return ValueToString(sensor.Min); }
moel@1
   101
    }
moel@1
   102
moel@1
   103
    public string Max {
moel@1
   104
      get { return ValueToString(sensor.Max); }
moel@1
   105
    }
moel@1
   106
moel@1
   107
    public override bool Equals(System.Object obj) {
moel@1
   108
      if (obj == null) 
moel@1
   109
        return false;
moel@1
   110
moel@1
   111
      SensorNode s = obj as SensorNode;
moel@1
   112
      if (s == null) 
moel@1
   113
        return false;
moel@1
   114
moel@1
   115
      return (sensor == s.sensor);
moel@1
   116
    }
moel@1
   117
moel@1
   118
    public override int GetHashCode() {
moel@1
   119
      return sensor.GetHashCode();
moel@1
   120
    }
moel@1
   121
moel@1
   122
  }
moel@1
   123
}