forked from openhardwaremonitor/openhardwaremonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControl.cs
116 lines (98 loc) · 3.17 KB
/
Control.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (C) 2010-2014 Michael Möller <[email protected]>
*/
using System;
using System.Globalization;
namespace OpenHardwareMonitor.Hardware {
internal delegate void ControlEventHandler(Control control);
internal class Control : IControl {
private readonly Identifier identifier;
private readonly ISettings settings;
private ControlMode mode;
private float softwareValue;
private float minSoftwareValue;
private float maxSoftwareValue;
public Control(ISensor sensor, ISettings settings, float minSoftwareValue,
float maxSoftwareValue)
{
this.identifier = new Identifier(sensor.Identifier, "control");
this.settings = settings;
this.minSoftwareValue = minSoftwareValue;
this.maxSoftwareValue = maxSoftwareValue;
if (!float.TryParse(settings.GetValue(
new Identifier(identifier, "value").ToString(), "0"),
NumberStyles.Float, CultureInfo.InvariantCulture,
out this.softwareValue))
{
this.softwareValue = 0;
}
int mode;
if (!int.TryParse(settings.GetValue(
new Identifier(identifier, "mode").ToString(),
((int)ControlMode.Undefined).ToString(CultureInfo.InvariantCulture)),
NumberStyles.Integer, CultureInfo.InvariantCulture,
out mode))
{
this.mode = ControlMode.Undefined;
} else {
this.mode = (ControlMode)mode;
}
}
public Identifier Identifier {
get {
return identifier;
}
}
public ControlMode ControlMode {
get {
return mode;
}
private set {
if (mode != value) {
mode = value;
if (ControlModeChanged != null)
ControlModeChanged(this);
this.settings.SetValue(new Identifier(identifier, "mode").ToString(),
((int)mode).ToString(CultureInfo.InvariantCulture));
}
}
}
public float SoftwareValue {
get {
return softwareValue;
}
private set {
if (softwareValue != value) {
softwareValue = value;
if (SoftwareControlValueChanged != null)
SoftwareControlValueChanged(this);
this.settings.SetValue(new Identifier(identifier,
"value").ToString(),
value.ToString(CultureInfo.InvariantCulture));
}
}
}
public void SetDefault() {
ControlMode = ControlMode.Default;
}
public float MinSoftwareValue {
get {
return minSoftwareValue;
}
}
public float MaxSoftwareValue {
get {
return maxSoftwareValue;
}
}
public void SetSoftware(float value) {
ControlMode = ControlMode.Software;
SoftwareValue = value;
}
internal event ControlEventHandler ControlModeChanged;
internal event ControlEventHandler SoftwareControlValueChanged;
}
}