moel@247
|
1 |
/*
|
moel@247
|
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@247
|
6 |
|
moel@428
|
7 |
Copyright (C) 2010-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
|
moel@344
|
8 |
|
moel@247
|
9 |
*/
|
moel@247
|
10 |
|
moel@247
|
11 |
using System;
|
moel@247
|
12 |
using System.Globalization;
|
moel@247
|
13 |
|
moel@247
|
14 |
namespace OpenHardwareMonitor.Hardware {
|
moel@247
|
15 |
|
moel@247
|
16 |
internal delegate void ControlEventHandler(Control control);
|
moel@247
|
17 |
|
moel@247
|
18 |
internal class Control : IControl {
|
moel@247
|
19 |
|
moel@247
|
20 |
private readonly Identifier identifier;
|
moel@247
|
21 |
private readonly ISettings settings;
|
moel@247
|
22 |
private ControlMode mode;
|
moel@247
|
23 |
private float softwareValue;
|
moel@247
|
24 |
private float minSoftwareValue;
|
moel@247
|
25 |
private float maxSoftwareValue;
|
moel@247
|
26 |
|
moel@247
|
27 |
public Control(ISensor sensor, ISettings settings, float minSoftwareValue,
|
moel@247
|
28 |
float maxSoftwareValue)
|
moel@247
|
29 |
{
|
moel@247
|
30 |
this.identifier = new Identifier(sensor.Identifier, "control");
|
moel@247
|
31 |
this.settings = settings;
|
moel@247
|
32 |
this.minSoftwareValue = minSoftwareValue;
|
moel@247
|
33 |
this.maxSoftwareValue = maxSoftwareValue;
|
moel@247
|
34 |
|
moel@247
|
35 |
if (!float.TryParse(settings.GetValue(
|
moel@247
|
36 |
new Identifier(identifier, "value").ToString(), "0"),
|
moel@247
|
37 |
NumberStyles.Float, CultureInfo.InvariantCulture,
|
moel@247
|
38 |
out this.softwareValue))
|
moel@247
|
39 |
{
|
moel@247
|
40 |
this.softwareValue = 0;
|
moel@247
|
41 |
}
|
moel@247
|
42 |
int mode;
|
moel@247
|
43 |
if (!int.TryParse(settings.GetValue(
|
moel@247
|
44 |
new Identifier(identifier, "mode").ToString(),
|
moel@428
|
45 |
((int)ControlMode.Undefined).ToString(CultureInfo.InvariantCulture)),
|
moel@247
|
46 |
NumberStyles.Integer, CultureInfo.InvariantCulture,
|
moel@247
|
47 |
out mode))
|
moel@247
|
48 |
{
|
moel@428
|
49 |
this.mode = ControlMode.Undefined;
|
moel@247
|
50 |
} else {
|
moel@247
|
51 |
this.mode = (ControlMode)mode;
|
moel@247
|
52 |
}
|
moel@247
|
53 |
}
|
moel@247
|
54 |
|
moel@247
|
55 |
public Identifier Identifier {
|
moel@247
|
56 |
get {
|
moel@247
|
57 |
return identifier;
|
moel@247
|
58 |
}
|
moel@247
|
59 |
}
|
moel@247
|
60 |
|
moel@247
|
61 |
public ControlMode ControlMode {
|
moel@247
|
62 |
get {
|
moel@247
|
63 |
return mode;
|
moel@247
|
64 |
}
|
moel@247
|
65 |
private set {
|
moel@247
|
66 |
if (mode != value) {
|
moel@247
|
67 |
mode = value;
|
moel@247
|
68 |
if (ControlModeChanged != null)
|
moel@247
|
69 |
ControlModeChanged(this);
|
moel@247
|
70 |
this.settings.SetValue(new Identifier(identifier, "mode").ToString(),
|
moel@247
|
71 |
((int)mode).ToString(CultureInfo.InvariantCulture));
|
moel@247
|
72 |
}
|
moel@247
|
73 |
}
|
moel@247
|
74 |
}
|
moel@247
|
75 |
|
moel@247
|
76 |
public float SoftwareValue {
|
moel@247
|
77 |
get {
|
moel@247
|
78 |
return softwareValue;
|
moel@247
|
79 |
}
|
moel@247
|
80 |
private set {
|
moel@247
|
81 |
if (softwareValue != value) {
|
moel@247
|
82 |
softwareValue = value;
|
moel@247
|
83 |
if (SoftwareControlValueChanged != null)
|
moel@247
|
84 |
SoftwareControlValueChanged(this);
|
moel@247
|
85 |
this.settings.SetValue(new Identifier(identifier,
|
moel@247
|
86 |
"value").ToString(),
|
moel@247
|
87 |
value.ToString(CultureInfo.InvariantCulture));
|
moel@247
|
88 |
}
|
moel@247
|
89 |
}
|
moel@247
|
90 |
}
|
moel@247
|
91 |
|
moel@247
|
92 |
public void SetDefault() {
|
moel@247
|
93 |
ControlMode = ControlMode.Default;
|
moel@247
|
94 |
}
|
moel@247
|
95 |
|
moel@247
|
96 |
public float MinSoftwareValue {
|
moel@247
|
97 |
get {
|
moel@247
|
98 |
return minSoftwareValue;
|
moel@247
|
99 |
}
|
moel@247
|
100 |
}
|
moel@247
|
101 |
|
moel@247
|
102 |
public float MaxSoftwareValue {
|
moel@247
|
103 |
get {
|
moel@247
|
104 |
return maxSoftwareValue;
|
moel@247
|
105 |
}
|
moel@247
|
106 |
}
|
moel@247
|
107 |
|
moel@247
|
108 |
public void SetSoftware(float value) {
|
moel@247
|
109 |
ControlMode = ControlMode.Software;
|
moel@247
|
110 |
SoftwareValue = value;
|
moel@247
|
111 |
}
|
moel@247
|
112 |
|
moel@247
|
113 |
internal event ControlEventHandler ControlModeChanged;
|
moel@247
|
114 |
internal event ControlEventHandler SoftwareControlValueChanged;
|
moel@247
|
115 |
}
|
moel@247
|
116 |
}
|