Hardware/Parameter.cs
changeset 63 1a7c13ac7348
child 109 70d0c3102424
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Hardware/Parameter.cs	Sat Feb 27 15:55:17 2010 +0000
     1.3 @@ -0,0 +1,118 @@
     1.4 +/*
     1.5 +  
     1.6 +  Version: MPL 1.1/GPL 2.0/LGPL 2.1
     1.7 +
     1.8 +  The contents of this file are subject to the Mozilla Public License Version
     1.9 +  1.1 (the "License"); you may not use this file except in compliance with
    1.10 +  the License. You may obtain a copy of the License at
    1.11 + 
    1.12 +  http://www.mozilla.org/MPL/
    1.13 +
    1.14 +  Software distributed under the License is distributed on an "AS IS" basis,
    1.15 +  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    1.16 +  for the specific language governing rights and limitations under the License.
    1.17 +
    1.18 +  The Original Code is the Open Hardware Monitor code.
    1.19 +
    1.20 +  The Initial Developer of the Original Code is 
    1.21 +  Michael Möller <m.moeller@gmx.ch>.
    1.22 +  Portions created by the Initial Developer are Copyright (C) 2009-2010
    1.23 +  the Initial Developer. All Rights Reserved.
    1.24 +
    1.25 +  Contributor(s):
    1.26 +
    1.27 +  Alternatively, the contents of this file may be used under the terms of
    1.28 +  either the GNU General Public License Version 2 or later (the "GPL"), or
    1.29 +  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    1.30 +  in which case the provisions of the GPL or the LGPL are applicable instead
    1.31 +  of those above. If you wish to allow use of your version of this file only
    1.32 +  under the terms of either the GPL or the LGPL, and not to allow others to
    1.33 +  use your version of this file under the terms of the MPL, indicate your
    1.34 +  decision by deleting the provisions above and replace them with the notice
    1.35 +  and other provisions required by the GPL or the LGPL. If you do not delete
    1.36 +  the provisions above, a recipient may use your version of this file under
    1.37 +  the terms of any one of the MPL, the GPL or the LGPL.
    1.38 + 
    1.39 +*/
    1.40 +
    1.41 +using System;
    1.42 +using System.Collections.Generic;
    1.43 +
    1.44 +namespace OpenHardwareMonitor.Hardware {
    1.45 +
    1.46 +  public struct ParameterDescription {
    1.47 +    private string name;
    1.48 +    private string description;
    1.49 +    private float defaultValue;    
    1.50 +
    1.51 +    public ParameterDescription(string name, string description, 
    1.52 +      float defaultValue) {
    1.53 +      this.name = name;
    1.54 +      this.description = description;
    1.55 +      this.defaultValue = defaultValue;
    1.56 +    }
    1.57 +
    1.58 +    public string Name { get { return name; } }
    1.59 +
    1.60 +    public string Description { get { return description; } }
    1.61 +
    1.62 +    public float DefaultValue { get { return defaultValue; } }
    1.63 +  }
    1.64 +
    1.65 +  public class Parameter : IParameter {
    1.66 +    private ISensor sensor;
    1.67 +    private ParameterDescription description;
    1.68 +    private float value;
    1.69 +    private bool isDefault;
    1.70 +
    1.71 +    public Parameter(ParameterDescription description, ISensor sensor) {
    1.72 +      this.sensor = sensor;
    1.73 +      this.description = description;
    1.74 +      this.value = Utilities.Config.Get(Identifier, description.DefaultValue);
    1.75 +      this.isDefault = !Utilities.Config.Contains(Identifier);
    1.76 +    }
    1.77 +
    1.78 +    public ISensor Sensor {
    1.79 +      get {
    1.80 +        return sensor;
    1.81 +      }
    1.82 +    }
    1.83 +
    1.84 +    public string Identifier {
    1.85 +      get {
    1.86 +        return sensor.Identifier + "/parameter/" + 
    1.87 +          Name.Replace(" ", "").ToLower();
    1.88 +      }
    1.89 +    }
    1.90 +
    1.91 +    public string Name { get { return description.Name; } }
    1.92 +
    1.93 +    public string Description { get { return description.Description; } }
    1.94 +
    1.95 +    public float Value {
    1.96 +      get {
    1.97 +        return value;
    1.98 +      }
    1.99 +      set {
   1.100 +        this.isDefault = false;
   1.101 +        this.value = value;        
   1.102 +        Utilities.Config.Set(Identifier, value);
   1.103 +      }
   1.104 +    }
   1.105 +
   1.106 +    public float DefaultValue { 
   1.107 +      get { return description.DefaultValue; } 
   1.108 +    }
   1.109 +
   1.110 +    public bool IsDefault {
   1.111 +      get { return isDefault; }
   1.112 +      set {
   1.113 +        this.isDefault = value;
   1.114 +        if (value) {
   1.115 +          this.value = description.DefaultValue;
   1.116 +          Utilities.Config.Remove(Identifier);
   1.117 +        }
   1.118 +      }
   1.119 +    }   
   1.120 +  }
   1.121 +}